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