blob: 77c9203cf992fce0892d7dc95d1564ec39a967d0 [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:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060047 bb.fatal("%s - FAILED - check the task log and the commands log" % pn)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050048
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:
Patrick Williamsc0f7c042017-02-23 20:41:17 -060068 bb.fatal("Couldn't install the SDK:\n%s" % e.output.decode("utf-8"))
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050069
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)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600116 sdkdir = os.path.join(testdir, 'tc')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500117 try:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600118 subprocess.check_output("%s -y -d %s" % (tcname, sdkdir), shell=True)
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500119 except subprocess.CalledProcessError as e:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600120 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 Williamsd8c66bc2016-06-20 12:57:21 -0500128
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
143testsdkext_main[vardepsexclude] =+ "BB_ORIGENV"
144
145python do_testsdkext() {
146 testsdkext_main(d)
147}
148addtask testsdkext
149do_testsdkext[nostamp] = "1"
150do_testsdkext[lockfiles] += "${TESTSDKEXTLOCK}"