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