summaryrefslogtreecommitdiffstats
path: root/meta/classes/testimage.bbclass
diff options
context:
space:
mode:
authorStefan Stanacar <stefanx.stanacar@intel.com>2013-11-26 11:18:22 +0200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-12-03 17:45:51 +0000
commitb4d9b4208b1c06164c4eeea2110408fb404dba1c (patch)
tree12709d6e6b26777f9a2973022a2e7b32ea0e3d2b /meta/classes/testimage.bbclass
parentfd2d16519d964ef3420cb83ac9680a4b6206cefa (diff)
downloadpoky-b4d9b4208b1c06164c4eeea2110408fb404dba1c.tar.gz
testimage: use the new targetcontrol.py module for running tests
This patch makes the necessary changes for using the targetcontrol.py module so that one can run the same tests on a qemu instance or a remote machine based on the value of TEST_TARGET variable: "qemu" or "simpleremote". The default value is "qemu" which starts a qemu instance and it's the with what we currently have. With "simpleremote", the remote machine must be up with network and ssh and you need to set TEST_TARGET_IP with the IP address of the remote machine (it can still be a qemu instance that was manually started). Basically testimage.bbclass now does something along the lines of: - load tests -> deploy (prepare) / start target -> run tests. There were a couple of changes necessary for tests and also some cleanups/renames that were needed to adjust this change. (use ip everywhere when refering to target and server_ip when refering to host/build machine) Also two unnecessary and unsed methods were dropped from sshcontrol. [ YOCTO #5554 ] (From OE-Core rev: a7820350fa3271d78ed7476e02f4aef593be1125) Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/testimage.bbclass')
-rw-r--r--meta/classes/testimage.bbclass104
1 files changed, 36 insertions, 68 deletions
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"