diff options
Diffstat (limited to 'support/testing')
| -rw-r--r-- | support/testing/infra/__init__.py | 31 | ||||
| -rw-r--r-- | support/testing/infra/basetest.py | 7 | ||||
| -rw-r--r-- | support/testing/infra/builder.py | 12 | ||||
| -rw-r--r-- | support/testing/infra/emulator.py | 15 | ||||
| -rwxr-xr-x | support/testing/run-tests | 12 | ||||
| -rw-r--r-- | support/testing/tests/fs/test_ext.py | 9 | ||||
| -rw-r--r-- | support/testing/tests/toolchain/test_external.py | 6 |
7 files changed, 41 insertions, 51 deletions
diff --git a/support/testing/infra/__init__.py b/support/testing/infra/__init__.py index c3f645cf99..a55ad7fdf5 100644 --- a/support/testing/infra/__init__.py +++ b/support/testing/infra/__init__.py @@ -8,24 +8,17 @@ from urllib2 import urlopen, HTTPError, URLError ARTIFACTS_URL = "http://autobuild.buildroot.net/artefacts/" -@contextlib.contextmanager -def smart_open(filename=None): +def open_log_file(builddir, stage, logtofile=True): """ - Return a file-like object that can be written to using the 'with' - keyword, as in the example: - with infra.smart_open("test.log") as outfile: - outfile.write("Hello, world!\n") + Open a file for logging and return its handler. + If logtofile is True, returns sys.stdout. Otherwise opens a file + with a suitable name in the build directory. """ - if filename and filename != '-': - fhandle = open(filename, 'a+') + if logtofile: + fhandle = open("{}-{}.log".format(builddir, stage), 'a+') else: fhandle = sys.stdout - - try: - yield fhandle - finally: - if fhandle is not sys.stdout: - fhandle.close() + return fhandle def filepath(relpath): return os.path.join(os.getcwd(), "support/testing", relpath) @@ -77,6 +70,16 @@ def get_file_arch(builddir, prefix, fpath): return get_elf_arch_tag(builddir, prefix, fpath, "Tag_CPU_arch") def get_elf_prog_interpreter(builddir, prefix, fpath): + """ + Runs the cross readelf on 'fpath' to extract the program interpreter + name and returns it. + Example: + >>> get_elf_prog_interpreter('br-tests/TestExternalToolchainLinaroArm', + 'arm-linux-gnueabihf', + 'bin/busybox') + /lib/ld-linux-armhf.so.3 + >>> + """ cmd = ["host/usr/bin/{}-readelf".format(prefix), "-l", os.path.join("target", fpath)] out = subprocess.check_output(cmd, cwd=builddir, env={"LANG": "C"}) diff --git a/support/testing/infra/basetest.py b/support/testing/infra/basetest.py index eb9da90119..557baa215c 100644 --- a/support/testing/infra/basetest.py +++ b/support/testing/infra/basetest.py @@ -36,14 +36,11 @@ class BRTest(unittest.TestCase): keepbuilds = False def show_msg(self, msg): - print "[%s/%s/%s] %s" % (os.path.basename(self.__class__.outputdir), - self.testname, - datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S"), - msg) + print "{} {:40s} {}".format(datetime.datetime.now().strftime("%H:%M:%S"), + self.testname, msg) def setUp(self): self.testname = self.__class__.__name__ self.builddir = os.path.join(self.__class__.outputdir, self.testname) - self.runlog = self.builddir + "-run.log" self.emulator = None self.show_msg("Starting") self.b = Builder(self.__class__.config, self.builddir, self.logtofile) diff --git a/support/testing/infra/builder.py b/support/testing/infra/builder.py index 105da01ca2..a475bb0a30 100644 --- a/support/testing/infra/builder.py +++ b/support/testing/infra/builder.py @@ -8,16 +8,12 @@ class Builder(object): def __init__(self, config, builddir, logtofile): self.config = config self.builddir = builddir - self.logtofile = logtofile + self.logfile = infra.open_log_file(builddir, "build", logtofile) def build(self): if not os.path.isdir(self.builddir): os.makedirs(self.builddir) - log = "{}-build.log".format(self.builddir) - if not self.logtofile: - log = None - config_file = os.path.join(self.builddir, ".config") with open(config_file, "w+") as cf: cf.write(self.config) @@ -25,14 +21,12 @@ class Builder(object): cmd = ["make", "O={}".format(self.builddir), "olddefconfig"] - with infra.smart_open(log) as log_fh: - ret = subprocess.call(cmd, stdout=log_fh, stderr=log_fh) + ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile) if ret != 0: raise SystemError("Cannot olddefconfig") cmd = ["make", "-C", self.builddir] - with infra.smart_open(log) as log_fh: - ret = subprocess.call(cmd, stdout=log_fh, stderr=log_fh) + ret = subprocess.call(cmd, stdout=self.logfile, stderr=self.logfile) if ret != 0: raise SystemError("Build failed") diff --git a/support/testing/infra/emulator.py b/support/testing/infra/emulator.py index 7c476cb0e4..2480b46540 100644 --- a/support/testing/infra/emulator.py +++ b/support/testing/infra/emulator.py @@ -14,9 +14,7 @@ class Emulator(object): self.__tn = None self.downloaddir = downloaddir self.log = "" - self.log_file = "{}-run.log".format(builddir) - if logtofile is None: - self.log_file = None + self.logfile = infra.open_log_file(builddir, "run", logtofile) # Start Qemu to boot the system # @@ -72,9 +70,8 @@ class Emulator(object): if kernel_cmdline: qemu_cmd += ["-append", " ".join(kernel_cmdline)] - with infra.smart_open(self.log_file) as lfh: - lfh.write("> starting qemu with '%s'\n" % " ".join(qemu_cmd)) - self.qemu = subprocess.Popen(qemu_cmd, stdout=lfh, stderr=lfh) + self.logfile.write("> starting qemu with '%s'\n" % " ".join(qemu_cmd)) + self.qemu = subprocess.Popen(qemu_cmd, stdout=self.logfile, stderr=self.logfile) # Wait for the telnet port to appear and connect to it. while True: @@ -88,8 +85,7 @@ class Emulator(object): def __read_until(self, waitstr, timeout=5): data = self.__tn.read_until(waitstr, timeout) self.log += data - with infra.smart_open(self.log_file) as lfh: - lfh.write(data) + self.logfile.write(data) return data def __write(self, wstr): @@ -100,8 +96,7 @@ class Emulator(object): def login(self, password=None): self.__read_until("buildroot login:", 10) if "buildroot login:" not in self.log: - with infra.smart_open(self.log_file) as lfh: - lfh.write("==> System does not boot") + self.logfile.write("==> System does not boot") raise SystemError("System does not boot") self.__write("root\n") diff --git a/support/testing/run-tests b/support/testing/run-tests index 339bb66efa..07dad0d8b9 100755 --- a/support/testing/run-tests +++ b/support/testing/run-tests @@ -10,17 +10,17 @@ def main(): parser = argparse.ArgumentParser(description='Run Buildroot tests') parser.add_argument('testname', nargs='*', help='list of test cases to execute') - parser.add_argument('--list', '-l', action='store_true', + parser.add_argument('-l', '--list', action='store_true', help='list of available test cases') - parser.add_argument('--all', '-a', action='store_true', + parser.add_argument('-a', '--all', action='store_true', help='execute all test cases') - parser.add_argument('--stdout', '-s', action='store_true', + parser.add_argument('-s', '--stdout', action='store_true', help='log everything to stdout') - parser.add_argument('--output', '-o', + parser.add_argument('-o', '--output', help='output directory') - parser.add_argument('--download', '-d', + parser.add_argument('-d', '--download', help='download directory') - parser.add_argument('--keep', '-k', + parser.add_argument('-k', '--keep', help='keep build directories', action='store_true') diff --git a/support/testing/tests/fs/test_ext.py b/support/testing/tests/fs/test_ext.py index f7e2e85055..ea3d3f11d7 100644 --- a/support/testing/tests/fs/test_ext.py +++ b/support/testing/tests/fs/test_ext.py @@ -21,10 +21,10 @@ def dumpe2fs_run(builddir, image): return ret.strip().splitlines() def dumpe2fs_getprop(out, prop): - for lines in out: - lines = lines.split(": ") - if lines[0] == prop: - return lines[1].strip() + for line in out: + fields = line.split(": ") + if fields[0] == prop: + return fields[1].strip() def boot_img_and_check_fs_type(emulator, builddir, fs_type): img = os.path.join(builddir, "images", "rootfs.{}".format(fs_type)) @@ -86,6 +86,7 @@ BR2_TARGET_ROOTFS_EXT2_3=y out = dumpe2fs_run(self.builddir, "rootfs.ext3") self.assertEqual(dumpe2fs_getprop(out, REVISION_PROP), "1 (dynamic)") self.assertIn("has_journal", dumpe2fs_getprop(out, FEATURES_PROP)) + self.assertNotIn("extent", dumpe2fs_getprop(out, FEATURES_PROP)) exit_code = boot_img_and_check_fs_type(self.emulator, self.builddir, "ext3") diff --git a/support/testing/tests/toolchain/test_external.py b/support/testing/tests/toolchain/test_external.py index 1fbf81f8d3..0b15d489db 100644 --- a/support/testing/tests/toolchain/test_external.py +++ b/support/testing/tests/toolchain/test_external.py @@ -7,7 +7,7 @@ BR2_TARGET_ROOTFS_CPIO=y # BR2_TARGET_ROOTFS_TAR is not set """ -def check_broken_links(path): +def has_broken_links(path): for root, dirs, files in os.walk(path): for f in files: fpath = os.path.join(root, f) @@ -20,9 +20,9 @@ class TestExternalToolchain(infra.basetest.BRTest): # Check for broken symlinks for d in ["lib", "usr/lib"]: path = os.path.join(self.builddir, "staging", d) - self.assertFalse(check_broken_links(path)) + self.assertFalse(has_broken_links(path)) path = os.path.join(self.builddir, "target", d) - self.assertFalse(check_broken_links(path)) + self.assertFalse(has_broken_links(path)) interp = infra.get_elf_prog_interpreter(self.builddir, self.toolchain_prefix, |

