diff options
author | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-09-21 17:49:25 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2023-09-22 07:45:17 +0100 |
commit | 7e6514b28b71f86fa911338e31ec4b284eb8fe46 (patch) | |
tree | 39252ae53c371cc47bc9ba1da1f412f7d19bbdbd /meta | |
parent | fbaa7da33b497088aa352f6cb8dbc02327310cd6 (diff) | |
download | poky-7e6514b28b71f86fa911338e31ec4b284eb8fe46.tar.gz |
oeqa: Streamline oe-selftest startup time
"bitbake -e" executions from get_bb_var calls are slow and slow down oe-selftest
startup. Rationalise the code to avoid them and minimise the number of "parsing"
locations we use by caching key variables and passing them around more.
This was particularly problematic with oe-selftest -j usage since it would
have multiple bitbake -e executions per process making parallel usage
particularly slow.
(From OE-Core rev: 3689cadeb07d76e66f97d890e844f899f69666fe)
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/lib/oeqa/core/utils/concurrencytest.py | 5 | ||||
-rw-r--r-- | meta/lib/oeqa/selftest/context.py | 35 | ||||
-rw-r--r-- | meta/lib/oeqa/utils/commands.py | 6 |
3 files changed, 28 insertions, 18 deletions
diff --git a/meta/lib/oeqa/core/utils/concurrencytest.py b/meta/lib/oeqa/core/utils/concurrencytest.py index 4f77589b00..5e20b0e126 100644 --- a/meta/lib/oeqa/core/utils/concurrencytest.py +++ b/meta/lib/oeqa/core/utils/concurrencytest.py | |||
@@ -193,11 +193,12 @@ class dummybuf(object): | |||
193 | # | 193 | # |
194 | class ConcurrentTestSuite(unittest.TestSuite): | 194 | class ConcurrentTestSuite(unittest.TestSuite): |
195 | 195 | ||
196 | def __init__(self, suite, processes, setupfunc, removefunc): | 196 | def __init__(self, suite, processes, setupfunc, removefunc, bb_vars): |
197 | super(ConcurrentTestSuite, self).__init__([suite]) | 197 | super(ConcurrentTestSuite, self).__init__([suite]) |
198 | self.processes = processes | 198 | self.processes = processes |
199 | self.setupfunc = setupfunc | 199 | self.setupfunc = setupfunc |
200 | self.removefunc = removefunc | 200 | self.removefunc = removefunc |
201 | self.bb_vars = bb_vars | ||
201 | 202 | ||
202 | def run(self, result): | 203 | def run(self, result): |
203 | testservers, totaltests = fork_for_tests(self.processes, self) | 204 | testservers, totaltests = fork_for_tests(self.processes, self) |
@@ -243,7 +244,7 @@ class ConcurrentTestSuite(unittest.TestSuite): | |||
243 | def fork_for_tests(concurrency_num, suite): | 244 | def fork_for_tests(concurrency_num, suite): |
244 | testservers = [] | 245 | testservers = [] |
245 | if 'BUILDDIR' in os.environ: | 246 | if 'BUILDDIR' in os.environ: |
246 | selftestdir = get_test_layer() | 247 | selftestdir = get_test_layer(suite.bb_vars['BBLAYERS']) |
247 | 248 | ||
248 | test_blocks = partition_tests(suite, concurrency_num) | 249 | test_blocks = partition_tests(suite, concurrency_num) |
249 | # Clear the tests from the original suite so it doesn't keep them alive | 250 | # Clear the tests from the original suite so it doesn't keep them alive |
diff --git a/meta/lib/oeqa/selftest/context.py b/meta/lib/oeqa/selftest/context.py index 16486e7eb9..5a09aeedff 100644 --- a/meta/lib/oeqa/selftest/context.py +++ b/meta/lib/oeqa/selftest/context.py | |||
@@ -35,12 +35,13 @@ def get_oeselftest_metadata(args): | |||
35 | return result | 35 | return result |
36 | 36 | ||
37 | class NonConcurrentTestSuite(unittest.TestSuite): | 37 | class NonConcurrentTestSuite(unittest.TestSuite): |
38 | def __init__(self, suite, processes, setupfunc, removefunc): | 38 | def __init__(self, suite, processes, setupfunc, removefunc, bb_vars): |
39 | super().__init__([suite]) | 39 | super().__init__([suite]) |
40 | self.processes = processes | 40 | self.processes = processes |
41 | self.suite = suite | 41 | self.suite = suite |
42 | self.setupfunc = setupfunc | 42 | self.setupfunc = setupfunc |
43 | self.removefunc = removefunc | 43 | self.removefunc = removefunc |
44 | self.bb_vars = bb_vars | ||
44 | 45 | ||
45 | def run(self, result): | 46 | def run(self, result): |
46 | (builddir, newbuilddir) = self.setupfunc("-st", None, self.suite) | 47 | (builddir, newbuilddir) = self.setupfunc("-st", None, self.suite) |
@@ -79,16 +80,15 @@ class OESelftestTestContext(OETestContext): | |||
79 | else: | 80 | else: |
80 | self.removebuilddir = removebuilddir | 81 | self.removebuilddir = removebuilddir |
81 | 82 | ||
83 | def set_variables(self, vars): | ||
84 | self.bb_vars = vars | ||
85 | |||
82 | def setup_builddir(self, suffix, selftestdir, suite): | 86 | def setup_builddir(self, suffix, selftestdir, suite): |
83 | # Get SSTATE_DIR from the parent build dir | 87 | sstatedir = self.bb_vars['SSTATE_DIR'] |
84 | with bb.tinfoil.Tinfoil(tracking=True) as tinfoil: | ||
85 | tinfoil.prepare(quiet=2, config_only=True) | ||
86 | d = tinfoil.config_data | ||
87 | sstatedir = str(d.getVar('SSTATE_DIR')) | ||
88 | 88 | ||
89 | builddir = os.environ['BUILDDIR'] | 89 | builddir = os.environ['BUILDDIR'] |
90 | if not selftestdir: | 90 | if not selftestdir: |
91 | selftestdir = get_test_layer() | 91 | selftestdir = get_test_layer(self.bb_vars['BBLAYERS']) |
92 | if self.newbuilddir: | 92 | if self.newbuilddir: |
93 | newbuilddir = os.path.join(self.newbuilddir, 'build' + suffix) | 93 | newbuilddir = os.path.join(self.newbuilddir, 'build' + suffix) |
94 | else: | 94 | else: |
@@ -155,9 +155,9 @@ class OESelftestTestContext(OETestContext): | |||
155 | if processes: | 155 | if processes: |
156 | from oeqa.core.utils.concurrencytest import ConcurrentTestSuite | 156 | from oeqa.core.utils.concurrencytest import ConcurrentTestSuite |
157 | 157 | ||
158 | return ConcurrentTestSuite(suites, processes, self.setup_builddir, self.removebuilddir) | 158 | return ConcurrentTestSuite(suites, processes, self.setup_builddir, self.removebuilddir, self.bb_vars) |
159 | else: | 159 | else: |
160 | return NonConcurrentTestSuite(suites, processes, self.setup_builddir, self.removebuilddir) | 160 | return NonConcurrentTestSuite(suites, processes, self.setup_builddir, self.removebuilddir, self.bb_vars) |
161 | 161 | ||
162 | def runTests(self, processes=None, machine=None, skips=[]): | 162 | def runTests(self, processes=None, machine=None, skips=[]): |
163 | if machine: | 163 | if machine: |
@@ -270,7 +270,7 @@ class OESelftestTestContextExecutor(OETestContextExecutor): | |||
270 | 270 | ||
271 | builddir = os.environ.get("BUILDDIR") | 271 | builddir = os.environ.get("BUILDDIR") |
272 | self.tc_kwargs['init']['config_paths'] = {} | 272 | self.tc_kwargs['init']['config_paths'] = {} |
273 | self.tc_kwargs['init']['config_paths']['testlayer_path'] = get_test_layer() | 273 | self.tc_kwargs['init']['config_paths']['testlayer_path'] = get_test_layer(bbvars["BBLAYERS"]) |
274 | self.tc_kwargs['init']['config_paths']['builddir'] = builddir | 274 | self.tc_kwargs['init']['config_paths']['builddir'] = builddir |
275 | self.tc_kwargs['init']['config_paths']['localconf'] = os.path.join(builddir, "conf/local.conf") | 275 | self.tc_kwargs['init']['config_paths']['localconf'] = os.path.join(builddir, "conf/local.conf") |
276 | self.tc_kwargs['init']['config_paths']['bblayers'] = os.path.join(builddir, "conf/bblayers.conf") | 276 | self.tc_kwargs['init']['config_paths']['bblayers'] = os.path.join(builddir, "conf/bblayers.conf") |
@@ -310,10 +310,10 @@ class OESelftestTestContextExecutor(OETestContextExecutor): | |||
310 | meta_selftestdir = os.path.join( | 310 | meta_selftestdir = os.path.join( |
311 | self.tc.td["BBLAYERS_FETCH_DIR"], 'meta-selftest') | 311 | self.tc.td["BBLAYERS_FETCH_DIR"], 'meta-selftest') |
312 | if os.path.isdir(meta_selftestdir): | 312 | if os.path.isdir(meta_selftestdir): |
313 | runCmd("bitbake-layers add-layer %s" %meta_selftestdir) | 313 | runCmd("bitbake-layers add-layer %s" % meta_selftestdir) |
314 | # reload data is needed because a meta-selftest layer was add | 314 | # reload data is needed because a meta-selftest layer was add |
315 | self.tc.td = get_bb_vars() | 315 | self.tc.td = get_bb_vars() |
316 | self.tc.config_paths['testlayer_path'] = get_test_layer() | 316 | self.tc.config_paths['testlayer_path'] = get_test_layer(self.tc.td["BBLAYERS"]) |
317 | else: | 317 | else: |
318 | self.tc.logger.error("could not locate meta-selftest in:\n%s" % meta_selftestdir) | 318 | self.tc.logger.error("could not locate meta-selftest in:\n%s" % meta_selftestdir) |
319 | raise OEQAPreRun | 319 | raise OEQAPreRun |
@@ -351,8 +351,15 @@ class OESelftestTestContextExecutor(OETestContextExecutor): | |||
351 | 351 | ||
352 | _add_layer_libs() | 352 | _add_layer_libs() |
353 | 353 | ||
354 | self.tc.logger.info("Running bitbake -e to test the configuration is valid/parsable") | 354 | self.tc.logger.info("Checking base configuration is valid/parsable") |
355 | runCmd("bitbake -e") | 355 | |
356 | with bb.tinfoil.Tinfoil(tracking=True) as tinfoil: | ||
357 | tinfoil.prepare(quiet=2, config_only=True) | ||
358 | d = tinfoil.config_data | ||
359 | vars = {} | ||
360 | vars['SSTATE_DIR'] = str(d.getVar('SSTATE_DIR')) | ||
361 | vars['BBLAYERS'] = str(d.getVar('BBLAYERS')) | ||
362 | self.tc.set_variables(vars) | ||
356 | 363 | ||
357 | def get_json_result_dir(self, args): | 364 | def get_json_result_dir(self, args): |
358 | json_result_dir = os.path.join(self.tc.td["LOG_DIR"], 'oeqa') | 365 | json_result_dir = os.path.join(self.tc.td["LOG_DIR"], 'oeqa') |
diff --git a/meta/lib/oeqa/utils/commands.py b/meta/lib/oeqa/utils/commands.py index c1f533802e..575e380017 100644 --- a/meta/lib/oeqa/utils/commands.py +++ b/meta/lib/oeqa/utils/commands.py | |||
@@ -285,8 +285,10 @@ def get_bb_vars(variables=None, target=None, postconfig=None): | |||
285 | def get_bb_var(var, target=None, postconfig=None): | 285 | def get_bb_var(var, target=None, postconfig=None): |
286 | return get_bb_vars([var], target, postconfig)[var] | 286 | return get_bb_vars([var], target, postconfig)[var] |
287 | 287 | ||
288 | def get_test_layer(): | 288 | def get_test_layer(bblayers=None): |
289 | layers = get_bb_var("BBLAYERS").split() | 289 | if bblayers is None: |
290 | bblayers = get_bb_var("BBLAYERS") | ||
291 | layers = bblayers.split() | ||
290 | testlayer = None | 292 | testlayer = None |
291 | for l in layers: | 293 | for l in layers: |
292 | if '~' in l: | 294 | if '~' in l: |