selftest/context: Avoid tracebacks from tests using multiprocessing
PATCH 1/3 selftest/context: Avoid tracebacks from tests using multiprocessing
We can see tracebacks where the SIGTERM handler catches things it shouldn't. Avoid exit(1) unless we're the process that it was intended for.
[YOCTO #13664]
--- meta/lib/oeqa/selftest/context.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
meta/lib/oeqa/selftest/context.py +5 -1
@@ -280,11 +280,15 @@ class OESelftestTestContextExecutor(OETestContextExecutor): return rc def _signal_clean_handler(self, signum, frame): - sys.exit(1) + if self.ourpid == os.getpid(): + sys.exit(1) def run(self, logger, args): self._process_args(logger, args) + # Setup a SIGTERM handler to allow restoration of files like local.conf and bblayers.conf + # but don't interfer with other processes + self.ourpid = os.getpid() signal.signal(signal.SIGTERM, self._signal_clean_handler) rc = None
Signature · 1 line
2.25.0
PATCH 2/3 oeqa/selftest: Startardise seperate builddir for concurrent and non-concurrent selftest
Currently oe-selftest reuses the current build directory and the concurrent version run with -j does not.
Standardise and use a separate new build directory in both cases. This will lead to simpler code and more reliable user run tests.
--- meta/lib/oeqa/core/context.py | 12 +++-- meta/lib/oeqa/core/utils/concurrencytest.py | 35 ++------------- meta/lib/oeqa/selftest/context.py | 50 +++++++++++++++++++++ 3 files changed, 58 insertions(+), 39 deletions(-)
meta/lib/oeqa/core/context.py +5 -7
@@ -72,6 +72,9 @@ class OETestContext(object): modules_required, **kwargs) self.suites = self.loader.discover() + def prepareSuite(self, suites, processes): + return suites + def runTests(self, processes=None, skips=[]): self.runner = self.runnerClass(self, descriptions=False, verbosity=2)
@@ -79,14 +82,9 @@ class OETestContext(object): self.skipTests(skips) self._run_start_time = time.time() - if processes: - from oeqa.core.utils.concurrencytest import ConcurrentTestSuite - - concurrent_suite = ConcurrentTestSuite(self.suites, processes) - result = self.runner.run(concurrent_suite) - else: + if not processes: self.runner.buffer = True - result = self.runner.run(self.suites) + result = self.runner.run(self.prepareSuite(self.suites, processes)) self._run_end_time = time.time() return result
meta/lib/oeqa/core/utils/concurrencytest.py +3 -32
@@ -177,9 +177,10 @@ class dummybuf(object): # class ConcurrentTestSuite(unittest.TestSuite): - def __init__(self, suite, processes): + def __init__(self, suite, processes, setupfunc): super(ConcurrentTestSuite, self).__init__([suite]) self.processes = processes + self.setupfunc = setupfunc def run(self, result): tests, totaltests = fork_for_tests(self.processes, self)
@@ -272,37 +273,7 @@ def fork_for_tests(concurrency_num, suite): stream = os.fdopen(c2pwrite, 'wb', 1) os.close(c2pread) - # Create a new separate BUILDDIR for each group of tests - if 'BUILDDIR' in os.environ: - builddir = os.environ['BUILDDIR'] - newbuilddir = builddir + "-st-" + str(ourpid) - newselftestdir = newbuilddir + "/meta-selftest" - - bb.utils.mkdirhier(newbuilddir) - oe.path.copytree(builddir + "/conf", newbuilddir + "/conf") - oe.path.copytree(builddir + "/cache", newbuilddir + "/cache") - oe.path.copytree(selftestdir, newselftestdir) - - for e in os.environ: - if builddir in os.environ[e]: - os.environ[e] = os.environ[e].replace(builddir, newbuilddir) - - subprocess.check_output("git init; git add *; git commit -a -m 'initial'", cwd=newselftestdir, shell=True) - - # Tried to used bitbake-layers add/remove but it requires recipe parsing and hence is too slow - subprocess.check_output("sed %s/conf/bblayers.conf -i -e 's#%s#%s#g'" % (newbuilddir, selftestdir, newselftestdir), cwd=newbuilddir, shell=True) - - os.chdir(newbuilddir) - - for t in process_suite: - if not hasattr(t, "tc"): - continue - cp = t.tc.config_paths - for p in cp: - if selftestdir in cp[p] and newselftestdir not in cp[p]: - cp[p] = cp[p].replace(selftestdir, newselftestdir) - if builddir in cp[p] and newbuilddir not in cp[p]: - cp[p] = cp[p].replace(builddir, newbuilddir) + (builddir, newbuilddir) = suite.setupfunc("-st-" + str(ourpid), selftestdir, process_suite) # Leave stderr and stdout open so we can see test noise # Close stdin so that the child goes away if it decides to
meta/lib/oeqa/selftest/context.py +50 -0
67 lines not on this page · raw message
Signature · 1 line
2.25.0
PATCH 3/3 oeqa/selftest: Drop 'backup' code and SIGTERM handler
In reply to Richard PurdieNow selftest is using its own copied build directory, we can stop worrying about copying files around as backup, and drop the SIGTERM handler to try and restore them, simplifying the code.
--- meta/lib/oeqa/selftest/case.py | 30 +------------------- meta/lib/oeqa/selftest/context.py | 47 ++----------------------------- 2 files changed, 4 insertions(+), 73 deletions(-)
meta/lib/oeqa/selftest/case.py +1 -29
@@ -6,7 +6,6 @@ import sys import os -import shutil import glob import errno from unittest.util import safe_repr
@@ -30,9 +29,7 @@ class OESelftestTestCase(OETestCase): cls.builddir = cls.tc.config_paths['builddir'] cls.localconf_path = cls.tc.config_paths['localconf'] - cls.localconf_backup = cls.tc.config_paths['localconf_class_backup'] cls.local_bblayers_path = cls.tc.config_paths['bblayers'] - cls.local_bblayers_backup = cls.tc.config_paths['bblayers_class_backup'] cls.testinc_path = os.path.join(cls.tc.config_paths['builddir'], "conf/selftest.inc")
@@ -43,8 +40,7 @@ class OESelftestTestCase(OETestCase): cls._track_for_cleanup = [ cls.testinc_path, cls.testinc_bblayers_path, - cls.machineinc_path, cls.localconf_backup, - cls.local_bblayers_backup] + cls.machineinc_path] cls.add_include()
@@ -102,30 +98,6 @@ class OESelftestTestCase(OETestCase): def setUp(self): super(OESelftestTestCase, self).setUp() os.chdir(self.builddir) - # Check if local.conf or bblayers.conf files backup exists - # from a previous failed test and restore them - if os.path.isfile(self.localconf_backup) or os.path.isfile( - self.local_bblayers_backup): - self.logger.debug("\ -Found a local.conf and/or bblayers.conf backup from a previously aborted test.\ -Restoring these files now, but tests should be re-executed from a clean environment\ -to ensure accurate results.") - try: - shutil.copyfile(self.localconf_backup, self.localconf_path) - except OSError as e: - if e.errno != errno.ENOENT: - raise - try: - shutil.copyfile(self.local_bblayers_backup, - self.local_bblayers_path) - except OSError as e: - if e.errno != errno.ENOENT: - raise - else: - # backup local.conf and bblayers.conf - shutil.copyfile(self.localconf_path, self.localconf_backup) - shutil.copyfile(self.local_bblayers_path, self.local_bblayers_backup) - self.logger.debug("Creating local.conf and bblayers.conf backups.") # we don't know what the previous test left around in config or inc files # if it failed so we need a fresh start try:
meta/lib/oeqa/selftest/context.py +3 -44
76 lines not on this page · raw message
Signature · 1 line
2.25.0
Re: [PATCH 3/3] oeqa/selftest: Drop 'backup' code and SIGTERM handler
Quoted 15 lines
-----Original Message-----
From: [email protected] <[email protected]> On Behalf Of Richard Purdie
Sent: den 19 februari 2020 19:38
To: [email protected]
Subject: [OE-core] [PATCH 3/3] oeqa/selftest: Drop 'backup' code and SIGTERM handlerNow selftest is using its own copied build directory, we can stop worrying about copying files around as backup, and drop the SIGTERM handler to try and restore them, simplifying the code.
Signed-off-by Richard Purdie <[email protected]>--- meta/lib/oeqa/selftest/case.py | 30 +------------------- meta/lib/oeqa/selftest/context.py | 47 ++----------------------------- 2 files changed, 4 insertions(+), 73 deletions(-)
[cut]
Quoted 7 lines
(quoted diff) +0
-0@@ -329,18 +311,9 @@ classOESelftestTestContextExecutor(OETestContextExecutor):
return rc
meta/lib/oeqa/selftest/context.py +0
-2- def _signal_clean_handler(self, signum, frame): - if self.ourpid == os.getpid():
meta/lib/oeqa/selftest/context.py class OESelftestTestContextExecutor(OETestContextExecutor): · line 343
Quoted 10 lines
meta/lib/oeqa/selftest/context.py +0
-7- sys.exit(1) - def run(self, logger, args): self._process_args(logger, args) - # Setup a SIGTERM handler to allow restoration of files like local.conf and bblayers.conf - # but don't interfer with other processes - self.ourpid = os.getpid() - signal.signal(signal.SIGTERM, self._signal_clean_handler) -
What's the point of the first patch in this series, when you just remove it all again here in the third patch?
Quoted 3 lines
rc = None
try:
if args.machine:
//Peter
Re: [PATCH 3/3] oeqa/selftest: Drop 'backup' code and SIGTERM handler
Quoted 36 lines · Peter Kjellerstedt
Quoted 21 lines
-----Original Message-----
From: [email protected] < [email protected]> On Behalf Of Richard Purdie
Sent: den 19 februari 2020 19:38
To: [email protected]
Subject: [OE-core] [PATCH 3/3] oeqa/selftest: Drop 'backup' code and SIGTERM handlerNow selftest is using its own copied build directory, we can stop worrying about
copying files around as backup, and drop the SIGTERM handler to try and restore
them, simplifying the code.Signed-off-by Richard Purdie <[email protected]>--- meta/lib/oeqa/selftest/case.py | 30 +------------------- meta/lib/oeqa/selftest/context.py | 47 ++------------------------- ---- 2 files changed, 4 insertions(+), 73 deletions(-)[cut]
Quoted 12 lines
(quoted diff) +0
-0@@ -329,18 +311,9 @@ classOESelftestTestContextExecutor(OETestContextExecutor):
return rc
meta/lib/oeqa/selftest/context.py +0
-4- def _signal_clean_handler(self, signum, frame): - if self.ourpid == os.getpid(): - sys.exit(1) - def run(self, logger, args): self._process_args(logger, args)
Quoted 9 lines
meta/lib/oeqa/selftest/context.py class OESelftestTestContextExecutor(OETestContextExecutor): · line 343
Quoted 6 lines
- # Setup a SIGTERM handler to allow restoration of files
like local.conf and bblayers.confmeta/lib/oeqa/selftest/context.py +0
-4- # but don't interfer with other processes - self.ourpid = os.getpid() - signal.signal(signal.SIGTERM, self._signal_clean_handler) -What's the point of the first patch in this series, when you just remove it all again here in the third patch?
The bug affects stable series builds as well as master. We're probably unlikely to accept 2/3 or 3/3 into stable builds? I therefore wrote it as a series, just in case the stable maintainers do pick up 1/3 which I'd figured out before writing 2/3 and 3/3.
Cheers,
Richard