oeqa/core/runner: Improve test case comparision
PATCH 1/12 oeqa/core/runner: Improve test case comparision
We can directly compare the test case IDs rather than representations, then if we're using subunit to split the tests, the comparisions still work as intended.
--- meta/lib/oeqa/core/runner.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
meta/lib/oeqa/core/runner.py +2 -2
@@ -88,10 +88,10 @@ class OETestResult(_TestResult): break scase_str = scase.test_id else: - if case == scase: + if case.id() == scase.id(): found = True break - scase_str = str(scase) + scase_str = str(scase.id()) # When fails at module or class level the class name is passed as string # so figure out to see if match
Signature · 1 line
2.17.1
PATCH 2/12 oeqa/selftest/image_tyypedep: Avoid undefined variable failure
If something goes wrong with the test, dep can be undefined. Avoid a traceback for this and handle it more gracefully.
--- meta/lib/oeqa/selftest/cases/image_typedep.py | 3 +++ 1 file changed, 3 insertions(+)
meta/lib/oeqa/selftest/cases/image_typedep.py +3 -0
@@ -29,11 +29,14 @@ inherit image # like CONVERSION_DEPENDS_bz2="somedep" result = bitbake('-e emptytest') + dep = None for line in result.output.split('\n'): if line.startswith('CONVERSION_DEPENDS_bz2'): dep = line.split('=')[1].strip('"') break + self.assertIsNotNone(dep, "CONVERSION_DEPENDS_bz2 dependency not found in bitbake -e output") + # Now get the dependency task list and check for the expected task # dependency bitbake('-g emptytest')
Signature · 1 line
2.17.1
PATCH 3/12 oqqa/selftest/lic_checksum: Avoid cache reparse
In reply to Richard PurdieBy having a consistent config for the test, a second reparse is avoided and the test runs slightly faster.
--- meta/lib/oeqa/selftest/cases/lic_checksum.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
meta/lib/oeqa/selftest/cases/lic_checksum.py +2 -1
@@ -19,6 +19,8 @@ class LicenseTests(OESelftestTestCase): os.close(lic_file) self.track_for_cleanup(lic_path) + self.write_config("INHERIT_remove = \"report-error\"") + self.write_recipeinc('emptytest', """ INHIBIT_DEFAULT_DEPS = "1" LIC_FILES_CHKSUM = "file://%s;md5=d41d8cd98f00b204e9800998ecf8427e"
@@ -29,7 +31,6 @@ SRC_URI = "file://%s;md5=d41d8cd98f00b204e9800998ecf8427e" with open(lic_path, "w") as f: f.write("data") - self.write_config("INHERIT_remove = \"report-error\"") result = bitbake(bitbake_cmd, ignore_status=True) if error_msg not in result.output: raise AssertionError(result.output)
Signature · 1 line
2.17.1
PATCH 4/12 oeqa/runner: Ensure we don't print misleading results output
In reply to Richard PurdieThe current code assumes if something isn't a failure of some kind, it was a pass. When test case IDs weren't matching, this lead to very confusing output where things would fail, then be listed as passing.
This adds code to track successes, ensuring we don't end up in this position again with unmatched entries being listed as UNKNOWN.
--- meta/lib/oeqa/core/runner.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-)
meta/lib/oeqa/core/runner.py +11 -3
@@ -42,6 +42,8 @@ class OETestResult(_TestResult): def __init__(self, tc, *args, **kwargs): super(OETestResult, self).__init__(*args, **kwargs) + self.successes = [] + self.tc = tc self._tc_map_results()
@@ -58,6 +60,7 @@ class OETestResult(_TestResult): self.tc._results['errors'] = self.errors self.tc._results['skipped'] = self.skipped self.tc._results['expectedFailures'] = self.expectedFailures + self.tc._results['successes'] = self.successes def logSummary(self, component, context_msg=''): elapsed_time = self.tc._run_end_time - self.tc._run_start_time
@@ -115,13 +118,18 @@ class OETestResult(_TestResult): return (found, None) + def addSuccess(self, test): + #Added so we can keep track of successes too + self.successes.append((test, None)) + super(OETestResult, self).addSuccess(test) + def logDetails(self): self.tc.logger.info("RESULTS:") for case_name in self.tc._registry['cases']: case = self.tc._registry['cases'][case_name] - result_types = ['failures', 'errors', 'skipped', 'expectedFailures'] - result_desc = ['FAILED', 'ERROR', 'SKIPPED', 'EXPECTEDFAIL'] + result_types = ['failures', 'errors', 'skipped', 'expectedFailures', 'successes'] + result_desc = ['FAILED', 'ERROR', 'SKIPPED', 'EXPECTEDFAIL', 'PASSED'] fail = False desc = None
@@ -143,7 +151,7 @@ class OETestResult(_TestResult): oeid, desc)) else: self.tc.logger.info("RESULTS - %s - Testcase %s: %s" % (case.id(), - oeid, 'PASSED')) + oeid, 'UNKNOWN')) class OEListTestsResult(object): def wasSuccessful(self):
Signature · 1 line
2.17.1
PATCH 5/12 oeqa/selftest/package: Use setUpLocal, not setUp
In reply to Richard PurdieThe main setUp function needs to be called and tests are meant to define setUpLocal. For some reason this one didn't leading to errors with recent code changes. Fix it.
--- meta/lib/oeqa/selftest/cases/package.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/lib/oeqa/selftest/cases/package.py +1 -1
@@ -29,7 +29,7 @@ class VersionOrdering(OESelftestTestCase): cls.bindir = oe.path.join(cls.staging, vars["bindir_native"]) cls.libdir = oe.path.join(cls.staging, vars["libdir_native"]) - def setUp(self): + def setUpLocal(self): # Just for convenience self.staging = type(self).staging self.bindir = type(self).bindir
Signature · 1 line
2.17.1
PATCH 6/12 oeqa/selftest/devtool: Ensure dbus is built befoe running test
In reply to Richard PurdieIf dbus isn't build first the dbus dependency of dbus-wait can't be detected through pkgconfig and the test fails:
AssertionError: {'DEPENDS': {'dbus'}} != {}
- {'DEPENDS': {'dbus'}}
+ {} : Some expected variables not found in recipe: {'DEPENDS': {'dbus'}}
Ensure dbus is built and present in the sysroot.
--- meta/lib/oeqa/selftest/cases/devtool.py | 2 ++ 1 file changed, 2 insertions(+)
meta/lib/oeqa/selftest/cases/devtool.py +2 -0
@@ -235,6 +235,8 @@ class DevtoolTests(DevtoolBase): @OETestID(1423) def test_devtool_add_git_local(self): + # We need dbus built so that DEPENDS recognition works + bitbake('dbus') # Fetch source from a remote URL, but do it outside of devtool tempdir = tempfile.mkdtemp(prefix='devtoolqa') self.track_for_cleanup(tempdir)
Signature · 1 line
2.17.1
PATCH 7/12 oeqa/selftest/wic: Use a subdir of builddir, not /var/
In reply to Richard PurdieUsing /var/ leave wic open to races with other processes on the system, use a subdir of builddir instead to avoid this.
--- meta/lib/oeqa/selftest/cases/wic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/lib/oeqa/selftest/cases/wic.py +1 -1
@@ -64,13 +64,13 @@ def only_for_arch(archs, image='core-image-minimal'): class Wic(OESelftestTestCase): """Wic test class.""" - resultdir = "/var/tmp/wic.oe-selftest/" image_is_ready = False native_sysroot = None wicenv_cache = {} def setUpLocal(self): """This code is executed before each test method.""" + self.resultdir = self.builddir + "/wic-tmp/" super(Wic, self).setUpLocal() if not self.native_sysroot: Wic.native_sysroot = get_bb_var('STAGING_DIR_NATIVE', 'wic-tools')
Signature · 1 line
2.17.1
PATCH 8/12 oeqa/selftest/wic: Ensure initramfs exists for test_iso_image
In reply to Richard PurdieAssertionError: Command 'wic create mkhybridiso --image-name core-image-minimal -o /var/tmp/wic.oe-selftest/' returned non-zero exit status 1:
ERROR: _exec_cmd: gzip -f -9 -c /var/tmp/wic.oe-selftest/tmp.wic.drhn6edm/initrd.cpio > /var/tmp/wic.oe-selftest/tmp.wic.drhn6edm/initrd.cpio.gz returned '1' instead of 0
output: gzip: /var/tmp/wic.oe-selftest/tmp.wic.drhn6edm/initrd.cpio: No such file or directory
This is because in a clean build directory, the initramfs may not be rebuilt. Add a call to ensure it is built to avoid the error.
--- meta/lib/oeqa/selftest/cases/wic.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/lib/oeqa/selftest/cases/wic.py +1 -1
@@ -191,7 +191,7 @@ class Wic(OESelftestTestCase): 'MACHINE_FEATURES_append = " efi"\n'\ 'DEPENDS_pn-core-image-minimal += "syslinux"\n' self.append_config(config) - bitbake('core-image-minimal') + bitbake('core-image-minimal core-image-minimal-initramfs') self.remove_config(config) cmd = "wic create mkhybridiso --image-name core-image-minimal -o %s" % self.resultdir self.assertEqual(0, runCmd(cmd).status)
Signature · 1 line
2.17.1
PATCH 9/12 oeqa: Default to buffer mode for tests
In reply to Richard PurdieCurrently some tests run in buffer mode and some don't. Those that don't can corrupt stdout/stderr. Switch to using buffer mode everywhere so we're consistent.
If there is useful output on stdout/stderr, it will be displayed if the test fails.
--- meta/lib/oeqa/core/context.py | 2 +- meta/lib/oeqa/core/runner.py | 5 ----- meta/lib/oeqa/selftest/cases/devtool.py | 2 -- meta/lib/oeqa/selftest/cases/efibootpartition.py | 1 - meta/lib/oeqa/selftest/cases/imagefeatures.py | 2 -- meta/lib/oeqa/selftest/cases/runqemu.py | 2 -- 6 files changed, 1 insertion(+), 13 deletions(-)
meta/lib/oeqa/core/context.py +1 -1
@@ -59,7 +59,7 @@ class OETestContext(object): self.suites = self.loader.discover() def runTests(self, skips=[]): - self.runner = self.runnerClass(self, descriptions=False, verbosity=2) + self.runner = self.runnerClass(self, descriptions=False, verbosity=2, buffer=True) # Dinamically skip those tests specified though arguments self.skipTests(skips)
meta/lib/oeqa/core/runner.py +0 -5
@@ -48,11 +48,6 @@ class OETestResult(_TestResult): self._tc_map_results() def startTest(self, test): - # Allow us to trigger the testcase buffer mode on a per test basis - # so stdout/stderr are only printed upon failure. Enables debugging - # but clean output - if hasattr(test, "buffer"): - self.buffer = test.buffer super(OETestResult, self).startTest(test) def _tc_map_results(self):
meta/lib/oeqa/selftest/cases/devtool.py +0 -2
@@ -13,8 +13,6 @@ from oeqa.core.decorator.oeid import OETestID class DevtoolBase(OESelftestTestCase): - buffer = True - def _test_recipe_contents(self, recipefile, checkvars, checkinherits): with open(recipefile, 'r') as f: invar = None
meta/lib/oeqa/selftest/cases/efibootpartition.py +0 -1
@@ -11,7 +11,6 @@ from oeqa.utils.commands import bitbake, runqemu, get_bb_var class GenericEFITest(OESelftestTestCase): """EFI booting test class""" - buffer = True cmd_common = "runqemu nographic serial wic ovmf" efi_provider = "systemd-boot" image = "core-image-minimal"
meta/lib/oeqa/selftest/cases/imagefeatures.py +0 -2
@@ -10,8 +10,6 @@ class ImageFeatures(OESelftestTestCase): test_user = 'tester' root_user = 'root' - buffer = True - @OETestID(1107) def test_non_root_user_can_connect_via_ssh_without_password(self): """
meta/lib/oeqa/selftest/cases/runqemu.py +0 -2
@@ -14,8 +14,6 @@ class RunqemuTests(OESelftestTestCase): image_is_ready = False deploy_dir_image = '' - # We only want to print runqemu stdout/stderr if there is a test case failure - buffer = True def setUpLocal(self): super(RunqemuTests, self).setUpLocal()
Signature · 1 line
2.17.1
PATCH 10/12 devtool: Split tests into multiple classes
In reply to Richard PurdieThis allows better parallelism between the different tests as currently this block takes the longest time to execute. devtool tests are still all grouped into the "devtool" module for ease of exection.
This also makes it easier to execute some subset of devtool tests for testing devtool changes.
--- meta/lib/oeqa/selftest/cases/devtool.py | 113 +++++++++++++----------- 1 file changed, 61 insertions(+), 52 deletions(-)
meta/lib/oeqa/selftest/cases/devtool.py +61 -52
@@ -13,6 +13,58 @@ from oeqa.core.decorator.oeid import OETestID class DevtoolBase(OESelftestTestCase): + @classmethod + def setUpClass(cls): + super(DevtoolBase, cls).setUpClass() + bb_vars = get_bb_vars(['TOPDIR', 'SSTATE_DIR']) + cls.original_sstate = bb_vars['SSTATE_DIR'] + cls.devtool_sstate = os.path.join(bb_vars['TOPDIR'], 'sstate_devtool') + cls.sstate_conf = 'SSTATE_DIR = "%s"\n' % cls.devtool_sstate + cls.sstate_conf += ('SSTATE_MIRRORS += "file://.* file:///%s/PATH"\n' + % cls.original_sstate) + + @classmethod + def tearDownClass(cls): + cls.logger.debug('Deleting devtool sstate cache on %s' % cls.devtool_sstate) + runCmd('rm -rf %s' % cls.devtool_sstate) + super(DevtoolBase, cls).tearDownClass() + + def setUp(self): + """Test case setup function""" + super(DevtoolBase, self).setUp() + self.workspacedir = os.path.join(self.builddir, 'workspace') + self.assertTrue(not os.path.exists(self.workspacedir), + 'This test cannot be run with a workspace directory ' + 'under the build directory') + self.append_config(self.sstate_conf) + + def _check_src_repo(self, repo_dir): + """Check srctree git repository""" + self.assertTrue(os.path.isdir(os.path.join(repo_dir, '.git')), + 'git repository for external source tree not found') + result = runCmd('git status --porcelain', cwd=repo_dir) + self.assertEqual(result.output.strip(), "", + 'Created git repo is not clean') + result = runCmd('git symbolic-ref HEAD', cwd=repo_dir) + self.assertEqual(result.output.strip(), "refs/heads/devtool", + 'Wrong branch in git repo') + + def _check_repo_status(self, repo_dir, expected_status): + """Check the worktree status of a repository""" + result = runCmd('git status . --porcelain', + cwd=repo_dir) + for line in result.output.splitlines(): + for ind, (f_status, fn_re) in enumerate(expected_status): + if re.match(fn_re, line[3:]): + if f_status != line[:2]: + self.fail('Unexpected status in line: %s' % line) + expected_status.pop(ind) + break + else: + self.fail('Unexpected modified file in line: %s' % line) + if expected_status: + self.fail('Missing file changes: %s' % expected_status) + def _test_recipe_contents(self, recipefile, checkvars, checkinherits): with open(recipefile, 'r') as f: invar = None
@@ -116,58 +168,6 @@ class DevtoolBase(OESelftestTestCase): class DevtoolTests(DevtoolBase): - @classmethod - def setUpClass(cls): - super(DevtoolTests, cls).setUpClass() - bb_vars = get_bb_vars(['TOPDIR', 'SSTATE_DIR']) - cls.original_sstate = bb_vars['SSTATE_DIR'] - cls.devtool_sstate = os.path.join(bb_vars['TOPDIR'], 'sstate_devtool') - cls.sstate_conf = 'SSTATE_DIR = "%s"\n' % cls.devtool_sstate - cls.sstate_conf += ('SSTATE_MIRRORS += "file://.* file:///%s/PATH"\n' - % cls.original_sstate) - - @classmethod - def tearDownClass(cls): - cls.logger.debug('Deleting devtool sstate cache on %s' % cls.devtool_sstate) - runCmd('rm -rf %s' % cls.devtool_sstate) - super(DevtoolTests, cls).tearDownClass() - - def setUp(self): - """Test case setup function""" - super(DevtoolTests, self).setUp() - self.workspacedir = os.path.join(self.builddir, 'workspace') - self.assertTrue(not os.path.exists(self.workspacedir), - 'This test cannot be run with a workspace directory ' - 'under the build directory') - self.append_config(self.sstate_conf) - - def _check_src_repo(self, repo_dir): - """Check srctree git repository""" - self.assertTrue(os.path.isdir(os.path.join(repo_dir, '.git')), - 'git repository for external source tree not found') - result = runCmd('git status --porcelain', cwd=repo_dir) - self.assertEqual(result.output.strip(), "", - 'Created git repo is not clean') - result = runCmd('git symbolic-ref HEAD', cwd=repo_dir) - self.assertEqual(result.output.strip(), "refs/heads/devtool", - 'Wrong branch in git repo') - - def _check_repo_status(self, repo_dir, expected_status): - """Check the worktree status of a repository""" - result = runCmd('git status . --porcelain', - cwd=repo_dir) - for line in result.output.splitlines(): - for ind, (f_status, fn_re) in enumerate(expected_status): - if re.match(fn_re, line[3:]): - if f_status != line[:2]: - self.fail('Unexpected status in line: %s' % line) - expected_status.pop(ind) - break - else: - self.fail('Unexpected modified file in line: %s' % line) - if expected_status: - self.fail('Missing file changes: %s' % expected_status) - @OETestID(1158) def test_create_workspace(self): # Check preconditions
@@ -189,6 +189,8 @@ class DevtoolTests(DevtoolBase): self.assertNotIn(tempdir, result.output) self.assertIn(self.workspacedir, result.output) +class DevtoolAddTests(DevtoolBase): + @OETestID(1159) def test_devtool_add(self): # Fetch source
@@ -444,6 +446,8 @@ class DevtoolTests(DevtoolBase): checkvars['SRC_URI'] = url.replace(testver, '${PV}') self._test_recipe_contents(recipefile, checkvars, []) +class DevtoolModifyTests(DevtoolBase): + @OETestID(1164) def test_devtool_modify(self): import oe.path
@@ -689,6 +693,7 @@ class DevtoolTests(DevtoolBase): self._check_src_repo(tempdir) # This is probably sufficient +class DevtoolUpdateTests(DevtoolBase): @OETestID(1169) def test_devtool_update_recipe(self):
@@ -1105,6 +1110,8 @@ class DevtoolTests(DevtoolBase): expected_status = [] self._check_repo_status(os.path.dirname(recipefile), expected_status) +class DevtoolExtractTests(DevtoolBase): + @OETestID(1163) def test_devtool_extract(self): tempdir = tempfile.mkdtemp(prefix='devtoolqa')
@@ -1274,6 +1281,8 @@ class DevtoolTests(DevtoolBase): if reqpkgs: self.fail('The following packages were not present in the image as expected: %s' % ', '.join(reqpkgs)) +class DevtoolUpgradeTests(DevtoolBase): + @OETestID(1367) def test_devtool_upgrade(self): # Check preconditions
Signature · 1 line
2.17.1
PATCH 11/12 oeqa/sdkbuildproject: Capture output to quieten selftest logs
In reply to Richard PurdieOnly show the output in the failure case.
--- meta/lib/oeqa/sdk/utils/sdkbuildproject.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
meta/lib/oeqa/sdk/utils/sdkbuildproject.py +6 -1
@@ -42,4 +42,9 @@ class SDKBuildProject(BuildProject): def _run(self, cmd): self.log("Running . %s; " % self.sdkenv + cmd) - return subprocess.call(". %s; " % self.sdkenv + cmd, shell=True) + try: + output = subprocess.check_output(". %s; " % self.sdkenv + cmd, shell=True, stderr=subprocess.STDOUT) + except subprocess.CalledProcessError as exc: + print(exc.output.decode('utf-8')) + return exc.returncode + return 0
Signature · 1 line
2.17.1
PATCH 12/12 oeqa/selftest/wic: Split tests into two class groups
In reply to Richard PurdieThis improves test parallelism.
--- meta/lib/oeqa/selftest/cases/wic.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-)
meta/lib/oeqa/selftest/cases/wic.py +9 -5
@@ -61,7 +61,7 @@ def only_for_arch(archs, image='core-image-minimal'): return wrapper -class Wic(OESelftestTestCase): +class WicTestCase(OESelftestTestCase): """Wic test class.""" image_is_ready = False
@@ -71,7 +71,7 @@ class Wic(OESelftestTestCase): def setUpLocal(self): """This code is executed before each test method.""" self.resultdir = self.builddir + "/wic-tmp/" - super(Wic, self).setUpLocal() + super(WicTestCase, self).setUpLocal() if not self.native_sysroot: Wic.native_sysroot = get_bb_var('STAGING_DIR_NATIVE', 'wic-tools')
@@ -92,7 +92,9 @@ class Wic(OESelftestTestCase): def tearDownLocal(self): """Remove resultdir as it may contain images.""" rmtree(self.resultdir, ignore_errors=True) - super(Wic, self).tearDownLocal() + super(WicTestCase, self).tearDownLocal() + +class Wic(WicTestCase): @OETestID(1552) def test_version(self):
@@ -522,6 +524,8 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r % (wks_file, self.resultdir), ignore_status=True).status) os.remove(wks_file) +class Wic2(WicTestCase): + @OETestID(1496) def test_bmap_short(self): """Test generation of .bmap file -m option"""
@@ -679,7 +683,7 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r Test creation of a simple image with partition size controlled through --fixed-size flag """ - wkspath, wksname = Wic._make_fixed_size_wks(200) + wkspath, wksname = Wic2._make_fixed_size_wks(200) self.assertEqual(0, runCmd("wic create %s -e core-image-minimal -o %s" \ % (wkspath, self.resultdir)).status)
@@ -711,7 +715,7 @@ part /etc --source rootfs --ondisk mmcblk0 --fstype=ext4 --exclude-path bin/ --r --fixed-size flag. The size of partition is intentionally set to 1MiB in order to trigger an error in wic. """ - wkspath, wksname = Wic._make_fixed_size_wks(1) + wkspath, wksname = Wic2._make_fixed_size_wks(1) self.assertEqual(1, runCmd("wic create %s -e core-image-minimal -o %s" \ % (wkspath, self.resultdir), ignore_status=True).status)
Signature · 1 line
2.17.1