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