diff options
author | Joshua Watt <jpewhacker@gmail.com> | 2018-11-19 12:11:13 -0600 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2019-02-06 16:38:30 +0000 |
commit | 676046bc36b450f25e213a35000be20e68e7f19e (patch) | |
tree | 53625ddf1cf73b7447e392ba16ffb948cb7ab0db /meta/lib/oeqa/sdk | |
parent | f54aac732b70730b6ed393ae8cbacb1a0feab327 (diff) | |
download | poky-676046bc36b450f25e213a35000be20e68e7f19e.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)
(From OE-Core rev: d0828522fc3a4bd3f86488edcedcce10833c18dc)
Signed-off-by: Joshua Watt <JPEWhacker@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Signed-off-by: Armin Kuster <akuster808@gmail.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/lib/oeqa/sdk')
-rw-r--r-- | meta/lib/oeqa/sdk/testsdk.py | 142 |
1 files changed, 142 insertions, 0 deletions
diff --git a/meta/lib/oeqa/sdk/testsdk.py b/meta/lib/oeqa/sdk/testsdk.py new file mode 100644 index 0000000000..632ac50d0c --- /dev/null +++ b/meta/lib/oeqa/sdk/testsdk.py | |||
@@ -0,0 +1,142 @@ | |||
1 | # Copyright 2018 by Garmin Ltd. or its subsidiaries | ||
2 | # Released under the MIT license (see COPYING.MIT) | ||
3 | |||
4 | from oeqa.sdk.context import OESDKTestContext, OESDKTestContextExecutor | ||
5 | |||
6 | class TestSDKBase(object): | ||
7 | @staticmethod | ||
8 | def get_sdk_configuration(d, test_type): | ||
9 | import platform | ||
10 | import oe.lsb | ||
11 | from oeqa.utils.metadata import get_layers | ||
12 | configuration = {'TEST_TYPE': test_type, | ||
13 | 'MACHINE': d.getVar("MACHINE"), | ||
14 | 'SDKMACHINE': d.getVar("SDKMACHINE"), | ||
15 | 'IMAGE_BASENAME': d.getVar("IMAGE_BASENAME"), | ||
16 | 'IMAGE_PKGTYPE': d.getVar("IMAGE_PKGTYPE"), | ||
17 | 'STARTTIME': d.getVar("DATETIME"), | ||
18 | 'HOST_DISTRO': oe.lsb.distro_identifier().replace(' ', '-'), | ||
19 | 'LAYERS': get_layers(d.getVar("BBLAYERS"))} | ||
20 | return configuration | ||
21 | |||
22 | @staticmethod | ||
23 | def get_sdk_json_result_dir(d): | ||
24 | json_result_dir = os.path.join(d.getVar("LOG_DIR"), 'oeqa') | ||
25 | custom_json_result_dir = d.getVar("OEQA_JSON_RESULT_DIR") | ||
26 | if custom_json_result_dir: | ||
27 | json_result_dir = custom_json_result_dir | ||
28 | return json_result_dir | ||
29 | |||
30 | @staticmethod | ||
31 | def get_sdk_result_id(configuration): | ||
32 | return '%s_%s_%s_%s_%s' % (configuration['TEST_TYPE'], configuration['IMAGE_BASENAME'], configuration['SDKMACHINE'], configuration['MACHINE'], configuration['STARTTIME']) | ||
33 | |||
34 | class TestSDK(TestSDKBase): | ||
35 | context_executor_class = OESDKTestContextExecutor | ||
36 | context_class = OESDKTestContext | ||
37 | test_type = 'sdk' | ||
38 | |||
39 | def get_tcname(self, d): | ||
40 | """ | ||
41 | Get the name of the SDK file | ||
42 | """ | ||
43 | return d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh") | ||
44 | |||
45 | def extract_sdk(self, tcname, sdk_dir, d): | ||
46 | """ | ||
47 | Extract the SDK to the specified location | ||
48 | """ | ||
49 | import subprocess | ||
50 | |||
51 | try: | ||
52 | subprocess.check_output("cd %s; %s <<EOF\n./\nY\nEOF" % (sdk_dir, tcname), shell=True) | ||
53 | except subprocess.CalledProcessError as e: | ||
54 | bb.fatal("Couldn't install the SDK:\n%s" % e.output.decode("utf-8")) | ||
55 | |||
56 | def setup_context(self, d): | ||
57 | """ | ||
58 | Return a dictionary of additional arguments that should be passed to | ||
59 | the context_class on construction | ||
60 | """ | ||
61 | return dict() | ||
62 | |||
63 | def run(self, d): | ||
64 | |||
65 | import os | ||
66 | import subprocess | ||
67 | import json | ||
68 | import logging | ||
69 | |||
70 | from bb.utils import export_proxies | ||
71 | from oeqa.utils import make_logger_bitbake_compatible | ||
72 | |||
73 | pn = d.getVar("PN") | ||
74 | logger = make_logger_bitbake_compatible(logging.getLogger("BitBake")) | ||
75 | |||
76 | # sdk use network for download projects for build | ||
77 | export_proxies(d) | ||
78 | |||
79 | tcname = self.get_tcname(d) | ||
80 | |||
81 | if not os.path.exists(tcname): | ||
82 | bb.fatal("The toolchain %s is not built. Build it before running the tests: 'bitbake <image> -c populate_sdk' ." % tcname) | ||
83 | |||
84 | tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.testdata.json") | ||
85 | test_data = json.load(open(tdname, "r")) | ||
86 | |||
87 | target_pkg_manifest = self.context_executor_class._load_manifest( | ||
88 | d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.target.manifest")) | ||
89 | host_pkg_manifest = self.context_executor_class._load_manifest( | ||
90 | d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.host.manifest")) | ||
91 | |||
92 | processes = d.getVar("TESTIMAGE_NUMBER_THREADS") or d.getVar("BB_NUMBER_THREADS") | ||
93 | if processes: | ||
94 | try: | ||
95 | import testtools, subunit | ||
96 | except ImportError: | ||
97 | bb.warn("Failed to import testtools or subunit, the testcases will run serially") | ||
98 | processes = None | ||
99 | |||
100 | sdk_dir = d.expand("${WORKDIR}/testimage-sdk/") | ||
101 | bb.utils.remove(sdk_dir, True) | ||
102 | bb.utils.mkdirhier(sdk_dir) | ||
103 | |||
104 | context_args = self.setup_context(d) | ||
105 | |||
106 | self.extract_sdk(tcname, sdk_dir, d) | ||
107 | |||
108 | fail = False | ||
109 | sdk_envs = self.context_executor_class._get_sdk_environs(sdk_dir) | ||
110 | for s in sdk_envs: | ||
111 | sdk_env = sdk_envs[s] | ||
112 | bb.plain("SDK testing environment: %s" % s) | ||
113 | tc = self.context_class(td=test_data, logger=logger, sdk_dir=sdk_dir, | ||
114 | sdk_env=sdk_env, target_pkg_manifest=target_pkg_manifest, | ||
115 | host_pkg_manifest=host_pkg_manifest, **context_args) | ||
116 | |||
117 | try: | ||
118 | tc.loadTests(self.context_executor_class.default_cases) | ||
119 | except Exception as e: | ||
120 | import traceback | ||
121 | bb.fatal("Loading tests failed:\n%s" % traceback.format_exc()) | ||
122 | |||
123 | if processes: | ||
124 | result = tc.runTests(processes=int(processes)) | ||
125 | else: | ||
126 | result = tc.runTests() | ||
127 | |||
128 | component = "%s %s" % (pn, self.context_executor_class.name) | ||
129 | context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env)) | ||
130 | configuration = self.get_sdk_configuration(d, self.test_type) | ||
131 | result.logDetails(self.get_sdk_json_result_dir(d), | ||
132 | configuration, | ||
133 | self.get_sdk_result_id(configuration)) | ||
134 | result.logSummary(component, context_msg) | ||
135 | |||
136 | if not result.wasSuccessful(): | ||
137 | fail = True | ||
138 | |||
139 | if fail: | ||
140 | bb.fatal("%s - FAILED - check the task log and the commands log" % pn) | ||
141 | |||
142 | |||