blob: 785b5dda53a77758b694904d90e8938ac50d0b5f [file] [log] [blame]
Brad Bishopc342db32019-05-15 21:57:59 -04001#
Brad Bishop977dc1a2019-02-06 16:01:43 -05002# Copyright 2018 by Garmin Ltd. or its subsidiaries
Brad Bishopc342db32019-05-15 21:57:59 -04003#
4# SPDX-License-Identifier: MIT
5#
Brad Bishop977dc1a2019-02-06 16:01:43 -05006
7from oeqa.sdk.testsdk import TestSDKBase
8
9class TestSDKExt(TestSDKBase):
10 def run(self, d):
11 import os
12 import json
13 import subprocess
14 import logging
15
16 from bb.utils import export_proxies
17 from oeqa.utils import avoid_paths_in_environ, make_logger_bitbake_compatible, subprocesstweak
18 from oeqa.sdkext.context import OESDKExtTestContext, OESDKExtTestContextExecutor
19
20 pn = d.getVar("PN")
21 logger = make_logger_bitbake_compatible(logging.getLogger("BitBake"))
22
23 # extensible sdk use network
24 export_proxies(d)
25
26 subprocesstweak.errors_have_output()
27
28 # extensible sdk can be contaminated if native programs are
29 # in PATH, i.e. use perl-native instead of eSDK one.
30 paths_to_avoid = [d.getVar('STAGING_DIR'),
31 d.getVar('BASE_WORKDIR')]
32 os.environ['PATH'] = avoid_paths_in_environ(paths_to_avoid)
33
34 tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.sh")
35 if not os.path.exists(tcname):
36 bb.fatal("The toolchain ext %s is not built. Build it before running the" \
37 " tests: 'bitbake <image> -c populate_sdk_ext' ." % tcname)
38
39 tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.testdata.json")
40 test_data = json.load(open(tdname, "r"))
41
42 target_pkg_manifest = OESDKExtTestContextExecutor._load_manifest(
43 d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest"))
44 host_pkg_manifest = OESDKExtTestContextExecutor._load_manifest(
45 d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.host.manifest"))
46
47 sdk_dir = d.expand("${WORKDIR}/testsdkext/")
48 bb.utils.remove(sdk_dir, True)
49 bb.utils.mkdirhier(sdk_dir)
50 try:
51 subprocess.check_output("%s -y -d %s" % (tcname, sdk_dir), shell=True)
52 except subprocess.CalledProcessError as e:
53 msg = "Couldn't install the extensible SDK:\n%s" % e.output.decode("utf-8")
54 logfn = os.path.join(sdk_dir, 'preparing_build_system.log')
55 if os.path.exists(logfn):
56 msg += '\n\nContents of preparing_build_system.log:\n'
57 with open(logfn, 'r') as f:
58 for line in f:
59 msg += line
60 bb.fatal(msg)
61
62 fail = False
63 sdk_envs = OESDKExtTestContextExecutor._get_sdk_environs(sdk_dir)
64 for s in sdk_envs:
65 bb.plain("Extensible SDK testing environment: %s" % s)
66
67 sdk_env = sdk_envs[s]
68
69 # Use our own SSTATE_DIR and DL_DIR so that updates to the eSDK come from our sstate cache
70 # and we don't spend hours downloading kernels for the kernel module test
71 # Abuse auto.conf since local.conf would be overwritten by the SDK
72 with open(os.path.join(sdk_dir, 'conf', 'auto.conf'), 'a+') as f:
73 f.write('SSTATE_MIRRORS += " \\n file://.* file://%s/PATH"\n' % test_data.get('SSTATE_DIR'))
74 f.write('SOURCE_MIRROR_URL = "file://%s"\n' % test_data.get('DL_DIR'))
75 f.write('INHERIT += "own-mirrors"\n')
76 f.write('PREMIRRORS_prepend = " git://git.yoctoproject.org/.* git://%s/git2/git.yoctoproject.org.BASENAME \\n "\n' % test_data.get('DL_DIR'))
77
78 # We need to do this in case we have a minimal SDK
79 subprocess.check_output(". %s > /dev/null; devtool sdk-install meta-extsdk-toolchain" % \
80 sdk_env, cwd=sdk_dir, shell=True, stderr=subprocess.STDOUT)
81
82 tc = OESDKExtTestContext(td=test_data, logger=logger, sdk_dir=sdk_dir,
83 sdk_env=sdk_env, target_pkg_manifest=target_pkg_manifest,
84 host_pkg_manifest=host_pkg_manifest)
85
86 try:
87 tc.loadTests(OESDKExtTestContextExecutor.default_cases)
88 except Exception as e:
89 import traceback
90 bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
91
92 result = tc.runTests()
93
94 component = "%s %s" % (pn, OESDKExtTestContextExecutor.name)
95 context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env))
96 configuration = self.get_sdk_configuration(d, 'sdkext')
97 result.logDetails(self.get_sdk_json_result_dir(d),
98 configuration,
99 self.get_sdk_result_id(configuration))
100 result.logSummary(component, context_msg)
101
102 if not result.wasSuccessful():
103 fail = True
104
105 if fail:
106 bb.fatal("%s - FAILED - check the task log and the commands log" % pn)
107