blob: 6b51a33db2a2b4f05f63f2fc97a0faf0d2f2ba0a [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
Brad Bishop6e60e8b2018-02-01 10:27:11 -050024 from oeqa.sdk.context import OESDKTestContext, OESDKTestContextExecutor
25 from oeqa.utils import make_logger_bitbake_compatible
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050026
Brad Bishopd7bf8c12018-02-25 22:55:05 -050027 bb.event.enable_threadlock()
28
Brad Bishop6e60e8b2018-02-01 10:27:11 -050029 pn = d.getVar("PN")
30 logger = make_logger_bitbake_compatible(logging.getLogger("BitBake"))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050031
Brad Bishop6e60e8b2018-02-01 10:27:11 -050032 # sdk use network for download projects for build
33 export_proxies(d)
34
35 tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh")
36 if not os.path.exists(tcname):
37 bb.fatal("The toolchain %s is not built. Build it before running the tests: 'bitbake <image> -c populate_sdk' ." % tcname)
38
39 tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.testdata.json")
40 test_data = json.load(open(tdname, "r"))
41
42 target_pkg_manifest = OESDKTestContextExecutor._load_manifest(
43 d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.target.manifest"))
44 host_pkg_manifest = OESDKTestContextExecutor._load_manifest(
45 d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.host.manifest"))
46
47 sdk_dir = d.expand("${WORKDIR}/testimage-sdk/")
48 bb.utils.remove(sdk_dir, True)
49 bb.utils.mkdirhier(sdk_dir)
50 try:
51 subprocess.check_output("cd %s; %s <<EOF\n./\nY\nEOF" % (sdk_dir, tcname), shell=True)
52 except subprocess.CalledProcessError as e:
53 bb.fatal("Couldn't install the SDK:\n%s" % e.output.decode("utf-8"))
54
55 fail = False
56 sdk_envs = OESDKTestContextExecutor._get_sdk_environs(sdk_dir)
57 for s in sdk_envs:
58 sdk_env = sdk_envs[s]
59 bb.plain("SDK testing environment: %s" % s)
60 tc = OESDKTestContext(td=test_data, logger=logger, sdk_dir=sdk_dir,
61 sdk_env=sdk_env, target_pkg_manifest=target_pkg_manifest,
62 host_pkg_manifest=host_pkg_manifest)
63
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050064 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050065 tc.loadTests(OESDKTestContextExecutor.default_cases)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050066 except Exception as e:
67 import traceback
68 bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
69
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050070 result = tc.runTests()
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050071
Brad Bishop6e60e8b2018-02-01 10:27:11 -050072 component = "%s %s" % (pn, OESDKTestContextExecutor.name)
73 context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050074
Brad Bishopd7bf8c12018-02-25 22:55:05 -050075 result.logDetails()
76 result.logSummary(component, context_msg)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050077
Brad Bishop6e60e8b2018-02-01 10:27:11 -050078 if not result.wasSuccessful():
79 fail = True
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050080
Brad Bishop6e60e8b2018-02-01 10:27:11 -050081 if fail:
82 bb.fatal("%s - FAILED - check the task log and the commands log" % pn)
83
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050084testsdk_main[vardepsexclude] =+ "BB_ORIGENV"
85
86python do_testsdk() {
87 testsdk_main(d)
88}
89addtask testsdk
90do_testsdk[nostamp] = "1"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050091
92def testsdkext_main(d):
93 import os
Brad Bishop6e60e8b2018-02-01 10:27:11 -050094 import json
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050095 import subprocess
Brad Bishop6e60e8b2018-02-01 10:27:11 -050096 import logging
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050097
Brad Bishop6e60e8b2018-02-01 10:27:11 -050098 from bb.utils import export_proxies
99 from oeqa.utils import avoid_paths_in_environ, make_logger_bitbake_compatible, subprocesstweak
100 from oeqa.sdkext.context import OESDKExtTestContext, OESDKExtTestContextExecutor
101
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500102 bb.event.enable_threadlock()
103
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500104 pn = d.getVar("PN")
105 logger = make_logger_bitbake_compatible(logging.getLogger("BitBake"))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500106
107 # extensible sdk use network
108 export_proxies(d)
109
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500110 subprocesstweak.errors_have_output()
111
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500112 # extensible sdk can be contaminated if native programs are
113 # in PATH, i.e. use perl-native instead of eSDK one.
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500114 paths_to_avoid = [d.getVar('STAGING_DIR'),
115 d.getVar('BASE_WORKDIR')]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500116 os.environ['PATH'] = avoid_paths_in_environ(paths_to_avoid)
117
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500118 tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.sh")
119 if not os.path.exists(tcname):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500120 bb.fatal("The toolchain ext %s is not built. Build it before running the" \
121 " tests: 'bitbake <image> -c populate_sdk_ext' ." % tcname)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500122
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500123 tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.testdata.json")
124 test_data = json.load(open(tdname, "r"))
125
126 target_pkg_manifest = OESDKExtTestContextExecutor._load_manifest(
127 d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest"))
128 host_pkg_manifest = OESDKExtTestContextExecutor._load_manifest(
129 d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.host.manifest"))
130
131 sdk_dir = d.expand("${WORKDIR}/testsdkext/")
132 bb.utils.remove(sdk_dir, True)
133 bb.utils.mkdirhier(sdk_dir)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500134 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500135 subprocess.check_output("%s -y -d %s" % (tcname, sdk_dir), shell=True)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500136 except subprocess.CalledProcessError as e:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600137 msg = "Couldn't install the extensible SDK:\n%s" % e.output.decode("utf-8")
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500138 logfn = os.path.join(sdk_dir, 'preparing_build_system.log')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600139 if os.path.exists(logfn):
140 msg += '\n\nContents of preparing_build_system.log:\n'
141 with open(logfn, 'r') as f:
142 for line in f:
143 msg += line
144 bb.fatal(msg)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500145
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500146 fail = False
147 sdk_envs = OESDKExtTestContextExecutor._get_sdk_environs(sdk_dir)
148 for s in sdk_envs:
149 bb.plain("Extensible SDK testing environment: %s" % s)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500150
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500151 sdk_env = sdk_envs[s]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500152
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500153 # Use our own SSTATE_DIR and DL_DIR so that updates to the eSDK come from our sstate cache
154 # and we don't spend hours downloading kernels for the kernel module test
155 # Abuse auto.conf since local.conf would be overwritten by the SDK
156 with open(os.path.join(sdk_dir, 'conf', 'auto.conf'), 'a+') as f:
157 f.write('SSTATE_MIRRORS += " \\n file://.* file://%s/PATH"\n' % test_data.get('SSTATE_DIR'))
158 f.write('SOURCE_MIRROR_URL = "file://%s"\n' % test_data.get('DL_DIR'))
159 f.write('INHERIT += "own-mirrors"')
160
161 # We need to do this in case we have a minimal SDK
162 subprocess.check_output(". %s > /dev/null; devtool sdk-install meta-extsdk-toolchain" % sdk_env, cwd=sdk_dir, shell=True)
163
164 tc = OESDKExtTestContext(td=test_data, logger=logger, sdk_dir=sdk_dir,
165 sdk_env=sdk_env, target_pkg_manifest=target_pkg_manifest,
166 host_pkg_manifest=host_pkg_manifest)
167
168 try:
169 tc.loadTests(OESDKExtTestContextExecutor.default_cases)
170 except Exception as e:
171 import traceback
172 bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
173
174 result = tc.runTests()
175
176 component = "%s %s" % (pn, OESDKExtTestContextExecutor.name)
177 context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env))
178
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500179 result.logDetails()
180 result.logSummary(component, context_msg)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500181
182 if not result.wasSuccessful():
183 fail = True
184
185 if fail:
186 bb.fatal("%s - FAILED - check the task log and the commands log" % pn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500187
188testsdkext_main[vardepsexclude] =+ "BB_ORIGENV"
189
190python do_testsdkext() {
191 testsdkext_main(d)
192}
193addtask testsdkext
194do_testsdkext[nostamp] = "1"
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500195