blob: f4dc2c36dc0130194835ff91317d36e22a1b4169 [file] [log] [blame]
Patrick Williamsd8c66bc2016-06-20 12:57:21 -05001# 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
15TEST_LOG_DIR ?= "${WORKDIR}/testimage"
16TESTSDKLOCK = "${TMPDIR}/testsdk.lock"
17
18def 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:
47 raise bb.build.FuncFailed("%s - FAILED - check the task log and the commands log" % pn )
48
49def 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:
68 bb.fatal("Couldn't install the SDK:\n%s" % e.output)
69
70 try:
71 run_test_context(SDKTestContext, d, sdktestdir, tcname, pn)
72 finally:
73 bb.utils.remove(sdktestdir, True)
74
75testsdk_main[vardepsexclude] =+ "BB_ORIGENV"
76
77python do_testsdk() {
78 testsdk_main(d)
79}
80addtask testsdk
81do_testsdk[nostamp] = "1"
82do_testsdk[lockfiles] += "${TESTSDKLOCK}"
83
84TEST_LOG_SDKEXT_DIR ?= "${WORKDIR}/testsdkext"
85TESTSDKEXTLOCK = "${TMPDIR}/testsdkext.lock"
86
87def 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)
116 try:
117 subprocess.check_output("%s -y -d %s/tc" % (tcname, testdir), shell=True)
118 except subprocess.CalledProcessError as e:
119 bb.fatal("Couldn't install the SDK EXT:\n%s" % e.output)
120
121 try:
122 bb.plain("Running SDK Compatibility tests ...")
123 run_test_context(SDKExtTestContext, d, testdir, tcname, pn, True)
124 finally:
125 pass
126
127 try:
128 bb.plain("Running Extensible SDK tests ...")
129 run_test_context(SDKExtTestContext, d, testdir, tcname, pn)
130 finally:
131 pass
132
133 bb.utils.remove(testdir, True)
134
135testsdkext_main[vardepsexclude] =+ "BB_ORIGENV"
136
137python do_testsdkext() {
138 testsdkext_main(d)
139}
140addtask testsdkext
141do_testsdkext[nostamp] = "1"
142do_testsdkext[lockfiles] += "${TESTSDKEXTLOCK}"