diff options
| author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-02-19 18:19:49 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-02-21 09:39:00 +0000 |
| commit | c569157d9d8aa43eddb98e9fbe66339bf7f20958 (patch) | |
| tree | 671587e101ad4c141a21e5f776de2b6fe14bde15 | |
| parent | dba8c1d5ef0b574b7772d59e5992bfad8b7cca13 (diff) | |
| download | poky-c569157d9d8aa43eddb98e9fbe66339bf7f20958.tar.gz | |
oeqa/selftest: Standardise 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.
(From OE-Core rev: 50238b0717b04e0a1fa69d618e8c8aa8445a80b0)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/lib/oeqa/core/context.py | 12 | ||||
| -rw-r--r-- | meta/lib/oeqa/core/utils/concurrencytest.py | 35 | ||||
| -rw-r--r-- | meta/lib/oeqa/selftest/context.py | 50 |
3 files changed, 58 insertions, 39 deletions
diff --git a/meta/lib/oeqa/core/context.py b/meta/lib/oeqa/core/context.py index 14fc6a54f4..16320af115 100644 --- a/meta/lib/oeqa/core/context.py +++ b/meta/lib/oeqa/core/context.py | |||
| @@ -72,6 +72,9 @@ class OETestContext(object): | |||
| 72 | modules_required, **kwargs) | 72 | modules_required, **kwargs) |
| 73 | self.suites = self.loader.discover() | 73 | self.suites = self.loader.discover() |
| 74 | 74 | ||
| 75 | def prepareSuite(self, suites, processes): | ||
| 76 | return suites | ||
| 77 | |||
| 75 | def runTests(self, processes=None, skips=[]): | 78 | def runTests(self, processes=None, skips=[]): |
| 76 | self.runner = self.runnerClass(self, descriptions=False, verbosity=2) | 79 | self.runner = self.runnerClass(self, descriptions=False, verbosity=2) |
| 77 | 80 | ||
| @@ -79,14 +82,9 @@ class OETestContext(object): | |||
| 79 | self.skipTests(skips) | 82 | self.skipTests(skips) |
| 80 | 83 | ||
| 81 | self._run_start_time = time.time() | 84 | self._run_start_time = time.time() |
| 82 | if processes: | 85 | if not processes: |
| 83 | from oeqa.core.utils.concurrencytest import ConcurrentTestSuite | ||
| 84 | |||
| 85 | concurrent_suite = ConcurrentTestSuite(self.suites, processes) | ||
| 86 | result = self.runner.run(concurrent_suite) | ||
| 87 | else: | ||
| 88 | self.runner.buffer = True | 86 | self.runner.buffer = True |
| 89 | result = self.runner.run(self.suites) | 87 | result = self.runner.run(self.prepareSuite(self.suites, processes)) |
| 90 | self._run_end_time = time.time() | 88 | self._run_end_time = time.time() |
| 91 | 89 | ||
| 92 | return result | 90 | return result |
diff --git a/meta/lib/oeqa/core/utils/concurrencytest.py b/meta/lib/oeqa/core/utils/concurrencytest.py index 0d9c01e6d4..fac59f765a 100644 --- a/meta/lib/oeqa/core/utils/concurrencytest.py +++ b/meta/lib/oeqa/core/utils/concurrencytest.py | |||
| @@ -177,9 +177,10 @@ class dummybuf(object): | |||
| 177 | # | 177 | # |
| 178 | class ConcurrentTestSuite(unittest.TestSuite): | 178 | class ConcurrentTestSuite(unittest.TestSuite): |
| 179 | 179 | ||
| 180 | def __init__(self, suite, processes): | 180 | def __init__(self, suite, processes, setupfunc): |
| 181 | super(ConcurrentTestSuite, self).__init__([suite]) | 181 | super(ConcurrentTestSuite, self).__init__([suite]) |
| 182 | self.processes = processes | 182 | self.processes = processes |
| 183 | self.setupfunc = setupfunc | ||
| 183 | 184 | ||
| 184 | def run(self, result): | 185 | def run(self, result): |
| 185 | tests, totaltests = fork_for_tests(self.processes, self) | 186 | tests, totaltests = fork_for_tests(self.processes, self) |
| @@ -272,37 +273,7 @@ def fork_for_tests(concurrency_num, suite): | |||
| 272 | stream = os.fdopen(c2pwrite, 'wb', 1) | 273 | stream = os.fdopen(c2pwrite, 'wb', 1) |
| 273 | os.close(c2pread) | 274 | os.close(c2pread) |
| 274 | 275 | ||
| 275 | # Create a new separate BUILDDIR for each group of tests | 276 | (builddir, newbuilddir) = suite.setupfunc("-st-" + str(ourpid), selftestdir, process_suite) |
| 276 | if 'BUILDDIR' in os.environ: | ||
| 277 | builddir = os.environ['BUILDDIR'] | ||
| 278 | newbuilddir = builddir + "-st-" + str(ourpid) | ||
| 279 | newselftestdir = newbuilddir + "/meta-selftest" | ||
| 280 | |||
| 281 | bb.utils.mkdirhier(newbuilddir) | ||
| 282 | oe.path.copytree(builddir + "/conf", newbuilddir + "/conf") | ||
| 283 | oe.path.copytree(builddir + "/cache", newbuilddir + "/cache") | ||
| 284 | oe.path.copytree(selftestdir, newselftestdir) | ||
| 285 | |||
| 286 | for e in os.environ: | ||
| 287 | if builddir in os.environ[e]: | ||
| 288 | os.environ[e] = os.environ[e].replace(builddir, newbuilddir) | ||
| 289 | |||
| 290 | subprocess.check_output("git init; git add *; git commit -a -m 'initial'", cwd=newselftestdir, shell=True) | ||
| 291 | |||
| 292 | # Tried to used bitbake-layers add/remove but it requires recipe parsing and hence is too slow | ||
| 293 | subprocess.check_output("sed %s/conf/bblayers.conf -i -e 's#%s#%s#g'" % (newbuilddir, selftestdir, newselftestdir), cwd=newbuilddir, shell=True) | ||
| 294 | |||
| 295 | os.chdir(newbuilddir) | ||
| 296 | |||
| 297 | for t in process_suite: | ||
| 298 | if not hasattr(t, "tc"): | ||
| 299 | continue | ||
| 300 | cp = t.tc.config_paths | ||
| 301 | for p in cp: | ||
| 302 | if selftestdir in cp[p] and newselftestdir not in cp[p]: | ||
| 303 | cp[p] = cp[p].replace(selftestdir, newselftestdir) | ||
| 304 | if builddir in cp[p] and newbuilddir not in cp[p]: | ||
| 305 | cp[p] = cp[p].replace(builddir, newbuilddir) | ||
| 306 | 277 | ||
| 307 | # Leave stderr and stdout open so we can see test noise | 278 | # Leave stderr and stdout open so we can see test noise |
| 308 | # Close stdin so that the child goes away if it decides to | 279 | # Close stdin so that the child goes away if it decides to |
diff --git a/meta/lib/oeqa/selftest/context.py b/meta/lib/oeqa/selftest/context.py index 3d3b19c6e8..cd893261d3 100644 --- a/meta/lib/oeqa/selftest/context.py +++ b/meta/lib/oeqa/selftest/context.py | |||
| @@ -10,11 +10,13 @@ import glob | |||
| 10 | import sys | 10 | import sys |
| 11 | import importlib | 11 | import importlib |
| 12 | import signal | 12 | import signal |
| 13 | import subprocess | ||
| 13 | from shutil import copyfile | 14 | from shutil import copyfile |
| 14 | from random import choice | 15 | from random import choice |
| 15 | 16 | ||
| 16 | import oeqa | 17 | import oeqa |
| 17 | import oe | 18 | import oe |
| 19 | import bb.utils | ||
| 18 | 20 | ||
| 19 | from oeqa.core.context import OETestContext, OETestContextExecutor | 21 | from oeqa.core.context import OETestContext, OETestContextExecutor |
| 20 | from oeqa.core.exception import OEQAPreRun, OEQATestNotFound | 22 | from oeqa.core.exception import OEQAPreRun, OEQATestNotFound |
| @@ -29,6 +31,54 @@ class OESelftestTestContext(OETestContext): | |||
| 29 | self.custommachine = None | 31 | self.custommachine = None |
| 30 | self.config_paths = config_paths | 32 | self.config_paths = config_paths |
| 31 | 33 | ||
| 34 | def setup_builddir(self, suffix, selftestdir, suite): | ||
| 35 | builddir = os.environ['BUILDDIR'] | ||
| 36 | if not selftestdir: | ||
| 37 | selftestdir = get_test_layer() | ||
| 38 | newbuilddir = builddir + suffix | ||
| 39 | newselftestdir = newbuilddir + "/meta-selftest" | ||
| 40 | |||
| 41 | if os.path.exists(newbuilddir): | ||
| 42 | self.logger.error("Build directory %s already exists, aborting" % newbuilddir) | ||
| 43 | sys.exit(1) | ||
| 44 | |||
| 45 | bb.utils.mkdirhier(newbuilddir) | ||
| 46 | oe.path.copytree(builddir + "/conf", newbuilddir + "/conf") | ||
| 47 | oe.path.copytree(builddir + "/cache", newbuilddir + "/cache") | ||
| 48 | oe.path.copytree(selftestdir, newselftestdir) | ||
| 49 | |||
| 50 | for e in os.environ: | ||
| 51 | if builddir in os.environ[e]: | ||
| 52 | os.environ[e] = os.environ[e].replace(builddir, newbuilddir) | ||
| 53 | |||
| 54 | subprocess.check_output("git init; git add *; git commit -a -m 'initial'", cwd=newselftestdir, shell=True) | ||
| 55 | |||
| 56 | # Tried to used bitbake-layers add/remove but it requires recipe parsing and hence is too slow | ||
| 57 | subprocess.check_output("sed %s/conf/bblayers.conf -i -e 's#%s#%s#g'" % (newbuilddir, selftestdir, newselftestdir), cwd=newbuilddir, shell=True) | ||
| 58 | |||
| 59 | os.chdir(newbuilddir) | ||
| 60 | |||
| 61 | for t in suite: | ||
| 62 | if not hasattr(t, "tc"): | ||
| 63 | continue | ||
| 64 | cp = t.tc.config_paths | ||
| 65 | for p in cp: | ||
| 66 | if selftestdir in cp[p] and newselftestdir not in cp[p]: | ||
| 67 | cp[p] = cp[p].replace(selftestdir, newselftestdir) | ||
| 68 | if builddir in cp[p] and newbuilddir not in cp[p]: | ||
| 69 | cp[p] = cp[p].replace(builddir, newbuilddir) | ||
| 70 | |||
| 71 | return (builddir, newbuilddir) | ||
| 72 | |||
| 73 | def prepareSuite(self, suites, processes): | ||
| 74 | if processes: | ||
| 75 | from oeqa.core.utils.concurrencytest import ConcurrentTestSuite | ||
| 76 | |||
| 77 | return ConcurrentTestSuite(suites, processes, self.setup_builddir) | ||
| 78 | else: | ||
| 79 | self.setup_builddir("-st", None, suites) | ||
| 80 | return suites | ||
| 81 | |||
| 32 | def runTests(self, processes=None, machine=None, skips=[]): | 82 | def runTests(self, processes=None, machine=None, skips=[]): |
| 33 | if machine: | 83 | if machine: |
| 34 | self.custommachine = machine | 84 | self.custommachine = machine |
