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