Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 1 | # 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 Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 7 | # To run SDK tests, run the commands: |
| 8 | # $ bitbake <image-name> -c populate_sdk |
| 9 | # $ bitbake <image-name> -c testsdk |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10 | # |
Brad Bishop | 37a0e4d | 2017-12-04 01:01:44 -0500 | [diff] [blame] | 11 | # 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 Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 16 | |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame^] | 17 | def get_sdk_configuration(d, test_type): |
| 18 | import platform |
| 19 | from oeqa.utils.metadata import get_layers |
| 20 | configuration = {'TEST_TYPE': test_type, |
| 21 | 'MACHINE': d.getVar("MACHINE"), |
| 22 | 'SDKMACHINE': d.getVar("SDKMACHINE"), |
| 23 | 'IMAGE_BASENAME': d.getVar("IMAGE_BASENAME"), |
| 24 | 'IMAGE_PKGTYPE': d.getVar("IMAGE_PKGTYPE"), |
| 25 | 'STARTTIME': d.getVar("DATETIME"), |
| 26 | 'HOST_DISTRO': ('-'.join(platform.linux_distribution())).replace(' ', '-'), |
| 27 | 'LAYERS': get_layers(d.getVar("BBLAYERS"))} |
| 28 | return configuration |
| 29 | get_sdk_configuration[vardepsexclude] = "DATETIME" |
| 30 | |
| 31 | def get_sdk_json_result_dir(d): |
| 32 | json_result_dir = os.path.join(d.getVar("LOG_DIR"), 'oeqa') |
| 33 | custom_json_result_dir = d.getVar("OEQA_JSON_RESULT_DIR") |
| 34 | if custom_json_result_dir: |
| 35 | json_result_dir = custom_json_result_dir |
| 36 | return json_result_dir |
| 37 | |
| 38 | def get_sdk_result_id(configuration): |
| 39 | return '%s_%s_%s_%s_%s' % (configuration['TEST_TYPE'], configuration['IMAGE_BASENAME'], configuration['SDKMACHINE'], configuration['MACHINE'], configuration['STARTTIME']) |
| 40 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 41 | def testsdk_main(d): |
| 42 | import os |
| 43 | import subprocess |
| 44 | import json |
| 45 | import logging |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 46 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 47 | from bb.utils import export_proxies |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 48 | from oeqa.sdk.context import OESDKTestContext, OESDKTestContextExecutor |
| 49 | from oeqa.utils import make_logger_bitbake_compatible |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 50 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 51 | pn = d.getVar("PN") |
| 52 | logger = make_logger_bitbake_compatible(logging.getLogger("BitBake")) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 53 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 54 | # sdk use network for download projects for build |
| 55 | export_proxies(d) |
| 56 | |
| 57 | tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh") |
| 58 | if not os.path.exists(tcname): |
| 59 | bb.fatal("The toolchain %s is not built. Build it before running the tests: 'bitbake <image> -c populate_sdk' ." % tcname) |
| 60 | |
| 61 | tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.testdata.json") |
| 62 | test_data = json.load(open(tdname, "r")) |
| 63 | |
| 64 | target_pkg_manifest = OESDKTestContextExecutor._load_manifest( |
| 65 | d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.target.manifest")) |
| 66 | host_pkg_manifest = OESDKTestContextExecutor._load_manifest( |
| 67 | d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.host.manifest")) |
| 68 | |
| 69 | sdk_dir = d.expand("${WORKDIR}/testimage-sdk/") |
| 70 | bb.utils.remove(sdk_dir, True) |
| 71 | bb.utils.mkdirhier(sdk_dir) |
| 72 | try: |
| 73 | subprocess.check_output("cd %s; %s <<EOF\n./\nY\nEOF" % (sdk_dir, tcname), shell=True) |
| 74 | except subprocess.CalledProcessError as e: |
| 75 | bb.fatal("Couldn't install the SDK:\n%s" % e.output.decode("utf-8")) |
| 76 | |
| 77 | fail = False |
| 78 | sdk_envs = OESDKTestContextExecutor._get_sdk_environs(sdk_dir) |
| 79 | for s in sdk_envs: |
| 80 | sdk_env = sdk_envs[s] |
| 81 | bb.plain("SDK testing environment: %s" % s) |
| 82 | tc = OESDKTestContext(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 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 86 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 87 | tc.loadTests(OESDKTestContextExecutor.default_cases) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 88 | except Exception as e: |
| 89 | import traceback |
| 90 | bb.fatal("Loading tests failed:\n%s" % traceback.format_exc()) |
| 91 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 92 | result = tc.runTests() |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 93 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 94 | component = "%s %s" % (pn, OESDKTestContextExecutor.name) |
| 95 | context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env)) |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame^] | 96 | configuration = get_sdk_configuration(d, 'sdk') |
| 97 | result.logDetails(get_sdk_json_result_dir(d), |
| 98 | configuration, |
| 99 | get_sdk_result_id(configuration)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 100 | result.logSummary(component, context_msg) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 101 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 102 | if not result.wasSuccessful(): |
| 103 | fail = True |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 104 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 105 | if fail: |
| 106 | bb.fatal("%s - FAILED - check the task log and the commands log" % pn) |
| 107 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 108 | testsdk_main[vardepsexclude] =+ "BB_ORIGENV" |
| 109 | |
| 110 | python do_testsdk() { |
| 111 | testsdk_main(d) |
| 112 | } |
| 113 | addtask testsdk |
| 114 | do_testsdk[nostamp] = "1" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 115 | |
| 116 | def testsdkext_main(d): |
| 117 | import os |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 118 | import json |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 119 | import subprocess |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 120 | import logging |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 121 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 122 | from bb.utils import export_proxies |
| 123 | from oeqa.utils import avoid_paths_in_environ, make_logger_bitbake_compatible, subprocesstweak |
| 124 | from oeqa.sdkext.context import OESDKExtTestContext, OESDKExtTestContextExecutor |
| 125 | |
| 126 | pn = d.getVar("PN") |
| 127 | logger = make_logger_bitbake_compatible(logging.getLogger("BitBake")) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 128 | |
| 129 | # extensible sdk use network |
| 130 | export_proxies(d) |
| 131 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 132 | subprocesstweak.errors_have_output() |
| 133 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 134 | # extensible sdk can be contaminated if native programs are |
| 135 | # in PATH, i.e. use perl-native instead of eSDK one. |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 136 | paths_to_avoid = [d.getVar('STAGING_DIR'), |
| 137 | d.getVar('BASE_WORKDIR')] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 138 | os.environ['PATH'] = avoid_paths_in_environ(paths_to_avoid) |
| 139 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 140 | tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.sh") |
| 141 | if not os.path.exists(tcname): |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 142 | bb.fatal("The toolchain ext %s is not built. Build it before running the" \ |
| 143 | " tests: 'bitbake <image> -c populate_sdk_ext' ." % tcname) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 144 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 145 | tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.testdata.json") |
| 146 | test_data = json.load(open(tdname, "r")) |
| 147 | |
| 148 | target_pkg_manifest = OESDKExtTestContextExecutor._load_manifest( |
| 149 | d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest")) |
| 150 | host_pkg_manifest = OESDKExtTestContextExecutor._load_manifest( |
| 151 | d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.host.manifest")) |
| 152 | |
| 153 | sdk_dir = d.expand("${WORKDIR}/testsdkext/") |
| 154 | bb.utils.remove(sdk_dir, True) |
| 155 | bb.utils.mkdirhier(sdk_dir) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 156 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 157 | subprocess.check_output("%s -y -d %s" % (tcname, sdk_dir), shell=True) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 158 | except subprocess.CalledProcessError as e: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 159 | msg = "Couldn't install the extensible SDK:\n%s" % e.output.decode("utf-8") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 160 | logfn = os.path.join(sdk_dir, 'preparing_build_system.log') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 161 | if os.path.exists(logfn): |
| 162 | msg += '\n\nContents of preparing_build_system.log:\n' |
| 163 | with open(logfn, 'r') as f: |
| 164 | for line in f: |
| 165 | msg += line |
| 166 | bb.fatal(msg) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 167 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 168 | fail = False |
| 169 | sdk_envs = OESDKExtTestContextExecutor._get_sdk_environs(sdk_dir) |
| 170 | for s in sdk_envs: |
| 171 | bb.plain("Extensible SDK testing environment: %s" % s) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 172 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 173 | sdk_env = sdk_envs[s] |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 174 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 175 | # Use our own SSTATE_DIR and DL_DIR so that updates to the eSDK come from our sstate cache |
| 176 | # and we don't spend hours downloading kernels for the kernel module test |
| 177 | # Abuse auto.conf since local.conf would be overwritten by the SDK |
| 178 | with open(os.path.join(sdk_dir, 'conf', 'auto.conf'), 'a+') as f: |
| 179 | f.write('SSTATE_MIRRORS += " \\n file://.* file://%s/PATH"\n' % test_data.get('SSTATE_DIR')) |
| 180 | f.write('SOURCE_MIRROR_URL = "file://%s"\n' % test_data.get('DL_DIR')) |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 181 | f.write('INHERIT += "own-mirrors"\n') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 182 | |
| 183 | # We need to do this in case we have a minimal SDK |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 184 | subprocess.check_output(". %s > /dev/null; devtool sdk-install meta-extsdk-toolchain" % \ |
| 185 | sdk_env, cwd=sdk_dir, shell=True, stderr=subprocess.STDOUT) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 186 | |
| 187 | tc = OESDKExtTestContext(td=test_data, logger=logger, sdk_dir=sdk_dir, |
| 188 | sdk_env=sdk_env, target_pkg_manifest=target_pkg_manifest, |
| 189 | host_pkg_manifest=host_pkg_manifest) |
| 190 | |
| 191 | try: |
| 192 | tc.loadTests(OESDKExtTestContextExecutor.default_cases) |
| 193 | except Exception as e: |
| 194 | import traceback |
| 195 | bb.fatal("Loading tests failed:\n%s" % traceback.format_exc()) |
| 196 | |
| 197 | result = tc.runTests() |
| 198 | |
| 199 | component = "%s %s" % (pn, OESDKExtTestContextExecutor.name) |
| 200 | context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env)) |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame^] | 201 | configuration = get_sdk_configuration(d, 'sdkext') |
| 202 | result.logDetails(get_sdk_json_result_dir(d), |
| 203 | configuration, |
| 204 | get_sdk_result_id(configuration)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 205 | result.logSummary(component, context_msg) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 206 | |
| 207 | if not result.wasSuccessful(): |
| 208 | fail = True |
| 209 | |
| 210 | if fail: |
| 211 | bb.fatal("%s - FAILED - check the task log and the commands log" % pn) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 212 | |
| 213 | testsdkext_main[vardepsexclude] =+ "BB_ORIGENV" |
| 214 | |
| 215 | python do_testsdkext() { |
| 216 | testsdkext_main(d) |
| 217 | } |
| 218 | addtask testsdkext |
| 219 | do_testsdkext[nostamp] = "1" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 220 | |