Currently many test cases call subprocess.check_output on their own.
Factor out that code to an infra method so the call get standardized.
This will be handful when switching the test infra to use Python 3.
Signed-off-by: Ricardo Martincoski <ricardo.martincoski@gmail.com>
Signed-off-by: Thomas Petazzoni <thomas.petazzoni@bootlin.com>
return finalpath
+def run_cmd_on_host(builddir, cmd):
+ """Call subprocess.check_output and return the text output."""
+ out = subprocess.check_output(cmd,
+ stderr=open(os.devnull, "w"),
+ cwd=builddir,
+ env={"LANG": "C"})
+ return out
+
+
def get_elf_arch_tag(builddir, prefix, fpath, tag):
"""
Runs the cross readelf on 'fpath', then extracts the value of tag 'tag'.
"""
cmd = ["host/bin/{}-readelf".format(prefix),
"-A", os.path.join("target", fpath)]
- out = subprocess.check_output(cmd, cwd=builddir, env={"LANG": "C"})
+ out = run_cmd_on_host(builddir, cmd)
regexp = re.compile("^ {}: (.*)$".format(tag))
for line in out.splitlines():
m = regexp.match(line)
"""
cmd = ["host/bin/{}-readelf".format(prefix),
"-l", os.path.join("target", fpath)]
- out = subprocess.check_output(cmd, cwd=builddir, env={"LANG": "C"})
+ out = run_cmd_on_host(builddir, cmd)
regexp = re.compile("^ *\[Requesting program interpreter: (.*)\]$")
for line in out.splitlines():
m = regexp.match(line)
import os
-import subprocess
import json
import infra.basetest
"--file={}".format(filepath)]
# Checksec is being used for elf file analysis only. There are no
# assumptions of target/run-time checks as part of this testing.
- ret = subprocess.check_output(cmd,
- stderr=open(os.devnull, "w"),
- cwd=self.builddir,
- env={"LANG": "C"})
+ ret = infra.run_cmd_on_host(self.builddir, cmd)
return json.loads(ret)
import os
-import subprocess
import infra.basetest
def dumpe2fs_run(builddir, image):
cmd = ["host/sbin/dumpe2fs", os.path.join("images", image)]
- ret = subprocess.check_output(cmd,
- stderr=open(os.devnull, "w"),
- cwd=builddir,
- env={"LANG": "C"})
+ ret = infra.run_cmd_on_host(builddir, cmd)
return ret.strip().splitlines()
import os
-import subprocess
import infra.basetest
def test_run(self):
img = os.path.join(self.builddir, "images", "rootfs.f2fs")
- out = subprocess.check_output(["host/sbin/dump.f2fs", img],
- cwd=self.builddir,
- env={"LANG": "C"})
+ out = infra.run_cmd_on_host(self.builddir, ["host/sbin/dump.f2fs", img])
out = out.splitlines()
prop = dumpf2fs_getprop(out, "Info: total sectors")
self.assertEqual(prop, "262144 (128 MB)")
import os
-import subprocess
import infra.basetest
def test_run(self):
img = os.path.join(self.builddir, "images", "rootfs.jffs2")
- out = subprocess.check_output(["host/sbin/jffs2dump", "-c", img],
- cwd=self.builddir,
- env={"LANG": "C"})
+ cmd = ["host/sbin/jffs2dump", "-c", img]
+ out = infra.run_cmd_on_host(self.builddir, cmd)
out = out.splitlines()
self.assertTrue(jffs2dump_find_file(out, "busybox"))
def test_run(self):
unsquashfs_cmd = ["host/bin/unsquashfs", "-s", "images/rootfs.squashfs"]
- out = subprocess.check_output(unsquashfs_cmd,
- cwd=self.builddir,
- env={"LANG": "C"})
+ out = infra.run_cmd_on_host(self.builddir, unsquashfs_cmd)
out = out.splitlines()
self.assertEqual(out[0],
"Found a valid SQUASHFS 4:0 superblock on images/rootfs.squashfs.")
# To be investigated.
def test_run(self):
img = os.path.join(self.builddir, "images", "rootfs.ubi")
- out = subprocess.check_output(["file", img],
- cwd=self.builddir,
- env={"LANG": "C"})
+ out = infra.run_cmd_on_host(self.builddir, ["file", img])
out = out.splitlines()
self.assertIn("UBI image, version 1", out[0])