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 | |
| 17 | TEST_LOG_DIR ?= "${WORKDIR}/testimage" |
| 18 | TESTSDKLOCK = "${TMPDIR}/testsdk.lock" |
| 19 | |
| 20 | def run_test_context(CTestContext, d, testdir, tcname, pn, *args): |
| 21 | import glob |
| 22 | import time |
| 23 | |
| 24 | targets = glob.glob(d.expand(testdir + "/tc/environment-setup-*")) |
| 25 | for sdkenv in targets: |
| 26 | bb.plain("Testing %s" % sdkenv) |
| 27 | tc = CTestContext(d, testdir, sdkenv, tcname, args) |
| 28 | |
| 29 | # this is a dummy load of tests |
| 30 | # we are doing that to find compile errors in the tests themselves |
| 31 | # before booting the image |
| 32 | try: |
| 33 | tc.loadTests() |
| 34 | except Exception as e: |
| 35 | import traceback |
| 36 | bb.fatal("Loading tests failed:\n%s" % traceback.format_exc()) |
| 37 | |
| 38 | starttime = time.time() |
| 39 | result = tc.runTests() |
| 40 | stoptime = time.time() |
| 41 | if result.wasSuccessful(): |
| 42 | bb.plain("%s SDK(%s):%s - Ran %d test%s in %.3fs" % (pn, os.path.basename(tcname), os.path.basename(sdkenv),result.testsRun, result.testsRun != 1 and "s" or "", stoptime - starttime)) |
| 43 | msg = "%s - OK - All required tests passed" % pn |
| 44 | skipped = len(result.skipped) |
| 45 | if skipped: |
| 46 | msg += " (skipped=%d)" % skipped |
| 47 | bb.plain(msg) |
| 48 | else: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 49 | 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] | 50 | |
| 51 | def testsdk_main(d): |
| 52 | import os |
| 53 | import oeqa.sdk |
| 54 | import subprocess |
| 55 | from oeqa.oetest import SDKTestContext |
| 56 | |
| 57 | pn = d.getVar("PN", True) |
| 58 | bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True)) |
| 59 | |
| 60 | tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh") |
| 61 | if not os.path.exists(tcname): |
| 62 | bb.fatal("The toolchain is not built. Build it before running the tests: 'bitbake <image> -c populate_sdk' .") |
| 63 | |
| 64 | sdktestdir = d.expand("${WORKDIR}/testimage-sdk/") |
| 65 | bb.utils.remove(sdktestdir, True) |
| 66 | bb.utils.mkdirhier(sdktestdir) |
| 67 | try: |
| 68 | subprocess.check_output("cd %s; %s <<EOF\n./tc\nY\nEOF" % (sdktestdir, tcname), shell=True) |
| 69 | except subprocess.CalledProcessError as e: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 70 | bb.fatal("Couldn't install the SDK:\n%s" % e.output.decode("utf-8")) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 71 | |
| 72 | try: |
| 73 | run_test_context(SDKTestContext, d, sdktestdir, tcname, pn) |
| 74 | finally: |
| 75 | bb.utils.remove(sdktestdir, True) |
| 76 | |
| 77 | testsdk_main[vardepsexclude] =+ "BB_ORIGENV" |
| 78 | |
| 79 | python do_testsdk() { |
| 80 | testsdk_main(d) |
| 81 | } |
| 82 | addtask testsdk |
| 83 | do_testsdk[nostamp] = "1" |
| 84 | do_testsdk[lockfiles] += "${TESTSDKLOCK}" |
| 85 | |
| 86 | TEST_LOG_SDKEXT_DIR ?= "${WORKDIR}/testsdkext" |
| 87 | TESTSDKEXTLOCK = "${TMPDIR}/testsdkext.lock" |
| 88 | |
| 89 | def testsdkext_main(d): |
| 90 | import os |
| 91 | import oeqa.sdkext |
| 92 | import subprocess |
| 93 | from bb.utils import export_proxies |
| 94 | from oeqa.oetest import SDKTestContext, SDKExtTestContext |
| 95 | from oeqa.utils import avoid_paths_in_environ |
| 96 | |
| 97 | |
| 98 | # extensible sdk use network |
| 99 | export_proxies(d) |
| 100 | |
| 101 | # extensible sdk can be contaminated if native programs are |
| 102 | # in PATH, i.e. use perl-native instead of eSDK one. |
| 103 | paths_to_avoid = [d.getVar('STAGING_DIR', True), |
| 104 | d.getVar('BASE_WORKDIR', True)] |
| 105 | os.environ['PATH'] = avoid_paths_in_environ(paths_to_avoid) |
| 106 | |
| 107 | pn = d.getVar("PN", True) |
| 108 | bb.utils.mkdirhier(d.getVar("TEST_LOG_SDKEXT_DIR", True)) |
| 109 | |
| 110 | tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.sh") |
| 111 | if not os.path.exists(tcname): |
| 112 | bb.fatal("The toolchain ext is not built. Build it before running the" \ |
| 113 | " tests: 'bitbake <image> -c populate_sdk_ext' .") |
| 114 | |
| 115 | testdir = d.expand("${WORKDIR}/testsdkext/") |
| 116 | bb.utils.remove(testdir, True) |
| 117 | bb.utils.mkdirhier(testdir) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 118 | sdkdir = os.path.join(testdir, 'tc') |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 119 | try: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 120 | subprocess.check_output("%s -y -d %s" % (tcname, sdkdir), shell=True) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 121 | except subprocess.CalledProcessError as e: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 122 | msg = "Couldn't install the extensible SDK:\n%s" % e.output.decode("utf-8") |
| 123 | logfn = os.path.join(sdkdir, 'preparing_build_system.log') |
| 124 | if os.path.exists(logfn): |
| 125 | msg += '\n\nContents of preparing_build_system.log:\n' |
| 126 | with open(logfn, 'r') as f: |
| 127 | for line in f: |
| 128 | msg += line |
| 129 | bb.fatal(msg) |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 130 | |
| 131 | try: |
| 132 | bb.plain("Running SDK Compatibility tests ...") |
| 133 | run_test_context(SDKExtTestContext, d, testdir, tcname, pn, True) |
| 134 | finally: |
| 135 | pass |
| 136 | |
| 137 | try: |
| 138 | bb.plain("Running Extensible SDK tests ...") |
| 139 | run_test_context(SDKExtTestContext, d, testdir, tcname, pn) |
| 140 | finally: |
| 141 | pass |
| 142 | |
| 143 | bb.utils.remove(testdir, True) |
| 144 | |
| 145 | testsdkext_main[vardepsexclude] =+ "BB_ORIGENV" |
| 146 | |
| 147 | python do_testsdkext() { |
| 148 | testsdkext_main(d) |
| 149 | } |
| 150 | addtask testsdkext |
| 151 | do_testsdkext[nostamp] = "1" |
| 152 | do_testsdkext[lockfiles] += "${TESTSDKEXTLOCK}" |