diff options
author | Joshua Watt <jpewhacker@gmail.com> | 2018-11-19 12:11:13 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2018-11-21 11:54:14 +0000 |
commit | 1554c7c3a69e1996c2d901feb22be37aa85c42a5 (patch) | |
tree | a49496be4c1a01a70556fb070d67578e65ad8be8 /meta/lib/oeqa/sdkext/testsdk.py | |
parent | bdffa0ce10870f70e0a7ab7636ff0d797df43e3a (diff) | |
download | poky-1554c7c3a69e1996c2d901feb22be37aa85c42a5.tar.gz |
classes/testsdk: Split implementation into classes
Splits the SDK test implementation into configurable Python classes. The
classes used for the normal and extensible SDKs are
${TESTSDK_CLASS_NAME} and ${TESTSDKEXT_CLASS_NAME} respectively.
This allows SDK machines to override the classes used to implement the
tests. For the traditional SDK, a common "run()" function is provided by
the class (oeqa.sdk.testsdk.TestSDK), with several hook member functions
that can be overridden in child classes, making it easier to have
consistent behavior. The extensible SDK class
(oeqa.sdkext.testsdk.TestSDKEXT) also has a common "run()" function, but
no hooks have yet been added as there is not currently a known use case
for create derived classes.
These changes should be purely organizational; no functional changes
have been made to either the standard SDK or extensible SDK tests.
[YOCTO #13020]
(From OE-Core rev: a06d53928b22d5f88276023c4d57b206db2f27f9)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/sdkext/testsdk.py')
-rw-r--r-- | meta/lib/oeqa/sdkext/testsdk.py | 104 |
1 files changed, 104 insertions, 0 deletions
diff --git a/meta/lib/oeqa/sdkext/testsdk.py b/meta/lib/oeqa/sdkext/testsdk.py new file mode 100644 index 0000000000..57b2e0e03f --- /dev/null +++ b/meta/lib/oeqa/sdkext/testsdk.py | |||
@@ -0,0 +1,104 @@ | |||
1 | # Copyright 2018 by Garmin Ltd. or its subsidiaries | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | |||
4 | from oeqa.sdk.testsdk import TestSDKBase | ||
5 | |||
6 | class TestSDKExt(TestSDKBase): | ||
7 | def run(self, d): | ||
8 | import os | ||
9 | import json | ||
10 | import subprocess | ||
11 | import logging | ||
12 | |||
13 | from bb.utils import export_proxies | ||
14 | from oeqa.utils import avoid_paths_in_environ, make_logger_bitbake_compatible, subprocesstweak | ||
15 | from oeqa.sdkext.context import OESDKExtTestContext, OESDKExtTestContextExecutor | ||
16 | |||
17 | pn = d.getVar("PN") | ||
18 | logger = make_logger_bitbake_compatible(logging.getLogger("BitBake")) | ||
19 | |||
20 | # extensible sdk use network | ||
21 | export_proxies(d) | ||
22 | |||
23 | subprocesstweak.errors_have_output() | ||
24 | |||
25 | # extensible sdk can be contaminated if native programs are | ||
26 | # in PATH, i.e. use perl-native instead of eSDK one. | ||
27 | paths_to_avoid = [d.getVar('STAGING_DIR'), | ||
28 | d.getVar('BASE_WORKDIR')] | ||
29 | os.environ['PATH'] = avoid_paths_in_environ(paths_to_avoid) | ||
30 | |||
31 | tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.sh") | ||
32 | if not os.path.exists(tcname): | ||
33 | bb.fatal("The toolchain ext %s is not built. Build it before running the" \ | ||
34 | " tests: 'bitbake <image> -c populate_sdk_ext' ." % tcname) | ||
35 | |||
36 | tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.testdata.json") | ||
37 | test_data = json.load(open(tdname, "r")) | ||
38 | |||
39 | target_pkg_manifest = OESDKExtTestContextExecutor._load_manifest( | ||
40 | d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest")) | ||
41 | host_pkg_manifest = OESDKExtTestContextExecutor._load_manifest( | ||
42 | d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.host.manifest")) | ||
43 | |||
44 | sdk_dir = d.expand("${WORKDIR}/testsdkext/") | ||
45 | bb.utils.remove(sdk_dir, True) | ||
46 | bb.utils.mkdirhier(sdk_dir) | ||
47 | try: | ||
48 | subprocess.check_output("%s -y -d %s" % (tcname, sdk_dir), shell=True) | ||
49 | except subprocess.CalledProcessError as e: | ||
50 | msg = "Couldn't install the extensible SDK:\n%s" % e.output.decode("utf-8") | ||
51 | logfn = os.path.join(sdk_dir, 'preparing_build_system.log') | ||
52 | if os.path.exists(logfn): | ||
53 | msg += '\n\nContents of preparing_build_system.log:\n' | ||
54 | with open(logfn, 'r') as f: | ||
55 | for line in f: | ||
56 | msg += line | ||
57 | bb.fatal(msg) | ||
58 | |||
59 | fail = False | ||
60 | sdk_envs = OESDKExtTestContextExecutor._get_sdk_environs(sdk_dir) | ||
61 | for s in sdk_envs: | ||
62 | bb.plain("Extensible SDK testing environment: %s" % s) | ||
63 | |||
64 | sdk_env = sdk_envs[s] | ||
65 | |||
66 | # Use our own SSTATE_DIR and DL_DIR so that updates to the eSDK come from our sstate cache | ||
67 | # and we don't spend hours downloading kernels for the kernel module test | ||
68 | # Abuse auto.conf since local.conf would be overwritten by the SDK | ||
69 | with open(os.path.join(sdk_dir, 'conf', 'auto.conf'), 'a+') as f: | ||
70 | f.write('SSTATE_MIRRORS += " \\n file://.* file://%s/PATH"\n' % test_data.get('SSTATE_DIR')) | ||
71 | f.write('SOURCE_MIRROR_URL = "file://%s"\n' % test_data.get('DL_DIR')) | ||
72 | f.write('INHERIT += "own-mirrors"\n') | ||
73 | f.write('PREMIRRORS_prepend = " git://git.yoctoproject.org/.* git://%s/git2/git.yoctoproject.org.BASENAME \\n "\n' % test_data.get('DL_DIR')) | ||
74 | |||
75 | # We need to do this in case we have a minimal SDK | ||
76 | subprocess.check_output(". %s > /dev/null; devtool sdk-install meta-extsdk-toolchain" % \ | ||
77 | sdk_env, cwd=sdk_dir, shell=True, stderr=subprocess.STDOUT) | ||
78 | |||
79 | tc = OESDKExtTestContext(td=test_data, logger=logger, sdk_dir=sdk_dir, | ||
80 | sdk_env=sdk_env, target_pkg_manifest=target_pkg_manifest, | ||
81 | host_pkg_manifest=host_pkg_manifest) | ||
82 | |||
83 | try: | ||
84 | tc.loadTests(OESDKExtTestContextExecutor.default_cases) | ||
85 | except Exception as e: | ||
86 | import traceback | ||
87 | bb.fatal("Loading tests failed:\n%s" % traceback.format_exc()) | ||
88 | |||
89 | result = tc.runTests() | ||
90 | |||
91 | component = "%s %s" % (pn, OESDKExtTestContextExecutor.name) | ||
92 | context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env)) | ||
93 | configuration = self.get_sdk_configuration(d, 'sdkext') | ||
94 | result.logDetails(self.get_sdk_json_result_dir(d), | ||
95 | configuration, | ||
96 | self.get_sdk_result_id(configuration)) | ||
97 | result.logSummary(component, context_msg) | ||
98 | |||
99 | if not result.wasSuccessful(): | ||
100 | fail = True | ||
101 | |||
102 | if fail: | ||
103 | bb.fatal("%s - FAILED - check the task log and the commands log" % pn) | ||
104 | |||