diff options
Diffstat (limited to 'meta/classes/testsdk.bbclass')
| -rw-r--r-- | meta/classes/testsdk.bbclass | 100 |
1 files changed, 100 insertions, 0 deletions
diff --git a/meta/classes/testsdk.bbclass b/meta/classes/testsdk.bbclass new file mode 100644 index 0000000000..42c49134c8 --- /dev/null +++ b/meta/classes/testsdk.bbclass | |||
| @@ -0,0 +1,100 @@ | |||
| 1 | # Copyright (C) 2013 - 2016 Intel Corporation | ||
| 2 | # | ||
| 3 | # Released under the MIT license (see COPYING.MIT) | ||
| 4 | |||
| 5 | TEST_LOG_DIR ?= "${WORKDIR}/testimage" | ||
| 6 | TESTSDKLOCK = "${TMPDIR}/testsdk.lock" | ||
| 7 | |||
| 8 | def testsdk_main(d): | ||
| 9 | import unittest | ||
| 10 | import os | ||
| 11 | import glob | ||
| 12 | import oeqa.runtime | ||
| 13 | import oeqa.sdk | ||
| 14 | import time | ||
| 15 | import subprocess | ||
| 16 | from oeqa.oetest import loadTests, runTests, get_test_suites, get_tests_list | ||
| 17 | |||
| 18 | pn = d.getVar("PN", True) | ||
| 19 | bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True)) | ||
| 20 | |||
| 21 | # tests in TEST_SUITES become required tests | ||
| 22 | # they won't be skipped even if they aren't suitable. | ||
| 23 | # testslist is what we'll actually pass to the unittest loader | ||
| 24 | testslist = get_tests_list(get_test_suites(d, "sdk"), d.getVar("BBPATH", True).split(':'), "sdk") | ||
| 25 | testsrequired = [t for t in (d.getVar("TEST_SUITES_SDK", True) or "auto").split() if t != "auto"] | ||
| 26 | |||
| 27 | tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh") | ||
| 28 | if not os.path.exists(tcname): | ||
| 29 | bb.fatal("The toolchain is not built. Build it before running the tests: 'bitbake <image> -c populate_sdk' .") | ||
| 30 | |||
| 31 | class TestContext(object): | ||
| 32 | def __init__(self): | ||
| 33 | self.d = d | ||
| 34 | self.testslist = testslist | ||
| 35 | self.testsrequired = testsrequired | ||
| 36 | self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files") | ||
| 37 | self.sdktestdir = sdktestdir | ||
| 38 | self.sdkenv = sdkenv | ||
| 39 | self.imagefeatures = d.getVar("IMAGE_FEATURES", True).split() | ||
| 40 | self.distrofeatures = d.getVar("DISTRO_FEATURES", True).split() | ||
| 41 | manifest = d.getVar("SDK_TARGET_MANIFEST", True) | ||
| 42 | try: | ||
| 43 | with open(manifest) as f: | ||
| 44 | self.pkgmanifest = f.read() | ||
| 45 | except IOError as e: | ||
| 46 | bb.fatal("No package manifest file found. Did you build the sdk image?\n%s" % e) | ||
| 47 | hostmanifest = d.getVar("SDK_HOST_MANIFEST", True) | ||
| 48 | try: | ||
| 49 | with open(hostmanifest) as f: | ||
| 50 | self.hostpkgmanifest = f.read() | ||
| 51 | except IOError as e: | ||
| 52 | bb.fatal("No host package manifest file found. Did you build the sdk image?\n%s" % e) | ||
| 53 | |||
| 54 | sdktestdir = d.expand("${WORKDIR}/testimage-sdk/") | ||
| 55 | bb.utils.remove(sdktestdir, True) | ||
| 56 | bb.utils.mkdirhier(sdktestdir) | ||
| 57 | try: | ||
| 58 | subprocess.check_output("cd %s; %s <<EOF\n./tc\nY\nEOF" % (sdktestdir, tcname), shell=True) | ||
| 59 | except subprocess.CalledProcessError as e: | ||
| 60 | bb.fatal("Couldn't install the SDK:\n%s" % e.output) | ||
| 61 | |||
| 62 | try: | ||
| 63 | targets = glob.glob(d.expand(sdktestdir + "/tc/environment-setup-*")) | ||
| 64 | for sdkenv in targets: | ||
| 65 | bb.plain("Testing %s" % sdkenv) | ||
| 66 | # test context | ||
| 67 | tc = TestContext() | ||
| 68 | |||
| 69 | # this is a dummy load of tests | ||
| 70 | # we are doing that to find compile errors in the tests themselves | ||
| 71 | # before booting the image | ||
| 72 | try: | ||
| 73 | loadTests(tc, "sdk") | ||
| 74 | except Exception as e: | ||
| 75 | import traceback | ||
| 76 | bb.fatal("Loading tests failed:\n%s" % traceback.format_exc()) | ||
| 77 | |||
| 78 | starttime = time.time() | ||
| 79 | result = runTests(tc, "sdk") | ||
| 80 | stoptime = time.time() | ||
| 81 | if result.wasSuccessful(): | ||
| 82 | 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)) | ||
| 83 | msg = "%s - OK - All required tests passed" % pn | ||
| 84 | skipped = len(result.skipped) | ||
| 85 | if skipped: | ||
| 86 | msg += " (skipped=%d)" % skipped | ||
| 87 | bb.plain(msg) | ||
| 88 | else: | ||
| 89 | raise bb.build.FuncFailed("%s - FAILED - check the task log and the commands log" % pn ) | ||
| 90 | finally: | ||
| 91 | bb.utils.remove(sdktestdir, True) | ||
| 92 | |||
| 93 | testsdk_main[vardepsexclude] =+ "BB_ORIGENV" | ||
| 94 | |||
| 95 | python do_testsdk() { | ||
| 96 | testsdk_main(d) | ||
| 97 | } | ||
| 98 | addtask testsdk | ||
| 99 | do_testsdk[nostamp] = "1" | ||
| 100 | do_testsdk[lockfiles] += "${TESTSDKLOCK}" | ||
