blob: 6a201aa41b5679f91f2123f929ad8f8ef23ccb51 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001# Copyright (C) 2013 - 2016 Intel Corporation
2#
3# Released under the MIT license (see COPYING.MIT)
4
5# testsdk.bbclass enables testing for SDK and Extensible SDK
6#
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007# To run SDK tests, run the commands:
8# $ bitbake <image-name> -c populate_sdk
9# $ bitbake <image-name> -c testsdk
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010#
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011# To run eSDK tests, run the commands:
12# $ bitbake <image-name> -c populate_sdk_ext
13# $ bitbake <image-name> -c testsdkext
14#
15# where "<image-name>" is an image like core-image-sato.
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050016
Brad Bishop6e60e8b2018-02-01 10:27:11 -050017def testsdk_main(d):
18 import os
19 import subprocess
20 import json
21 import logging
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050022
Brad Bishop6e60e8b2018-02-01 10:27:11 -050023 from bb.utils import export_proxies
24 from oeqa.core.runner import OEStreamLogger
25 from oeqa.sdk.context import OESDKTestContext, OESDKTestContextExecutor
26 from oeqa.utils import make_logger_bitbake_compatible
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050027
Brad Bishop6e60e8b2018-02-01 10:27:11 -050028 pn = d.getVar("PN")
29 logger = make_logger_bitbake_compatible(logging.getLogger("BitBake"))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050030
Brad Bishop6e60e8b2018-02-01 10:27:11 -050031 # sdk use network for download projects for build
32 export_proxies(d)
33
34 tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh")
35 if not os.path.exists(tcname):
36 bb.fatal("The toolchain %s is not built. Build it before running the tests: 'bitbake <image> -c populate_sdk' ." % tcname)
37
38 tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.testdata.json")
39 test_data = json.load(open(tdname, "r"))
40
41 target_pkg_manifest = OESDKTestContextExecutor._load_manifest(
42 d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.target.manifest"))
43 host_pkg_manifest = OESDKTestContextExecutor._load_manifest(
44 d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.host.manifest"))
45
46 sdk_dir = d.expand("${WORKDIR}/testimage-sdk/")
47 bb.utils.remove(sdk_dir, True)
48 bb.utils.mkdirhier(sdk_dir)
49 try:
50 subprocess.check_output("cd %s; %s <<EOF\n./\nY\nEOF" % (sdk_dir, tcname), shell=True)
51 except subprocess.CalledProcessError as e:
52 bb.fatal("Couldn't install the SDK:\n%s" % e.output.decode("utf-8"))
53
54 fail = False
55 sdk_envs = OESDKTestContextExecutor._get_sdk_environs(sdk_dir)
56 for s in sdk_envs:
57 sdk_env = sdk_envs[s]
58 bb.plain("SDK testing environment: %s" % s)
59 tc = OESDKTestContext(td=test_data, logger=logger, sdk_dir=sdk_dir,
60 sdk_env=sdk_env, target_pkg_manifest=target_pkg_manifest,
61 host_pkg_manifest=host_pkg_manifest)
62
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050063 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050064 tc.loadTests(OESDKTestContextExecutor.default_cases)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050065 except Exception as e:
66 import traceback
67 bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
68
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050069 result = tc.runTests()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050070
Brad Bishop6e60e8b2018-02-01 10:27:11 -050071 component = "%s %s" % (pn, OESDKTestContextExecutor.name)
72 context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050073
Brad Bishop6e60e8b2018-02-01 10:27:11 -050074 tc.logSummary(result, component, context_msg)
75 tc.logDetails()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050076
Brad Bishop6e60e8b2018-02-01 10:27:11 -050077 if not result.wasSuccessful():
78 fail = True
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050079
Brad Bishop6e60e8b2018-02-01 10:27:11 -050080 if fail:
81 bb.fatal("%s - FAILED - check the task log and the commands log" % pn)
82
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050083testsdk_main[vardepsexclude] =+ "BB_ORIGENV"
84
85python do_testsdk() {
86 testsdk_main(d)
87}
88addtask testsdk
89do_testsdk[nostamp] = "1"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050090
91def testsdkext_main(d):
92 import os
Brad Bishop6e60e8b2018-02-01 10:27:11 -050093 import json
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050094 import subprocess
Brad Bishop6e60e8b2018-02-01 10:27:11 -050095 import logging
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050096
Brad Bishop6e60e8b2018-02-01 10:27:11 -050097 from bb.utils import export_proxies
98 from oeqa.utils import avoid_paths_in_environ, make_logger_bitbake_compatible, subprocesstweak
99 from oeqa.sdkext.context import OESDKExtTestContext, OESDKExtTestContextExecutor
100
101 pn = d.getVar("PN")
102 logger = make_logger_bitbake_compatible(logging.getLogger("BitBake"))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500103
104 # extensible sdk use network
105 export_proxies(d)
106
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500107 subprocesstweak.errors_have_output()
108
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500109 # extensible sdk can be contaminated if native programs are
110 # in PATH, i.e. use perl-native instead of eSDK one.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500111 paths_to_avoid = [d.getVar('STAGING_DIR'),
112 d.getVar('BASE_WORKDIR')]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500113 os.environ['PATH'] = avoid_paths_in_environ(paths_to_avoid)
114
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500115 tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.sh")
116 if not os.path.exists(tcname):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500117 bb.fatal("The toolchain ext %s is not built. Build it before running the" \
118 " tests: 'bitbake <image> -c populate_sdk_ext' ." % tcname)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500119
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500120 tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.testdata.json")
121 test_data = json.load(open(tdname, "r"))
122
123 target_pkg_manifest = OESDKExtTestContextExecutor._load_manifest(
124 d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest"))
125 host_pkg_manifest = OESDKExtTestContextExecutor._load_manifest(
126 d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.host.manifest"))
127
128 sdk_dir = d.expand("${WORKDIR}/testsdkext/")
129 bb.utils.remove(sdk_dir, True)
130 bb.utils.mkdirhier(sdk_dir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500131 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500132 subprocess.check_output("%s -y -d %s" % (tcname, sdk_dir), shell=True)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500133 except subprocess.CalledProcessError as e:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600134 msg = "Couldn't install the extensible SDK:\n%s" % e.output.decode("utf-8")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500135 logfn = os.path.join(sdk_dir, 'preparing_build_system.log')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600136 if os.path.exists(logfn):
137 msg += '\n\nContents of preparing_build_system.log:\n'
138 with open(logfn, 'r') as f:
139 for line in f:
140 msg += line
141 bb.fatal(msg)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500142
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500143 fail = False
144 sdk_envs = OESDKExtTestContextExecutor._get_sdk_environs(sdk_dir)
145 for s in sdk_envs:
146 bb.plain("Extensible SDK testing environment: %s" % s)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500147
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500148 sdk_env = sdk_envs[s]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500149
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500150 # Use our own SSTATE_DIR and DL_DIR so that updates to the eSDK come from our sstate cache
151 # and we don't spend hours downloading kernels for the kernel module test
152 # Abuse auto.conf since local.conf would be overwritten by the SDK
153 with open(os.path.join(sdk_dir, 'conf', 'auto.conf'), 'a+') as f:
154 f.write('SSTATE_MIRRORS += " \\n file://.* file://%s/PATH"\n' % test_data.get('SSTATE_DIR'))
155 f.write('SOURCE_MIRROR_URL = "file://%s"\n' % test_data.get('DL_DIR'))
156 f.write('INHERIT += "own-mirrors"')
157
158 # We need to do this in case we have a minimal SDK
159 subprocess.check_output(". %s > /dev/null; devtool sdk-install meta-extsdk-toolchain" % sdk_env, cwd=sdk_dir, shell=True)
160
161 tc = OESDKExtTestContext(td=test_data, logger=logger, sdk_dir=sdk_dir,
162 sdk_env=sdk_env, target_pkg_manifest=target_pkg_manifest,
163 host_pkg_manifest=host_pkg_manifest)
164
165 try:
166 tc.loadTests(OESDKExtTestContextExecutor.default_cases)
167 except Exception as e:
168 import traceback
169 bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
170
171 result = tc.runTests()
172
173 component = "%s %s" % (pn, OESDKExtTestContextExecutor.name)
174 context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env))
175
176 tc.logSummary(result, component, context_msg)
177 tc.logDetails()
178
179 if not result.wasSuccessful():
180 fail = True
181
182 if fail:
183 bb.fatal("%s - FAILED - check the task log and the commands log" % pn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500184
185testsdkext_main[vardepsexclude] =+ "BB_ORIGENV"
186
187python do_testsdkext() {
188 testsdkext_main(d)
189}
190addtask testsdkext
191do_testsdkext[nostamp] = "1"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500192