blob: 43342b1f251a8e1a84dc0c9b7ae028c94c64a3cc [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#
Brad Bishop37a0e4d2017-12-04 01:01:44 -05007# To run SDK tests, run the commands:
8# $ bitbake <image-name> -c populate_sdk
9# $ bitbake <image-name> -c testsdk
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050010#
Brad Bishop37a0e4d2017-12-04 01:01:44 -050011# 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 Williamsd8c66bc2016-06-20 12:57:21 -050016
17TEST_LOG_DIR ?= "${WORKDIR}/testimage"
18TESTSDKLOCK = "${TMPDIR}/testsdk.lock"
19
20def 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 Williamsc0f7c042017-02-23 20:41:17 -060049 bb.fatal("%s - FAILED - check the task log and the commands log" % pn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050050
51def 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 Williamsc0f7c042017-02-23 20:41:17 -060070 bb.fatal("Couldn't install the SDK:\n%s" % e.output.decode("utf-8"))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050071
72 try:
73 run_test_context(SDKTestContext, d, sdktestdir, tcname, pn)
74 finally:
75 bb.utils.remove(sdktestdir, True)
76
77testsdk_main[vardepsexclude] =+ "BB_ORIGENV"
78
79python do_testsdk() {
80 testsdk_main(d)
81}
82addtask testsdk
83do_testsdk[nostamp] = "1"
84do_testsdk[lockfiles] += "${TESTSDKLOCK}"
85
86TEST_LOG_SDKEXT_DIR ?= "${WORKDIR}/testsdkext"
87TESTSDKEXTLOCK = "${TMPDIR}/testsdkext.lock"
88
89def 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 Williamsc0f7c042017-02-23 20:41:17 -0600118 sdkdir = os.path.join(testdir, 'tc')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500119 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600120 subprocess.check_output("%s -y -d %s" % (tcname, sdkdir), shell=True)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500121 except subprocess.CalledProcessError as e:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600122 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 Williamsd8c66bc2016-06-20 12:57:21 -0500130
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
145testsdkext_main[vardepsexclude] =+ "BB_ORIGENV"
146
147python do_testsdkext() {
148 testsdkext_main(d)
149}
150addtask testsdkext
151do_testsdkext[nostamp] = "1"
152do_testsdkext[lockfiles] += "${TESTSDKEXTLOCK}"