oeqa/loader: Drop code for pre python 3.5
PATCH 1/41 oeqa/loader: Drop code for pre python 3.5
We require python 3.9+ now so drop this dead code.
--- meta/lib/oeqa/core/loader.py | 37 +++++++++++------------------------- 1 file changed, 11 insertions(+), 26 deletions(-)
meta/lib/oeqa/core/loader.py +11 -26
@@ -322,29 +322,14 @@ class OETestLoader(unittest.TestLoader): return (load_module, load_underscore) - # XXX After Python 3.5, remove backward compatibility hacks for - # use_load_tests deprecation via *args and **kws. See issue 16662. - if sys.version_info >= (3,5): - def loadTestsFromModule(self, module, *args, pattern=None, **kws): - """ - Returns a suite of all tests cases contained in module. - """ - load_module, load_underscore = self._filterModule(module) - - if load_module or load_underscore: - return super(OETestLoader, self).loadTestsFromModule( - module, *args, pattern=pattern, **kws) - else: - return self.suiteClass() - else: - def loadTestsFromModule(self, module, use_load_tests=True): - """ - Returns a suite of all tests cases contained in module. - """ - load_module, load_underscore = self._filterModule(module) - - if load_module or load_underscore: - return super(OETestLoader, self).loadTestsFromModule( - module, use_load_tests) - else: - return self.suiteClass() + def loadTestsFromModule(self, module, *args, pattern=None, **kws): + """ + Returns a suite of all tests cases contained in module. + """ + load_module, load_underscore = self._filterModule(module) + + if load_module or load_underscore: + return super(OETestLoader, self).loadTestsFromModule( + module, *args, pattern=pattern, **kws) + else: + return self.suiteClass()
PATCH 2/41 lib: Simplify super() calls
python3 allows the super() calls to be simplified, make this change through our python code.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oe/classutils.py | 2 +- meta/lib/oe/package_manager/common_deb_ipk.py | 2 +- meta/lib/oe/package_manager/deb/__init__.py | 2 +- meta/lib/oe/package_manager/deb/rootfs.py | 4 ++-- meta/lib/oe/package_manager/deb/sdk.py | 2 +- meta/lib/oe/package_manager/ipk/__init__.py | 4 ++-- meta/lib/oe/package_manager/ipk/rootfs.py | 4 ++-- meta/lib/oe/package_manager/ipk/sdk.py | 2 +- meta/lib/oe/package_manager/rpm/__init__.py | 2 +- meta/lib/oe/package_manager/rpm/rootfs.py | 2 +- meta/lib/oe/package_manager/rpm/sdk.py | 2 +- meta/lib/oe/terminal.py | 2 +- meta/lib/oeqa/buildperf/base.py | 20 +++++++++---------- meta/lib/oeqa/controllers/controllerimage.py | 6 +++--- meta/lib/oeqa/core/decorator/depends.py | 2 +- meta/lib/oeqa/core/loader.py | 6 +++--- meta/lib/oeqa/core/runner.py | 18 ++++++++--------- meta/lib/oeqa/core/target/qemu.py | 2 +- meta/lib/oeqa/core/target/serial.py | 2 +- meta/lib/oeqa/core/target/ssh.py | 2 +- meta/lib/oeqa/core/utils/concurrencytest.py | 6 +++--- meta/lib/oeqa/oetest.py | 12 +++++------ meta/lib/oeqa/runtime/case.py | 4 ++-- meta/lib/oeqa/runtime/context.py | 6 +++--- meta/lib/oeqa/runtime/loader.py | 2 +- meta/lib/oeqa/sdk/context.py | 8 ++++---- meta/lib/oeqa/sdk/utils/sdkbuildproject.py | 4 ++-- meta/lib/oeqa/selftest/case.py | 10 +++++----- .../selftest/cases/_sstatetests_noauto.py | 2 +- meta/lib/oeqa/selftest/cases/bblayers.py | 2 +- meta/lib/oeqa/selftest/cases/bblock.py | 2 +- meta/lib/oeqa/selftest/cases/devtool.py | 8 ++++---- meta/lib/oeqa/selftest/cases/esdk.py | 2 +- meta/lib/oeqa/selftest/cases/gotoolchain.py | 4 ++-- .../oeqa/selftest/cases/kerneldevelopment.py | 6 +++--- meta/lib/oeqa/selftest/cases/layerappend.py | 2 +- meta/lib/oeqa/selftest/cases/manifest.py | 2 +- meta/lib/oeqa/selftest/cases/meta_ide.py | 4 ++-- meta/lib/oeqa/selftest/cases/pkgdata.py | 2 +- meta/lib/oeqa/selftest/cases/prservice.py | 2 +- meta/lib/oeqa/selftest/cases/recipetool.py | 8 ++++---- meta/lib/oeqa/selftest/cases/runqemu.py | 4 ++-- meta/lib/oeqa/selftest/cases/runtime_test.py | 4 ++-- meta/lib/oeqa/selftest/cases/sstatetests.py | 2 +- meta/lib/oeqa/selftest/cases/wic.py | 4 ++-- meta/lib/oeqa/selftest/context.py | 8 ++++---- meta/lib/oeqa/targetcontrol.py | 8 ++++---- meta/lib/oeqa/utils/dump.py | 4 ++-- meta/lib/oeqa/utils/targetbuild.py | 4 ++-- meta/lib/patchtest/tests/base.py | 4 ++-- scripts/lib/argparse_oe.py | 14 ++++++------- scripts/lib/buildstats.py | 2 +- scripts/lib/checklayer/context.py | 2 +- scripts/lib/devtool/__init__.py | 2 +- scripts/test-remote-image | 4 ++-- 55 files changed, 126 insertions(+), 126 deletions(-) mode change 100755 => 100644 scripts/test-remote-image
meta/lib/oe/classutils.py +1 -1
@@ -25,7 +25,7 @@ control over whether the class will be added to the registry (e.g. to keep abstract base classes out of the registry).""" priority = 0 def __init__(cls, name, bases, attrs): - super(ClassRegistry, cls).__init__(name, bases, attrs) + super().__init__(name, bases, attrs) try: if not cls.implemented: return
meta/lib/oe/package_manager/common_deb_ipk.py +1 -1
@@ -18,7 +18,7 @@ class OpkgDpkgPM(PackageManager): """ This is an abstract class. Do not instantiate this directly. """ - super(OpkgDpkgPM, self).__init__(d, target_rootfs) + super().__init__(d, target_rootfs) def package_info(self, pkg): """
meta/lib/oe/package_manager/deb/__init__.py +1 -1
@@ -115,7 +115,7 @@ class PMPkgsList(PkgsList): class DpkgPM(OpkgDpkgPM): def __init__(self, d, target_rootfs, archs, base_archs, apt_conf_dir=None, deb_repo_workdir="oe-rootfs-repo", filterbydependencies=True): - super(DpkgPM, self).__init__(d, target_rootfs) + super().__init__(d, target_rootfs) self.deploy_dir = oe.path.join(self.d.getVar('WORKDIR'), deb_repo_workdir) create_packages_dir(self.d, self.deploy_dir, d.getVar("DEPLOY_DIR_DEB"), "package_write_deb", filterbydependencies)
meta/lib/oe/package_manager/deb/rootfs.py +2 -2
@@ -14,7 +14,7 @@ from oe.package_manager.deb import DpkgPM class DpkgOpkgRootfs(Rootfs): def __init__(self, d, progress_reporter=None, logcatcher=None): - super(DpkgOpkgRootfs, self).__init__(d, progress_reporter, logcatcher) + super().__init__(d, progress_reporter, logcatcher) def _get_pkgs_postinsts(self, status_file): def _get_pkg_depends_list(pkg_depends):
@@ -124,7 +124,7 @@ class DpkgOpkgRootfs(Rootfs): class PkgRootfs(DpkgOpkgRootfs): def __init__(self, d, manifest_dir, progress_reporter=None, logcatcher=None): - super(PkgRootfs, self).__init__(d, progress_reporter, logcatcher) + super().__init__(d, progress_reporter, logcatcher) self.log_check_regex = '^E:' self.log_check_expected_regexes = \ [
meta/lib/oe/package_manager/deb/sdk.py +1 -1
@@ -14,7 +14,7 @@ from oe.package_manager.deb.manifest import PkgManifest class PkgSdk(Sdk): def __init__(self, d, manifest_dir=None): - super(PkgSdk, self).__init__(d, manifest_dir) + super().__init__(d, manifest_dir) self.target_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt") self.host_conf_dir = os.path.join(self.d.getVar("APTCONF_TARGET"), "apt-sdk")
meta/lib/oe/package_manager/ipk/__init__.py +2 -2
@@ -67,7 +67,7 @@ class OpkgIndexer(Indexer): class PMPkgsList(PkgsList): def __init__(self, d, rootfs_dir): - super(PMPkgsList, self).__init__(d, rootfs_dir) + super().__init__(d, rootfs_dir) config_file = d.getVar("IPKGCONF_TARGET") self.opkg_cmd = bb.utils.which(os.getenv('PATH'), "opkg")
@@ -95,7 +95,7 @@ class PMPkgsList(PkgsList): class OpkgPM(OpkgDpkgPM): def __init__(self, d, target_rootfs, config_file, archs, task_name='target', ipk_repo_workdir="oe-rootfs-repo", filterbydependencies=True, prepare_index=True): - super(OpkgPM, self).__init__(d, target_rootfs) + super().__init__(d, target_rootfs) self.config_file = config_file self.pkg_archs = archs
meta/lib/oe/package_manager/ipk/rootfs.py +2 -2
@@ -15,7 +15,7 @@ from oe.package_manager.ipk import OpkgPM class DpkgOpkgRootfs(Rootfs): def __init__(self, d, progress_reporter=None, logcatcher=None): - super(DpkgOpkgRootfs, self).__init__(d, progress_reporter, logcatcher) + super().__init__(d, progress_reporter, logcatcher) def _get_pkgs_postinsts(self, status_file): def _get_pkg_depends_list(pkg_depends):
@@ -125,7 +125,7 @@ class DpkgOpkgRootfs(Rootfs): class PkgRootfs(DpkgOpkgRootfs): def __init__(self, d, manifest_dir, progress_reporter=None, logcatcher=None): - super(PkgRootfs, self).__init__(d, progress_reporter, logcatcher) + super().__init__(d, progress_reporter, logcatcher) self.log_check_regex = '(exit 1|Collected errors)' self.manifest = PkgManifest(d, manifest_dir)
meta/lib/oe/package_manager/ipk/sdk.py +1 -1
@@ -14,7 +14,7 @@ from oe.package_manager.ipk import OpkgPM class PkgSdk(Sdk): def __init__(self, d, manifest_dir=None): - super(PkgSdk, self).__init__(d, manifest_dir) + super().__init__(d, manifest_dir) # In sdk_list_installed_packages the call to opkg is hardcoded to # always use IPKGCONF_TARGET and there's no exposed API to change this
meta/lib/oe/package_manager/rpm/__init__.py +1 -1
@@ -64,7 +64,7 @@ class RpmPM(PackageManager): rpm_repo_workdir="oe-rootfs-repo", filterbydependencies=True, needfeed=True): - super(RpmPM, self).__init__(d, target_rootfs) + super().__init__(d, target_rootfs) self.target_vendor = target_vendor self.task_name = task_name if arch_var == None:
meta/lib/oe/package_manager/rpm/rootfs.py +1 -1
@@ -12,7 +12,7 @@ from oe.package_manager.rpm import RpmPM class PkgRootfs(Rootfs): def __init__(self, d, manifest_dir, progress_reporter=None, logcatcher=None): - super(PkgRootfs, self).__init__(d, progress_reporter, logcatcher) + super().__init__(d, progress_reporter, logcatcher) self.log_check_regex = r'(unpacking of archive failed|Cannot find package'\ r'|exit 1\b|ERROR: |Error: |Error |ERROR '\ r'|Failed |Failed: |Failed$|Failed\(\d+\):)'
meta/lib/oe/package_manager/rpm/sdk.py +1 -1
@@ -13,7 +13,7 @@ from oe.package_manager.rpm import RpmPM class PkgSdk(Sdk): def __init__(self, d, manifest_dir=None, rpm_workdir="oe-sdk-repo"): - super(PkgSdk, self).__init__(d, manifest_dir) + super().__init__(d, manifest_dir) self.target_manifest = PkgManifest(d, self.manifest_dir, Manifest.MANIFEST_TYPE_SDK_TARGET)
meta/lib/oe/terminal.py +1 -1
@@ -24,7 +24,7 @@ class Registry(oe.classutils.ClassRegistry): command = None def __init__(cls, name, bases, attrs): - super(Registry, cls).__init__(name.lower(), bases, attrs) + super().__init__(name.lower(), bases, attrs) @property def implemented(cls):
meta/lib/oeqa/buildperf/base.py +10 -10
@@ -90,7 +90,7 @@ class BuildPerfTestResult(unittest.TextTestResult): test_run_queue = [] def __init__(self, out_dir, *args, **kwargs): - super(BuildPerfTestResult, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.out_dir = out_dir self.hostname = socket.gethostname()
@@ -100,30 +100,30 @@ class BuildPerfTestResult(unittest.TextTestResult): def addSuccess(self, test): """Record results from successful tests""" - super(BuildPerfTestResult, self).addSuccess(test) + super().addSuccess(test) self.successes.append(test) def addError(self, test, err): """Record results from crashed test""" test.err = err - super(BuildPerfTestResult, self).addError(test, err) + super().addError(test, err) def addFailure(self, test, err): """Record results from failed test""" test.err = err - super(BuildPerfTestResult, self).addFailure(test, err) + super().addFailure(test, err) def addExpectedFailure(self, test, err): """Record results from expectedly failed test""" test.err = err - super(BuildPerfTestResult, self).addExpectedFailure(test, err) + super().addExpectedFailure(test, err) def startTest(self, test): """Pre-test hook""" test.base_dir = self.out_dir log.info("Executing test %s: %s", test.name, test.shortDescription()) self.stream.write(datetime.now().strftime("[%Y-%m-%d %H:%M:%S] ")) - super(BuildPerfTestResult, self).startTest(test) + super().startTest(test) def startTestRun(self): """Pre-run hook"""
@@ -248,7 +248,7 @@ class BuildPerfTestCase(unittest.TestCase): build_target = None def __init__(self, *args, **kwargs): - super(BuildPerfTestCase, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.name = self._testMethodName self.base_dir = None self.start_time = None
@@ -268,7 +268,7 @@ class BuildPerfTestCase(unittest.TestCase): return os.path.join(self.base_dir, self.name + '.tmp') def shortDescription(self): - return super(BuildPerfTestCase, self).shortDescription() or "" + return super().shortDescription() or "" def setUp(self): """Set-up fixture for each test"""
@@ -285,7 +285,7 @@ class BuildPerfTestCase(unittest.TestCase): def run(self, *args, **kwargs): """Run test""" self.start_time = datetime.now() - super(BuildPerfTestCase, self).run(*args, **kwargs) + super().run(*args, **kwargs) self.elapsed_time = datetime.now() - self.start_time def run_cmd(self, cmd):
@@ -496,7 +496,7 @@ class BuildPerfTestRunner(unittest.TextTestRunner): sortTestMethodsUsing = None def __init__(self, out_dir, *args, **kwargs): - super(BuildPerfTestRunner, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.out_dir = out_dir def _makeResult(self):
meta/lib/oeqa/controllers/controllerimage.py +3 -3
@@ -29,7 +29,7 @@ class ControllerImageHardwareTarget(oeqa.targetcontrol.BaseTarget, metaclass=ABC supported_image_fstypes = ['tar.gz', 'tar.bz2'] def __init__(self, d): - super(ControllerImageHardwareTarget, self).__init__(d) + super().__init__(d) # target ip addr = d.getVar("TEST_TARGET_IP") or bb.fatal('Please set TEST_TARGET_IP with the IP address of the machine you want to run the tests on.')
@@ -119,7 +119,7 @@ class ControllerImageHardwareTarget(oeqa.targetcontrol.BaseTarget, metaclass=ABC def deploy(self): # base class just sets the ssh log file for us - super(ControllerImageHardwareTarget, self).deploy() + super().deploy() self.controller = sshcontrol.SSHControl(ip=self.ip, logfile=self.sshlog, timeout=600, port=self.port) status, output = self.controller.run("cat /etc/controllerimage") if status != 0:
@@ -162,7 +162,7 @@ class ControllerImageHardwareTarget(oeqa.targetcontrol.BaseTarget, metaclass=ABC class SystemdbootTarget(ControllerImageHardwareTarget): def __init__(self, d): - super(SystemdbootTarget, self).__init__(d) + super().__init__(d) # this the value we need to set in the LoaderEntryOneShot EFI variable # so the system boots the 'test' bootloader label and not the default # The first four bytes are EFI bits, and the rest is an utf-16le string
meta/lib/oeqa/core/decorator/depends.py +1 -1
@@ -81,7 +81,7 @@ class OETestDepends(OETestDiscover): attrs = ('depends',) def bind(self, registry, case): - super(OETestDepends, self).bind(registry, case) + super().bind(registry, case) if not registry.get('depends'): registry['depends'] = {} _add_depends(registry['depends'], case, self.depends)
meta/lib/oeqa/core/loader.py +3 -3
@@ -95,7 +95,7 @@ class OETestLoader(unittest.TestLoader): self._patchCaseClass(self.caseClass) - super(OETestLoader, self).__init__() + super().__init__() def _patchCaseClass(self, testCaseClass): # Adds custom attributes to the OETestCase class
@@ -274,7 +274,7 @@ class OETestLoader(unittest.TestLoader): big_suite = self.suiteClass() for path in self.module_paths: _find_duplicated_modules(big_suite, path) - suite = super(OETestLoader, self).discover(path, + suite = super().discover(path, pattern='*.py', top_level_dir=path) big_suite.addTests(suite)
@@ -329,7 +329,7 @@ class OETestLoader(unittest.TestLoader): load_module, load_underscore = self._filterModule(module) if load_module or load_underscore: - return super(OETestLoader, self).loadTestsFromModule( + return super().loadTestsFromModule( module, *args, pattern=pattern, **kws) else: return self.suiteClass()
meta/lib/oeqa/core/runner.py +9 -9
@@ -37,7 +37,7 @@ class OEStreamLogger(object): class OETestResult(_TestResult): def __init__(self, tc, *args, **kwargs): - super(OETestResult, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.successes = [] self.starttime = {}
@@ -58,14 +58,14 @@ class OETestResult(_TestResult): # May have been set by concurrencytest if test.id() not in self.starttime: self.starttime[test.id()] = time.time() - super(OETestResult, self).startTest(test) + super().startTest(test) def stopTest(self, test): self.endtime[test.id()] = time.time() if self.buffer: self.logged_output[test.id()] = ( sys.stdout.getvalue(), sys.stderr.getvalue()) - super(OETestResult, self).stopTest(test) + super().stopTest(test) if test.id() in self.progressinfo: self.tc.logger.info(self.progressinfo[test.id()])
@@ -153,25 +153,25 @@ class OETestResult(_TestResult): def addError(self, test, *args, details = None): self.extractExtraResults(test, details = details) - return super(OETestResult, self).addError(test, *args) + return super().addError(test, *args) def addFailure(self, test, *args, details = None): self.extractExtraResults(test, details = details) - return super(OETestResult, self).addFailure(test, *args) + return super().addFailure(test, *args) def addSuccess(self, test, details = None): #Added so we can keep track of successes too self.successes.append((test, None)) self.extractExtraResults(test, details = details) - return super(OETestResult, self).addSuccess(test) + return super().addSuccess(test) def addExpectedFailure(self, test, *args, details = None): self.extractExtraResults(test, details = details) - return super(OETestResult, self).addExpectedFailure(test, *args) + return super().addExpectedFailure(test, *args) def addUnexpectedSuccess(self, test, details = None): self.extractExtraResults(test, details = details) - return super(OETestResult, self).addUnexpectedSuccess(test) + return super().addUnexpectedSuccess(test) def logDetails(self, json_file_dir=None, configuration=None, result_id=None, dump_streams=False):
@@ -252,7 +252,7 @@ class OETestRunner(_TestRunner): def __init__(self, tc, *args, **kwargs): kwargs['stream'] = self.streamLoggerClass(tc.logger) - super(OETestRunner, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self.tc = tc self.resultclass = OETestResult
meta/lib/oeqa/core/target/qemu.py +1 -1
@@ -24,7 +24,7 @@ class OEQemuTarget(OESSHTarget): tmpdir='', dir_image='', boottime=60, serial_ports=2, boot_patterns = defaultdict(str), ovmf=False, tmpfsdir=None, native_sysroot=None, **kwargs): - super(OEQemuTarget, self).__init__(logger, None, server_ip, timeout, + super().__init__(logger, None, server_ip, timeout, user, port) self.server_ip = server_ip
meta/lib/oeqa/core/target/serial.py +1 -1
@@ -25,7 +25,7 @@ class OESerialTarget(OETarget): fileHandler.setFormatter(formatter) logger.addHandler(fileHandler) - super(OESerialTarget, self).__init__(logger) + super().__init__(logger) if serialcontrol_ps1: self.target_ps1 = serialcontrol_ps1
meta/lib/oeqa/core/target/ssh.py +1 -1
@@ -27,7 +27,7 @@ class OESSHTarget(OETarget): fileHandler.setFormatter(formatter) logger.addHandler(fileHandler) - super(OESSHTarget, self).__init__(logger) + super().__init__(logger) self.ip = ip self.server_ip = server_ip self.server_port = server_port
meta/lib/oeqa/core/utils/concurrencytest.py +3 -3
@@ -51,7 +51,7 @@ _all__ = [ class BBThreadsafeForwardingResult(ThreadsafeForwardingResult): def __init__(self, target, semaphore, threadnum, totalinprocess, totaltests, output, finalresult): - super(BBThreadsafeForwardingResult, self).__init__(target, semaphore) + super().__init__(target, semaphore) self.threadnum = threadnum self.totalinprocess = totalinprocess self.totaltests = totaltests
@@ -81,7 +81,7 @@ class BBThreadsafeForwardingResult(ThreadsafeForwardingResult): self.semaphore.release() self.finalresult._stderr_buffer = io.StringIO(initial_value=self.outputbuf.getvalue().decode("utf-8")) self.finalresult._stdout_buffer = io.StringIO() - super(BBThreadsafeForwardingResult, self)._add_result_with_semaphore(method, test, *args, **kwargs) + super()._add_result_with_semaphore(method, test, *args, **kwargs) class ProxyTestResult: # a very basic TestResult proxy, in order to modify add* calls
@@ -194,7 +194,7 @@ class dummybuf(object): class ConcurrentTestSuite(unittest.TestSuite): def __init__(self, suite, processes, setupfunc, removefunc, bb_vars): - super(ConcurrentTestSuite, self).__init__([suite]) + super().__init__([suite]) self.processes = processes self.setupfunc = setupfunc self.removefunc = removefunc
meta/lib/oeqa/oetest.py +6 -6
@@ -88,7 +88,7 @@ class oeTest(unittest.TestCase): class oeRuntimeTest(oeTest): def __init__(self, methodName='runTest'): self.target = oeRuntimeTest.tc.target - super(oeRuntimeTest, self).__init__(methodName) + super().__init__(methodName) def setUp(self): # Install packages in the DUT
@@ -346,7 +346,7 @@ class TestContext(object): class RuntimeTestContext(TestContext): def __init__(self, d, target, exported=False): - super(RuntimeTestContext, self).__init__(d, exported) + super().__init__(d, exported) self.target = target
@@ -549,7 +549,7 @@ class RuntimeTestContext(TestContext): class ImageTestContext(RuntimeTestContext): def __init__(self, d, target, host_dumper): - super(ImageTestContext, self).__init__(d, target) + super().__init__(d, target) self.tagexp = d.getVar("TEST_SUITES_TAGS")
@@ -570,7 +570,7 @@ class ImageTestContext(RuntimeTestContext): """ pkg_dir = self.d.getVar("TEST_EXTRACTED_DIR") - super(ImageTestContext, self).install_uninstall_packages(test_id, pkg_dir, install) + super().install_uninstall_packages(test_id, pkg_dir, install) class ExportTestContext(RuntimeTestContext): def __init__(self, d, target, exported=False, parsedArgs={}):
@@ -580,7 +580,7 @@ class ExportTestContext(RuntimeTestContext): parsedArgs can contain the following: - tag: Filter test by tag. """ - super(ExportTestContext, self).__init__(d, target, exported) + super().__init__(d, target, exported) tag = parsedArgs.get("tag", None) self.tagexp = tag if tag != None else d.getVar("TEST_SUITES_TAGS")
@@ -595,4 +595,4 @@ class ExportTestContext(RuntimeTestContext): export_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) extracted_dir = self.d.getVar("TEST_EXPORT_EXTRACTED_DIR") pkg_dir = os.path.join(export_dir, extracted_dir) - super(ExportTestContext, self).install_uninstall_packages(test_id, pkg_dir, install) + super().install_uninstall_packages(test_id, pkg_dir, install)
meta/lib/oeqa/runtime/case.py +2 -2
@@ -15,11 +15,11 @@ class OERuntimeTestCase(OETestCase): target = None def setUp(self): - super(OERuntimeTestCase, self).setUp() + super().setUp() install_package(self) def tearDown(self): - super(OERuntimeTestCase, self).tearDown() + super().tearDown() uninstall_package(self) def run_network_serialdebug(target):
meta/lib/oeqa/runtime/context.py +3 -3
@@ -21,7 +21,7 @@ class OERuntimeTestContext(OETestContext): def __init__(self, td, logger, target, image_packages, extract_dir): - super(OERuntimeTestContext, self).__init__(td, logger) + super().__init__(td, logger) self.target = target self.image_packages = image_packages
@@ -56,7 +56,7 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): default_extract_dir = 'packages/extracted' def register_commands(self, logger, subparsers): - super(OERuntimeTestContextExecutor, self).register_commands(logger, subparsers) + super().register_commands(logger, subparsers) runtime_group = self.parser.add_argument_group('runtime options')
@@ -204,7 +204,7 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): if not args.packages_manifest: raise TypeError('Manifest file not provided') - super(OERuntimeTestContextExecutor, self)._process_args(logger, args) + super()._process_args(logger, args) td = self.tc_kwargs['init']['td']
meta/lib/oeqa/runtime/loader.py +1 -1
@@ -11,7 +11,7 @@ class OERuntimeTestLoader(OETestLoader): caseClass = OERuntimeTestCase def _getTestCase(self, testCaseClass, tcName): - case = super(OERuntimeTestLoader, self)._getTestCase(testCaseClass, tcName) + case = super()._getTestCase(testCaseClass, tcName) # Adds custom attributes to the OERuntimeTestCase setattr(case, 'target', self.tc.target)
meta/lib/oeqa/sdk/context.py +4 -4
@@ -16,7 +16,7 @@ class OESDKTestContext(OETestContext): def __init__(self, td=None, logger=None, sdk_dir=None, sdk_env=None, target_pkg_manifest=None, host_pkg_manifest=None): - super(OESDKTestContext, self).__init__(td, logger) + super().__init__(td, logger) self.sdk_dir = sdk_dir self.sdk_env = sdk_env
@@ -63,7 +63,7 @@ class OESDKTestContextExecutor(OETestContextExecutor): default_test_data = None def register_commands(self, logger, subparsers): - super(OESDKTestContextExecutor, self).register_commands(logger, subparsers) + super().register_commands(logger, subparsers) sdk_group = self.parser.add_argument_group('sdk options') sdk_group.add_argument('--sdk-env', action='store',
@@ -99,7 +99,7 @@ class OESDKTestContextExecutor(OETestContextExecutor): return pkg_manifest def _process_args(self, logger, args): - super(OESDKTestContextExecutor, self)._process_args(logger, args) + super()._process_args(logger, args) self.tc_kwargs['init']['sdk_dir'] = args.sdk_dir self.tc_kwargs['init']['sdk_env'] = self.sdk_env
@@ -151,6 +151,6 @@ class OESDKTestContextExecutor(OETestContextExecutor): "environment (%s) specified" % args.sdk_env, self.name) self.sdk_env = sdk_envs[args.sdk_env] - return super(OESDKTestContextExecutor, self).run(logger, args) + return super().run(logger, args) _executor_class = OESDKTestContextExecutor
meta/lib/oeqa/sdk/utils/sdkbuildproject.py +2 -2
@@ -32,10 +32,10 @@ class SDKBuildProject(BuildProject): self.targetdir = os.path.join(self.targetdir, self.fname) def run_configure(self, configure_args='', extra_cmds=''): - return super(SDKBuildProject, self).run_configure(configure_args=(configure_args or '$CONFIGURE_FLAGS'), extra_cmds=extra_cmds) + return super().run_configure(configure_args=(configure_args or '$CONFIGURE_FLAGS'), extra_cmds=extra_cmds) def run_install(self, install_args=''): - return super(SDKBuildProject, self).run_install(install_args=(install_args or "DESTDIR=%s/../install" % self.targetdir)) + return super().run_install(install_args=(install_args or "DESTDIR=%s/../install" % self.targetdir)) def log(self, msg): if self.logfile:
meta/lib/oeqa/selftest/case.py +5 -5
@@ -17,11 +17,11 @@ import bb.utils class OESelftestTestCase(OETestCase): def __init__(self, methodName="runTest"): self._extra_tear_down_commands = [] - super(OESelftestTestCase, self).__init__(methodName) + super().__init__(methodName) @classmethod def setUpClass(cls): - super(OESelftestTestCase, cls).setUpClass() + super().setUpClass() cls.testlayer_path = cls.tc.config_paths['testlayer_path'] cls.builddir = cls.tc.config_paths['builddir']
@@ -46,7 +46,7 @@ class OESelftestTestCase(OETestCase): def tearDownClass(cls): cls.remove_include() cls.remove_inc_files() - super(OESelftestTestCase, cls).tearDownClass() + super().tearDownClass() @classmethod def add_include(cls):
@@ -94,7 +94,7 @@ class OESelftestTestCase(OETestCase): pass def setUp(self): - super(OESelftestTestCase, self).setUp() + super().setUp() os.chdir(self.builddir) # we don't know what the previous test left around in config or inc files # if it failed so we need a fresh start
@@ -144,7 +144,7 @@ class OESelftestTestCase(OETestCase): self._track_for_cleanup = [] self.tearDownLocal() - super(OESelftestTestCase, self).tearDown() + super().tearDown() def tearDownLocal(self): pass
meta/lib/oeqa/selftest/cases/_sstatetests_noauto.py +1 -1
@@ -16,7 +16,7 @@ class RebuildFromSState(SStateBase): @classmethod def setUpClass(self): - super(RebuildFromSState, self).setUpClass() + super().setUpClass() self.builddir = os.path.join(os.environ.get('BUILDDIR')) def get_dep_targets(self, primary_targets):
meta/lib/oeqa/selftest/cases/bblayers.py +1 -1
@@ -16,7 +16,7 @@ class BitbakeLayers(OESelftestTestCase): @classmethod def setUpClass(cls): - super(BitbakeLayers, cls).setUpClass() + super().setUpClass() bitbake("python3-jsonschema-native") bitbake("-c addto_recipe_sysroot python3-jsonschema-native")
meta/lib/oeqa/selftest/cases/bblock.py +1 -1
@@ -18,7 +18,7 @@ from oeqa.selftest.case import OESelftestTestCase class BBLock(OESelftestTestCase): @classmethod def setUpClass(cls): - super(BBLock, cls).setUpClass() + super().setUpClass() cls.lockfile = cls.builddir + "/conf/bblock.conf" def unlock_recipes(self, recipes=None, tasks=None):
meta/lib/oeqa/selftest/cases/devtool.py +4 -4
@@ -110,7 +110,7 @@ class DevtoolTestCase(OESelftestTestCase): def setUp(self): """Test case setup function""" - super(DevtoolTestCase, self).setUp() + super().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 '
@@ -315,7 +315,7 @@ class DevtoolBase(DevtoolTestCase): @classmethod def setUpClass(cls): - super(DevtoolBase, cls).setUpClass() + super().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')
@@ -328,11 +328,11 @@ class DevtoolBase(DevtoolTestCase): 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() + super().tearDownClass() def setUp(self): """Test case setup function""" - super(DevtoolBase, self).setUp() + super().setUp() self.append_config(self.sstate_conf)
meta/lib/oeqa/selftest/cases/esdk.py +1 -1
@@ -69,7 +69,7 @@ CORE_IMAGE_EXTRA_INSTALL = "perl" @classmethod def setUpClass(cls): - super(oeSDKExtSelfTest, cls).setUpClass() + super().setUpClass() cls.image = 'core-image-minimal' bb_vars = get_bb_vars(['SSTATE_DIR', 'WORKDIR'], cls.image)
meta/lib/oeqa/selftest/cases/gotoolchain.py +2 -2
@@ -33,7 +33,7 @@ class oeGoToolchainSelfTest(OESelftestTestCase): @classmethod def setUpClass(cls): - super(oeGoToolchainSelfTest, cls).setUpClass() + super().setUpClass() cls.tmpdir_SDKQA = tempfile.mkdtemp(prefix='SDKQA') cls.go_path = os.path.join(cls.tmpdir_SDKQA, "go") # Build the SDK and locate it in DEPLOYDIR
@@ -46,7 +46,7 @@ class oeGoToolchainSelfTest(OESelftestTestCase): @classmethod def tearDownClass(cls): shutil.rmtree(cls.tmpdir_SDKQA, ignore_errors=True) - super(oeGoToolchainSelfTest, cls).tearDownClass() + super().tearDownClass() def run_sdk_go_command(self, gocmd, proj, name): cmd = "cd %s/src/%s/%s; " % (self.go_path, proj, name)
meta/lib/oeqa/selftest/cases/kerneldevelopment.py +3 -3
@@ -13,7 +13,7 @@ class KernelDev(OESelftestTestCase): @classmethod def setUpClass(cls): - super(KernelDev, cls).setUpClass() + super().setUpClass() # Create the recipe directory structure inside the created layer cls.layername = 'meta-kerneltest' runCmd('bitbake-layers create-layer %s' % cls.layername)
@@ -27,10 +27,10 @@ class KernelDev(OESelftestTestCase): def tearDownClass(cls): runCmd('bitbake-layers remove-layer %s' % cls.layername, ignore_status=True) runCmd('rm -rf %s' % cls.layername) - super(KernelDev, cls).tearDownClass() + super().tearDownClass() def setUp(self): - super(KernelDev, self).setUp() + super().setUp() self.set_machine_config('MACHINE = "qemux86-64"\n') def test_apply_patches(self):
meta/lib/oeqa/selftest/cases/layerappend.py +1 -1
@@ -53,7 +53,7 @@ SRC_URI:append = " file://appendtest.txt" def tearDownLocal(self): if self.layerappend: ftools.remove_from_file(self.builddir + "/conf/bblayers.conf", self.layerappend) - super(LayerAppendTests, self).tearDownLocal() + super().tearDownLocal() def test_layer_appends(self): corebase = get_bb_var("COREBASE")
meta/lib/oeqa/selftest/cases/manifest.py +1 -1
@@ -52,7 +52,7 @@ class VerifyManifest(OESelftestTestCase): @classmethod def setUpClass(self): - super(VerifyManifest, self).setUpClass() + super().setUpClass() self.buildtarget = 'core-image-minimal' self.classname = 'VerifyManifest'
meta/lib/oeqa/selftest/cases/meta_ide.py +2 -2
@@ -16,7 +16,7 @@ class MetaIDE(OESelftestTestCase): @classmethod def setUpClass(cls): - super(MetaIDE, cls).setUpClass() + super().setUpClass() bitbake('meta-ide-support') bitbake('build-sysroots -c build_native_sysroot') bitbake('build-sysroots -c build_target_sysroot')
@@ -30,7 +30,7 @@ class MetaIDE(OESelftestTestCase): @classmethod def tearDownClass(cls): shutil.rmtree(cls.tmpdir_metaideQA, ignore_errors=True) - super(MetaIDE, cls).tearDownClass() + super().tearDownClass() def test_meta_ide_had_installed_meta_ide_support(self): self.assertExists(self.environment_script_path)
meta/lib/oeqa/selftest/cases/pkgdata.py +1 -1
@@ -15,7 +15,7 @@ class OePkgdataUtilTests(OESelftestTestCase): @classmethod def setUpClass(cls): - super(OePkgdataUtilTests, cls).setUpClass() + super().setUpClass() # Ensure we have the right data in pkgdata cls.logger.info('Running bitbake to generate pkgdata') bitbake('target-sdk-provides-dummy -c clean')
meta/lib/oeqa/selftest/cases/prservice.py +1 -1
@@ -20,7 +20,7 @@ class BitbakePrTests(OESelftestTestCase): @classmethod def setUpClass(cls): - super(BitbakePrTests, cls).setUpClass() + super().setUpClass() cls.pkgdata_dir = get_bb_var('PKGDATA_DIR') cls.exported_db_path = os.path.join(cls.builddir, 'export.inc')
meta/lib/oeqa/selftest/cases/recipetool.py +4 -4
@@ -43,7 +43,7 @@ def needTomllib(test): class RecipetoolBase(devtool.DevtoolTestCase): def setUpLocal(self): - super(RecipetoolBase, self).setUpLocal() + super().setUpLocal() self.templayerdir = templayerdir self.tempdir = tempfile.mkdtemp(prefix='recipetoolqa') self.track_for_cleanup(self.tempdir)
@@ -55,7 +55,7 @@ class RecipetoolBase(devtool.DevtoolTestCase): def tearDownLocal(self): runCmd('rm -rf %s/recipes-*' % self.templayerdir) - super(RecipetoolBase, self).tearDownLocal() + super().tearDownLocal() def _try_recipetool_appendcmd(self, cmd, testrecipe, expectedfiles, expectedlines=None): result = runCmd(cmd)
@@ -89,7 +89,7 @@ class RecipetoolAppendTests(RecipetoolBase): @classmethod def setUpClass(cls): - super(RecipetoolAppendTests, cls).setUpClass() + super().setUpClass() # Ensure we have the right data in shlibs/pkgdata cls.logger.info('Running bitbake to generate pkgdata') bitbake('-c packagedata base-files coreutils busybox selftest-recipetool-appendfile')
@@ -858,7 +858,7 @@ class RecipetoolTests(RecipetoolBase): def setUpClass(cls): import sys - super(RecipetoolTests, cls).setUpClass() + super().setUpClass() bb_vars = get_bb_vars(['BBPATH']) cls.bbpath = bb_vars['BBPATH'] libpath = os.path.join(get_bb_var('COREBASE'), 'scripts', 'lib', 'recipetool')
meta/lib/oeqa/selftest/cases/runqemu.py +2 -2
@@ -22,7 +22,7 @@ class RunqemuTests(OESelftestTestCase): deploy_dir_image = '' def setUpLocal(self): - super(RunqemuTests, self).setUpLocal() + super().setUpLocal() self.recipe = 'core-image-minimal' self.machine = self.td['MACHINE'] self.image_link_name = get_bb_var('IMAGE_LINK_NAME', self.recipe)
@@ -187,7 +187,7 @@ class QemuTest(OESelftestTestCase): @classmethod def setUpClass(cls): - super(QemuTest, cls).setUpClass() + super().setUpClass() cls.recipe = 'core-image-minimal' cls.image_fstypes = "tar.zst"
meta/lib/oeqa/selftest/cases/runtime_test.py +2 -2
@@ -475,7 +475,7 @@ class SystemTap(OESelftestTestCase): @classmethod def setUpClass(cls): - super(SystemTap, cls).setUpClass() + super().setUpClass() cls.image = "core-image-minimal" def default_config(self):
@@ -545,7 +545,7 @@ IMAGE_INSTALL:append = " systemtap-runtime" class RustKernel(OESelftestTestCase): @classmethod def setUpClass(cls): - super(RustKernel, cls).setUpClass() + super().setUpClass() cls.image = "core-image-minimal" def test_kernel_rust_sample(self):
meta/lib/oeqa/selftest/cases/sstatetests.py +1 -1
@@ -26,7 +26,7 @@ keep_temp_files = False class SStateBase(OESelftestTestCase): def setUpLocal(self): - super(SStateBase, self).setUpLocal() + super().setUpLocal() self.temp_sstate_location = None needed_vars = ['SSTATE_DIR', 'TCLIBC', 'TUNE_ARCH', 'TOPDIR', 'TARGET_VENDOR', 'TARGET_OS']
meta/lib/oeqa/selftest/cases/wic.py +2 -2
@@ -63,7 +63,7 @@ class WicTestCase(OESelftestTestCase): """This code is executed before each test method.""" self.resultdir = os.path.join(self.builddir, "wic-tmp") self._old_path = os.environ.get('PATH') - super(WicTestCase, self).setUpLocal() + super().setUpLocal() # Do this here instead of in setUpClass as the base setUp does some # clean up which can result in the native tools built earlier in
@@ -96,7 +96,7 @@ class WicTestCase(OESelftestTestCase): else: os.environ['PATH'] = self._old_path rmtree(self.resultdir, ignore_errors=True) - super(WicTestCase, self).tearDownLocal() + super().tearDownLocal() def _get_wic_path(self): if WicTestCase.wic_bindir is None:
meta/lib/oeqa/selftest/context.py +4 -4
@@ -72,7 +72,7 @@ def removebuilddir(d): class OESelftestTestContext(OETestContext): def __init__(self, td=None, logger=None, machines=None, config_paths=None, newbuilddir=None, keep_builddir=None): - super(OESelftestTestContext, self).__init__(td, logger) + super().__init__(td, logger) self.config_paths = config_paths self.newbuilddir = newbuilddir
@@ -173,10 +173,10 @@ class OESelftestTestContext(OETestContext): return NonConcurrentTestSuite(suites, processes, self.setup_builddir, self.removebuilddir, self.bb_vars) def runTests(self, processes=None, machine=None, skips=[]): - return super(OESelftestTestContext, self).runTests(processes, skips) + return super().runTests(processes, skips) def listTests(self, display_type, machine=None): - return super(OESelftestTestContext, self).listTests(display_type) + return super().listTests(display_type) class OESelftestTestContextExecutor(OETestContextExecutor): _context_class = OESelftestTestContext
@@ -261,7 +261,7 @@ class OESelftestTestContextExecutor(OETestContextExecutor): bb.utils.mkdirhier(logdir) args.output_log = logdir + '/%s-results-%s.log' % (self.name, args.test_start_time) - super(OESelftestTestContextExecutor, self)._process_args(logger, args) + super()._process_args(logger, args) if args.list_modules: args.list_tests = 'module'
meta/lib/oeqa/targetcontrol.py +4 -4
@@ -93,7 +93,7 @@ class QemuTarget(BaseTarget): import oe.types - super(QemuTarget, self).__init__(d, logger) + super().__init__(d, logger) self.rootfs = '' self.kernel = ''
@@ -161,7 +161,7 @@ class QemuTarget(BaseTarget): self.logger.info("rootfs file: %s" % self.rootfs) self.logger.info("Qemu log file: %s" % self.qemulog) - super(QemuTarget, self).deploy() + super().deploy() def start(self, params=None, ssh=True, extra_bootparams='', runqemuparams='', launch_cmd='', discard_writes=True): if 'slirp' in runqemuparams.split():
@@ -228,7 +228,7 @@ class QemuTarget(BaseTarget): class SimpleRemoteTarget(BaseTarget): def __init__(self, d): - super(SimpleRemoteTarget, self).__init__(d) + super().__init__(d) addr = d.getVar("TEST_TARGET_IP") or bb.fatal('Please set TEST_TARGET_IP with the IP address of the machine you want to run the tests on.') self.ip = addr.split(":")[0] try:
@@ -245,7 +245,7 @@ class SimpleRemoteTarget(BaseTarget): self.logger.info("Server IP: %s" % self.server_ip) def deploy(self): - super(SimpleRemoteTarget, self).deploy() + super().deploy() def start(self, params=None, ssh=True, extra_bootparams=None): if ssh:
meta/lib/oeqa/utils/dump.py +2 -2
@@ -82,7 +82,7 @@ class TargetDumper(BaseDumper): """ def __init__(self, cmds, parent_dir, runner): - super(TargetDumper, self).__init__(cmds, parent_dir) + super().__init__(cmds, parent_dir) self.runner = runner self.errors = 0
@@ -112,7 +112,7 @@ class MonitorDumper(BaseDumper): """ def __init__(self, cmds, parent_dir, runner): - super(MonitorDumper, self).__init__(cmds, parent_dir) + super().__init__(cmds, parent_dir) self.runner = runner self.errors = 0
meta/lib/oeqa/utils/targetbuild.py +2 -2
@@ -129,10 +129,10 @@ class SDKBuildProject(BuildProject): self.targetdir = os.path.join(self.targetdir, self.fname) def run_configure(self, configure_args='', extra_cmds=' gnu-configize; '): - return super(SDKBuildProject, self).run_configure(configure_args=(configure_args or '$CONFIGURE_FLAGS'), extra_cmds=extra_cmds) + return super().run_configure(configure_args=(configure_args or '$CONFIGURE_FLAGS'), extra_cmds=extra_cmds) def run_install(self, install_args=''): - return super(SDKBuildProject, self).run_install(install_args=(install_args or "DESTDIR=%s/../install" % self.targetdir)) + return super().run_install(install_args=(install_args or "DESTDIR=%s/../install" % self.targetdir)) def log(self, msg): if self.logfile:
meta/lib/patchtest/tests/base.py +2 -2
@@ -109,7 +109,7 @@ class Base(unittest.TestCase): if data: value['data'] = data - return super(Base, self).fail(json.dumps(value)) + return super().fail(json.dumps(value)) def skip(self, issue, data=None): """ Convert the skip string to JSON"""
@@ -120,7 +120,7 @@ class Base(unittest.TestCase): if data: value['data'] = data - return super(Base, self).skipTest(json.dumps(value)) + return super().skipTest(json.dumps(value)) def shortid(self): return self.id().split('.')[-1]
scripts/lib/argparse_oe.py +7 -7
@@ -19,7 +19,7 @@ class ArgumentParser(argparse.ArgumentParser): def __init__(self, *args, **kwargs): kwargs.setdefault('formatter_class', OeHelpFormatter) self._subparser_groups = OrderedDict() - super(ArgumentParser, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) self._positionals.title = 'arguments' self._optionals.title = 'options'
@@ -49,7 +49,7 @@ class ArgumentParser(argparse.ArgumentParser): if 'dest' not in kwargs: kwargs['dest'] = '_subparser_name' - ret = super(ArgumentParser, self).add_subparsers(*args, **kwargs) + ret = super().add_subparsers(*args, **kwargs) # Need a way of accessing the parent parser ret._parent_parser = self # Ensure our class gets instantiated
@@ -100,7 +100,7 @@ class ArgumentSubParser(ArgumentParser): self._group = kwargs.pop('group') if 'order' in kwargs: self._order = kwargs.pop('order') - super(ArgumentSubParser, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) def parse_known_args(self, args=None, namespace=None): # This works around argparse not handling optional positional arguments being
@@ -117,7 +117,7 @@ class ArgumentSubParser(ArgumentParser): action.save_nargs = action.nargs action.nargs = 0 - namespace, remaining_args = super(ArgumentSubParser, self).parse_known_args(args, namespace) + namespace, remaining_args = super().parse_known_args(args, namespace) for action in positionals: # remove the empty positional values from namespace if hasattr(namespace, action.dest):
@@ -125,7 +125,7 @@ class ArgumentSubParser(ArgumentParser): for action in positionals: action.nargs = action.save_nargs # parse positionals - namespace, extras = super(ArgumentSubParser, self).parse_known_args(remaining_args, namespace) + namespace, extras = super().parse_known_args(remaining_args, namespace) return namespace, extras def format_help(self):
@@ -134,7 +134,7 @@ class ArgumentSubParser(ArgumentParser): for action in positionals: if hasattr(action, 'save_nargs'): action.nargs = action.save_nargs - return super(ArgumentParser, self).format_help() + return super().format_help() class OeHelpFormatter(argparse.HelpFormatter):
@@ -172,7 +172,7 @@ class OeHelpFormatter(argparse.HelpFormatter): lines.append('%s%s' % (groupindent, self._format_action(subaction).rstrip())) return '\n'.join(lines) else: - return super(OeHelpFormatter, self)._format_action(action) + return super()._format_action(action) def int_positive(value): ivalue = int(value)
scripts/lib/buildstats.py +1 -1
@@ -33,7 +33,7 @@ class BSTask(dict): self['iostat'] = {} self['rusage'] = {} self['child_rusage'] = {} - super(BSTask, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) @property def cputime(self):
scripts/lib/checklayer/context.py +1 -1
@@ -12,6 +12,6 @@ from oeqa.core.context import OETestContext class CheckLayerTestContext(OETestContext): def __init__(self, td=None, logger=None, layer=None, test_software_layer_signatures=True): - super(CheckLayerTestContext, self).__init__(td, logger) + super().__init__(td, logger) self.layer = layer self.test_software_layer_signatures = test_software_layer_signatures
scripts/lib/devtool/__init__.py +1 -1
@@ -20,7 +20,7 @@ logger = logging.getLogger('devtool') class DevtoolError(Exception): """Exception for handling devtool errors""" def __init__(self, message, exitcode=1): - super(DevtoolError, self).__init__(message) + super().__init__(message) self.exitcode = exitcode
scripts/test-remote-image +2 -2
@@ -126,7 +126,7 @@ class BaseTargetProfile(object, metaclass=ABCMeta): class AutoTargetProfile(BaseTargetProfile): def __init__(self, image_type): - super(AutoTargetProfile, self).__init__(image_type) + super().__init__(image_type) self.image_name = get_bb_var('IMAGE_LINK_NAME', target=image_type) self.kernel_type = get_bb_var('KERNEL_IMAGETYPE', target=image_type) self.controller = self.get_controller()
@@ -203,7 +203,7 @@ class BaseRepoProfile(object, metaclass=ABCMeta): class PublicAB(BaseRepoProfile): def __init__(self, repolink, localdir=None): - super(PublicAB, self).__init__(repolink, localdir) + super().__init__(repolink, localdir) if localdir is None: self.localdir = os.path.join(os.environ['BUILDDIR'], 'PublicABMirror')
PATCH 3/41 oe-buildenv-internal: Correct minimum python version
In reply to Richard PurdieWe have python 3.9 as the minimum version now.
--- scripts/oe-buildenv-internal | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
scripts/oe-buildenv-internal +4 -4
@@ -32,12 +32,12 @@ fi # We potentially have code that doesn't parse correctly with older versions # of Python, and rather than fixing that and being eternally vigilant for # any other new feature use, just check the version here. -py_v38_check=$(python3 -c 'import sys; print(sys.version_info >= (3,8,0))') -if [ "$py_v38_check" != "True" ]; then - echo >&2 "BitBake requires Python 3.8.0 or later as 'python3' (scripts/install-buildtools can be used if needed)" +py_v39_check=$(python3 -c 'import sys; print(sys.version_info >= (3,9,0))') +if [ "$py_v39_check" != "True" ]; then + echo >&2 "BitBake requires Python 3.9.0 or later as 'python3' (scripts/install-buildtools can be used if needed)" return 1 fi -unset py_v38_check +unset py_v39_check if [ -z "$BDIR" ]; then if [ -z "$1" ]; then
PATCH 4/41 oeqa/core/utils/concurrencytest: Fix losing results after class setup failures
In reply to Richard PurdieWhen setUpClass() or setUpModule() fails or skips in a test process, the result is reported outside of any test. The subunit parser patches which handle this reported the outcome and the stopTest() which follows it without a startTest(). testtools tracks per test state between those calls, so this broke its forwarding result and the thread reading that process' results crashed on the next test, losing the results of all the remaining tests in the process. These were then reported as UNKNOWN.
Start the placeholder test before reporting its outcome, as the parser does for normal tests, and add a test comparing results from a concurrent run with a normal run. The test is skipped if testtools, subunit or bitbake aren't available.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/tests/test_concurrency.py | 42 ++++++++++++++++++++ meta/lib/oeqa/core/utils/concurrencytest.py | 6 +++ 2 files changed, 48 insertions(+) create mode 100644 meta/lib/oeqa/core/tests/test_concurrency.py
meta/lib/oeqa/core/tests/test_concurrency.py new file +42 -0
@@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +import os +import unittest +from unittest import mock + +from common import setup_sys_path, TestBase +setup_sys_path() + +try: + from oeqa.core.utils.concurrencytest import ConcurrentTestSuite +except ImportError: + ConcurrentTestSuite = None + [email protected](ConcurrentTestSuite is None, "concurrencytest needs testtools, subunit and bitbake") +class TestConcurrency(TestBase): + def _statuses(self, modules, processes=None): + tc = self._testLoader(modules=modules) + if processes: + setup = lambda suffix, selftestdir, suite: (None, None) + tc.prepareSuite = lambda suites, processes: ConcurrentTestSuite(suites, processes, setup, None, {'BBLAYERS': ''}) + # fork_for_tests() only looks up the selftest layer with BUILDDIR set + with mock.patch.dict(os.environ, {'BUILDDIR': '/nonexistent'}): + result = tc.runTests(processes=processes) + return {case_id: result._getTestResultDetails(case)[0] + for case_id, case in tc._registry['cases'].items()} + + def test_concurrent_status(self): + # Class and module setup failures must not stop the results of the + # other tests run by the same process being reported + modules = ['results', 'resultsmodule', 'subtest'] + sequential = self._statuses(modules) + self.assertNotIn('UNKNOWN', sequential.values()) + self.assertEqual(self._statuses(modules, processes=1), sequential) + +if __name__ == '__main__': + unittest.main()
meta/lib/oeqa/core/utils/concurrencytest.py +6 -0
@@ -156,6 +156,9 @@ def outSideTestaddError(self, offset, line): test_name = line[offset:-1].decode('utf8') self.parser._current_test = subunit.RemotedTestCase(test_name) self.parser.current_test_description = test_name + # The outcome is followed by stopTest(), which testtools needs to match + # a startTest() or it loses track and breaks on the following tests + self.parser.client.startTest(self.parser._current_test) self.parser._state = self.parser._reading_error_details self.parser._reading_error_details.set_simple() self.parser.subunitLineReceived(line)
@@ -171,6 +174,9 @@ def outSideTestaddSkip(self, offset, line): test_name = line[offset:-1].decode('utf8') self.parser._current_test = subunit.RemotedTestCase(test_name) self.parser.current_test_description = test_name + # The outcome is followed by stopTest(), which testtools needs to match + # a startTest() or it loses track and breaks on the following tests + self.parser.client.startTest(self.parser._current_test) self.parser._state = self.parser._reading_skip_details self.parser._reading_skip_details.set_simple() self.parser.subunitLineReceived(line)
PATCH 5/41 oeqa/core/utils/concurrencytest: Only show each test's own output
In reply to Richard PurdieWhen tests run in separate processes, each process' output is collected in a buffer as it arrives. Each result was given the whole buffer as its output, so a failing test showed the output of every earlier test run by the same process, as did the stdout/stderr saved in the results.
Each process runs its tests one at a time, so only give a result the output received since the previous one, and add a test. stdout and stderr still share a pipe and are reported together as stderr.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/tests/cases/streams.py | 24 ++++++++++++++++++++ meta/lib/oeqa/core/tests/test_concurrency.py | 17 +++++++++++++- meta/lib/oeqa/core/utils/concurrencytest.py | 10 +++++++- 3 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 meta/lib/oeqa/core/tests/cases/streams.py
meta/lib/oeqa/core/tests/cases/streams.py new file +24 -0
@@ -0,0 +1,24 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +import sys + +from oeqa.core.case import OETestCase + +class StreamsTest(OETestCase): + + def testStreams1(self): + print("Output from testStreams1") + sys.stderr.write("Error output from testStreams1\n") + + def testStreams2(self): + print("Output from testStreams2") + sys.stderr.write("Error output from testStreams2\n") + self.fail("Failed on purpose") + + def testStreams3(self): + print("Output from testStreams3") + self.fail("Failed on purpose")
meta/lib/oeqa/core/tests/test_concurrency.py +16 -1
@@ -19,7 +19,7 @@ except ImportError: @unittest.skipIf(ConcurrentTestSuite is None, "concurrencytest needs testtools, subunit and bitbake") class TestConcurrency(TestBase): - def _statuses(self, modules, processes=None): + def _run(self, modules, processes=None): tc = self._testLoader(modules=modules) if processes: setup = lambda suffix, selftestdir, suite: (None, None)
@@ -27,6 +27,10 @@ class TestConcurrency(TestBase): # fork_for_tests() only looks up the selftest layer with BUILDDIR set with mock.patch.dict(os.environ, {'BUILDDIR': '/nonexistent'}): result = tc.runTests(processes=processes) + return tc, result + + def _statuses(self, modules, processes=None): + tc, result = self._run(modules, processes) return {case_id: result._getTestResultDetails(case)[0] for case_id, case in tc._registry['cases'].items()}
@@ -38,5 +42,16 @@ class TestConcurrency(TestBase): self.assertNotIn('UNKNOWN', sequential.values()) self.assertEqual(self._statuses(modules, processes=1), sequential) + def test_concurrent_output(self): + # Each test's results must only have the output from that test, not + # everything its process has output so far + tc, result = self._run(['streams'], processes=1) + for n in (1, 2, 3): + stdout, stderr = result.logged_output['streams.StreamsTest.testStreams%d' % n] + output = stdout + stderr + self.assertIn("Output from testStreams%d" % n, output) + for other in {1, 2, 3} - {n}: + self.assertNotIn("testStreams%d" % other, output) + if __name__ == '__main__': unittest.main()
meta/lib/oeqa/core/utils/concurrencytest.py +9 -1
@@ -57,6 +57,9 @@ class BBThreadsafeForwardingResult(ThreadsafeForwardingResult): self.totaltests = totaltests self.buffer = True self.outputbuf = output + # The process' output accumulates in outputbuf; this is how much of + # it was given to earlier results + self.outputoffset = 0 self.finalresult = finalresult self.finalresult.buffer = True self.target = target
@@ -79,8 +82,13 @@ class BBThreadsafeForwardingResult(ThreadsafeForwardingResult): test.id()) finally: self.semaphore.release() - self.finalresult._stderr_buffer = io.StringIO(initial_value=self.outputbuf.getvalue().decode("utf-8")) + # The process runs its tests one at a time, so the output since the + # previous result is this test's. stdout and stderr share one pipe so + # it is all given as stderr. + output = self.outputbuf.getvalue() + self.finalresult._stderr_buffer = io.StringIO(initial_value=output[self.outputoffset:].decode("utf-8")) self.finalresult._stdout_buffer = io.StringIO() + self.outputoffset = len(output) super()._add_result_with_semaphore(method, test, *args, **kwargs) class ProxyTestResult:
PATCH 6/41 oeqa/core/utils/concurrencytest: Don't buffer output in the forwarding results
In reply to Richard PurdieBBThreadsafeForwardingResult set buffer = True, so the forwarding result for each test process swapped sys.stdout and sys.stderr for buffers in its startTest() and restored them in stopTest(). These run in separate reader threads without any locking, and each result records the streams to restore when it is created, which happens after the reader threads for earlier processes have started. sys.stdout/stderr could be left pointing at a buffer after the tests ran, losing later output and making any later forked test process fail at sys.stdout.fileno().
The output of the test processes comes through the passthrough buffer and is given to the final result, which does its own buffering under the semaphore, so don't buffer in the forwarding results. Add a test which checks the streams are restored after concurrent runs.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/tests/test_concurrency.py | 11 +++++++++++ meta/lib/oeqa/core/utils/concurrencytest.py | 4 +++- 2 files changed, 14 insertions(+), 1 deletion(-)
meta/lib/oeqa/core/tests/test_concurrency.py +11 -0
@@ -6,6 +6,7 @@ # import os +import sys import unittest from unittest import mock
@@ -53,5 +54,15 @@ class TestConcurrency(TestBase): for other in {1, 2, 3} - {n}: self.assertNotIn("testStreams%d" % other, output) + def test_concurrent_streams_restored(self): + # Each process' results are read in a separate thread; after running, + # sys.stdout and sys.stderr must be the original streams again. Any + # problem here is a race, so run several times. + stdout, stderr = sys.stdout, sys.stderr + for i in range(50): + self._run(['results'], processes=2) + self.assertIs(sys.stdout, stdout) + self.assertIs(sys.stderr, stderr) + if __name__ == '__main__': unittest.main()
meta/lib/oeqa/core/utils/concurrencytest.py +3 -1
@@ -55,7 +55,9 @@ class BBThreadsafeForwardingResult(ThreadsafeForwardingResult): self.threadnum = threadnum self.totalinprocess = totalinprocess self.totaltests = totaltests - self.buffer = True + # Don't set self.buffer, the output comes through outputbuf. Buffering + # here would swap sys.stdout/stderr in each reader thread, unlocked, + # and could leave them replaced after the tests have run. self.outputbuf = output # The process' output accumulates in outputbuf; this is how much of # it was given to earlier results
PATCH 7/41 oeqa/core/utils/concurrencytest: Fix the failed count in the test progress
In reply to Richard PurdieThe "(N failed)" count shown in the progress line for each test when running tests concurrently came from the result proxy for the process which ran the test. It was only that process' count, was read before the current test's result was counted, and counted each failure twice since testtools first passes a failure with details, which OETestResult rejects, and then retries without.
Count the failing tests across all processes on the final result in _add_result_with_semaphore(), which is called once per result under the semaphore shared by the reader threads, before the progress line is formatted. Add a test which checks the count in each progress line.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/tests/cases/failures.py | 29 ++++++++++++++++++++ meta/lib/oeqa/core/tests/test_concurrency.py | 16 +++++++++++ meta/lib/oeqa/core/utils/concurrencytest.py | 8 +++++- 3 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 meta/lib/oeqa/core/tests/cases/failures.py
meta/lib/oeqa/core/tests/cases/failures.py new file +29 -0
@@ -0,0 +1,29 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +from oeqa.core.case import OETestCase + +class FailuresATest(OETestCase): + + def testFailuresA1(self): + self.fail("Failed on purpose") + + def testFailuresA2(self): + pass + + def testFailuresA3(self): + raise Exception("Error on purpose") + +class FailuresBTest(OETestCase): + + def testFailuresB1(self): + pass + + def testFailuresB2(self): + self.fail("Failed on purpose") + + def testFailuresB3(self): + self.fail("Failed on purpose")
meta/lib/oeqa/core/tests/test_concurrency.py +16 -0
@@ -6,6 +6,7 @@ # import os +import re import sys import unittest from unittest import mock
@@ -64,5 +65,20 @@ class TestConcurrency(TestBase): self.assertIs(sys.stdout, stdout) self.assertIs(sys.stderr, stderr) + def test_concurrent_failed_count(self): + # The failed count in the progress shown for each test must be the + # number of tests which failed so far in all processes + tc, result = self._run(['failures'], processes=2) + failed = {test.id() for test, _ in result.failures + result.errors} + self.assertEqual(len(failed), 4) + # progressinfo is in the order the results were received + seen = set() + for test_id, progress in result.progressinfo.items(): + if test_id in failed: + seen.add(test_id) + count = int(re.search(r"\((\d+) failed\)", progress).group(1)) + self.assertEqual(count, len(seen), msg=progress) + self.assertEqual(seen, failed) + if __name__ == '__main__': unittest.main()
meta/lib/oeqa/core/utils/concurrencytest.py +7 -1
@@ -70,6 +70,11 @@ class BBThreadsafeForwardingResult(ThreadsafeForwardingResult): self.semaphore.acquire() try: if self._test_start: + # Count failing tests across all the processes. This is called + # once per result, unlike the add* methods of the target which + # testtools may call twice. + if method.__name__ in ('addError', 'addFailure'): + self.finalresult.failedtests.add(test.id()) self.result.starttime[test.id()] = self._test_start.timestamp() self.result.threadprogress[self.threadnum].append(test.id()) totalprogress = sum(len(x) for x in self.result.threadprogress.values())
@@ -80,7 +85,7 @@ class BBThreadsafeForwardingResult(ThreadsafeForwardingResult): totalprogress, self.totaltests, "{0:.2f}".format(time.time()-self._test_start.timestamp()), - self.target.failed_tests, + len(self.finalresult.failedtests), test.id()) finally: self.semaphore.release()
@@ -223,6 +228,7 @@ class ConcurrentTestSuite(unittest.TestSuite): queue = Queue() semaphore = threading.Semaphore(1) result.threadprogress = {} + result.failedtests = set() for i, (testserver, testnum, output) in enumerate(testservers): result.threadprogress[i] = [] process_result = BBThreadsafeForwardingResult(
PATCH 8/41 oeqa: Drop explicit 'object' base classes
In reply to Richard PurdieAll classes are new-style in Python 3 so inheriting from object is redundant.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/buildperf/base.py | 2 +- meta/lib/oeqa/core/context.py | 4 ++-- meta/lib/oeqa/core/runner.py | 6 +++--- meta/lib/oeqa/core/target/__init__.py | 2 +- meta/lib/oeqa/core/utils/concurrencytest.py | 2 +- meta/lib/oeqa/oetest.py | 2 +- meta/lib/oeqa/runexported.py | 2 +- meta/lib/oeqa/sdk/testmetaidesupport.py | 2 +- meta/lib/oeqa/sdk/testsdk.py | 2 +- meta/lib/oeqa/selftest/cases/reproducible.py | 4 ++-- meta/lib/oeqa/selftest/cases/runcmd.py | 2 +- meta/lib/oeqa/selftest/cases/spdx.py | 2 +- meta/lib/oeqa/utils/commands.py | 4 ++-- meta/lib/oeqa/utils/decorators.py | 2 +- meta/lib/oeqa/utils/dump.py | 2 +- meta/lib/oeqa/utils/git.py | 2 +- meta/lib/oeqa/utils/logparser.py | 4 ++-- meta/lib/oeqa/utils/sshcontrol.py | 4 ++-- 18 files changed, 25 insertions(+), 25 deletions(-)
meta/lib/oeqa/buildperf/base.py +1 -1
@@ -32,7 +32,7 @@ log = logging.getLogger('build-perf') runCmd2 = partial(runCmd, assert_error=False, limit_exc_output=40) -class KernelDropCaches(object): +class KernelDropCaches: """Container of the functions for dropping kernel caches""" sudo_passwd = None
meta/lib/oeqa/core/context.py +2 -2
@@ -15,7 +15,7 @@ from oeqa.core.loader import OETestLoader from oeqa.core.runner import OETestRunner from oeqa.core.exception import OEQAMissingManifest, OEQATestNotFound -class OETestContext(object): +class OETestContext: loaderClass = OETestLoader runnerClass = OETestRunner
@@ -97,7 +97,7 @@ class OETestContext(object): self.runner = self.runnerClass(self, verbosity=2) return self.runner.list_tests(self.suites, display_type) -class OETestContextExecutor(object): +class OETestContextExecutor: _context_class = OETestContext _script_executor = 'oe-test'
meta/lib/oeqa/core/runner.py +3 -3
@@ -15,7 +15,7 @@ import sys from unittest import TextTestResult as _TestResult from unittest import TextTestRunner as _TestRunner -class OEStreamLogger(object): +class OEStreamLogger: def __init__(self, logger): self.logger = logger self.buffer = ""
@@ -243,7 +243,7 @@ class OETestResult(_TestResult): # Account for expected failures return not self.wasSuccessful() or len(self.expectedFailures) -class OEListTestsResult(object): +class OEListTestsResult: def wasSuccessful(self): return True
@@ -333,7 +333,7 @@ class OETestRunner(_TestRunner): return OEListTestsResult() -class OETestResultJSONHelper(object): +class OETestResultJSONHelper: testresult_filename = 'testresults.json'
meta/lib/oeqa/core/target/__init__.py +1 -1
@@ -6,7 +6,7 @@ from abc import abstractmethod -class OETarget(object): +class OETarget: def __init__(self, logger, *args, **kwargs): self.logger = logger
meta/lib/oeqa/core/utils/concurrencytest.py +1 -1
@@ -203,7 +203,7 @@ subunit._OutSideTest.addSkip = outSideTestaddSkip # is available and accepts writes. This allows unittest with buffer=True # to interact ok with subunit which wants to access sys.stdout.buffer. # -class dummybuf(object): +class dummybuf: def __init__(self, parent): self.p = parent def write(self, data):
meta/lib/oeqa/oetest.py +1 -1
@@ -155,7 +155,7 @@ def custom_verbose(msg, *args, **kwargs): logger.info(_buffer_logger.rstrip("\n"), *args, **kwargs) _buffer_logger = "" -class TestContext(object): +class TestContext: def __init__(self, d, exported=False): self.d = d
meta/lib/oeqa/runexported.py +1 -1
@@ -37,7 +37,7 @@ from oeqa.utils.sshcontrol import SSHControl # this isn't pretty but we need a fake target object # for running the tests externally as we don't care # about deploy/start we only care about the connection methods (run, copy) -class FakeTarget(object): +class FakeTarget: def __init__(self, d): self.connection = None self.ip = None
meta/lib/oeqa/sdk/testmetaidesupport.py +1 -1
@@ -4,7 +4,7 @@ # SPDX-License-Identifier: MIT # -class TestSDK(object): +class TestSDK: def run(self, d): import json import logging
meta/lib/oeqa/sdk/testsdk.py +1 -1
@@ -6,7 +6,7 @@ from oeqa.sdk.context import OESDKTestContext, OESDKTestContextExecutor -class TestSDKBase(object): +class TestSDKBase: @staticmethod def get_sdk_configuration(d, test_type): import platform
meta/lib/oeqa/selftest/cases/reproducible.py +2 -2
@@ -30,7 +30,7 @@ DIFFERENT = 'DIFFERENT' SAME = 'SAME' @functools.total_ordering -class CompareResult(object): +class CompareResult: def __init__(self): self.reference = None self.test = None
@@ -42,7 +42,7 @@ class CompareResult(object): def __lt__(self, other): return (self.status, self.test) < (other.status, other.test) -class PackageCompareResults(object): +class PackageCompareResults: def __init__(self, exclusions): self.total = [] self.missing = []
meta/lib/oeqa/selftest/cases/runcmd.py +1 -1
@@ -13,7 +13,7 @@ import threading import time import signal -class MemLogger(object): +class MemLogger: def __init__(self): self.info_msgs = [] self.error_msgs = []
meta/lib/oeqa/selftest/cases/spdx.py +1 -1
@@ -12,7 +12,7 @@ from oeqa.utils.commands import bitbake, get_bb_var, get_bb_vars import oe.spdx30 -class SPDX3CheckBase(object): +class SPDX3CheckBase: """ Base class for checking SPDX 3 based tests """
meta/lib/oeqa/utils/commands.py +2 -2
@@ -25,7 +25,7 @@ try: except ImportError: pass -class Command(object): +class Command: def __init__(self, command, bg=False, timeout=None, data=None, output_log=None, **options): self.defaultopts = {
@@ -161,7 +161,7 @@ class Command(object): self.log.debug("Last 20 lines:\n%s" % lout) -class Result(object): +class Result: pass
meta/lib/oeqa/utils/decorators.py +1 -1
@@ -16,7 +16,7 @@ import threading import signal from functools import wraps -class testcase(object): +class testcase: def __init__(self, test_case): self.test_case = test_case
meta/lib/oeqa/utils/dump.py +1 -1
@@ -12,7 +12,7 @@ import datetime import itertools from .commands import runCmd -class BaseDumper(object): +class BaseDumper: """ Base class to dump commands from host/target """ def __init__(self, cmds, parent_dir):
meta/lib/oeqa/utils/git.py +1 -1
@@ -13,7 +13,7 @@ class GitError(Exception): """Git error handling""" pass -class GitRepo(object): +class GitRepo: """Class representing a Git repository clone""" def __init__(self, path, is_topdir=False): git_dir = self._run_git_cmd_at(['rev-parse', '--git-dir'], path)
meta/lib/oeqa/utils/logparser.py +2 -2
@@ -9,7 +9,7 @@ import os import re # A parser that can be used to identify weather a line is a test result or a section statement. -class PtestParser(object): +class PtestParser: def __init__(self): self.results = {} self.sections = {}
@@ -144,7 +144,7 @@ class LtpParser: # ltp Compliance log parsing -class LtpComplianceParser(object): +class LtpComplianceParser: def __init__(self): self.results = {} self.section = {'duration': "", 'log': ""}
meta/lib/oeqa/utils/sshcontrol.py +2 -2
@@ -14,7 +14,7 @@ import os import select -class SSHProcess(object): +class SSHProcess: def __init__(self, **options): self.defaultopts = {
@@ -99,7 +99,7 @@ class SSHProcess(object): raise return (self.status, self.output) -class SSHControl(object): +class SSHControl: def __init__(self, ip, logfile=None, timeout=300, user='root', port=None): self.ip = ip self.defaulttimeout = timeout
PATCH 9/41 oeqa: Use OSError instead of IOError and socket.error
In reply to Richard PurdieIOError and socket.error are aliases of OSError in Python 3.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/oetest.py | 2 +- meta/lib/oeqa/selftest/cases/manifest.py | 12 ++++++------ meta/lib/oeqa/utils/ftools.py | 2 +- meta/lib/oeqa/utils/qemurunner.py | 6 +++--- meta/lib/oeqa/utils/qemutinyrunner.py | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-)
meta/lib/oeqa/oetest.py +1 -1
@@ -360,7 +360,7 @@ class RuntimeTestContext(TestContext): for line in f: (pkg, arch, version) = line.strip().split() self.pkgmanifest[pkg] = (version, arch) - except IOError as e: + except OSError as e: bb.fatal("No package manifest file found. Did you build the image?\n%s" % e) def _get_test_namespace(self):
meta/lib/oeqa/selftest/cases/manifest.py +6 -6
@@ -94,7 +94,7 @@ class VerifyManifest(OESelftestTestCase): if not os.path.isfile(mpath[k]): self.logger.debug("{}: {} does not exist".format( self.classname, mpath[k])) - raise IOError + raise OSError m_entry[k] = ManifestEntry(mpath[k]) pkgdata_dir[k] = self.get_dir_from_bb_var('PKGDATA_DIR',
@@ -104,11 +104,11 @@ class VerifyManifest(OESelftestTestCase): if not os.path.exists(reverse_dir[k]): self.logger.debug("{}: {} does not exist".format( self.classname, reverse_dir[k])) - raise IOError + raise OSError except OSError: raise self.skipTest("{}: Error in obtaining manifest dirs"\ .format(self.classname)) - except IOError: + except OSError: msg = "{}: Error cannot find manifests in the specified dir:\n{}"\ .format(self.classname, mdir) self.fail(msg)
@@ -137,18 +137,18 @@ class VerifyManifest(OESelftestTestCase): mfilename = get_bb_var("IMAGE_LINK_NAME", self.buildtarget)\ + ".manifest" mpath = os.path.join(mdir, mfilename) - if not os.path.isfile(mpath): raise IOError + if not os.path.isfile(mpath): raise OSError m_entry = ManifestEntry(mpath) pkgdata_dir = {} pkgdata_dir = self.get_dir_from_bb_var('PKGDATA_DIR', self.buildtarget) revdir = os.path.join(pkgdata_dir, 'runtime-reverse') - if not os.path.exists(revdir): raise IOError + if not os.path.exists(revdir): raise OSError except OSError: raise self.skipTest("{}: Error in obtaining manifest dirs"\ .format(self.classname)) - except IOError: + except OSError: msg = "{}: Error cannot find manifests in dir:\n{}"\ .format(self.classname, mdir) self.fail(msg)
meta/lib/oeqa/utils/ftools.py +1 -1
@@ -36,7 +36,7 @@ def remove_from_file(path, data): return try: rdata = read_file(path) - except IOError as e: + except OSError as e: # if file does not exit, just quit, otherwise raise an exception if e.errno == errno.ENOENT: return
meta/lib/oeqa/utils/qemurunner.py +3 -3
@@ -119,7 +119,7 @@ class QemuRunner: self.logger.debug("Created listening socket for qemu serial console on: 127.0.0.1:%s" % port) return (sock, port) - except socket.error: + except OSError: sock.close() raise
@@ -216,7 +216,7 @@ class QemuRunner: if self.serial_ports >= 2: self.threadsock, threadport = self.create_socket() self.server_socket, self.serverport = self.create_socket() - except socket.error as msg: + except OSError as msg: self.logger.error("Failed to create listening socket: %s" % msg[1]) return False
@@ -858,7 +858,7 @@ class LoggingThread(threading.Thread): def recv(self, count, sock): try: data = sock.recv(count) - except socket.error as e: + except OSError as e: if e.errno == errno.EAGAIN or e.errno == errno.EWOULDBLOCK: return b'' else:
meta/lib/oeqa/utils/qemutinyrunner.py +1 -1
@@ -55,7 +55,7 @@ class QemuTinyRunner(QemuRunner): self.server_socket.connect(self.socketfile) bb.note("Created listening socket for qemu serial console.") tries = 0 - except socket.error as msg: + except OSError as msg: self.server_socket.close() bb.fatal("Failed to create listening socket.") tries -= 1
PATCH 10/41 oeqa: Use 'is None' for None comparisons
In reply to Richard PurdieComparing to None with == or != is unidiomatic and can be overridden by __eq__; use identity checks instead.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/loader.py | 2 +- meta/lib/oeqa/core/target/ssh.py | 4 ++-- meta/lib/oeqa/oetest.py | 2 +- meta/lib/oeqa/selftest/cases/oelib/path.py | 2 +- meta/lib/oeqa/utils/subprocesstweak.py | 2 +- 5 files changed, 6 insertions(+), 6 deletions(-)
meta/lib/oeqa/core/loader.py +1 -1
@@ -40,7 +40,7 @@ def _find_duplicated_modules(suite, directory): def _built_modules_dict(modules, logger): modules_dict = {} - if modules == None: + if modules is None: return modules_dict for module in modules:
meta/lib/oeqa/core/target/ssh.py +2 -2
@@ -293,7 +293,7 @@ def SSHCall(command, logger, timeout=None, raw=False, **opts): logger.debug('No output from SSH call') # timout or not, make sure process exits and is not hanging - if process.returncode == None: + if process.returncode is None: try: process.wait(timeout=5) except TimeoutExpired:
@@ -339,7 +339,7 @@ def SSHCall(command, logger, timeout=None, raw=False, **opts): # whilst running and ensure we don't leave a process behind. if process.poll() is None: process.kill() - if process.returncode == None: + if process.returncode is None: process.wait() logger.debug('Something went wrong, killing SSH process') raise
meta/lib/oeqa/oetest.py +1 -1
@@ -583,7 +583,7 @@ class ExportTestContext(RuntimeTestContext): super().__init__(d, target, exported) tag = parsedArgs.get("tag", None) - self.tagexp = tag if tag != None else d.getVar("TEST_SUITES_TAGS") + self.tagexp = tag if tag is not None else d.getVar("TEST_SUITES_TAGS") self.sigterm = None
meta/lib/oeqa/selftest/cases/oelib/path.py +1 -1
@@ -67,7 +67,7 @@ class TestRealPath(TestCase): def test_norm(self): for l in self.LINKS: - if l[2] == None: + if l[2] is None: continue target_p = self.__realpath(l[0], True)
meta/lib/oeqa/utils/subprocesstweak.py +1 -1
@@ -13,7 +13,7 @@ class OETestCalledProcessError(subprocess.CalledProcessError): s = super().__str__() s = s + "\nStandard Output: " + strify(self.output) # stderr is not available for check_output method - if self.stderr != None: + if self.stderr is not None: s = s + "\nStandard Error: " + strify(self.stderr) return s
PATCH 11/41 oeqa: Drop redundant .keys() calls on dicts
In reply to Richard PurdieDict membership tests and iteration work on the dict directly, so wrapping in list(d.keys()) or calling .keys() is unnecessary.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/sdk/context.py | 4 +- meta/lib/oeqa/selftest/cases/manifest.py | 4 +- meta/lib/oeqa/selftest/cases/pkgdata.py | 56 ++++++++++++------------ 3 files changed, 32 insertions(+), 32 deletions(-)
meta/lib/oeqa/sdk/context.py +2 -2
@@ -34,12 +34,12 @@ class OESDKTestContext(OETestContext): if regex: # do regex match pat = re.compile(pkg) - for p in manifest.keys(): + for p in manifest: if pat.search(p): return True else: # do exact match - if pkg in manifest.keys(): + if pkg in manifest: return True return False
meta/lib/oeqa/selftest/cases/manifest.py +2 -2
@@ -87,7 +87,7 @@ class VerifyManifest(OESelftestTestCase): host = 'nativesdk-packagegroup-sdk-host') try: mdir = self.get_dir_from_bb_var('SDK_DEPLOY', self.buildtarget) - for k in d_target.keys(): + for k in d_target: toolchain_outputname = get_bb_var('TOOLCHAIN_OUTPUTNAME', self.buildtarget) mfilename[k] = "{}.{}.manifest".format(toolchain_outputname, k) mpath[k] = os.path.join(mdir, mfilename[k])
@@ -113,7 +113,7 @@ class VerifyManifest(OESelftestTestCase): .format(self.classname, mdir) self.fail(msg) - for k in d_target.keys(): + for k in d_target: self.logger.debug("{}: Check manifest {}".format( self.classname, m_entry[k].file))
meta/lib/oeqa/selftest/cases/pkgdata.py +28 -28
91 lines not on this page · raw message
PATCH 12/41 oeqa/core/context: Use isinstance() for type check
In reply to Richard PurdieAI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/context.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/lib/oeqa/core/context.py +1 -1
@@ -23,7 +23,7 @@ class OETestContext: os.path.abspath(__file__)), "../files")) def __init__(self, td=None, logger=None): - if not type(td) is dict: + if not isinstance(td, dict): raise TypeError("td isn't dictionary type") self.td = td
PATCH 13/41 oeqa: Use bare raise to re-raise exceptions
In reply to Richard PurdieA bare raise re-raises the current exception without needing to name it.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/selftest/cases/devtool.py | 2 +- meta/lib/oeqa/selftest/cases/manifest.py | 2 +- meta/lib/oeqa/selftest/cases/recipetool.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-)
meta/lib/oeqa/selftest/cases/devtool.py +1 -1
@@ -2591,7 +2591,7 @@ class DevtoolUpgradeTests(DevtoolBase): if e.errno == errno.EROFS: return False else: - raise e + raise if p == "lib": # Can race with other tests self.add_command_to_tearDown('rmdir --ignore-fail-on-non-empty %s' % dstdir)
meta/lib/oeqa/selftest/cases/manifest.py +1 -1
@@ -34,7 +34,7 @@ class VerifyManifest(OESelftestTestCase): except OSError as e: self.logger.debug("{}: checking of {} failed"\ .format(self.classname, manifest)) - raise e + raise return manifest_errors
meta/lib/oeqa/selftest/cases/recipetool.py +1 -1
@@ -878,7 +878,7 @@ class RecipetoolTests(RecipetoolBase): if e.errno == errno.EROFS: return False else: - raise e + raise if p == "lib": # Can race with other tests self.add_command_to_tearDown('rmdir --ignore-fail-on-non-empty %s' % dstdir)
PATCH 14/41 oeqa: Let subprocess decode output instead of calling .decode()
In reply to Richard PurdiePass text=True to the subprocess calls rather than decoding the bytes afterwards. This also covers CalledProcessError.output. Raw socket/pty reads and base64 output are left as bytes.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/target/qemu.py | 2 +- meta/lib/oeqa/runtime/cases/boot.py | 4 ++-- meta/lib/oeqa/runtime/cases/dnf.py | 2 +- meta/lib/oeqa/runtime/cases/ping.py | 4 ++-- meta/lib/oeqa/sdk/testsdk.py | 4 ++-- meta/lib/oeqa/sdk/utils/sdkbuildproject.py | 5 +++-- meta/lib/oeqa/sdkext/testsdk.py | 4 ++-- .../lib/oeqa/selftest/cases/yoctotestresultsquerytests.py | 2 +- meta/lib/oeqa/utils/metadata.py | 8 ++++---- meta/lib/oeqa/utils/qemurunner.py | 3 +-- meta/lib/oeqa/utils/qemutinyrunner.py | 4 ++-- 11 files changed, 21 insertions(+), 21 deletions(-)
meta/lib/oeqa/core/target/qemu.py +1 -1
@@ -81,7 +81,7 @@ class OEQemuTarget(OESSHTarget): blcmd = ["tail", "-20", self.bootlog] msg += "===== start: snippet =====\n\n" try: - out = subprocess.check_output(blcmd, stderr=subprocess.STDOUT, timeout=1).decode('utf-8') + out = subprocess.check_output(blcmd, stderr=subprocess.STDOUT, timeout=1, text=True) msg += "file: %s\n\n" % self.bootlog msg += out except (subprocess.CalledProcessError, subprocess.TimeoutExpired, FileNotFoundError) as err:
meta/lib/oeqa/runtime/cases/boot.py +2 -2
@@ -24,8 +24,8 @@ class BootTest(OERuntimeTestCase): while count < 5: time.sleep(5) cmd = 'ping -c 1 %s' % self.target.ip - proc = Popen(cmd, shell=True, stdout=PIPE) - output += proc.communicate()[0].decode('utf-8') + proc = Popen(cmd, shell=True, stdout=PIPE, text=True) + output += proc.communicate()[0] if proc.poll() == 0: count += 1 else:
meta/lib/oeqa/runtime/cases/dnf.py +1 -1
@@ -103,7 +103,7 @@ class DnfRepoTest(DnfTest): @OETestDepends(['dnf.DnfRepoTest.test_dnf_install_from_disk']) def test_dnf_install_from_http(self): output = subprocess.check_output('%s %s -name dnf-test-dep*' % (bb.utils.which(os.getenv('PATH'), "find"), - os.path.join(self.tc.td['WORKDIR'], 'oe-testimage-repo')), shell=True).decode("utf-8") + os.path.join(self.tc.td['WORKDIR'], 'oe-testimage-repo')), shell=True, text=True) rpm_path = output.split("/")[-2] + "/" + output.split("/")[-1] url = 'http://%s:%s/%s' %(self.target.server_ip, self.repo_server.port, rpm_path) self.dnf_with_repo('remove -y dnf-test-dep')
meta/lib/oeqa/runtime/cases/ping.py +2 -2
@@ -28,8 +28,8 @@ class PingTest(OERuntimeTestCase): try: while count < 5: cmd = 'ping -c 1 %s' % self.target.ip - proc = Popen(cmd, shell=True, stdout=PIPE) - output += proc.communicate()[0].decode('utf-8') + proc = Popen(cmd, shell=True, stdout=PIPE, text=True) + output += proc.communicate()[0] if proc.poll() == 0: count += 1 else:
meta/lib/oeqa/sdk/testsdk.py +2 -2
@@ -66,9 +66,9 @@ class TestSDK(TestSDKBase): import subprocess try: - subprocess.check_output("cd %s; %s <<EOF\n./\nY\nEOF" % (sdk_dir, tcname), shell=True) + subprocess.check_output("cd %s; %s <<EOF\n./\nY\nEOF" % (sdk_dir, tcname), shell=True, text=True) except subprocess.CalledProcessError as e: - bb.fatal("Couldn't install the SDK:\n%s" % e.output.decode("utf-8")) + bb.fatal("Couldn't install the SDK:\n%s" % e.output) def setup_context(self, d): """
meta/lib/oeqa/sdk/utils/sdkbuildproject.py +3 -2
@@ -46,8 +46,9 @@ class SDKBuildProject(BuildProject): self.log("Running . %s; " % self.sdkenv + cmd) try: output = subprocess.check_output(". %s; " % self.sdkenv + cmd, shell=True, - executable='/bin/bash', stderr=subprocess.STDOUT) + executable='/bin/bash', stderr=subprocess.STDOUT, + text=True) except subprocess.CalledProcessError as exc: - print(exc.output.decode('utf-8')) + print(exc.output) return exc.returncode return 0
meta/lib/oeqa/sdkext/testsdk.py +2 -2
@@ -47,9 +47,9 @@ class TestSDKExt(TestSDKBase): bb.utils.remove(sdk_dir, True) bb.utils.mkdirhier(sdk_dir) try: - subprocess.check_output([tcname, '-y', '-d', sdk_dir]) + subprocess.check_output([tcname, '-y', '-d', sdk_dir], text=True) except subprocess.CalledProcessError as e: - msg = "Couldn't install the extensible SDK:\n%s" % e.output.decode("utf-8") + msg = "Couldn't install the extensible SDK:\n%s" % e.output logfn = os.path.join(sdk_dir, 'preparing_build_system.log') if os.path.exists(logfn): msg += '\n\nContents of preparing_build_system.log:\n'
meta/lib/oeqa/selftest/cases/yoctotestresultsquerytests.py +1 -1
@@ -31,7 +31,7 @@ class TestResultsQueryTests(OESelftestTestCase): workdir = create_workdir() try: url = subprocess.check_output( - ["git", "-C", workdir, "remote", "get-url", "origin"]).strip().decode("utf-8") + ["git", "-C", workdir, "remote", "get-url", "origin"], text=True).strip() except: shutil.rmtree(workdir, ignore_errors=True) self.fail(f"Can not execute git commands in {workdir}")
meta/lib/oeqa/utils/metadata.py +4 -4
@@ -68,19 +68,19 @@ def git_rev_info(path): except ImportError: import subprocess try: - info['branch'] = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=path).decode('utf-8').strip() + info['branch'] = subprocess.check_output(["git", "rev-parse", "--abbrev-ref", "HEAD"], cwd=path, text=True).strip() except subprocess.CalledProcessError: pass try: - info['commit'] = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=path).decode('utf-8').strip() + info['commit'] = subprocess.check_output(["git", "rev-parse", "HEAD"], cwd=path, text=True).strip() except subprocess.CalledProcessError: pass try: - info['commit_count'] = int(subprocess.check_output(["git", "rev-list", "--count", "HEAD"], cwd=path).decode('utf-8').strip()) + info['commit_count'] = int(subprocess.check_output(["git", "rev-list", "--count", "HEAD"], cwd=path, text=True).strip()) except subprocess.CalledProcessError: pass try: - info['commit_time'] = int(subprocess.check_output(["git", "show", "--no-patch", "--format=%ct", "HEAD"], cwd=path).decode('utf-8').strip()) + info['commit_time'] = int(subprocess.check_output(["git", "show", "--no-patch", "--format=%ct", "HEAD"], cwd=path, text=True).strip()) except subprocess.CalledProcessError: pass return info
meta/lib/oeqa/utils/qemurunner.py +1 -2
@@ -316,8 +316,7 @@ class QemuRunner: % (self.runqemu.poll(), os.path.isfile(self.qemu_pidfile), str(qemu_pid), os.path.exists("/proc/" + str(qemu_pid)))) # Dump all processes to help us to figure out what is going on... - ps = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,pri,ni,command '], stdout=subprocess.PIPE).communicate()[0] - processes = ps.decode("utf-8") + processes = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,pri,ni,command '], stdout=subprocess.PIPE, text=True).communicate()[0] self.logger.debug("Running processes:\n%s" % processes) op = getOutput(output) self.stop()
meta/lib/oeqa/utils/qemutinyrunner.py +2 -2
@@ -143,8 +143,8 @@ class QemuTinyRunner(QemuRunner): # # Walk the process tree from the process specified looking for a qemu-system. Return its [pid'cmd] # - ps = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,pri,ni,command'], stdout=subprocess.PIPE).communicate()[0] - processes = ps.decode("utf-8").split('\n') + ps = subprocess.Popen(['ps', 'axww', '-o', 'pid,ppid,pri,ni,command'], stdout=subprocess.PIPE, text=True).communicate()[0] + processes = ps.split('\n') nfields = len(processes[0].split()) - 1 pids = {} commands = {}
PATCH 15/41 oeqa/selftest/manifest: Remove broken/unused code
In reply to Richard PurdieThe code was using a broken comparison operator. We always set target anyway, so drop the broken code rather than fix it.
--- meta/lib/oeqa/selftest/cases/manifest.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
meta/lib/oeqa/selftest/cases/manifest.py +1 -2
@@ -40,8 +40,7 @@ class VerifyManifest(OESelftestTestCase): #this will possibly move from here @classmethod - def get_dir_from_bb_var(self, bb_var, target = None): - target == self.buildtarget if target == None else target + def get_dir_from_bb_var(self, bb_var, target): directory = get_bb_var(bb_var, target); if not directory or not os.path.isdir(directory): self.logger.debug("{}: {} points to {} when target = {}"\
PATCH 16/41 oeqa/utils/testexport.py: Drop file
In reply to Richard PurdieNothing uses these functions.
--- meta/lib/oeqa/utils/testexport.py | 265 ------------------------------ 1 file changed, 265 deletions(-) delete mode 100644 meta/lib/oeqa/utils/testexport.py
meta/lib/oeqa/utils/testexport.py deleted +0 -265
@@ -1,265 +0,0 @@ -# -# Copyright (C) 2015 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -# Provides functions to help with exporting binaries obtained from built targets - -import os, re, glob as g, shutil as sh,sys -from time import sleep -from .commands import runCmd -from difflib import SequenceMatcher as SM - -try: - import bb -except ImportError: - class my_log(): - def __init__(self): - pass - def plain(self, msg): - if msg: - print(msg) - def warn(self, msg): - if msg: - print("WARNING: " + msg) - def fatal(self, msg): - if msg: - print("FATAL:" + msg) - sys.exit(1) - bb = my_log() - - -def determine_if_poky_env(): - """ - used to determine if we are inside the poky env or not. Usefull for remote machine where poky is not present - """ - check_env = True if ("/scripts" and "/bitbake/bin") in os.getenv("PATH") else False - return check_env - - -def get_dest_folder(tune_features, folder_list): - """ - Function to determine what rpm deploy dir to choose for a given architecture based on TUNE_FEATURES - """ - features_list = tune_features.split(" ") - features_list.reverse() - features_list = "_".join(features_list) - match_rate = 0 - best_match = None - for folder in folder_list: - curr_match_rate = SM(None, folder, features_list).ratio() - if curr_match_rate > match_rate: - match_rate = curr_match_rate - best_match = folder - return best_match - - -def process_binaries(d, params): - param_list = params - export_env = d.getVar("TEST_EXPORT_ONLY") - - def extract_binary(pth_to_pkg, dest_pth=None): - tar_command = runCmd("which tar") - rpm2archive_command = runCmd("ls /usr/bin/rpm2archive") - if (tar_command.status != 0) and (rpm2archive_command.status != 0): - bb.fatal("Either \"rpm2archive\" or \"tar\" tools are not available on your system." - "All binaries extraction processes will not be available, crashing all related tests." - "Please install them according to your OS recommendations") # will exit here - if dest_pth: - os.chdir(dest_pth) - else: - os.chdir("%s" % os.sep)# this is for native package - extract_bin_command = runCmd("%s -n %s | %s xv" % (rpm2archive_command.output, pth_to_pkg, tar_command.output)) # semi-hardcoded because of a bug on poky's rpm2cpio - return extract_bin_command - - if determine_if_poky_env(): # machine with poky environment - exportpath = d.getVar("TEST_EXPORT_DIR") if export_env else d.getVar("DEPLOY_DIR") - rpm_deploy_dir = d.getVar("DEPLOY_DIR_RPM") - arch = get_dest_folder(d.getVar("TUNE_FEATURES"), os.listdir(rpm_deploy_dir)) - arch_rpm_dir = os.path.join(rpm_deploy_dir, arch) - extracted_bin_dir = os.path.join(exportpath,"binaries", arch, "extracted_binaries") - packaged_bin_dir = os.path.join(exportpath,"binaries", arch, "packaged_binaries") - # creating necessary directory structure in case testing is done in poky env. - if export_env == "0": - if not os.path.exists(extracted_bin_dir): bb.utils.mkdirhier(extracted_bin_dir) - if not os.path.exists(packaged_bin_dir): bb.utils.mkdirhier(packaged_bin_dir) - - if param_list[3] == "native": - if export_env == "1": #this is a native package and we only need to copy it. no need for extraction - native_rpm_dir = os.path.join(rpm_deploy_dir, get_dest_folder("{} nativesdk".format(d.getVar("BUILD_SYS")), os.listdir(rpm_deploy_dir))) - native_rpm_file_list = [item for item in os.listdir(native_rpm_dir) if re.search("nativesdk-" + param_list[0] + "-([0-9]+\.*)", item)] - if not native_rpm_file_list: - bb.warn("Couldn't find any version of {} native package. Related tests will most probably fail.".format(param_list[0])) - return "" - for item in native_rpm_file_list:# will copy all versions of package. Used version will be selected on remote machine - bb.plain("Copying native package file: %s" % item) - sh.copy(os.path.join(rpm_deploy_dir, native_rpm_dir, item), os.path.join(d.getVar("TEST_EXPORT_DIR"), "binaries", "native")) - else: # nothing to do here; running tests under bitbake, so we asume native binaries are in sysroots dir. - if param_list[1] or param_list[4]: - bb.warn("Native binary %s %s%s. Running tests under bitbake environment. Version can't be checked except when the test itself does it" - " and binary can't be removed."%(param_list[0],"has assigned ver. " + param_list[1] if param_list[1] else "", - ", is marked for removal" if param_list[4] else "")) - else:# the package is target aka DUT intended and it is either required to be delivered in an extracted form or in a packaged version - target_rpm_file_list = [item for item in os.listdir(arch_rpm_dir) if re.search(param_list[0] + "-([0-9]+\.*)", item)] - if not target_rpm_file_list: - bb.warn("Couldn't find any version of target package %s. Please ensure it was built. " - "Related tests will probably fail." % param_list[0]) - return "" - if param_list[2] == "rpm": # binary should be deployed as rpm; (other, .deb, .ipk? ; in the near future) - for item in target_rpm_file_list: # copying all related rpm packages. "Intuition" reasons, someone may need other versions too. Deciding later on version - bb.plain("Copying target specific packaged file: %s" % item) - sh.copy(os.path.join(arch_rpm_dir, item), packaged_bin_dir) - return "copied" - else: # it is required to extract the binary - if param_list[1]: # the package is versioned - for item in target_rpm_file_list: - if re.match(".*-{}-.*\.rpm".format(param_list[1]), item): - destination = os.path.join(extracted_bin_dir,param_list[0], param_list[1]) - bb.utils.mkdirhier(destination) - extract_binary(os.path.join(arch_rpm_dir, item), destination) - break - else: - bb.warn("Couldn't find the desired version %s for target binary %s. Related test cases will probably fail." % (param_list[1], param_list[0])) - return "" - return "extracted" - else: # no version provided, just extract one binary - destination = os.path.join(extracted_bin_dir,param_list[0], - re.search(".*-([0-9]+\.[0-9]+)-.*rpm", target_rpm_file_list[0]).group(1)) - bb.utils.mkdirhier(destination) - extract_binary(os.path.join(arch_rpm_dir, target_rpm_file_list[0]), destination) - return "extracted" - else: # remote machine - binaries_path = os.getenv("bin_dir")# in order to know where the binaries are, bin_dir is set as env. variable - if param_list[3] == "native": #need to extract the native pkg here - native_rpm_dir = os.path.join(binaries_path, "native") - native_rpm_file_list = os.listdir(native_rpm_dir) - for item in native_rpm_file_list: - if param_list[1] and re.match("nativesdk-{}-{}-.*\.rpm".format(param_list[0], param_list[1]), item): # native package has version - extract_binary(os.path.join(native_rpm_dir, item)) - break - else:# just copy any related native binary - found_version = re.match("nativesdk-{}-([0-9]+\.[0-9]+)-".format(param_list[0]), item).group(1) - if found_version: - extract_binary(os.path.join(native_rpm_dir, item)) - else: - bb.warn("Couldn't find native package %s%s. Related test cases will be influenced." % - (param_list[0], " with version " + param_list[1] if param_list[1] else "")) - return - - else: # this is for target device - if param_list[2] == "rpm": - return "No need to extract, this is an .rpm file" - arch = get_dest_folder(d.getVar("TUNE_FEATURES"), os.listdir(binaries_path)) - extracted_bin_path = os.path.join(binaries_path, arch, "extracted_binaries") - extracted_bin_list = [item for item in os.listdir(extracted_bin_path)] - packaged_bin_path = os.path.join(binaries_path, arch, "packaged_binaries") - packaged_bin_file_list = os.listdir(packaged_bin_path) - # see if the package is already in the extracted ones; maybe it was deployed when exported the env. - if os.path.exists(os.path.join(extracted_bin_path, param_list[0], param_list[1] if param_list[1] else "")): - return "binary %s is already extracted" % param_list[0] - else: # we need to search for it in the packaged binaries directory. It may have been shipped after export - for item in packaged_bin_file_list: - if param_list[1]: - if re.match("%s-%s.*rpm" % (param_list[0], param_list[1]), item): # package with version - if not os.path.exists(os.path.join(extracted_bin_path, param_list[0],param_list[1])): - os.makedirs(os.path.join(extracted_bin_path, param_list[0], param_list[1])) - extract_binary(os.path.join(packaged_bin_path, item), os.path.join(extracted_bin_path, param_list[0],param_list[1])) - bb.plain("Using {} for {}".format(os.path.join(packaged_bin_path, item), param_list[0])) - break - else: - if re.match("%s-.*rpm" % param_list[0], item): - found_version = re.match(".*-([0-9]+\.[0-9]+)-", item).group(1) - if not os.path.exists(os.path.join(extracted_bin_path, param_list[0], found_version)): - os.makedirs(os.path.join(extracted_bin_path, param_list[0], found_version)) - bb.plain("Used ver. %s for %s" % (found_version, param_list[0])) - extract_binary(os.path.join(packaged_bin_path, item), os.path.join(extracted_bin_path, param_list[0], found_version)) - break - else: - bb.warn("Couldn't find target package %s%s. Please ensure it is available " - "in either of these directories: extracted_binaries or packaged_binaries. " - "Related tests will probably fail." % (param_list[0], " with version " + param_list[1] if param_list[1] else "")) - return - return "Binary %s extracted successfully." % param_list[0] - - -def files_to_copy(base_dir): - """ - Produces a list of files relative to the base dir path sent as param - :return: the list of relative path files - """ - files_list = [] - dir_list = [base_dir] - count = 1 - dir_count = 1 - while (dir_count == 1 or dir_count != count): - count = dir_count - for dir in dir_list: - for item in os.listdir(dir): - if os.path.isdir(os.path.join(dir, item)) and os.path.join(dir, item) not in dir_list: - dir_list.append(os.path.join(dir, item)) - dir_count = len(dir_list) - elif os.path.join(dir, item) not in files_list and os.path.isfile(os.path.join(dir, item)): - files_list.append(os.path.join(dir, item)) - return files_list - - -def send_bin_to_DUT(d,params): - from oeqa.oetest import oeRuntimeTest - param_list = params - cleanup_list = list() - bins_dir = os.path.join(d.getVar("TEST_EXPORT_DIR"), "binaries") if determine_if_poky_env() \ - else os.getenv("bin_dir") - arch = get_dest_folder(d.getVar("TUNE_FEATURES"), os.listdir(bins_dir)) - arch_rpms_dir = os.path.join(bins_dir, arch, "packaged_binaries") - extracted_bin_dir = os.path.join(bins_dir, arch, "extracted_binaries", param_list[0]) - - def send_extracted_binary(): - bin_local_dir = os.path.join(extracted_bin_dir, param_list[1] if param_list[1] else os.listdir(extracted_bin_dir)[0]) - for item in files_to_copy(bin_local_dir): - split_path = item.split(bin_local_dir)[1] - path_on_DUT = split_path if split_path[0] is "/" else "/" + split_path # create the path as on DUT; eg. /usr/bin/bin_file - (status, output) = oeRuntimeTest.tc.target.copy_to(item, path_on_DUT) - if status != 0: - bb.warn("Failed to copy %s binary file %s on the remote target: %s" % - (param_list[0], "ver. " + param_list[1] if param_list[1] else "", d.getVar("MACHINE"))) - return - if param_list[4] == "rm": - cleanup_list.append(path_on_DUT) - return cleanup_list - - def send_rpm(remote_path): # if it is not required to have an extracted binary, but to send an .rpm file - rpm_to_send = "" - for item in os.listdir(arch_rpms_dir): - if param_list[1] and re.match("%s-%s-.*rpm"%(param_list[0], param_list[1]), item): - rpm_to_send = item - break - elif re.match("%s-[0-9]+\.[0-9]+-.*rpm" % param_list[0], item): - rpm_to_send = item - break - else: - bb.warn("No rpm package found for %s %s in .rpm files dir %s. Skipping deployment." % - (param_list[0], "ver. " + param_list[1] if param_list[1] else "", rpms_file_dir) ) - return - (status, output) = oeRuntimeTest.tc.target.copy_to(os.path.join(arch_rpms_dir, rpm_to_send), remote_path) - if status != 0: - bb.warn("Failed to copy %s on the remote target: %s" %(param_list[0], d.getVar("MACHINE"))) - return - if param_list[4] == "rm": - cleanup_list.append(os.path.join(remote_path, rpm_to_send)) - return cleanup_list - - if param_list[2] == "rpm": # send an .rpm file - return send_rpm("/home/root") # rpms will be sent on home dir of remote machine - else: - return send_extracted_binary() - - -def rm_bin(removal_list): # need to know both if the binary is sent archived and the path where it is sent if archived - from oeqa.oetest import oeRuntimeTest - for item in removal_list: - (status,output) = oeRuntimeTest.tc.target.run("rm " + item) - if status != 0: - bb.warn("Failed to remove: %s. Please ensure connection with the target device is up and running and " - "you have the needed rights." % item) -
PATCH 17/41 oeqa/runexported.py: Remove file
In reply to Richard Purdietestexport.bbclass uses scripts/oe-test to execute tests and this script hasn't been updated/used in years. Remove it as we don't need multiple ways to do things.
Fix various comments to match.
--- meta/classes-recipe/testexport.bbclass | 2 +- meta/lib/oeqa/runexported.py | 153 ------------------- meta/lib/oeqa/selftest/cases/runtime_test.py | 4 +- 3 files changed, 2 insertions(+), 157 deletions(-) delete mode 100755 meta/lib/oeqa/runexported.py
meta/classes-recipe/testexport.bbclass +1 -1
@@ -9,7 +9,7 @@ # - First build an image. i.e. core-image-sato # - Add IMAGE_CLASSES += "testexport" in local.conf # - Then bitbake core-image-sato -c testexport. That will generate the directory structure -# to execute the runtime tests using runexported.py. +# to execute the runtime tests using scripts/oe-test. # # For more information on TEST_SUITES check testimage class.
meta/lib/oeqa/runexported.py deleted +0 -153
153 lines not on this page · raw message
meta/lib/oeqa/selftest/cases/runtime_test.py +1 -3
@@ -20,8 +20,7 @@ class TestExport(OESelftestTestCase): """ Summary: Check basic testexport functionality with only ping test enabled. Expected: 1. testexport directory must be created. - 2. runexported.py must run without any error/exception. - 3. ping test must succeed. + 2. ping test must succeed. Product: oe-core Author: Mariano Lopez <[email protected]> """
@@ -44,7 +43,6 @@ class TestExport(OESelftestTestCase): self.assertEqual(True, isdir, 'Failed to create testexport dir: %s' % testexport_dir) with runqemu('core-image-minimal') as qemu: - # Attempt to run runexported.py to perform ping test test_path = os.path.join(testexport_dir, "oe-test") data_file = os.path.join(testexport_dir, 'data', 'testdata.json') manifest = os.path.join(testexport_dir, 'data', 'manifest')
PATCH 18/41 oeqa/oetest.py: Remove
In reply to Richard PurdieNothing uses this any more, it is dead code. Drop it.
--- meta/lib/oeqa/oetest.py | 598 ---------------------------------------- 1 file changed, 598 deletions(-) delete mode 100644 meta/lib/oeqa/oetest.py
meta/lib/oeqa/oetest.py deleted +0 -598
@@ -1,598 +0,0 @@ -# -# Copyright (C) 2013 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -# Main unittest module used by testimage.bbclass -# This provides the oeRuntimeTest base class which is inherited by all tests in meta/lib/oeqa/runtime. - -# It also has some helper functions and it's responsible for actually starting the tests - -import os, re, sys -import unittest -import inspect -import subprocess -import signal -import shutil -import functools -try: - import bb -except ImportError: - pass -import logging - -import oeqa.runtime -# Exported test doesn't require sdkext -try: - import oeqa.sdkext -except ImportError: - pass -from oeqa.utils.decorators import LogResults, gettag - -logger = logging.getLogger("BitBake") - -def getVar(obj): - #extend form dict, if a variable didn't exists, need find it in testcase - class VarDict(dict): - def __getitem__(self, key): - return gettag(obj, key) - return VarDict() - -def checkTags(tc, tagexp): - return eval(tagexp, None, getVar(tc)) - -def filterByTagExp(testsuite, tagexp): - if not tagexp: - return testsuite - caseList = [] - for each in testsuite: - if not isinstance(each, unittest.BaseTestSuite): - if checkTags(each, tagexp): - caseList.append(each) - else: - caseList.append(filterByTagExp(each, tagexp)) - return testsuite.__class__(caseList) - -@LogResults -class oeTest(unittest.TestCase): - - longMessage = True - - @classmethod - def hasPackage(self, pkg): - """ - True if the full package name exists in the manifest, False otherwise. - """ - return pkg in oeTest.tc.pkgmanifest - - @classmethod - def hasPackageMatch(self, match): - """ - True if match exists in the manifest as a regular expression substring, - False otherwise. - """ - for s in oeTest.tc.pkgmanifest: - if re.match(match, s): - return True - return False - - @classmethod - def hasFeature(self,feature): - if feature in oeTest.tc.imagefeatures or \ - feature in oeTest.tc.distrofeatures: - return True - else: - return False - -class oeRuntimeTest(oeTest): - def __init__(self, methodName='runTest'): - self.target = oeRuntimeTest.tc.target - super().__init__(methodName) - - def setUp(self): - # Install packages in the DUT - self.tc.install_uninstall_packages(self.id()) - - # Check if test needs to run - if self.tc.sigterm: - self.fail("Got SIGTERM") - elif (type(self.target).__name__ == "QemuTarget"): - self.assertTrue(self.target.check(), msg = "Qemu not running?") - - self.setUpLocal() - - # a setup method before tests but after the class instantiation - def setUpLocal(self): - pass - - def tearDown(self): - # Uninstall packages in the DUT - self.tc.install_uninstall_packages(self.id(), False) - self.tearDownLocal() - - # Method to be run after tearDown and implemented by child classes - def tearDownLocal(self): - pass - -def getmodule(pos=2): - # stack returns a list of tuples containg frame information - # First element of the list the is current frame, caller is 1 - frameinfo = inspect.stack()[pos] - modname = inspect.getmodulename(frameinfo[1]) - #modname = inspect.getmodule(frameinfo[0]).__name__ - return modname - -def skipModule(reason, pos=2): - modname = getmodule(pos) - if modname not in oeTest.tc.testsrequired: - raise unittest.SkipTest("%s: %s" % (modname, reason)) - else: - raise Exception("\nTest %s wants to be skipped.\nReason is: %s" \ - "\nTest was required in TEST_SUITES, so either the condition for skipping is wrong" \ - "\nor the image really doesn't have the required feature/package when it should." % (modname, reason)) - -def skipModuleIf(cond, reason): - - if cond: - skipModule(reason, 3) - -def skipModuleUnless(cond, reason): - - if not cond: - skipModule(reason, 3) - -_buffer_logger = "" -def custom_verbose(msg, *args, **kwargs): - global _buffer_logger - if msg[-1] != "\n": - _buffer_logger += msg - else: - _buffer_logger += msg - try: - bb.plain(_buffer_logger.rstrip("\n"), *args, **kwargs) - except NameError: - logger.info(_buffer_logger.rstrip("\n"), *args, **kwargs) - _buffer_logger = "" - -class TestContext: - def __init__(self, d, exported=False): - self.d = d - - self.testsuites = self._get_test_suites() - - if exported: - path = [os.path.dirname(os.path.abspath(__file__))] - extrapath = "" - else: - path = d.getVar("BBPATH").split(':') - extrapath = "lib/oeqa" - - self.testslist = self._get_tests_list(path, extrapath) - self.testsrequired = self._get_test_suites_required() - - self.filesdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "runtime/files") - self.corefilesdir = os.path.join(os.path.dirname(os.path.abspath(__file__)), "files") - self.imagefeatures = d.getVar("IMAGE_FEATURES").split() - self.distrofeatures = d.getVar("DISTRO_FEATURES").split() - - # get testcase list from specified file - # if path is a relative path, then relative to build/conf/ - def _read_testlist(self, fpath, builddir): - if not os.path.isabs(fpath): - fpath = os.path.join(builddir, "conf", fpath) - if not os.path.exists(fpath): - bb.fatal("No such manifest file: ", fpath) - tcs = [] - for line in open(fpath).readlines(): - line = line.strip() - if line and not line.startswith("#"): - tcs.append(line) - return " ".join(tcs) - - # return test list by type also filter if TEST_SUITES is specified - def _get_tests_list(self, bbpath, extrapath): - testslist = [] - - type = self._get_test_namespace() - - # This relies on lib/ under each directory in BBPATH being added to sys.path - # (as done by default in base.bbclass) - for testname in self.testsuites: - if testname != "auto": - if testname.startswith("oeqa."): - testslist.append(testname) - continue - found = False - for p in bbpath: - if os.path.exists(os.path.join(p, extrapath, type, testname + ".py")): - testslist.append("oeqa." + type + "." + testname) - found = True - break - elif os.path.exists(os.path.join(p, extrapath, type, testname.split(".")[0] + ".py")): - testslist.append("oeqa." + type + "." + testname) - found = True - break - if not found: - bb.fatal('Test %s specified in TEST_SUITES could not be found in lib/oeqa/runtime under BBPATH' % testname) - - if "auto" in self.testsuites: - def add_auto_list(path): - files = sorted([f for f in os.listdir(path) if f.endswith('.py') and not f.startswith('_')]) - for f in files: - module = 'oeqa.' + type + '.' + f[:-3] - if module not in testslist: - testslist.append(module) - - for p in bbpath: - testpath = os.path.join(p, 'lib', 'oeqa', type) - bb.debug(2, 'Searching for tests in %s' % testpath) - if os.path.exists(testpath): - add_auto_list(testpath) - - return testslist - - def getTestModules(self): - """ - Returns all the test modules in the testlist. - """ - - import pkgutil - - modules = [] - for test in self.testslist: - if re.search(r"\w+\.\w+\.test_\S+", test): - test = '.'.join(t.split('.')[:3]) - module = pkgutil.get_loader(test) - modules.append(module) - - return modules - - def getModulefromID(self, test_id): - """ - Returns the test module based on a test id. - """ - - module_name = ".".join(test_id.split(".")[:3]) - modules = self.getTestModules() - for module in modules: - if module.name == module_name: - return module - - return None - - def getTests(self, test): - '''Return all individual tests executed when running the suite.''' - # Unfortunately unittest does not have an API for this, so we have - # to rely on implementation details. This only needs to work - # for TestSuite containing TestCase. - method = getattr(test, '_testMethodName', None) - if method: - # leaf case: a TestCase - yield test - else: - # Look into TestSuite. - tests = getattr(test, '_tests', []) - for t1 in tests: - for t2 in self.getTests(t1): - yield t2 - - def loadTests(self): - setattr(oeTest, "tc", self) - - testloader = unittest.TestLoader() - testloader.sortTestMethodsUsing = None - suites = [testloader.loadTestsFromName(name) for name in self.testslist] - suites = filterByTagExp(suites, getattr(self, "tagexp", None)) - - # Determine dependencies between suites by looking for @skipUnlessPassed - # method annotations. Suite A depends on suite B if any method in A - # depends on a method on B. - for suite in suites: - suite.dependencies = [] - suite.depth = 0 - for test in self.getTests(suite): - methodname = getattr(test, '_testMethodName', None) - if methodname: - method = getattr(test, methodname) - depends_on = getattr(method, '_depends_on', None) - if depends_on: - for dep_suite in suites: - if depends_on in [getattr(t, '_testMethodName', None) for t in self.getTests(dep_suite)]: - if dep_suite not in suite.dependencies and \ - dep_suite is not suite: - suite.dependencies.append(dep_suite) - break - else: - logger.warning("Test %s was declared as @skipUnlessPassed('%s') but that test is either not defined or not active. Will run the test anyway." % - (test, depends_on)) - - # Use brute-force topological sort to determine ordering. Sort by - # depth (higher depth = must run later), with original ordering to - # break ties. - def set_suite_depth(suite): - for dep in suite.dependencies: - new_depth = set_suite_depth(dep) + 1 - if new_depth > suite.depth: - suite.depth = new_depth - return suite.depth - - for index, suite in enumerate(suites): - set_suite_depth(suite) - suite.index = index - - def cmp(a, b): - return (a > b) - (a < b) - - def cmpfunc(a, b): - return cmp((a.depth, a.index), (b.depth, b.index)) - - suites.sort(key=functools.cmp_to_key(cmpfunc)) - - self.suite = testloader.suiteClass(suites) - - return self.suite - - def runTests(self): - logger.info("Test modules %s" % self.testslist) - if hasattr(self, "tagexp") and self.tagexp: - logger.info("Filter test cases by tags: %s" % self.tagexp) - logger.info("Found %s tests" % self.suite.countTestCases()) - runner = unittest.TextTestRunner(verbosity=2) - if 'bb' in sys.modules: - runner.stream.write = custom_verbose - - return runner.run(self.suite) - -class RuntimeTestContext(TestContext): - def __init__(self, d, target, exported=False): - super().__init__(d, exported) - - self.target = target - - self.pkgmanifest = {} - manifest = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), - d.getVar("IMAGE_LINK_NAME") + ".manifest") - nomanifest = d.getVar("IMAGE_NO_MANIFEST") - if nomanifest is None or nomanifest != "1": - try: - with open(manifest) as f: - for line in f: - (pkg, arch, version) = line.strip().split() - self.pkgmanifest[pkg] = (version, arch) - except OSError as e: - bb.fatal("No package manifest file found. Did you build the image?\n%s" % e) - - def _get_test_namespace(self): - return "runtime" - - def _get_test_suites(self): - testsuites = [] - - manifests = (self.d.getVar("TEST_SUITES_MANIFEST") or '').split() - if manifests: - for manifest in manifests: - testsuites.extend(self._read_testlist(manifest, - self.d.getVar("TOPDIR")).split()) - - else: - testsuites = self.d.getVar("TEST_SUITES").split() - - return testsuites - - def _get_test_suites_required(self): - return [t for t in self.d.getVar("TEST_SUITES").split() if t != "auto"] - - def extract_packages(self): - """ - Find packages that will be needed during runtime. - """ - - modules = self.getTestModules() - bbpaths = self.d.getVar("BBPATH").split(":") - - shutil.rmtree(self.d.getVar("TEST_EXTRACTED_DIR")) - shutil.rmtree(self.d.getVar("TEST_PACKAGED_DIR")) - for module in modules: - json_file = self._getJsonFile(module) - if json_file: - needed_packages = self._getNeededPackages(json_file) - self._perform_package_extraction(needed_packages) - - def _perform_package_extraction(self, needed_packages): - """ - Extract packages that will be needed during runtime. - """ - - import oe.path - - extracted_path = self.d.getVar("TEST_EXTRACTED_DIR") - packaged_path = self.d.getVar("TEST_PACKAGED_DIR") - - for key,value in needed_packages.items(): - packages = () - if isinstance(value, dict): - packages = (value, ) - elif isinstance(value, list): - packages = value - else: - bb.fatal("Failed to process needed packages for %s; " - "Value must be a dict or list" % key) - - for package in packages: - pkg = package["pkg"] - rm = package.get("rm", False) - extract = package.get("extract", True) - if extract: - dst_dir = os.path.join(extracted_path, pkg) - else: - dst_dir = os.path.join(packaged_path) - - # Extract package and copy it to TEST_EXTRACTED_DIR - pkg_dir = self._extract_in_tmpdir(pkg) - if extract: - - # Same package used for more than one test, - # don't need to extract again. - if os.path.exists(dst_dir): - continue - oe.path.copytree(pkg_dir, dst_dir) - shutil.rmtree(pkg_dir) - - # Copy package to TEST_PACKAGED_DIR - else: - self._copy_package(pkg) - - def _getJsonFile(self, module): - """ - Returns the path of the JSON file for a module, empty if doesn't exitst. - """ - - module_file = module.path - json_file = "%s.json" % module_file.rsplit(".", 1)[0] - if os.path.isfile(module_file) and os.path.isfile(json_file): - return json_file - else: - return "" - - def _getNeededPackages(self, json_file, test=None): - """ - Returns a dict with needed packages based on a JSON file. - - - If a test is specified it will return the dict just for that test. - """ - - import json - - needed_packages = {} - - with open(json_file) as f: - test_packages = json.load(f) - for key,value in test_packages.items(): - needed_packages[key] = value - - if test: - if test in needed_packages: - needed_packages = needed_packages[test] - else: - needed_packages = {} - - return needed_packages - - def _extract_in_tmpdir(self, pkg): - """" - Returns path to a temp directory where the package was - extracted without dependencies. - """ - - from oeqa.utils.package_manager import get_package_manager - - pkg_path = os.path.join(self.d.getVar("TEST_INSTALL_TMP_DIR"), pkg) - pm = get_package_manager(self.d, pkg_path) - extract_dir = pm.extract(pkg) - shutil.rmtree(pkg_path) - - return extract_dir - - def _copy_package(self, pkg): - """ - Copy the RPM, DEB or IPK package to dst_dir - """ - - from oeqa.utils.package_manager import get_package_manager - - pkg_path = os.path.join(self.d.getVar("TEST_INSTALL_TMP_DIR"), pkg) - dst_dir = self.d.getVar("TEST_PACKAGED_DIR") - pm = get_package_manager(self.d, pkg_path) - pkg_info = pm.package_info(pkg) - file_path = pkg_info[pkg]["filepath"] - shutil.copy2(file_path, dst_dir) - shutil.rmtree(pkg_path) - - def install_uninstall_packages(self, test_id, pkg_dir, install): - """ - Check if the test requires a package and Install/Uninstall it in the DUT - """ - - test = test_id.split(".")[4] - module = self.getModulefromID(test_id) - json = self._getJsonFile(module) - if json: - needed_packages = self._getNeededPackages(json, test) - if needed_packages: - self._install_uninstall_packages(needed_packages, pkg_dir, install) - - def _install_uninstall_packages(self, needed_packages, pkg_dir, install=True): - """ - Install/Uninstall packages in the DUT without using a package manager - """ - - if isinstance(needed_packages, dict): - packages = [needed_packages] - elif isinstance(needed_packages, list): - packages = needed_packages - - for package in packages: - pkg = package["pkg"] - rm = package.get("rm", False) - extract = package.get("extract", True) - src_dir = os.path.join(pkg_dir, pkg) - - # Install package - if install and extract: - self.target.connection.copy_dir_to(src_dir, "/") - - # Uninstall package - elif not install and rm: - self.target.connection.delete_dir_structure(src_dir, "/") - -class ImageTestContext(RuntimeTestContext): - def __init__(self, d, target, host_dumper): - super().__init__(d, target) - - self.tagexp = d.getVar("TEST_SUITES_TAGS") - - self.host_dumper = host_dumper - - self.sigterm = False - self.origsigtermhandler = signal.getsignal(signal.SIGTERM) - signal.signal(signal.SIGTERM, self._sigterm_exception) - - def _sigterm_exception(self, signum, stackframe): - bb.warn("TestImage received SIGTERM, shutting down...") - self.sigterm = True - self.target.stop() - - def install_uninstall_packages(self, test_id, install=True): - """ - Check if the test requires a package and Install/Uninstall it in the DUT - """ - - pkg_dir = self.d.getVar("TEST_EXTRACTED_DIR") - super().install_uninstall_packages(test_id, pkg_dir, install) - -class ExportTestContext(RuntimeTestContext): - def __init__(self, d, target, exported=False, parsedArgs={}): - """ - This class is used when exporting tests and when are executed outside OE environment. - - parsedArgs can contain the following: - - tag: Filter test by tag. - """ - super().__init__(d, target, exported) - - tag = parsedArgs.get("tag", None) - self.tagexp = tag if tag is not None else d.getVar("TEST_SUITES_TAGS") - - self.sigterm = None - - def install_uninstall_packages(self, test_id, install=True): - """ - Check if the test requires a package and Install/Uninstall it in the DUT - """ - - export_dir = os.path.dirname(os.path.dirname(os.path.realpath(__file__))) - extracted_dir = self.d.getVar("TEST_EXPORT_EXTRACTED_DIR") - pkg_dir = os.path.join(export_dir, extracted_dir) - super().install_uninstall_packages(test_id, pkg_dir, install)
PATCH 19/41 oeqa/lib/utils/decorators.py: Remove
In reply to Richard PurdieThis was only used by oetest.py which has been removed. Drop it. It was replaced by core/decorator/.
--- meta/lib/oeqa/utils/decorators.py | 212 ------------------------------ 1 file changed, 212 deletions(-) delete mode 100644 meta/lib/oeqa/utils/decorators.py
meta/lib/oeqa/utils/decorators.py deleted +0 -212
@@ -1,212 +0,0 @@ -# -# Copyright (C) 2013 Intel Corporation -# -# SPDX-License-Identifier: MIT -# - -# Some custom decorators that can be used by unittests -# Most useful is skipUnlessPassed which can be used for -# creating dependecies between two test methods. - -import os -import logging -import sys -import unittest -import threading -import signal -from functools import wraps - -class testcase: - def __init__(self, test_case): - self.test_case = test_case - - def __call__(self, func): - @wraps(func) - def wrapped_f(*args, **kwargs): - return func(*args, **kwargs) - wrapped_f.test_case = self.test_case - wrapped_f.__name__ = func.__name__ - return wrapped_f - -class NoParsingFilter(logging.Filter): - def filter(self, record): - return record.levelno == 100 - -import inspect - -def LogResults(original_class): - orig_method = original_class.run - - from time import strftime, gmtime - caller = os.path.basename(sys.argv[0]) - timestamp = strftime('%Y%m%d%H%M%S',gmtime()) - logfile = os.path.join(os.getcwd(),'results-'+caller+'.'+timestamp+'.log') - linkfile = os.path.join(os.getcwd(),'results-'+caller+'.log') - - def get_class_that_defined_method(meth): - if inspect.ismethod(meth): - for cls in inspect.getmro(meth.__self__.__class__): - if cls.__dict__.get(meth.__name__) is meth: - return cls - meth = meth.__func__ # fallback to __qualname__ parsing - if inspect.isfunction(meth): - cls = getattr(inspect.getmodule(meth), - meth.__qualname__.split('.<locals>', 1)[0].rsplit('.', 1)[0]) - if isinstance(cls, type): - return cls - return None - - #rewrite the run method of unittest.TestCase to add testcase logging - def run(self, result, *args, **kws): - orig_method(self, result, *args, **kws) - passed = True - testMethod = getattr(self, self._testMethodName) - #if test case is decorated then use it's number, else use it's name - try: - test_case = testMethod.test_case - except AttributeError: - test_case = self._testMethodName - - class_name = str(get_class_that_defined_method(testMethod)).split("'")[1] - - #create custom logging level for filtering. - custom_log_level = 100 - logging.addLevelName(custom_log_level, 'RESULTS') - - def results(self, message, *args, **kws): - if self.isEnabledFor(custom_log_level): - self.log(custom_log_level, message, *args, **kws) - logging.Logger.results = results - - logging.basicConfig(filename=logfile, - filemode='w', - format='%(asctime)s - %(name)s - %(levelname)s - %(message)s', - datefmt='%H:%M:%S', - level=custom_log_level) - for handler in logging.root.handlers: - handler.addFilter(NoParsingFilter()) - local_log = logging.getLogger(caller) - - #check status of tests and record it - - tcid = self.id() - for (name, msg) in result.errors: - if tcid == name.id(): - local_log.results("Testcase "+str(test_case)+": ERROR") - local_log.results("Testcase "+str(test_case)+":\n"+msg) - passed = False - for (name, msg) in result.failures: - if tcid == name.id(): - local_log.results("Testcase "+str(test_case)+": FAILED") - local_log.results("Testcase "+str(test_case)+":\n"+msg) - passed = False - for (name, msg) in result.skipped: - if tcid == name.id(): - local_log.results("Testcase "+str(test_case)+": SKIPPED") - passed = False - if passed: - local_log.results("Testcase "+str(test_case)+": PASSED") - - # XXX: In order to avoid race condition when test if exists the linkfile - # use bb.utils.lock, the best solution is to create a unique name for the - # link file. - try: - import bb - has_bb = True - lockfilename = linkfile + '.lock' - except ImportError: - has_bb = False - - if has_bb: - lf = bb.utils.lockfile(lockfilename, block=True) - # Create symlink to the current log - if os.path.lexists(linkfile): - os.remove(linkfile) - os.symlink(logfile, linkfile) - if has_bb: - bb.utils.unlockfile(lf) - - original_class.run = run - - return original_class - -class TimeOut(BaseException): - pass - -def timeout(seconds): - def decorator(fn): - if hasattr(signal, 'alarm'): - @wraps(fn) - def wrapped_f(*args, **kw): - current_frame = sys._getframe() - def raiseTimeOut(signal, frame): - if frame is not current_frame: - raise TimeOut('%s seconds' % seconds) - prev_handler = signal.signal(signal.SIGALRM, raiseTimeOut) - try: - signal.alarm(seconds) - return fn(*args, **kw) - finally: - signal.alarm(0) - signal.signal(signal.SIGALRM, prev_handler) - return wrapped_f - else: - return fn - return decorator - -__tag_prefix = "tag__" -def tag(*args, **kwargs): - """Decorator that adds attributes to classes or functions - for use with the Attribute (-a) plugin. - """ - def wrap_ob(ob): - for name in args: - setattr(ob, __tag_prefix + name, True) - for name, value in kwargs.items(): - setattr(ob, __tag_prefix + name, value) - return ob - return wrap_ob - -def gettag(obj, key, default=None): - key = __tag_prefix + key - if not isinstance(obj, unittest.TestCase): - return getattr(obj, key, default) - tc_method = getattr(obj, obj._testMethodName) - ret = getattr(tc_method, key, getattr(obj, key, default)) - return ret - -def getAllTags(obj): - def __gettags(o): - r = {k[len(__tag_prefix):]:getattr(o,k) for k in dir(o) if k.startswith(__tag_prefix)} - return r - if not isinstance(obj, unittest.TestCase): - return __gettags(obj) - tc_method = getattr(obj, obj._testMethodName) - ret = __gettags(obj) - ret.update(__gettags(tc_method)) - return ret - -def timeout_handler(seconds): - def decorator(fn): - if hasattr(signal, 'alarm'): - @wraps(fn) - def wrapped_f(self, *args, **kw): - current_frame = sys._getframe() - def raiseTimeOut(signal, frame): - if frame is not current_frame: - try: - self.target.restart() - raise TimeOut('%s seconds' % seconds) - except: - raise TimeOut('%s seconds' % seconds) - prev_handler = signal.signal(signal.SIGALRM, raiseTimeOut) - try: - signal.alarm(seconds) - return fn(self, *args, **kw) - finally: - signal.alarm(0) - signal.signal(signal.SIGALRM, prev_handler) - return wrapped_f - else: - return fn - return decorator
PATCH 20/41 oeqa/targetcontrol: Drop SimpleRemoteTarget
In reply to Richard PurdieThis code is unused. The "simpleremote" type connects directly over ssh and doesn't need this code so we can remove it as obsolete.
--- meta/lib/oeqa/targetcontrol.py | 32 -------------------------------- 1 file changed, 32 deletions(-)
meta/lib/oeqa/targetcontrol.py +0 -32
@@ -223,35 +223,3 @@ class QemuTarget(BaseTarget): def run_serial(self, command, timeout=60): return self.runner.run_serial(command, timeout=timeout) - - -class SimpleRemoteTarget(BaseTarget): - - def __init__(self, d): - super().__init__(d) - addr = d.getVar("TEST_TARGET_IP") or bb.fatal('Please set TEST_TARGET_IP with the IP address of the machine you want to run the tests on.') - self.ip = addr.split(":")[0] - try: - self.port = addr.split(":")[1] - except IndexError: - self.port = None - self.logger.info("Target IP: %s" % self.ip) - self.server_ip = d.getVar("TEST_SERVER_IP") - if not self.server_ip: - try: - self.server_ip = subprocess.check_output(['ip', 'route', 'get', self.ip ]).split("\n")[0].split()[-1] - except Exception as e: - bb.fatal("Failed to determine the host IP address (alternatively you can set TEST_SERVER_IP with the IP address of this machine): %s" % e) - self.logger.info("Server IP: %s" % self.server_ip) - - def deploy(self): - super().deploy() - - def start(self, params=None, ssh=True, extra_bootparams=None): - if ssh: - self.connection = SSHControl(self.ip, logfile=self.sshlog, port=self.port) - - def stop(self): - self.connection = None - self.ip = None - self.server_ip = None
PATCH 21/41 oeqa/core/target/ssh: Fix TimeoutExpired reference
In reply to Richard PurdieTimeoutExpired was never imported so if the ssh process failed to exit after 5 seconds, the cleanup code raised a NameError instead of killing the process.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/target/ssh.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/lib/oeqa/core/target/ssh.py +1 -1
@@ -296,7 +296,7 @@ def SSHCall(command, logger, timeout=None, raw=False, **opts): if process.returncode is None: try: process.wait(timeout=5) - except TimeoutExpired: + except subprocess.TimeoutExpired: try: process.kill() except OSError:
PATCH 22/41 oeqa/runtime/ltp: Share a single base class and fix tearDownClass failures
In reply to Richard Purdieltp.py, ltp_stress.py and ltp_compliance.py each carried a copy of the same setup/teardown base class, differing only in the log directory and result names. Move it to oeqa/runtime/utils/ltp.py and set the names as class attributes.
The teardown called cls.fail() from a classmethod, which passes the message as self and raises "AttributeError: 'str' object has no attribute 'failureException'" instead of reporting the failed LTP groups. Raise cls.failureException directly.
Also import os explicitly rather than relying on it being available as a builtin.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/runtime/cases/ltp.py | 47 ++------------- meta/lib/oeqa/runtime/cases/ltp_compliance.py | 49 ++------------- meta/lib/oeqa/runtime/cases/ltp_stress.py | 50 ++-------------- meta/lib/oeqa/runtime/utils/ltp.py | 59 +++++++++++++++++++ 4 files changed, 73 insertions(+), 132 deletions(-) create mode 100644 meta/lib/oeqa/runtime/utils/ltp.py
meta/lib/oeqa/runtime/cases/ltp.py +4 -43
@@ -5,57 +5,18 @@ # SPDX-License-Identifier: GPL-2.0-only # +import os import time -import datetime import pprint -from oeqa.runtime.case import OERuntimeTestCase +from oeqa.runtime.utils.ltp import LtpTestBase from oeqa.core.decorator.depends import OETestDepends from oeqa.runtime.decorator.package import OEHasPackage from oeqa.utils.logparser import LtpParser -class LtpTestBase(OERuntimeTestCase): - - @classmethod - def setUpClass(cls): - cls.ltp_startup() - - @classmethod - def tearDownClass(cls): - cls.ltp_finishup() - - @classmethod - def ltp_startup(cls): - cls.sections = {} - cls.failmsg = "" - test_log_dir = os.path.join(cls.td.get('WORKDIR', ''), 'testimage') - timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S') - - cls.ltptest_log_dir_link = os.path.join(test_log_dir, 'ltp_log') - cls.ltptest_log_dir = '%s.%s' % (cls.ltptest_log_dir_link, timestamp) - os.makedirs(cls.ltptest_log_dir) - - cls.tc.target.run("mkdir -p /opt/ltp/results") - - if not hasattr(cls.tc, "extraresults"): - cls.tc.extraresults = {} - cls.extras = cls.tc.extraresults - cls.extras['ltpresult.rawlogs'] = {'log': ""} - - - @classmethod - def ltp_finishup(cls): - cls.extras['ltpresult.sections'] = cls.sections - - # update symlink to ltp_log - if os.path.exists(cls.ltptest_log_dir_link): - os.remove(cls.ltptest_log_dir_link) - os.symlink(os.path.basename(cls.ltptest_log_dir), cls.ltptest_log_dir_link) - - if cls.failmsg: - cls.fail(cls.failmsg) - class LtpTest(LtpTestBase): + ltp_log_name = 'ltp_log' + ltp_result_prefix = 'ltpresult' ltp_groups = ["math", "syscalls", "dio", "mm", "sched", "nptl", "containers", "controllers", "fcntl-locktests", "commands", "net.ipv6_lib", "input","fs_perms_simple", "cve", "crypto", "ima", "net.nfs", "net_stress.ipsec_icmp", "net.ipv6", "numa", "uevent", "ltp-aiodio.part1", "ltp-aiodio.part2", "ltp-aiodio.part3", "ltp-aiodio.part4"]
meta/lib/oeqa/runtime/cases/ltp_compliance.py +5 -44
63 lines not on this page · raw message
meta/lib/oeqa/runtime/cases/ltp_stress.py +5 -45
64 lines not on this page · raw message
meta/lib/oeqa/runtime/utils/ltp.py new file +59 -0
59 lines not on this page · raw message
PATCH 23/41 oeqa/selftest/oelib/buildhistory: Fix variable removal in commit_vars()
In reply to Richard PurdieThe loop over to_remove popped the undefined name 'x' rather than the loop variable so passing to_remove would raise a NameError. No current caller passes it but fix it so the helper works as intended.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/selftest/cases/oelib/buildhistory.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
meta/lib/oeqa/selftest/cases/oelib/buildhistory.py +1 -1
@@ -45,7 +45,7 @@ class TestBlobParsing(OESelftestTestCase): return for k in to_remove: - self.var_map.pop(x,None) + self.var_map.pop(k, None) for k in to_add: self.var_map[k] = to_add[k]
PATCH 24/41 oeqa: Remove unused code
In reply to Richard PurdieDrop code nothing uses:
- utils/targetbuild.py, an older copy of the BuildProject classes which are now in utils/buildproject.py, runtime/utils and sdk/utils
- str_to_fn() in buildperf, which also always raised ValueError as re.LOCALE can't be used with str patterns
- the dummybuf class in concurrencytest
- getCaseClass() in core/utils/test.py
- the empty metadata_from_data_store() stub
- an unused variable in sdk/context.py and an unused assignment in the OETestDataDepends check
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/buildperf/base.py | 5 - meta/lib/oeqa/core/decorator/data.py | 4 +- meta/lib/oeqa/core/utils/concurrencytest.py | 11 -- meta/lib/oeqa/core/utils/test.py | 6 - meta/lib/oeqa/sdk/context.py | 1 - meta/lib/oeqa/utils/metadata.py | 9 -- meta/lib/oeqa/utils/targetbuild.py | 144 -------------------- 7 files changed, 1 insertion(+), 179 deletions(-) delete mode 100644 meta/lib/oeqa/utils/targetbuild.py
meta/lib/oeqa/buildperf/base.py +0 -5
@@ -65,11 +65,6 @@ class KernelDropCaches: runCmd2(cmd, data=input_data) -def str_to_fn(string): - """Convert string to a sanitized filename""" - return re.sub(r'(\W+)', '-', string, flags=re.LOCALE) - - class ResultsJsonEncoder(json.JSONEncoder): """Extended encoder for build perf test results""" unix_epoch = datetime.utcfromtimestamp(0)
meta/lib/oeqa/core/decorator/data.py +1 -3
@@ -99,9 +99,7 @@ class OETestDataDepends(OETestDecorator): def setUpDecorator(self): for v in self.td_depends: - try: - value = self.case.td[v] - except KeyError: + if v not in self.case.td: raise OEQAMissingVariable("Test case need %s variable but"\ " isn't into td" % v)
meta/lib/oeqa/core/utils/concurrencytest.py +0 -11
@@ -198,17 +198,6 @@ def outSideTestaddSkip(self, offset, line): subunit._OutSideTest.addSkip = outSideTestaddSkip -# -# A dummy structure to add to io.StringIO so that the .buffer object -# is available and accepts writes. This allows unittest with buffer=True -# to interact ok with subunit which wants to access sys.stdout.buffer. -# -class dummybuf: - def __init__(self, parent): - self.p = parent - def write(self, data): - self.p.write(data.decode("utf-8")) - # # Taken from testtools.ConncurrencyTestSuite but modified for OE use #
meta/lib/oeqa/core/utils/test.py +0 -6
@@ -64,12 +64,6 @@ def getCaseModule(test_case): """ return test_case.__module__ -def getCaseClass(test_case): - """ - Returns test case class name. - """ - return test_case.__class__.__name__ - def getCaseID(test_case): """ Returns test case complete id.
meta/lib/oeqa/sdk/context.py +0 -1
@@ -113,7 +113,6 @@ class OESDKTestContextExecutor(OETestContextExecutor): def _get_sdk_environs(sdk_dir): sdk_env = {} - environ_pattern = sdk_dir + '/environment-setup-*' full_sdk_env = glob.glob(sdk_dir + '/environment-setup-*') for env in full_sdk_env: m = re.search('environment-setup-(.*)', env)
meta/lib/oeqa/utils/metadata.py +0 -9
@@ -50,15 +50,6 @@ def metadata_from_bb(): info_dict['config'][var] = data_dict[var] return info_dict -def metadata_from_data_store(d): - """ Returns test's metadata as OrderedDict. - - Data will be collected from the provided data store. - """ - # TODO: Getting metadata from the data store would - # be useful when running within bitbake. - pass - def git_rev_info(path): """Get git revision information as a dict""" info = OrderedDict()
meta/lib/oeqa/utils/targetbuild.py deleted +0 -144
144 lines not on this page · raw message
PATCH 25/41 oeqa/core/loader: Simplify the _make_failed_test override
In reply to Richard PurdieWe now require python 3.9 or later so we can drop the python 3.4 era compatibility code.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/loader.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-)
meta/lib/oeqa/core/loader.py +2 -7
@@ -8,7 +8,6 @@ import os import re import sys import unittest -import inspect from oeqa.core.utils.path import findFile from oeqa.core.utils.test import getSuiteModules, getCaseID
@@ -23,12 +22,8 @@ from oeqa.core.decorator import decoratorClasses, OETestDecorator, \ # # For our purposes, it is better to raise the exceptions in the loading # step rather than waiting to run the test suite. -# -# Generate the function definition because this differ across python versions -# Python >= 3.4.4 uses tree parameters instead four but for example Python 3.5.3 -# ueses four parameters so isn't incremental. -_failed_test_args = inspect.getfullargspec(unittest.loader._make_failed_test).args -exec("""def _make_failed_test(%s): raise exception""" % ', '.join(_failed_test_args)) +def _make_failed_test(methodname, exception, *args, **kwargs): + raise exception unittest.loader._make_failed_test = _make_failed_test def _find_duplicated_modules(suite, directory):
PATCH 26/41 oeqa: Remove unused imports
In reply to Richard PurdieDrop imports which nothing in the module uses.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/buildperf/base.py | 1 - meta/lib/oeqa/core/loader.py | 1 - meta/lib/oeqa/core/target/qemu.py | 4 ---- meta/lib/oeqa/core/target/ssh.py | 1 - meta/lib/oeqa/core/utils/concurrencytest.py | 1 - meta/lib/oeqa/core/utils/path.py | 1 - meta/lib/oeqa/core/utils/test.py | 1 - meta/lib/oeqa/sdk/testsdk.py | 2 -- meta/lib/oeqa/sdkext/testsdk.py | 2 +- meta/lib/oeqa/selftest/cases/usergrouptests.py | 1 - meta/lib/oeqa/selftest/context.py | 3 --- meta/lib/oeqa/utils/commands.py | 1 - meta/lib/oeqa/utils/ftools.py | 2 -- meta/lib/oeqa/utils/httpserver.py | 2 +- meta/lib/oeqa/utils/nfs.py | 2 -- meta/lib/oeqa/utils/postactions.py | 2 -- meta/lib/oeqa/utils/qemurunner.py | 1 - 17 files changed, 2 insertions(+), 26 deletions(-)
meta/lib/oeqa/buildperf/base.py +0 -1
@@ -22,7 +22,6 @@ from xml.dom import minidom import oe.path from oeqa.utils.commands import CommandError, runCmd, get_bb_vars -from oeqa.utils.git import GitError, GitRepo # Get logger for this module log = logging.getLogger('build-perf')
meta/lib/oeqa/core/loader.py +0 -1
@@ -4,7 +4,6 @@ # SPDX-License-Identifier: MIT # -import os import re import sys import unittest
meta/lib/oeqa/core/target/qemu.py +0 -4
@@ -4,10 +4,6 @@ # SPDX-License-Identifier: MIT # -import os -import sys -import signal -import time import glob import subprocess from collections import defaultdict
meta/lib/oeqa/core/target/ssh.py +0 -1
@@ -9,7 +9,6 @@ import time import select import logging import subprocess -import codecs from . import OETarget
meta/lib/oeqa/core/utils/concurrencytest.py +0 -1
@@ -18,7 +18,6 @@ import os import sys import traceback import unittest -import subprocess import testtools import threading import time
meta/lib/oeqa/core/utils/path.py +0 -1
@@ -5,7 +5,6 @@ # import os -import sys def findFile(file_name, directory): """
meta/lib/oeqa/core/utils/test.py +0 -1
@@ -4,7 +4,6 @@ # SPDX-License-Identifier: MIT # -import os import inspect import unittest
meta/lib/oeqa/sdk/testsdk.py +0 -2
@@ -9,7 +9,6 @@ from oeqa.sdk.context import OESDKTestContext, OESDKTestContextExecutor class TestSDKBase: @staticmethod def get_sdk_configuration(d, test_type): - import platform import oe.lsb from oeqa.utils.metadata import get_layers configuration = {'TEST_TYPE': test_type,
@@ -80,7 +79,6 @@ class TestSDK(TestSDKBase): def run(self, d): import os - import subprocess import json import logging
meta/lib/oeqa/sdkext/testsdk.py +1 -1
@@ -14,7 +14,7 @@ class TestSDKExt(TestSDKBase): import logging from bb.utils import export_proxies - from oeqa.utils import avoid_paths_in_environ, make_logger_bitbake_compatible, subprocesstweak + from oeqa.utils import make_logger_bitbake_compatible, subprocesstweak from oeqa.sdkext.context import OESDKExtTestContext, OESDKExtTestContextExecutor from oeqa.utils import get_json_result_dir
meta/lib/oeqa/selftest/cases/usergrouptests.py +0 -1
@@ -7,7 +7,6 @@ import os import shutil from oeqa.selftest.case import OESelftestTestCase -from oeqa.utils.commands import bitbake from oeqa.utils.commands import bitbake, get_bb_var, get_test_layer class UserGroupTests(OESelftestTestCase):
meta/lib/oeqa/selftest/context.py +0 -3
@@ -6,12 +6,10 @@ import os import time -import glob import sys import importlib import subprocess import unittest -from random import choice import oeqa import oe
@@ -373,7 +371,6 @@ class OESelftestTestContextExecutor(OETestContextExecutor): return json_result_dir def get_configuration(self, args): - import platform from oeqa.utils.metadata import metadata_from_bb metadata = metadata_from_bb() oeselftest_metadata = get_oeselftest_metadata(args)
meta/lib/oeqa/utils/commands.py +0 -1
@@ -16,7 +16,6 @@ import time import logging from oeqa.utils import CommandError from oeqa.utils import ftools -import re import contextlib import errno # Export test doesn't require bb
meta/lib/oeqa/utils/ftools.py +0 -2
@@ -4,8 +4,6 @@ # SPDX-License-Identifier: MIT # -import os -import re import errno def write_file(path, data):
meta/lib/oeqa/utils/httpserver.py +1 -1
@@ -72,7 +72,7 @@ class HTTPService: self.logger.info("Stopped HTTPService on %s:%s" % (self.host, self.port)) if __name__ == "__main__": - import sys, logging + import sys logger = logging.getLogger(__name__) logging.basicConfig(level=logging.DEBUG)
meta/lib/oeqa/utils/nfs.py +0 -2
@@ -4,10 +4,8 @@ # SPDX-License-Identifier: MIT # import os -import sys import tempfile import contextlib -import socket from oeqa.utils.commands import bitbake, get_bb_var, Command from oeqa.utils.network import get_free_port
meta/lib/oeqa/utils/postactions.py +0 -2
@@ -8,10 +8,8 @@ # dictionary as well as test context to any action to run. import datetime -import io import os import stat -import subprocess import tempfile from oeqa.utils import get_artefact_dir
meta/lib/oeqa/utils/qemurunner.py +0 -1
@@ -18,7 +18,6 @@ import select import errno import string import threading -import codecs import tempfile from collections import defaultdict from contextlib import contextmanager
PATCH 27/41 oeqa/core/decorator/depends: Check resolved dependency ids when running
In reply to Richard PurdieOETestDepends allows dependencies to be given relative to the test's module or class and bind() resolves these to full test ids for ordering.
The runtime check compared the dependencies as written with the ids of the passed tests though, so a test with a relative dependency was always skipped, e.g. test_example_depends in the core example tests.
Use the resolved ids from the registry to avoid that.
Add a test which runs tests with relative dependencies.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/decorator/depends.py | 2 +- meta/lib/oeqa/core/tests/test_decorators.py | 14 ++++++++++++++ 2 files changed, 15 insertions(+), 1 deletion(-)
meta/lib/oeqa/core/decorator/depends.py +1 -1
@@ -95,4 +95,4 @@ class OETestDepends(OETestDiscover): return [registry['cases'][case_id] for case_id in registry['cases']] def setUpDecorator(self): - _skipTestDependency(self.case, self.depends) + _skipTestDependency(self.case, self.case.tc._registry['depends'][self.case.id()])
meta/lib/oeqa/core/tests/test_decorators.py +14 -0
@@ -112,6 +112,20 @@ class TestDependsDecorator(TestBase): msg = 'Expected OEQADependency exception having a circular dependency' self.assertTrue(result, msg=msg) + def test_depends_run(self): + # Dependencies given relative to the class must be found when the + # tests run, otherwise the dependent tests are skipped + tests = ['depends.DependsTest.testDependsFirst', + 'depends.DependsTest.testDependsSecond', + 'depends.DependsTest.testDependsThird', + 'depends.DependsTest.testDependsFourth', + 'depends.DependsTest.testDependsFifth'] + tc = self._testLoader(modules=self.modules, tests=tests) + result = tc.runTests() + self.assertTrue(result.wasSuccessful()) + self.assertEqual(result.skipped, []) + self.assertEqual(len(result.successes), len(tests)) + class TestTimeoutDecorator(TestBase): modules = ['timeout']
PATCH 28/41 oeqa/core/case: Tear down decorators if setUp() fails
In reply to Richard Purdieunittest doesn't call tearDown() when setUp() raises, so if a test's own setUp() failed after the decorators were set up, they were never torn down. For OETimeout this left the alarm running so it could fire during a later test. Tear the decorators down in that case too and add a test.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/case.py | 4 +++- meta/lib/oeqa/core/tests/cases/timeout.py | 9 +++++++++ meta/lib/oeqa/core/tests/test_decorators.py | 9 +++++++++ 3 files changed, 21 insertions(+), 1 deletion(-)
meta/lib/oeqa/core/case.py +3 -1
@@ -44,14 +44,16 @@ class OETestCase(unittest.TestCase): clss.tearDownClassMethod() def _oeSetUp(self): + # unittest doesn't call tearDown() if setUp() fails so the decorators + # need tearing down here in that case too try: for d in self.decorators: d.setUpDecorator() + self.setUpMethod() except: for d in self.decorators: d.tearDownDecorator() raise - self.setUpMethod() def _oeTearDown(self): for d in self.decorators:
meta/lib/oeqa/core/tests/cases/timeout.py +9 -0
@@ -32,3 +32,12 @@ class TimeoutTest(OETestCase): def testTimeoutUnrelated(self): sleep(6) + +class TimeoutSetUpFailTest(OETestCase): + + def setUp(self): + raise Exception("setUp failed") + + @OETimeout(10) + def testTimeoutSetUpFail(self): + self.assertTrue(True, msg='How is this possible?')
meta/lib/oeqa/core/tests/test_decorators.py +9 -0
@@ -147,6 +147,15 @@ class TestTimeoutDecorator(TestBase): msg = "OETestTimeout didn't restore SIGALRM" self.assertIs(alarm_signal, signal.getsignal(signal.SIGALRM), msg=msg) + def test_timeout_setup_fail(self): + tests = ['timeout.TimeoutSetUpFailTest.testTimeoutSetUpFail'] + alarm_signal = signal.getsignal(signal.SIGALRM) + tc = self._testLoader(modules=self.modules, tests=tests) + self.assertFalse(tc.runTests().wasSuccessful()) + # signal.alarm() returns the time left on any previous alarm + self.assertEqual(signal.alarm(0), 0, msg="OETestTimeout alarm left running after setUp failed") + self.assertIs(alarm_signal, signal.getsignal(signal.SIGALRM), msg="OETestTimeout didn't restore SIGALRM") + def test_timeout_cancel(self): tests = ['timeout.TimeoutTest.testTimeoutSkip', 'timeout.TimeoutTest.testTimeoutDepends', 'timeout.TimeoutTest.testTimeoutUnrelated'] msg = 'Unrelated test failed to complete'
PATCH 29/41 oeqa/core/loader: Bind a copy of each decorator per test case
In reply to Richard PurdieA decorator instance belongs to the decorated function, so when a test method is inherited by more than one test class the same instance was bound to each test case in turn and ended up referring to whichever case was bound last. Its setUpDecorator() then ran against the wrong case. Bind a copy for each test case instead and add a test.
Also fix the unregistered decorator error, which used obj.__name__ on a decorator instance and so raised AttributeError instead.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/loader.py | 7 +++++-- meta/lib/oeqa/core/tests/cases/inherit.py | 20 ++++++++++++++++++++ meta/lib/oeqa/core/tests/test_decorators.py | 14 ++++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 meta/lib/oeqa/core/tests/cases/inherit.py
meta/lib/oeqa/core/loader.py +5 -2
@@ -4,6 +4,7 @@ # SPDX-License-Identifier: MIT # +import copy import re import sys import unittest
@@ -106,8 +107,10 @@ class OETestLoader(unittest.TestLoader): if isinstance(obj, OETestDecorator): if not obj.__class__ in decoratorClasses: raise Exception("Decorator %s isn't registered" \ - " in decoratorClasses." % obj.__name__) - obj.bind(self.tc._registry, case) + " in decoratorClasses." % obj.__class__.__name__) + # The decorator instance is shared by every class that has + # the method so bind a copy for this test case + copy.copy(obj).bind(self.tc._registry, case) def _walk_closure(obj): if hasattr(obj, '__closure__') and obj.__closure__:
meta/lib/oeqa/core/tests/cases/inherit.py new file +20 -0
@@ -0,0 +1,20 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +from oeqa.core.case import OETestCase +from oeqa.core.decorator.depends import OETestDepends + +class InheritBaseTest(OETestCase): + + def testInheritFirst(self): + self.assertTrue(True, msg='How is this possible?') + + @OETestDepends(['testInheritFirst']) + def testInheritSecond(self): + self.assertTrue(True, msg='How is this possible?') + +class InheritSubTest(InheritBaseTest): + pass
meta/lib/oeqa/core/tests/test_decorators.py +14 -0
@@ -126,6 +126,20 @@ class TestDependsDecorator(TestBase): self.assertEqual(result.skipped, []) self.assertEqual(len(result.successes), len(tests)) +class TestInheritedDecorators(TestBase): + modules = ['inherit'] + + def test_inherited_decorators(self): + # Each test case needs its own decorator instances, even when the + # test method is inherited by another test class + tc = self._testLoader(modules=self.modules) + cases = tc._registry['cases'] + self.assertEqual(len(cases), 4) + for case in cases.values(): + for d in case.decorators: + self.assertIs(d.case, case) + self.assertTrue(tc.runTests().wasSuccessful()) + class TestTimeoutDecorator(TestBase): modules = ['timeout']
PATCH 30/41 oeqa/core/runner: Report the status of tests with failing subtests
In reply to Richard Purdieunittest records subtest failures against a subtest object rather than the test case, so the result lookups never matched them. Tests with failing subtests were reported as UNKNOWN in the results and their failure messages weren't shown as the test finished. Match subtests to their test case and add a test.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/runner.py | 9 +++++++-- meta/lib/oeqa/core/tests/cases/subtest.py | 19 +++++++++++++++++++ meta/lib/oeqa/core/tests/test_runner.py | 13 +++++++++++++ 3 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 meta/lib/oeqa/core/tests/cases/subtest.py
meta/lib/oeqa/core/runner.py +7 -2
@@ -15,6 +15,11 @@ import sys from unittest import TextTestResult as _TestResult from unittest import TextTestRunner as _TestRunner +def _case_id(case): + # Failures in subtests are recorded against a subtest object, use the + # id of the test case it belongs to + return getattr(case, 'test_case', case).id() + class OEStreamLogger: def __init__(self, logger): self.logger = logger
@@ -73,7 +78,7 @@ class OETestResult(_TestResult): # to wait until selftest finishes to see them. for t in ['failures', 'errors', 'skipped', 'expectedFailures']: for (scase, msg) in getattr(self, t): - if test.id() == scase.id(): + if test.id() == _case_id(scase): self.tc.logger.info(str(msg)) self.shownmsg.append(test.id()) break
@@ -109,7 +114,7 @@ class OETestResult(_TestResult): scase, msg = resultclass else: scase, msg = resultclass, None - if case.id() == scase.id(): + if case.id() == _case_id(scase): found = True break scase_str = str(scase.id())
meta/lib/oeqa/core/tests/cases/subtest.py new file +19 -0
@@ -0,0 +1,19 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +from oeqa.core.case import OETestCase + +class SubTestTest(OETestCase): + + def testSubTestFail(self): + for i in range(2): + with self.subTest(i=i): + self.assertEqual(i, 0) + + def testSubTestPass(self): + for i in range(2): + with self.subTest(i=i): + self.assertTrue(True, msg='How is this possible?')
meta/lib/oeqa/core/tests/test_runner.py +13 -0
@@ -36,5 +36,18 @@ class TestRunner(TestBase): fp.close() +class TestResultStatus(TestBase): + def _statuses(self, modules): + tc = self._testLoader(modules=modules) + result = tc.runTests() + return {case_id: result._getTestResultDetails(case)[0] + for case_id, case in tc._registry['cases'].items()} + + def test_subtest_status(self): + self.assertEqual(self._statuses(['subtest']), { + 'subtest.SubTestTest.testSubTestFail': 'FAILED', + 'subtest.SubTestTest.testSubTestPass': 'PASSED', + }) + if __name__ == '__main__': unittest.main()
PATCH 31/41 oeqa/buildperf: Drop sortTestMethodsUsing from the test runner
In reply to Richard PurdieOnly test loaders use sortTestMethodsUsing so setting it on the runner has no effect; BuildPerfTestLoader already sets it. Also fix the runner's docstring.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/buildperf/base.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
meta/lib/oeqa/buildperf/base.py +1 -2
@@ -486,8 +486,7 @@ class BuildPerfTestLoader(unittest.TestLoader): class BuildPerfTestRunner(unittest.TextTestRunner): - """Test loader for build performance tests""" - sortTestMethodsUsing = None + """Test runner for build performance tests""" def __init__(self, out_dir, *args, **kwargs): super().__init__(*args, **kwargs)
PATCH 32/41 oeqa/core/tests: Add tests for the reported test result status
In reply to Richard PurdieCheck the status OETestResult reports for each kind of test outcome, including setUpClass and setUpModule errors and skips, ahead of reworking how results are tracked.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/tests/cases/results.py | 49 +++++++++++++++++++ .../oeqa/core/tests/cases/resultsmodule.py | 15 ++++++ meta/lib/oeqa/core/tests/test_runner.py | 13 +++++ 3 files changed, 77 insertions(+) create mode 100644 meta/lib/oeqa/core/tests/cases/results.py create mode 100644 meta/lib/oeqa/core/tests/cases/resultsmodule.py
meta/lib/oeqa/core/tests/cases/results.py new file +49 -0
@@ -0,0 +1,49 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +import unittest + +from oeqa.core.case import OETestCase + +class ResultsTest(OETestCase): + + def testPass(self): + pass + + def testFail(self): + self.fail("Failed on purpose") + + def testError(self): + raise Exception("Error on purpose") + + def testSkip(self): + self.skipTest("Skipped on purpose") + + @unittest.expectedFailure + def testExpectedFailure(self): + self.fail("Failed on purpose") + + @unittest.expectedFailure + def testUnexpectedSuccess(self): + pass + +class ResultsClassErrorTest(OETestCase): + + @classmethod + def setUpClass(cls): + raise Exception("Error on purpose") + + def testClassError(self): + pass + +class ResultsClassSkipTest(OETestCase): + + @classmethod + def setUpClass(cls): + raise unittest.SkipTest("Skipped on purpose") + + def testClassSkip(self): + pass
meta/lib/oeqa/core/tests/cases/resultsmodule.py new file +15 -0
@@ -0,0 +1,15 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +from oeqa.core.case import OETestCase + +def setUpModule(): + raise Exception("Error on purpose") + +class ResultsModuleTest(OETestCase): + + def testModuleError(self): + pass
meta/lib/oeqa/core/tests/test_runner.py +13 -0
@@ -43,6 +43,19 @@ class TestResultStatus(TestBase): return {case_id: result._getTestResultDetails(case)[0] for case_id, case in tc._registry['cases'].items()} + def test_result_status(self): + self.assertEqual(self._statuses(['results', 'resultsmodule']), { + 'results.ResultsTest.testPass': 'PASSED', + 'results.ResultsTest.testFail': 'FAILED', + 'results.ResultsTest.testError': 'ERROR', + 'results.ResultsTest.testSkip': 'SKIPPED', + 'results.ResultsTest.testExpectedFailure': 'EXPECTEDFAIL', + 'results.ResultsTest.testUnexpectedSuccess': 'PASSED', + 'results.ResultsClassErrorTest.testClassError': 'ERROR', + 'results.ResultsClassSkipTest.testClassSkip': 'SKIPPED', + 'resultsmodule.ResultsModuleTest.testModuleError': 'ERROR', + }) + def test_subtest_status(self): self.assertEqual(self._statuses(['subtest']), { 'subtest.SubTestTest.testSubTestFail': 'FAILED',
PATCH 33/41 oeqa/core/runner: Track test results as they are added
In reply to Richard PurdieThe status of each test was worked out by searching every unittest result list, matching setUpClass/setUpModule failures with regular expressions, once per test when writing the results. After every test, stopTest() also searched all the failure, error and skip lists to show its messages. Both grow with the square of the number of tests which adds up for large selftest runs.
Record each result against its test, or against the class or module for setup failures, when it is added, and use that for both. If a test has more than one result, e.g. from subtests, the same precedence as before is used.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/runner.py | 107 +++++++++++++++++++---------------- 1 file changed, 57 insertions(+), 50 deletions(-)
meta/lib/oeqa/core/runner.py +57 -50
@@ -20,6 +20,10 @@ def _case_id(case): # id of the test case it belongs to return getattr(case, 'test_case', case).id() +# setUpClass/setUpModule failures are reported against a placeholder whose id +# names the class or module +_setup_failure_re = re.compile(r"^(?:setUpModule|setUpClass) \((?P<name>.*)\)") + class OEStreamLogger: def __init__(self, logger): self.logger = logger
@@ -41,6 +45,10 @@ class OEStreamLogger: handler.flush() class OETestResult(_TestResult): + # If a test has several results, e.g. from subtests, the status reported + # is the first of these which it has + status_priority = ('FAILED', 'ERROR', 'SKIPPED', 'EXPECTEDFAIL', 'PASSED') + def __init__(self, tc, *args, **kwargs): super().__init__(*args, **kwargs)
@@ -49,7 +57,12 @@ class OETestResult(_TestResult): self.endtime = {} self.progressinfo = {} self.extraresults = {} - self.shownmsg = [] + self.shownmsg = set() + + # (status, message) results for each test id, and for setUpClass and + # setUpModule failures by class or module name + self.test_results = {} + self.setup_results = {} # Inject into tc so that TestDepends decorator can see results tc.results = self
@@ -76,12 +89,10 @@ class OETestResult(_TestResult): # Print the errors/failures early to aid/speed debugging, its a pain # to wait until selftest finishes to see them. - for t in ['failures', 'errors', 'skipped', 'expectedFailures']: - for (scase, msg) in getattr(self, t): - if test.id() == _case_id(scase): - self.tc.logger.info(str(msg)) - self.shownmsg.append(test.id()) - break + for status, msg in self.test_results.get(test.id(), []): + if status != 'PASSED' and msg: + self.tc.logger.info(str(msg)) + self.shownmsg.add(test.id()) # Python 3.12 added this, stub it out for now def addDuration(self, test, elapsed):
@@ -101,45 +112,23 @@ class OETestResult(_TestResult): msg += " (successes=%d, skipped=%d, failures=%d, errors=%d)" % (len(self.successes), len(self.skipped), len(self.failures), len(self.errors)) self.tc.logger.info(msg) + def _addResult(self, test, status, msg=None): + m = _setup_failure_re.match(str(test.id())) + if m: + self.setup_results.setdefault(m.group('name'), []).append((status, msg)) + else: + self.test_results.setdefault(_case_id(test), []).append((status, msg)) + def _getTestResultDetails(self, case): - result_types = {'failures': 'FAILED', 'errors': 'ERROR', 'skipped': 'SKIPPED', - 'expectedFailures': 'EXPECTEDFAIL', 'successes': 'PASSED', - 'unexpectedSuccesses' : 'PASSED'} - - for rtype in result_types: - found = False - for resultclass in getattr(self, rtype): - # unexpectedSuccesses are just lists, not lists of tuples - if isinstance(resultclass, tuple): - scase, msg = resultclass - else: - scase, msg = resultclass, None - if case.id() == _case_id(scase): - found = True - break - 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 - m = re.search(r"^setUpModule \((?P<module_name>.*)\).*$", scase_str) - if m: - if case.__class__.__module__ == m.group('module_name'): - found = True - break - - m = re.search(r"^setUpClass \((?P<class_name>.*)\).*$", scase_str) - if m: - class_name = "%s.%s" % (case.__class__.__module__, - case.__class__.__name__) - - if class_name == m.group('class_name'): - found = True - break - - if found: - return result_types[rtype], msg - - return 'UNKNOWN', None + results = self.test_results.get(case.id()) + if not results: + # The test didn't run, look for a class or module setup failure + cls = case.__class__ + results = self.setup_results.get("%s.%s" % (cls.__module__, cls.__name__)) or \ + self.setup_results.get(cls.__module__) + if not results: + return 'UNKNOWN', None + return min(results, key=lambda r: self.status_priority.index(r[0])) def extractExtraResults(self, test, details = None): extraresults = None
@@ -158,25 +147,43 @@ class OETestResult(_TestResult): def addError(self, test, *args, details = None): self.extractExtraResults(test, details = details) - return super().addError(test, *args) + super().addError(test, *args) + self._addResult(test, 'ERROR', self.errors[-1][1]) def addFailure(self, test, *args, details = None): self.extractExtraResults(test, details = details) - return super().addFailure(test, *args) + super().addFailure(test, *args) + self._addResult(test, 'FAILED', self.failures[-1][1]) + + def addSubTest(self, test, subtest, err): + super().addSubTest(test, subtest, err) + if err is not None: + if issubclass(err[0], test.failureException): + self._addResult(test, 'FAILED', self.failures[-1][1]) + else: + self._addResult(test, 'ERROR', self.errors[-1][1]) + + # No details argument, so testtools passes the reason + def addSkip(self, test, reason): + super().addSkip(test, reason) + self._addResult(test, 'SKIPPED', reason) def addSuccess(self, test, details = None): #Added so we can keep track of successes too self.successes.append((test, None)) self.extractExtraResults(test, details = details) - return super().addSuccess(test) + super().addSuccess(test) + self._addResult(test, 'PASSED') def addExpectedFailure(self, test, *args, details = None): self.extractExtraResults(test, details = details) - return super().addExpectedFailure(test, *args) + super().addExpectedFailure(test, *args) + self._addResult(test, 'EXPECTEDFAIL', self.expectedFailures[-1][1]) def addUnexpectedSuccess(self, test, details = None): self.extractExtraResults(test, details = details) - return super().addUnexpectedSuccess(test) + super().addUnexpectedSuccess(test) + self._addResult(test, 'PASSED') def logDetails(self, json_file_dir=None, configuration=None, result_id=None, dump_streams=False):
PATCH 34/41 oeqa/core/runner: Use getSuiteCases() to list tests
In reply to Richard PurdieThe test listing code had its own recursive walk over the suite, and a counter stored on the runner, to do what getSuiteCases() already does. Use getSuiteCases() instead. The output is unchanged.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/runner.py | 79 +++++++++++++----------------------- 1 file changed, 28 insertions(+), 51 deletions(-)
meta/lib/oeqa/core/runner.py +28 -51
@@ -6,7 +6,6 @@ import os import time -import unittest import logging import re import json
@@ -15,6 +14,8 @@ import sys from unittest import TextTestResult as _TestResult from unittest import TextTestRunner as _TestRunner +from oeqa.core.utils.test import getSuiteCases + def _case_id(case): # Failures in subtests are recorded against a subtest object, use the # id of the test case it belongs to
@@ -272,68 +273,44 @@ class OETestRunner(_TestRunner): return self.resultclass(self.tc, self.stream, self.descriptions, self.verbosity) - def _walk_suite(self, suite, func): - for obj in suite: - if isinstance(obj, unittest.suite.TestSuite): - if len(obj._tests): - self._walk_suite(obj, func) - elif isinstance(obj, unittest.case.TestCase): - func(self.tc.logger, obj) - self._walked_cases = self._walked_cases + 1 - def _list_tests_name(self, suite): - self._walked_cases = 0 - - def _list_cases(logger, case): - oetags = [] - if hasattr(case, '__oeqa_testtags'): - oetags = getattr(case, '__oeqa_testtags') - if oetags: - logger.info("%s (%s)" % (case.id(), ",".join(oetags))) - else: - logger.info("%s" % (case.id())) + cases = getSuiteCases(suite) self.tc.logger.info("Listing all available tests:") - self._walked_cases = 0 self.tc.logger.info("test (tags)") self.tc.logger.info("-" * 80) - self._walk_suite(suite, _list_cases) + for case in cases: + oetags = getattr(case, '__oeqa_testtags', None) + if oetags: + self.tc.logger.info("%s (%s)" % (case.id(), ",".join(oetags))) + else: + self.tc.logger.info("%s" % (case.id())) self.tc.logger.info("-" * 80) - self.tc.logger.info("Total found:\t%s" % self._walked_cases) + self.tc.logger.info("Total found:\t%s" % len(cases)) def _list_tests_class(self, suite): - self._walked_cases = 0 - - curr = {} - def _list_classes(logger, case): - if not 'module' in curr or curr['module'] != case.__module__: - curr['module'] = case.__module__ - logger.info(curr['module']) - - if not 'class' in curr or curr['class'] != \ - case.__class__.__name__: - curr['class'] = case.__class__.__name__ - logger.info(" -- %s" % curr['class']) - - logger.info(" -- -- %s" % case._testMethodName) - self.tc.logger.info("Listing all available test classes:") - self._walk_suite(suite, _list_classes) + module = cls = None + for case in getSuiteCases(suite): + if case.__module__ != module: + module = case.__module__ + self.tc.logger.info(module) + if case.__class__.__name__ != cls: + cls = case.__class__.__name__ + self.tc.logger.info(" -- %s" % cls) + self.tc.logger.info(" -- -- %s" % case._testMethodName) def _list_tests_module(self, suite): - self._walked_cases = 0 - - listed = [] - def _list_modules(logger, case): - if not case.__module__ in listed: - if case.__module__.startswith('_'): - logger.info("%s (hidden)" % case.__module__) - else: - logger.info(case.__module__) - listed.append(case.__module__) - self.tc.logger.info("Listing all available test modules:") - self._walk_suite(suite, _list_modules) + listed = set() + for case in getSuiteCases(suite): + module = case.__module__ + if module not in listed: + if module.startswith('_'): + self.tc.logger.info("%s (hidden)" % module) + else: + self.tc.logger.info(module) + listed.add(module) def list_tests(self, suite, display_type): if display_type == 'name':
PATCH 35/41 oeqa/core/decorator: Record decorators on the test function
In reply to Richard PurdieOETestDecorator wrapped each test method in a function which only called it, with a dummy assignment to self so the decorator would be captured in the wrapper's closure. OETestLoader then walked the closures to find the decorators.
Instead, record the decorators in an attribute on the test function and return it unchanged. The order they are set up in is the same as before, innermost first, and a test now checks this.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/decorator/__init__.py | 10 ++++---- meta/lib/oeqa/core/loader.py | 26 +++++++-------------- meta/lib/oeqa/core/tests/test_decorators.py | 8 +++++++ 3 files changed, 20 insertions(+), 24 deletions(-)
meta/lib/oeqa/core/decorator/__init__.py +4 -6
@@ -4,7 +4,6 @@ # SPDX-License-Identifier: MIT # -from functools import wraps from abc import ABCMeta decoratorClasses = set()
@@ -29,11 +28,10 @@ class OETestDecorator(object, metaclass=ABCMeta): setattr(self, attr, value) def __call__(self, func): - @wraps(func) - def wrapped_f(*args, **kwargs): - self.attrs = self.attrs # XXX: Enables OETestLoader discover - return func(*args, **kwargs) - return wrapped_f + # Record the decorator on the test function for OETestLoader to find. + # They are set up in the order they are applied, innermost first. + func._oeqa_decorators = getattr(func, '_oeqa_decorators', []) + [self] + return func # OETestLoader call it when is loading test cases. # XXX: Most methods would change the registry for later
meta/lib/oeqa/core/loader.py +8 -18
@@ -14,8 +14,7 @@ from oeqa.core.utils.test import getSuiteModules, getCaseID from oeqa.core.exception import OEQATestNotFound from oeqa.core.case import OETestCase -from oeqa.core.decorator import decoratorClasses, OETestDecorator, \ - OETestDiscover +from oeqa.core.decorator import decoratorClasses, OETestDiscover # When loading tests, the unittest framework stores any exceptions and # displays them only when the run method is called.
@@ -103,23 +102,14 @@ class OETestLoader(unittest.TestLoader): self.tc._registry['cases'][case_id] = case def _handleTestCaseDecorators(self, case): - def _handle(obj): - if isinstance(obj, OETestDecorator): - if not obj.__class__ in decoratorClasses: - raise Exception("Decorator %s isn't registered" \ - " in decoratorClasses." % obj.__class__.__name__) - # The decorator instance is shared by every class that has - # the method so bind a copy for this test case - copy.copy(obj).bind(self.tc._registry, case) - - def _walk_closure(obj): - if hasattr(obj, '__closure__') and obj.__closure__: - for f in obj.__closure__: - obj = f.cell_contents - _handle(obj) - _walk_closure(obj) method = getattr(case, case._testMethodName, None) - _walk_closure(method) + for obj in getattr(method, '_oeqa_decorators', []): + if not obj.__class__ in decoratorClasses: + raise Exception("Decorator %s isn't registered" \ + " in decoratorClasses." % obj.__class__.__name__) + # The decorator instance is shared by every class that has + # the method so bind a copy for this test case + copy.copy(obj).bind(self.tc._registry, case) def _filterTest(self, case): """
meta/lib/oeqa/core/tests/test_decorators.py +8 -0
@@ -126,6 +126,14 @@ class TestDependsDecorator(TestBase): self.assertEqual(result.skipped, []) self.assertEqual(len(result.successes), len(tests)) +class TestDecoratorOrder(TestBase): + def test_decorator_order(self): + # Decorators are set up in the order they are applied, innermost first + tc = self._testLoader(modules=['timeout']) + case = tc._registry['cases']['timeout.TimeoutTest.testTimeoutDepends'] + self.assertEqual([d.__class__.__name__ for d in case.decorators], + ['OETimeout', 'OETestDepends']) + class TestInheritedDecorators(TestBase): modules = ['inherit']
PATCH 36/41 oeqa/core/tests: Add tests for skipping tests and td_vars checks
In reply to Richard PurdieCheck that tests and whole classes can be skipped by id and that a skipped class doesn't run its setUpClass(), and that a missing td_vars variable is reported, ahead of reworking how test setup is hooked.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/tests/cases/skips.py | 24 ++++++++++++++++++++++++ meta/lib/oeqa/core/tests/cases/tdvars.py | 13 +++++++++++++ meta/lib/oeqa/core/tests/test_runner.py | 21 +++++++++++++++++++++ 3 files changed, 58 insertions(+) create mode 100644 meta/lib/oeqa/core/tests/cases/skips.py create mode 100644 meta/lib/oeqa/core/tests/cases/tdvars.py
meta/lib/oeqa/core/tests/cases/skips.py new file +24 -0
@@ -0,0 +1,24 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +from oeqa.core.case import OETestCase + +class SkipsClassTest(OETestCase): + + @classmethod + def setUpClass(cls): + raise Exception("setUpClass of a skipped class shouldn't run") + + def testSkipsClass(self): + pass + +class SkipsTest(OETestCase): + + def testSkipsSkipped(self): + self.fail("Skipped test shouldn't run") + + def testSkipsRun(self): + pass
meta/lib/oeqa/core/tests/cases/tdvars.py new file +13 -0
@@ -0,0 +1,13 @@ +# +# Copyright OpenEmbedded Contributors +# +# SPDX-License-Identifier: MIT +# + +from oeqa.core.case import OETestCase + +class TdVarsMissingTest(OETestCase): + td_vars = ['NOT_IN_TD'] + + def testTdVarsMissing(self): + pass
meta/lib/oeqa/core/tests/test_runner.py +21 -0
@@ -56,6 +56,27 @@ class TestResultStatus(TestBase): 'resultsmodule.ResultsModuleTest.testModuleError': 'ERROR', }) + def test_skip_tests(self): + # Tests and classes can be skipped by id prefix; a skipped class must + # not run its setUpClass() + tc = self._testLoader(modules=['skips']) + result = tc.runTests(skips=['skips.SkipsClassTest', 'skips.SkipsTest.testSkipsSkipped']) + statuses = {case_id: result._getTestResultDetails(case)[0] + for case_id, case in tc._registry['cases'].items()} + self.assertEqual(statuses, { + 'skips.SkipsClassTest.testSkipsClass': 'SKIPPED', + 'skips.SkipsTest.testSkipsSkipped': 'SKIPPED', + 'skips.SkipsTest.testSkipsRun': 'PASSED', + }) + + def test_td_vars(self): + tc = self._testLoader(modules=['tdvars']) + result = tc.runTests() + statuses = {case_id: result._getTestResultDetails(case)[0] + for case_id, case in tc._registry['cases'].items()} + self.assertEqual(statuses, {'tdvars.TdVarsMissingTest.testTdVarsMissing': 'ERROR'}) + self.assertIn("OEQAMissingVariable", result.errors[0][1]) + def test_subtest_status(self): self.assertEqual(self._statuses(['subtest']), { 'subtest.SubTestTest.testSubTestFail': 'FAILED',
PATCH 37/41 oeqa/core: Use unittest's setup hook instead of patching test classes
In reply to Richard PurdieTo run the decorators and the td_vars check, OETestLoader renamed the setUp()/tearDown()/setUpClass()/tearDownClass() methods of every test class it loaded and replaced them with OETestCase wrappers, marking the class as patched. Since the marker was inherited, a subclass which overrode setUp() and was loaded after its parent class was left unpatched and silently lost its decorators.
Override TestCase._callSetUp(), which unittest uses to run setUp(), to check td_vars and set up the decorators, and register the decorator teardowns as cleanups so they run after tearDown() and when setUp() fails. The td_vars check now runs per test rather than in setUpClass(), none of the classes using td_vars need the variables in setUpClass().
The class level hook was otherwise only used to skip classes given on the command line, so use unittest.skip() for those and for skipped tests. Tests in a skipped class are now each reported as skipped rather than as a single class level skip.
This does mean we use python internal API but we can adapt if python changes that.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/case.py | 37 +++++++++++------------------------ meta/lib/oeqa/core/context.py | 25 +++++++++-------------- meta/lib/oeqa/core/loader.py | 30 +--------------------------- 3 files changed, 21 insertions(+), 71 deletions(-)
meta/lib/oeqa/core/case.py +11 -26
@@ -32,33 +32,18 @@ class OETestCase(unittest.TestCase): # OEQAMissingVariable exception is raised td_vars = None - @classmethod - def _oeSetUpClass(clss): - _validate_td_vars(clss.td, clss.td_vars, "class") - if hasattr(clss, 'setUpHooker') and callable(getattr(clss, 'setUpHooker')): - clss.setUpHooker() - clss.setUpClassMethod() - - @classmethod - def _oeTearDownClass(clss): - clss.tearDownClassMethod() - - def _oeSetUp(self): - # unittest doesn't call tearDown() if setUp() fails so the decorators - # need tearing down here in that case too - try: - for d in self.decorators: - d.setUpDecorator() - self.setUpMethod() - except: - for d in self.decorators: - d.tearDownDecorator() - raise - - def _oeTearDown(self): + # Decorators bound to this test case by OETestLoader + decorators = () + + def _callSetUp(self): + # unittest.TestCase.run() calls this to run setUp(). Check the test + # data and set up the decorators first. Decorators are torn down as + # cleanups, which run after tearDown() and also if setUp() fails. + _validate_td_vars(self.td, self.td_vars, "class") for d in self.decorators: - d.tearDownDecorator() - self.tearDownMethod() + d.setUpDecorator() + self.addCleanup(d.tearDownDecorator) + super()._callSetUp() def assertFileExists(self, filename, msg=None): """
meta/lib/oeqa/core/context.py +9 -16
@@ -47,24 +47,17 @@ class OETestContext: return modules def skipTests(self, skips): - if not skips: - return - def skipfuncgen(skipmsg): - def func(): - raise unittest.SkipTest(skipmsg) - return func - class_ids = {} + # Use unittest's skip support so that skipped tests, and the class + # setup of skipped classes, don't run for test in self.suites: - if test.__class__ not in class_ids: - class_ids[test.__class__] = '.'.join(test.id().split('.')[:-1]) + class_id = test.id().rsplit('.', 1)[0] for skip in skips: - if (test.id()+'.').startswith(skip+'.'): - setattr(test, 'setUp', skipfuncgen('Skip by the command line argument "%s"' % skip)) - for tclass in class_ids: - cid = class_ids[tclass] - for skip in skips: - if (cid + '.').startswith(skip + '.'): - setattr(tclass, 'setUpHooker', skipfuncgen('Skip by the command line argument "%s"' % skip)) + msg = 'Skip by the command line argument "%s"' % skip + if (class_id + '.').startswith(skip + '.'): + unittest.skip(msg)(test.__class__) + elif (test.id() + '.').startswith(skip + '.'): + method = getattr(test, test._testMethodName) + setattr(test, test._testMethodName, unittest.skip(msg)(method)) def loadTests(self, module_paths, modules=[], tests=[], modules_manifest="", modules_required=[], **kwargs):
meta/lib/oeqa/core/loader.py +1 -29
@@ -171,37 +171,9 @@ class OETestLoader(unittest.TestLoader): return False def _getTestCase(self, testCaseClass, tcName): - if not hasattr(testCaseClass, '__oeqa_loader') and \ - issubclass(testCaseClass, OETestCase): - # In order to support data_vars validation - # monkey patch the default setUp/tearDown{Class} to use - # the ones provided by OETestCase - setattr(testCaseClass, 'setUpClassMethod', - getattr(testCaseClass, 'setUpClass')) - setattr(testCaseClass, 'tearDownClassMethod', - getattr(testCaseClass, 'tearDownClass')) - setattr(testCaseClass, 'setUpClass', - testCaseClass._oeSetUpClass) - setattr(testCaseClass, 'tearDownClass', - testCaseClass._oeTearDownClass) - - # In order to support decorators initialization - # monkey patch the default setUp/tearDown to use - # a setUpDecorators/tearDownDecorators that methods - # will call setUp/tearDown original methods. - setattr(testCaseClass, 'setUpMethod', - getattr(testCaseClass, 'setUp')) - setattr(testCaseClass, 'tearDownMethod', - getattr(testCaseClass, 'tearDown')) - setattr(testCaseClass, 'setUp', testCaseClass._oeSetUp) - setattr(testCaseClass, 'tearDown', testCaseClass._oeTearDown) - - setattr(testCaseClass, '__oeqa_loader', True) - case = testCaseClass(tcName) if isinstance(case, OETestCase): - setattr(case, 'decorators', []) - + case.decorators = [] return case def loadTestsFromTestCase(self, testCaseClass):
PATCH 38/41 oeqa/core/loader: Always return a flat test suite
In reply to Richard PurdieOETestLoader.discover() returned a flat suite of the loaded tests only when a discovery decorator class was registered, which happens as a side effect of some loaded module importing oeqa.core.decorator.depends. Otherwise it returned unittest's nested per module suites. skipTests() expects a flat suite, so with no module importing OETestDepends, as for the oe-core selftests on their own, --skip-tests failed with:
AttributeError: 'TestSuite' object has no attribute 'id'
Always return a flat suite, using the registered test cases in the order they were loaded when no discovery decorator reorders them, and add a test which runs without OETestDepends registered.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/loader.py | 4 ++-- meta/lib/oeqa/core/tests/test_loader.py | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 2 deletions(-)
meta/lib/oeqa/core/loader.py +2 -2
@@ -237,7 +237,7 @@ class OETestLoader(unittest.TestLoader): pattern='*.py', top_level_dir=path) big_suite.addTests(suite) - cases = None + cases = list(self.tc._registry['cases'].values()) discover_classes = [clss for clss in decoratorClasses if issubclass(clss, OETestDiscover)] for clss in discover_classes:
@@ -246,7 +246,7 @@ class OETestLoader(unittest.TestLoader): if self.modules_required: self._required_modules_validation() - return self.suiteClass(cases) if cases else big_suite + return self.suiteClass(cases) def _filterModule(self, module): if module.__name__ in sys.builtin_module_names:
meta/lib/oeqa/core/tests/test_loader.py +23 -0
@@ -6,6 +6,9 @@ # import os +import subprocess +import sys +import textwrap import unittest from common import setup_sys_path, TestBase
@@ -59,5 +62,25 @@ class TestLoader(TestBase): msg = 'Expected modules from two different paths' self.assertEqual(modules, expected_modules, msg=msg) + def test_flat_suite(self): + # The loaded suite must be a flat list of tests, which skipTests() + # relies on, even if no module registers a discovery decorator such as + # OETestDepends. Registering one is global so use a new process. + oeqa_lib = os.path.realpath(os.path.join(os.path.dirname(os.path.abspath(__file__)), '../../../')) + cases_path = os.path.join(self.cases_path, 'loader', 'valid') + script = textwrap.dedent(""" + import logging, sys, unittest + sys.path.insert(0, %r) + from oeqa.core.context import OETestContext + from oeqa.core.decorator import decoratorClasses + tc = OETestContext({}, logging.getLogger('flat')) + tc.loadTests(%r) + assert not [c for c in decoratorClasses if c.__name__ == 'OETestDepends'] + tc.skipTests(['another.AnotherTest.testAnother']) + print(' '.join(type(t).__name__ for t in tc.suites)) + """) % (oeqa_lib, cases_path) + output = subprocess.check_output([sys.executable, '-c', script], text=True) + self.assertEqual(output.split(), ['AnotherTest']) + if __name__ == '__main__': unittest.main()
PATCH 39/41 oeqa: Drop the unused tc_kwargs list phase and dead selftest code
In reply to Richard PurdieNothing ever adds arguments to tc_kwargs['list'] and no context's listTests() takes any, so drop it. In oe-selftest, remove an unused config_paths assignment, the unused machines argument of OESelftestTestContext and its runTests()/listTests() overrides which only existed to drop an unused machine argument.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/context.py | 3 +-- meta/lib/oeqa/selftest/context.py | 12 ++---------- 2 files changed, 3 insertions(+), 12 deletions(-)
meta/lib/oeqa/core/context.py +1 -2
@@ -162,7 +162,6 @@ class OETestContextExecutor: self.tc_kwargs = {} self.tc_kwargs['init'] = {} self.tc_kwargs['load'] = {} - self.tc_kwargs['list'] = {} self.tc_kwargs['run'] = {} self.tc_kwargs['init']['logger'] = self._setup_logger(logger, args)
@@ -219,7 +218,7 @@ class OETestContextExecutor: sys.exit(1) if args.list_tests: - rc = self.tc.listTests(args.list_tests, **self.tc_kwargs['list']) + rc = self.tc.listTests(args.list_tests) else: self._pre_run() rc = self.tc.runTests(**self.tc_kwargs['run'])
meta/lib/oeqa/selftest/context.py +2 -10
@@ -69,7 +69,7 @@ def removebuilddir(d): bb.utils.prunedir(d, ionice=True) class OESelftestTestContext(OETestContext): - def __init__(self, td=None, logger=None, machines=None, config_paths=None, newbuilddir=None, keep_builddir=None): + def __init__(self, td=None, logger=None, config_paths=None, newbuilddir=None, keep_builddir=None): super().__init__(td, logger) self.config_paths = config_paths
@@ -170,12 +170,6 @@ class OESelftestTestContext(OETestContext): else: return NonConcurrentTestSuite(suites, processes, self.setup_builddir, self.removebuilddir, self.bb_vars) - def runTests(self, processes=None, machine=None, skips=[]): - return super().runTests(processes, skips) - - def listTests(self, display_type, machine=None): - return super().listTests(display_type) - class OESelftestTestContextExecutor(OETestContextExecutor): _context_class = OESelftestTestContext _script_executor = 'oe-selftest'
@@ -398,7 +392,7 @@ class OESelftestTestContextExecutor(OETestContextExecutor): sys.exit(1) if args.list_tests: - rc = self.tc.listTests(args.list_tests, **self.tc_kwargs['list']) + rc = self.tc.listTests(args.list_tests) else: self._pre_run() rc = self.tc.runTests(**self.tc_kwargs['run'])
@@ -417,8 +411,6 @@ class OESelftestTestContextExecutor(OETestContextExecutor): try: rc = self._internal_run(logger, args) finally: - config_paths = self.tc_kwargs['init']['config_paths'] - output_link = os.path.join(os.path.dirname(args.output_log), "%s-results.log" % self.name) if os.path.lexists(output_link):
PATCH 40/41 oeqa: Replace tc_kwargs with explicit attributes
In reply to Richard PurdieThe test component executors collected the arguments for the test context in a dict of dicts, tc_kwargs, which run() then expanded into the context constructor, loadTests() and runTests(). Apart from the constructor arguments, which vary by context, these were always the same few values.
Store the test data, logger, modules to load, tag filter, skips and process count as attributes and pass them explicitly, and keep a single context_args dict for the context specific constructor arguments. The calls made to the contexts are unchanged.
Layers with their own test components which extend tc_kwargs will need to set these attributes instead.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/context.py | 42 +++++++++++++++++-------------- meta/lib/oeqa/runtime/context.py | 8 +++--- meta/lib/oeqa/sdk/context.py | 10 ++++---- meta/lib/oeqa/selftest/context.py | 33 ++++++++++++------------ 4 files changed, 49 insertions(+), 44 deletions(-)
meta/lib/oeqa/core/context.py +23 -19
@@ -47,6 +47,8 @@ class OETestContext: return modules def skipTests(self, skips): + if not skips: + return # Use unittest's skip support so that skipped tests, and the class # setup of skipped classes, don't run for test in self.suites:
@@ -159,32 +161,33 @@ class OETestContextExecutor: return logger def _process_args(self, logger, args): - self.tc_kwargs = {} - self.tc_kwargs['init'] = {} - self.tc_kwargs['load'] = {} - self.tc_kwargs['run'] = {} - - self.tc_kwargs['init']['logger'] = self._setup_logger(logger, args) + self.logger = self._setup_logger(logger, args) if args.test_data_file: - self.tc_kwargs['init']['td'] = json.load( - open(args.test_data_file, "r")) + with open(args.test_data_file, "r") as f: + self.td = json.load(f) else: - self.tc_kwargs['init']['td'] = {} + self.td = {} + + # Any further arguments for the test context, for subclasses to add + self.context_args = {} # Run image specific TEST_SUITE like testimage.bbclass by default - test_suites = self.tc_kwargs['init']['td'].get("TEST_SUITES") + test_suites = self.td.get("TEST_SUITES") if test_suites: test_suites = test_suites.split() + self.modules_required = [] if args.run_tests: - self.tc_kwargs['load']['modules'] = args.run_tests - self.tc_kwargs['load']['modules_required'] = args.run_tests + self.modules = args.run_tests + self.modules_required = args.run_tests elif test_suites: - self.tc_kwargs['load']['modules'] = test_suites + self.modules = test_suites else: - self.tc_kwargs['load']['modules'] = [] + self.modules = [] + self.tags_filter = None - self.tc_kwargs['run']['skips'] = [] + self.processes = None + self.skips = [] self.module_paths = args.CASES_PATHS
@@ -192,7 +195,7 @@ class OETestContextExecutor: return args.json_result_dir def _get_configuration(self): - td = self.tc_kwargs['init']['td'] + td = self.td configuration = {'TEST_TYPE': self.name, 'MACHINE': td.get("MACHINE"), 'DISTRO': td.get("DISTRO"),
@@ -210,9 +213,10 @@ class OETestContextExecutor: def run(self, logger, args): self._process_args(logger, args) - self.tc = self._context_class(**self.tc_kwargs['init']) + self.tc = self._context_class(td=self.td, logger=self.logger, **self.context_args) try: - self.tc.loadTests(self.module_paths, **self.tc_kwargs['load']) + self.tc.loadTests(self.module_paths, modules=self.modules, + modules_required=self.modules_required, tags_filter=self.tags_filter) except OEQATestNotFound as ex: logger.error(ex) sys.exit(1)
@@ -221,7 +225,7 @@ class OETestContextExecutor: rc = self.tc.listTests(args.list_tests) else: self._pre_run() - rc = self.tc.runTests(**self.tc_kwargs['run']) + rc = self.tc.runTests(processes=self.processes, skips=self.skips) json_result_dir = self._get_json_result_dir(args) if json_result_dir:
meta/lib/oeqa/runtime/context.py +4 -4
@@ -206,7 +206,7 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): super()._process_args(logger, args) - td = self.tc_kwargs['init']['td'] + td = self.td target_kwargs = {} target_kwargs['machine'] = td.get("MACHINE") or None
@@ -216,12 +216,12 @@ class OERuntimeTestContextExecutor(OETestContextExecutor): target_kwargs['serialcontrol_ps1'] = td.get("TEST_SERIALCONTROL_PS1") or None target_kwargs['serialcontrol_connect_timeout'] = td.get("TEST_SERIALCONTROL_CONNECT_TIMEOUT") or None - self.tc_kwargs['init']['target'] = \ + self.context_args['target'] = \ OERuntimeTestContextExecutor.getTarget(args.target_type, None, args.target_ip, args.server_ip, **target_kwargs) - self.tc_kwargs['init']['image_packages'] = \ + self.context_args['image_packages'] = \ OERuntimeTestContextExecutor.readPackagesManifest( args.packages_manifest) - self.tc_kwargs['init']['extract_dir'] = args.extract_dir + self.context_args['extract_dir'] = args.extract_dir _executor_class = OERuntimeTestContextExecutor
meta/lib/oeqa/sdk/context.py +5 -5
@@ -101,13 +101,13 @@ class OESDKTestContextExecutor(OETestContextExecutor): def _process_args(self, logger, args): super()._process_args(logger, args) - self.tc_kwargs['init']['sdk_dir'] = args.sdk_dir - self.tc_kwargs['init']['sdk_env'] = self.sdk_env - self.tc_kwargs['init']['target_pkg_manifest'] = \ + self.context_args['sdk_dir'] = args.sdk_dir + self.context_args['sdk_env'] = self.sdk_env + self.context_args['target_pkg_manifest'] = \ OESDKTestContextExecutor._load_manifest(args.target_manifest) - self.tc_kwargs['init']['host_pkg_manifest'] = \ + self.context_args['host_pkg_manifest'] = \ OESDKTestContextExecutor._load_manifest(args.host_manifest) - self.tc_kwargs['run']['processes'] = args.processes + self.processes = args.processes @staticmethod def _get_sdk_environs(sdk_dir):
meta/lib/oeqa/selftest/context.py +17 -16
@@ -262,16 +262,17 @@ class OESelftestTestContextExecutor(OETestContextExecutor): elif args.list_tests: args.list_tests = 'name' - self.tc_kwargs['init']['td'] = bbvars + self.td = bbvars builddir = os.environ.get("BUILDDIR") - self.tc_kwargs['init']['config_paths'] = {} - self.tc_kwargs['init']['config_paths']['testlayer_path'] = get_test_layer(bbvars["BBLAYERS"]) - self.tc_kwargs['init']['config_paths']['builddir'] = builddir - self.tc_kwargs['init']['config_paths']['localconf'] = os.path.join(builddir, "conf/local.conf") - self.tc_kwargs['init']['config_paths']['bblayers'] = os.path.join(builddir, "conf/bblayers.conf") - self.tc_kwargs['init']['newbuilddir'] = args.newbuilddir - self.tc_kwargs['init']['keep_builddir'] = args.keep_builddir + self.context_args['config_paths'] = { + 'testlayer_path': get_test_layer(bbvars["BBLAYERS"]), + 'builddir': builddir, + 'localconf': os.path.join(builddir, "conf/local.conf"), + 'bblayers': os.path.join(builddir, "conf/bblayers.conf"), + } + self.context_args['newbuilddir'] = args.newbuilddir + self.context_args['keep_builddir'] = args.keep_builddir def tag_filter(tags): if args.exclude_tags:
@@ -283,10 +284,10 @@ class OESelftestTestContextExecutor(OETestContextExecutor): return False if args.select_tags or args.exclude_tags: - self.tc_kwargs['load']['tags_filter'] = tag_filter + self.tags_filter = tag_filter - self.tc_kwargs['run']['skips'] = args.skips - self.tc_kwargs['run']['processes'] = args.processes + self.skips = args.skips + self.processes = args.processes def _pre_run(self): def _check_required_env_variables(vars):
@@ -381,12 +382,12 @@ class OESelftestTestContextExecutor(OETestContextExecutor): return '%s_%s_%s_%s' % (configuration['TEST_TYPE'], configuration['HOST_DISTRO'], configuration['MACHINE'], configuration['STARTTIME']) def _internal_run(self, logger, args): - self.module_paths = self._get_cases_paths( - self.tc_kwargs['init']['td']['BBPATH'].split(':')) + self.module_paths = self._get_cases_paths(self.td['BBPATH'].split(':')) - self.tc = self._context_class(**self.tc_kwargs['init']) + self.tc = self._context_class(td=self.td, logger=self.logger, **self.context_args) try: - self.tc.loadTests(self.module_paths, **self.tc_kwargs['load']) + self.tc.loadTests(self.module_paths, modules=self.modules, + modules_required=self.modules_required, tags_filter=self.tags_filter) except OEQATestNotFound as ex: logger.error(ex) sys.exit(1)
@@ -395,7 +396,7 @@ class OESelftestTestContextExecutor(OETestContextExecutor): rc = self.tc.listTests(args.list_tests) else: self._pre_run() - rc = self.tc.runTests(**self.tc_kwargs['run']) + rc = self.tc.runTests(processes=self.processes, skips=self.skips) configuration = self.get_configuration(args) rc.logDetails(self.get_json_result_dir(args), configuration,
PATCH 41/41 oeqa/selftest: Use the core executor's run()
In reply to Richard PurdieOESelftestTestContextExecutor carried its own copy of run(), split into run() and _internal_run(), which differed from the core version only in finding the test module paths from BBPATH, always writing the json results and creating the results log link even when the run raised an exception. It also had its own versions of the configuration, result id and json directory hooks under different names, which the core code never called.
Split the core run() so the results log link is always created, pass args to _get_configuration() as the selftest version needs it, rename the selftest hooks to match the core ones and set the module paths in _process_args(). The selftest copy of run() can then be dropped.
This also fixes the core run() failing with FileExistsError when the old results log link is dangling, as os.path.exists() is false for a broken link. Use os.path.lexists() as the selftest code did.
AI-Generated: Uses Claude Opus 5.5
--- meta/lib/oeqa/core/context.py | 52 +++++++++++++++++-------------- meta/lib/oeqa/selftest/context.py | 49 ++++------------------------- 2 files changed, 34 insertions(+), 67 deletions(-)
meta/lib/oeqa/core/context.py +28 -24
@@ -194,7 +194,7 @@ class OETestContextExecutor: def _get_json_result_dir(self, args): return args.json_result_dir - def _get_configuration(self): + def _get_configuration(self, args): td = self.td configuration = {'TEST_TYPE': self.name, 'MACHINE': td.get("MACHINE"),
@@ -210,9 +210,7 @@ class OETestContextExecutor: def _pre_run(self): pass - def run(self, logger, args): - self._process_args(logger, args) - + def _run(self, logger, args): self.tc = self._context_class(td=self.td, logger=self.logger, **self.context_args) try: self.tc.loadTests(self.module_paths, modules=self.modules,
@@ -222,28 +220,34 @@ class OETestContextExecutor: sys.exit(1) if args.list_tests: - rc = self.tc.listTests(args.list_tests) + return self.tc.listTests(args.list_tests) + + self._pre_run() + rc = self.tc.runTests(processes=self.processes, skips=self.skips) + + json_result_dir = self._get_json_result_dir(args) + if json_result_dir: + configuration = self._get_configuration(args) + rc.logDetails(json_result_dir, + configuration, + self._get_result_id(configuration)) else: - self._pre_run() - rc = self.tc.runTests(processes=self.processes, skips=self.skips) - - json_result_dir = self._get_json_result_dir(args) - if json_result_dir: - configuration = self._get_configuration() - rc.logDetails(json_result_dir, - configuration, - self._get_result_id(configuration)) - else: - rc.logDetails() - - rc.logSummary(self.name) - - output_link = os.path.join(os.path.dirname(args.output_log), - "%s-results.log" % self.name) - if os.path.exists(output_link): - os.remove(output_link) - os.symlink(args.output_log, output_link) + rc.logDetails() + rc.logSummary(self.name) return rc + def run(self, logger, args): + self._process_args(logger, args) + try: + return self._run(logger, args) + finally: + # Link to the latest log, even if running the tests failed. The + # old link may be dangling if its log was removed. + output_link = os.path.join(os.path.dirname(args.output_log), + "%s-results.log" % self.name) + if os.path.lexists(output_link): + os.unlink(output_link) + os.symlink(args.output_log, output_link) + _executor_class = OETestContextExecutor
meta/lib/oeqa/selftest/context.py +6 -43
79 lines not on this page · raw message