blob: 9d5a99d900fd195c90cf15ef87ca7a5fd0860481 [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
Patrick Williams39653562024-03-01 08:54:02 -060019 from oeqa.utils import get_json_result_dir
Brad Bishop977dc1a2019-02-06 16:01:43 -050020
21 pn = d.getVar("PN")
22 logger = make_logger_bitbake_compatible(logging.getLogger("BitBake"))
23
24 # extensible sdk use network
25 export_proxies(d)
26
27 subprocesstweak.errors_have_output()
28
Andrew Geissler82c905d2020-04-13 13:39:40 -050029 # We need the original PATH for testing the eSDK, not with our manipulations
30 os.environ['PATH'] = d.getVar("BB_ORIGENV", False).getVar("PATH")
Brad Bishop977dc1a2019-02-06 16:01:43 -050031
32 tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.sh")
33 if not os.path.exists(tcname):
34 bb.fatal("The toolchain ext %s is not built. Build it before running the" \
35 " tests: 'bitbake <image> -c populate_sdk_ext' ." % tcname)
36
37 tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.testdata.json")
38 test_data = json.load(open(tdname, "r"))
39
40 target_pkg_manifest = OESDKExtTestContextExecutor._load_manifest(
41 d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest"))
42 host_pkg_manifest = OESDKExtTestContextExecutor._load_manifest(
43 d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.host.manifest"))
44
45 sdk_dir = d.expand("${WORKDIR}/testsdkext/")
46 bb.utils.remove(sdk_dir, True)
47 bb.utils.mkdirhier(sdk_dir)
48 try:
49 subprocess.check_output("%s -y -d %s" % (tcname, sdk_dir), shell=True)
50 except subprocess.CalledProcessError as e:
51 msg = "Couldn't install the extensible SDK:\n%s" % e.output.decode("utf-8")
52 logfn = os.path.join(sdk_dir, 'preparing_build_system.log')
53 if os.path.exists(logfn):
54 msg += '\n\nContents of preparing_build_system.log:\n'
55 with open(logfn, 'r') as f:
56 for line in f:
57 msg += line
58 bb.fatal(msg)
59
60 fail = False
61 sdk_envs = OESDKExtTestContextExecutor._get_sdk_environs(sdk_dir)
62 for s in sdk_envs:
63 bb.plain("Extensible SDK testing environment: %s" % s)
64
65 sdk_env = sdk_envs[s]
66
67 # Use our own SSTATE_DIR and DL_DIR so that updates to the eSDK come from our sstate cache
68 # and we don't spend hours downloading kernels for the kernel module test
69 # Abuse auto.conf since local.conf would be overwritten by the SDK
70 with open(os.path.join(sdk_dir, 'conf', 'auto.conf'), 'a+') as f:
Andrew Geissler595f6302022-01-24 19:11:47 +000071 f.write('SSTATE_MIRRORS += "file://.* file://%s/PATH"\n' % test_data.get('SSTATE_DIR'))
Brad Bishop977dc1a2019-02-06 16:01:43 -050072 f.write('SOURCE_MIRROR_URL = "file://%s"\n' % test_data.get('DL_DIR'))
73 f.write('INHERIT += "own-mirrors"\n')
Andrew Geissler595f6302022-01-24 19:11:47 +000074 f.write('PREMIRRORS:prepend = "git://git.yoctoproject.org/.* git://%s/git2/git.yoctoproject.org.BASENAME "\n' % test_data.get('DL_DIR'))
Brad Bishop977dc1a2019-02-06 16:01:43 -050075
76 # We need to do this in case we have a minimal SDK
77 subprocess.check_output(". %s > /dev/null; devtool sdk-install meta-extsdk-toolchain" % \
78 sdk_env, cwd=sdk_dir, shell=True, stderr=subprocess.STDOUT)
79
80 tc = OESDKExtTestContext(td=test_data, logger=logger, sdk_dir=sdk_dir,
81 sdk_env=sdk_env, target_pkg_manifest=target_pkg_manifest,
82 host_pkg_manifest=host_pkg_manifest)
83
84 try:
85 tc.loadTests(OESDKExtTestContextExecutor.default_cases)
86 except Exception as e:
87 import traceback
88 bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
89
90 result = tc.runTests()
91
92 component = "%s %s" % (pn, OESDKExtTestContextExecutor.name)
93 context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env))
94 configuration = self.get_sdk_configuration(d, 'sdkext')
Patrick Williams39653562024-03-01 08:54:02 -060095 result.logDetails(get_json_result_dir(d),
Brad Bishop977dc1a2019-02-06 16:01:43 -050096 configuration,
97 self.get_sdk_result_id(configuration))
98 result.logSummary(component, context_msg)
99
100 if not result.wasSuccessful():
101 fail = True
102
Andrew Geisslerc3d88e42020-10-02 09:45:00 -0500103 # Clean the workspace/sources to avoid `devtool add' failure because of non-empty source directory
104 bb.utils.remove(sdk_dir+'workspace/sources', True)
105
Brad Bishop977dc1a2019-02-06 16:01:43 -0500106 if fail:
107 bb.fatal("%s - FAILED - check the task log and the commands log" % pn)
108