summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/testimage.bbclass98
-rw-r--r--meta/classes/testsdk.bbclass100
2 files changed, 100 insertions, 98 deletions
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass
index 3fe27a27db..956fb3fa0c 100644
--- a/meta/classes/testimage.bbclass
+++ b/meta/classes/testimage.bbclass
@@ -98,14 +98,6 @@ do_testimage[nostamp] = "1"
98do_testimage[depends] += "${TESTIMAGEDEPENDS}" 98do_testimage[depends] += "${TESTIMAGEDEPENDS}"
99do_testimage[lockfiles] += "${TESTIMAGELOCK}" 99do_testimage[lockfiles] += "${TESTIMAGELOCK}"
100 100
101python do_testsdk() {
102 testsdk_main(d)
103}
104addtask testsdk
105do_testsdk[nostamp] = "1"
106do_testsdk[depends] += "${TESTIMAGEDEPENDS}"
107do_testsdk[lockfiles] += "${TESTIMAGELOCK}"
108
109def exportTests(d,tc): 101def exportTests(d,tc):
110 import json 102 import json
111 import shutil 103 import shutil
@@ -197,7 +189,6 @@ def exportTests(d,tc):
197 189
198 bb.plain("Exported tests to: %s" % exportpath) 190 bb.plain("Exported tests to: %s" % exportpath)
199 191
200
201def testimage_main(d): 192def testimage_main(d):
202 import unittest 193 import unittest
203 import os 194 import os
@@ -299,92 +290,3 @@ def testimage_main(d):
299 target.stop() 290 target.stop()
300 291
301testimage_main[vardepsexclude] =+ "BB_ORIGENV" 292testimage_main[vardepsexclude] =+ "BB_ORIGENV"
302
303def testsdk_main(d):
304 import unittest
305 import os
306 import glob
307 import oeqa.runtime
308 import oeqa.sdk
309 import time
310 import subprocess
311 from oeqa.oetest import loadTests, runTests, get_test_suites, get_tests_list
312
313 pn = d.getVar("PN", True)
314 bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True))
315
316 # tests in TEST_SUITES become required tests
317 # they won't be skipped even if they aren't suitable.
318 # testslist is what we'll actually pass to the unittest loader
319 testslist = get_tests_list(get_test_suites(d, "sdk"), d.getVar("BBPATH", True).split(':'), "sdk")
320 testsrequired = [t for t in (d.getVar("TEST_SUITES_SDK", True) or "auto").split() if t != "auto"]
321
322 tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh")
323 if not os.path.exists(tcname):
324 bb.fatal("The toolchain is not built. Build it before running the tests: 'bitbake <image> -c populate_sdk' .")
325
326 class TestContext(object):
327 def __init__(self):
328 self.d = d
329 self.testslist = testslist
330 self.testsrequired = testsrequired
331 self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files")
332 self.sdktestdir = sdktestdir
333 self.sdkenv = sdkenv
334 self.imagefeatures = d.getVar("IMAGE_FEATURES", True).split()
335 self.distrofeatures = d.getVar("DISTRO_FEATURES", True).split()
336 manifest = d.getVar("SDK_TARGET_MANIFEST", True)
337 try:
338 with open(manifest) as f:
339 self.pkgmanifest = f.read()
340 except IOError as e:
341 bb.fatal("No package manifest file found. Did you build the sdk image?\n%s" % e)
342 hostmanifest = d.getVar("SDK_HOST_MANIFEST", True)
343 try:
344 with open(hostmanifest) as f:
345 self.hostpkgmanifest = f.read()
346 except IOError as e:
347 bb.fatal("No host package manifest file found. Did you build the sdk image?\n%s" % e)
348
349 sdktestdir = d.expand("${WORKDIR}/testimage-sdk/")
350 bb.utils.remove(sdktestdir, True)
351 bb.utils.mkdirhier(sdktestdir)
352 try:
353 subprocess.check_output("cd %s; %s <<EOF\n./tc\nY\nEOF" % (sdktestdir, tcname), shell=True)
354 except subprocess.CalledProcessError as e:
355 bb.fatal("Couldn't install the SDK:\n%s" % e.output)
356
357 try:
358 targets = glob.glob(d.expand(sdktestdir + "/tc/environment-setup-*"))
359 bb.warn(str(targets))
360 for sdkenv in targets:
361 bb.plain("Testing %s" % sdkenv)
362 # test context
363 tc = TestContext()
364
365 # this is a dummy load of tests
366 # we are doing that to find compile errors in the tests themselves
367 # before booting the image
368 try:
369 loadTests(tc, "sdk")
370 except Exception as e:
371 import traceback
372 bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
373
374
375 starttime = time.time()
376 result = runTests(tc, "sdk")
377 stoptime = time.time()
378 if result.wasSuccessful():
379 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))
380 msg = "%s - OK - All required tests passed" % pn
381 skipped = len(result.skipped)
382 if skipped:
383 msg += " (skipped=%d)" % skipped
384 bb.plain(msg)
385 else:
386 raise bb.build.FuncFailed("%s - FAILED - check the task log and the commands log" % pn )
387 finally:
388 bb.utils.remove(sdktestdir, True)
389
390testsdk_main[vardepsexclude] =+ "BB_ORIGENV"
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
5TEST_LOG_DIR ?= "${WORKDIR}/testimage"
6TESTSDKLOCK = "${TMPDIR}/testsdk.lock"
7
8def 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
93testsdk_main[vardepsexclude] =+ "BB_ORIGENV"
94
95python do_testsdk() {
96 testsdk_main(d)
97}
98addtask testsdk
99do_testsdk[nostamp] = "1"
100do_testsdk[lockfiles] += "${TESTSDKLOCK}"