diff options
author | Stefan Stanacar <stefanx.stanacar@intel.com> | 2013-06-28 10:57:04 +0300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-07-09 10:53:43 +0100 |
commit | 1328d49625e0030e00d09d74d35f57bd87b14a04 (patch) | |
tree | 7369794ca0f8301121b38529608c57608b0de1ca /meta | |
parent | dc86293f0444384e8ae5131fdd10b6cb077164b0 (diff) | |
download | poky-1328d49625e0030e00d09d74d35f57bd87b14a04.tar.gz |
classes/testimage.bbclass: new class for image tests
Replacement class for imagetest-qemu.bbclass. It launches a qemu instance and
runs test modules defined in TEST_SUITES.
(From OE-Core rev: e0e32b978e5af128d7ff4ee2686777b49f919e27)
Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com>
Signed-off-by: Radu Moisan <radu.moisan@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta')
-rw-r--r-- | meta/classes/testimage.bbclass | 92 |
1 files changed, 92 insertions, 0 deletions
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass new file mode 100644 index 0000000000..35c6811c89 --- /dev/null +++ b/meta/classes/testimage.bbclass | |||
@@ -0,0 +1,92 @@ | |||
1 | TEST_LOG_DIR ?= "${WORKDIR}/testimage" | ||
2 | |||
3 | DEFAULT_TEST_SUITES = "ping auto" | ||
4 | DEFAULT_TEST_SUITES_pn-core-image-minimal = "ping" | ||
5 | DEFAULT_TEST_SUITES_pn-core-image-sato = "ping ssh connman rpm smart xorg dmesg" | ||
6 | DEFAULT_TEST_SUITES_pn-core-image-sato-sdk = "ping ssh connman rpm smart gcc xorg dmesg" | ||
7 | |||
8 | TEST_SUITES ?= "${DEFAULT_TEST_SUITES}" | ||
9 | |||
10 | python do_testimage() { | ||
11 | testimage_main(d) | ||
12 | } | ||
13 | addtask testimage | ||
14 | do_testimage[nostamp] = "1" | ||
15 | do_testimage[depends] += "qemu-native:do_populate_sysroot" | ||
16 | do_testimage[depends] += "qemu-helper-native:do_populate_sysroot" | ||
17 | |||
18 | def testimage_main(d): | ||
19 | import unittest | ||
20 | import os | ||
21 | import oeqa.runtime | ||
22 | import re | ||
23 | from oeqa.oetest import runTests | ||
24 | from oeqa.utils.sshcontrol import SSHControl | ||
25 | from oeqa.utils.qemurunner import QemuRunner | ||
26 | |||
27 | testdir = d.getVar("TEST_LOG_DIR", True) | ||
28 | bb.utils.mkdirhier(testdir) | ||
29 | sshlog = os.path.join(testdir, "ssh_target_log.%s" % d.getVar('DATETIME', True)) | ||
30 | sshloglink = os.path.join(testdir, "ssh_target_log") | ||
31 | if os.path.islink(sshloglink): | ||
32 | os.unlink(sshloglink) | ||
33 | os.symlink(sshlog, sshloglink) | ||
34 | |||
35 | # tests in TEST_SUITES become required tests | ||
36 | # they won't be skipped even if they aren't suitable for a default image (like xorg for minimal) | ||
37 | testsuites = d.getVar("TEST_SUITES", True) | ||
38 | # testslist is what we'll run and order matters | ||
39 | testslist = [ x for x in testsuites.split() if x != "auto" ] | ||
40 | # if we have auto search for other modules | ||
41 | if "auto" in testsuites: | ||
42 | for f in os.listdir(os.path.dirname(os.path.abspath(oeqa.runtime.__file__))): | ||
43 | if f.endswith('.py') and not f.startswith('_') and f[:-3] not in testslist: | ||
44 | testslist.append(f[:-3]) | ||
45 | |||
46 | testslist = [ "oeqa.runtime." + x for x in testslist ] | ||
47 | |||
48 | class TestContext: | ||
49 | def __init__(self): | ||
50 | self.d = d | ||
51 | self.testslist = testslist | ||
52 | self.testsrequired = testsuites.split() | ||
53 | self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files") | ||
54 | |||
55 | # test context | ||
56 | tc = TestContext() | ||
57 | |||
58 | # prepare qemu instance | ||
59 | # and boot each supported fs type | ||
60 | machine=d.getVar("MACHINE", True) | ||
61 | #will handle fs type eventually, stick with ext3 for now | ||
62 | rootfs=d.getVar("DEPLOY_DIR_IMAGE", True) + '/' + d.getVar("IMAGE_BASENAME",True) + '-' + machine + '.ext3' | ||
63 | |||
64 | qemu = QemuRunner(machine, rootfs) | ||
65 | qemu.tmpdir = d.getVar("TMPDIR", True) | ||
66 | qemu.display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True) | ||
67 | qemu.logfile = os.path.join(testdir, "qemu_boot_log.%s" % d.getVar('DATETIME', True)) | ||
68 | |||
69 | bb.note("DISPLAY value: %s" % qemu.display) | ||
70 | bb.note("rootfs file: %s" % rootfs) | ||
71 | bb.note("Qemu logfile: %s" % qemu.logfile) | ||
72 | |||
73 | #catch exceptions when loading or running tests (mostly our own errors) | ||
74 | try: | ||
75 | if qemu.launch(): | ||
76 | |||
77 | # set more context - ssh instance and qemu | ||
78 | # we do these here because we needed qemu to boot and get the ip | ||
79 | tc.qemu = qemu | ||
80 | tc.target = SSHControl(host=qemu.ip,logfile=sshlog) | ||
81 | # run tests and get the results | ||
82 | result = runTests(tc) | ||
83 | |||
84 | if result.wasSuccessful(): | ||
85 | bb.note("All required tests passed") | ||
86 | else: | ||
87 | raise bb.build.FuncFailed("Some tests failed. You should check the task log and the ssh log. (ssh log is %s" % sshlog) | ||
88 | |||
89 | else: | ||
90 | raise bb.build.FuncFailed("Failed to start qemu. You should check the task log and the qemu boot log (qemu log is %s)" % qemu.logfile) | ||
91 | finally: | ||
92 | qemu.kill() | ||