summaryrefslogtreecommitdiffstats
path: root/meta/classes
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes')
-rw-r--r--meta/classes/testimage-auto.bbclass3
-rw-r--r--meta/classes/testimage.bbclass104
2 files changed, 37 insertions, 70 deletions
diff --git a/meta/classes/testimage-auto.bbclass b/meta/classes/testimage-auto.bbclass
index 3d0e28994a..a5b8f7f14a 100644
--- a/meta/classes/testimage-auto.bbclass
+++ b/meta/classes/testimage-auto.bbclass
@@ -19,5 +19,4 @@ python do_testimage_auto() {
19 testimage_main(d) 19 testimage_main(d)
20} 20}
21addtask testimage_auto before do_build after do_rootfs 21addtask testimage_auto before do_build after do_rootfs
22do_testimage_auto[depends] += "qemu-native:do_populate_sysroot" 22do_testimage_auto[depends] += "${TESTIMAGEDEPENDS}"
23do_testimage_auto[depends] += "qemu-helper-native:do_populate_sysroot"
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass
index 5d61c2baee..add8009d47 100644
--- a/meta/classes/testimage.bbclass
+++ b/meta/classes/testimage.bbclass
@@ -34,13 +34,19 @@ TEST_SUITES ?= "${DEFAULT_TEST_SUITES}"
34 34
35TEST_QEMUBOOT_TIMEOUT ?= "1000" 35TEST_QEMUBOOT_TIMEOUT ?= "1000"
36 36
37TEST_TARGET ?= "qemu"
38TEST_TARGET_IP ?= ""
39TEST_SERVER_IP ?= ""
40
41TESTIMAGEDEPENDS = ""
42TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot"
43
37python do_testimage() { 44python do_testimage() {
38 testimage_main(d) 45 testimage_main(d)
39} 46}
40addtask testimage 47addtask testimage
41do_testimage[nostamp] = "1" 48do_testimage[nostamp] = "1"
42do_testimage[depends] += "qemu-native:do_populate_sysroot" 49do_testimage[depends] += "${TESTIMAGEDEPENDS}"
43do_testimage[depends] += "qemu-helper-native:do_populate_sysroot"
44 50
45 51
46def get_tests_list(d): 52def get_tests_list(d):
@@ -83,15 +89,12 @@ def testimage_main(d):
83 import unittest 89 import unittest
84 import os 90 import os
85 import oeqa.runtime 91 import oeqa.runtime
86 import re
87 import shutil
88 import time 92 import time
89 from oeqa.oetest import runTests 93 from oeqa.oetest import loadTests, runTests
90 from oeqa.utils.sshcontrol import SSHControl 94 from oeqa.targetcontrol import get_target_controller
91 from oeqa.utils.qemurunner import QemuRunner
92 95
93 testdir = d.getVar("TEST_LOG_DIR", True) 96 pn = d.getVar("PN", True)
94 bb.utils.mkdirhier(testdir) 97 bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True))
95 98
96 # tests in TEST_SUITES become required tests 99 # tests in TEST_SUITES become required tests
97 # they won't be skipped even if they aren't suitable for a image (like xorg for minimal) 100 # they won't be skipped even if they aren't suitable for a image (like xorg for minimal)
@@ -99,81 +102,46 @@ def testimage_main(d):
99 testslist = get_tests_list(d) 102 testslist = get_tests_list(d)
100 testsrequired = [t for t in d.getVar("TEST_SUITES", True).split() if t != "auto"] 103 testsrequired = [t for t in d.getVar("TEST_SUITES", True).split() if t != "auto"]
101 104
105 # the robot dance
106 target = get_target_controller(d)
107
102 class TestContext: 108 class TestContext:
103 def __init__(self): 109 def __init__(self):
104 self.d = d 110 self.d = d
105 self.testslist = testslist 111 self.testslist = testslist
106 self.testsrequired = testsrequired 112 self.testsrequired = testsrequired
107 self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files") 113 self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files")
114 self.target = target
108 115
109 # test context 116 # test context
110 tc = TestContext() 117 tc = TestContext()
111 118
112 # prepare qemu instance 119 # this is a dummy load of tests
113 # and boot each supported fs type 120 # we are doing that to find compile errors in the tests themselves
114 machine=d.getVar("MACHINE", True) 121 # before booting the image
115 #will handle fs type eventually, stick with ext3 for now
116 #make a copy of the original rootfs and use that for tests
117 origrootfs=os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME",True) + '.ext3')
118 testrootfs=os.path.join(testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.ext3')
119 try: 122 try:
120 shutil.copyfile(origrootfs, testrootfs) 123 loadTests(tc)
121 except Exception as e: 124 except Exception as e:
122 bb.fatal("Error copying rootfs: %s" % e) 125 bb.fatal("Loading tests failed:\n %s" % e)
123 126
124 try: 127 target.deploy()
125 boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True))
126 except ValueError:
127 boottime = 1000
128
129 qemu = QemuRunner(machine=machine, rootfs=testrootfs,
130 tmpdir = d.getVar("TMPDIR", True),
131 deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True),
132 display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True),
133 logfile = os.path.join(testdir, "qemu_boot_log.%s" % d.getVar('DATETIME', True)),
134 boottime = boottime)
135
136 qemuloglink = os.path.join(testdir, "qemu_boot_log")
137 if os.path.islink(qemuloglink):
138 os.unlink(qemuloglink)
139 os.symlink(qemu.logfile, qemuloglink)
140
141 sshlog = os.path.join(testdir, "ssh_target_log.%s" % d.getVar('DATETIME', True))
142 sshloglink = os.path.join(testdir, "ssh_target_log")
143 if os.path.islink(sshloglink):
144 os.unlink(sshloglink)
145 os.symlink(sshlog, sshloglink)
146
147 bb.note("DISPLAY value: %s" % qemu.display)
148 bb.note("rootfs file: %s" % qemu.rootfs)
149 bb.note("Qemu log file: %s" % qemu.logfile)
150 bb.note("SSH log file: %s" % sshlog)
151 128
152 pn = d.getVar("PN", True)
153 #catch exceptions when loading or running tests (mostly our own errors)
154 try: 129 try:
155 if qemu.launch(): 130 target.start()
156 131 # run tests and get the results
157 # set more context - ssh instance and qemu 132 starttime = time.time()
158 # we do these here because we needed qemu to boot and get the ip 133 result = runTests(tc)
159 tc.qemu = qemu 134 stoptime = time.time()
160 tc.target = SSHControl(host=qemu.ip,logfile=sshlog) 135 if result.wasSuccessful():
161 # run tests and get the results 136 bb.plain("%s - Ran %d test%s in %.3fs" % (pn, result.testsRun, result.testsRun != 1 and "s" or "", stoptime - starttime))
162 starttime = time.time() 137 msg = "%s - OK - All required tests passed" % pn
163 result = runTests(tc) 138 skipped = len(result.skipped)
164 stoptime = time.time() 139 if skipped:
165 if result.wasSuccessful(): 140 msg += " (skipped=%d)" % skipped
166 bb.plain("%s - Ran %d test%s in %.3fs" % (pn, result.testsRun, result.testsRun != 1 and "s" or "", stoptime - starttime)) 141 bb.plain(msg)
167 msg = "%s - OK - All required tests passed" % pn
168 skipped = len(result.skipped)
169 if skipped:
170 msg += " (skipped=%d)" % skipped
171 bb.plain(msg)
172 else:
173 raise bb.build.FuncFailed("%s - FAILED - check the task log and the ssh log" % pn )
174 else: 142 else:
175 raise bb.build.FuncFailed("%s - FAILED to start qemu - check the task log and the boot log" % pn) 143 raise bb.build.FuncFailed("%s - FAILED - check the task log and the ssh log" % pn )
176 finally: 144 finally:
177 qemu.kill() 145 target.stop()
178 146
179testimage_main[vardepsexclude] =+ "BB_ORIGENV" 147testimage_main[vardepsexclude] =+ "BB_ORIGENV"