mirror of
https://git.yoctoproject.org/poky
synced 2026-03-06 15:29:40 +01:00
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>
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -10,11 +10,13 @@ import glob
|
||||
import sys
|
||||
import importlib
|
||||
import signal
|
||||
import subprocess
|
||||
from shutil import copyfile
|
||||
from random import choice
|
||||
|
||||
import oeqa
|
||||
import oe
|
||||
import bb.utils
|
||||
|
||||
from oeqa.core.context import OETestContext, OETestContextExecutor
|
||||
from oeqa.core.exception import OEQAPreRun, OEQATestNotFound
|
||||
@@ -29,6 +31,54 @@ class OESelftestTestContext(OETestContext):
|
||||
self.custommachine = None
|
||||
self.config_paths = config_paths
|
||||
|
||||
def setup_builddir(self, suffix, selftestdir, suite):
|
||||
builddir = os.environ['BUILDDIR']
|
||||
if not selftestdir:
|
||||
selftestdir = get_test_layer()
|
||||
newbuilddir = builddir + suffix
|
||||
newselftestdir = newbuilddir + "/meta-selftest"
|
||||
|
||||
if os.path.exists(newbuilddir):
|
||||
self.logger.error("Build directory %s already exists, aborting" % newbuilddir)
|
||||
sys.exit(1)
|
||||
|
||||
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 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)
|
||||
|
||||
return (builddir, newbuilddir)
|
||||
|
||||
def prepareSuite(self, suites, processes):
|
||||
if processes:
|
||||
from oeqa.core.utils.concurrencytest import ConcurrentTestSuite
|
||||
|
||||
return ConcurrentTestSuite(suites, processes, self.setup_builddir)
|
||||
else:
|
||||
self.setup_builddir("-st", None, suites)
|
||||
return suites
|
||||
|
||||
def runTests(self, processes=None, machine=None, skips=[]):
|
||||
if machine:
|
||||
self.custommachine = machine
|
||||
|
||||
Reference in New Issue
Block a user