summaryrefslogtreecommitdiffstats
path: root/meta/classes/testimage.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/testimage.bbclass')
-rw-r--r--meta/classes/testimage.bbclass137
1 files changed, 17 insertions, 120 deletions
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass
index e77bb11922..a2e13df710 100644
--- a/meta/classes/testimage.bbclass
+++ b/meta/classes/testimage.bbclass
@@ -30,7 +30,6 @@
30TEST_LOG_DIR ?= "${WORKDIR}/testimage" 30TEST_LOG_DIR ?= "${WORKDIR}/testimage"
31 31
32TEST_EXPORT_DIR ?= "${TMPDIR}/testimage/${PN}" 32TEST_EXPORT_DIR ?= "${TMPDIR}/testimage/${PN}"
33TEST_EXPORT_ONLY ?= "0"
34 33
35RPMTESTSUITE = "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'smart rpm', '', d)}" 34RPMTESTSUITE = "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'smart rpm', '', d)}"
36MINTESTSUITE = "ping" 35MINTESTSUITE = "ping"
@@ -62,8 +61,6 @@ TEST_SUITES ?= "${DEFAULT_TEST_SUITES}"
62 61
63TEST_QEMUBOOT_TIMEOUT ?= "1000" 62TEST_QEMUBOOT_TIMEOUT ?= "1000"
64TEST_TARGET ?= "qemu" 63TEST_TARGET ?= "qemu"
65TEST_TARGET_IP ?= ""
66TEST_SERVER_IP ?= ""
67 64
68TESTIMAGEDEPENDS = "" 65TESTIMAGEDEPENDS = ""
69TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot" 66TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot"
@@ -108,97 +105,6 @@ do_testimage[nostamp] = "1"
108do_testimage[depends] += "${TESTIMAGEDEPENDS}" 105do_testimage[depends] += "${TESTIMAGEDEPENDS}"
109do_testimage[lockfiles] += "${TESTIMAGELOCK}" 106do_testimage[lockfiles] += "${TESTIMAGELOCK}"
110 107
111def exportTests(d,tc):
112 import json
113 import shutil
114 import pkgutil
115 import re
116
117 exportpath = d.getVar("TEST_EXPORT_DIR", True)
118
119 savedata = {}
120 savedata["d"] = {}
121 savedata["target"] = {}
122 savedata["host_dumper"] = {}
123 for key in tc.__dict__:
124 # special cases
125 if key not in ['d', 'target', 'host_dumper', 'suite']:
126 savedata[key] = getattr(tc, key)
127 savedata["target"]["ip"] = tc.target.ip or d.getVar("TEST_TARGET_IP", True)
128 savedata["target"]["server_ip"] = tc.target.server_ip or d.getVar("TEST_SERVER_IP", True)
129
130 keys = [ key for key in d.keys() if not key.startswith("_") and not key.startswith("BB") \
131 and not key.startswith("B_pn") and not key.startswith("do_") and not d.getVarFlag(key, "func", True)]
132 for key in keys:
133 try:
134 savedata["d"][key] = d.getVar(key, True)
135 except bb.data_smart.ExpansionError:
136 # we don't care about those anyway
137 pass
138
139 savedata["host_dumper"]["parent_dir"] = tc.host_dumper.parent_dir
140 savedata["host_dumper"]["cmds"] = tc.host_dumper.cmds
141
142 json_file = os.path.join(exportpath, "testdata.json")
143 with open(json_file, "w") as f:
144 json.dump(savedata, f, skipkeys=True, indent=4, sort_keys=True)
145
146 # Replace absolute path with relative in the file
147 exclude_path = os.path.join(d.getVar("COREBASE", True),'meta','lib','oeqa')
148 f1 = open(json_file,'r').read()
149 f2 = open(json_file,'w')
150 m = f1.replace(exclude_path,'oeqa')
151 f2.write(m)
152 f2.close()
153
154 # now start copying files
155 # we'll basically copy everything under meta/lib/oeqa, with these exceptions
156 # - oeqa/targetcontrol.py - not needed
157 # - oeqa/selftest - something else
158 # That means:
159 # - all tests from oeqa/runtime defined in TEST_SUITES (including from other layers)
160 # - the contents of oeqa/utils and oeqa/runtime/files
161 # - oeqa/oetest.py and oeqa/runexport.py (this will get copied to exportpath not exportpath/oeqa)
162 # - __init__.py files
163 bb.utils.mkdirhier(os.path.join(exportpath, "oeqa/runtime/files"))
164 bb.utils.mkdirhier(os.path.join(exportpath, "oeqa/utils"))
165 # copy test modules, this should cover tests in other layers too
166 bbpath = d.getVar("BBPATH", True).split(':')
167 for t in tc.testslist:
168 isfolder = False
169 if re.search("\w+\.\w+\.test_\S+", t):
170 t = '.'.join(t.split('.')[:3])
171 mod = pkgutil.get_loader(t)
172 # More depth than usual?
173 if (t.count('.') > 2):
174 for p in bbpath:
175 foldername = os.path.join(p, 'lib', os.sep.join(t.split('.')).rsplit(os.sep, 1)[0])
176 if os.path.isdir(foldername):
177 isfolder = True
178 target_folder = os.path.join(exportpath, "oeqa", "runtime", os.path.basename(foldername))
179 if not os.path.exists(target_folder):
180 shutil.copytree(foldername, target_folder)
181 if not isfolder:
182 shutil.copy2(mod.filename, os.path.join(exportpath, "oeqa/runtime"))
183 # copy __init__.py files
184 oeqadir = pkgutil.get_loader("oeqa").filename
185 shutil.copy2(os.path.join(oeqadir, "__init__.py"), os.path.join(exportpath, "oeqa"))
186 shutil.copy2(os.path.join(oeqadir, "runtime/__init__.py"), os.path.join(exportpath, "oeqa/runtime"))
187 # copy oeqa/oetest.py and oeqa/runexported.py
188 shutil.copy2(os.path.join(oeqadir, "oetest.py"), os.path.join(exportpath, "oeqa"))
189 shutil.copy2(os.path.join(oeqadir, "runexported.py"), exportpath)
190 # copy oeqa/utils/*.py
191 for root, dirs, files in os.walk(os.path.join(oeqadir, "utils")):
192 for f in files:
193 if f.endswith(".py"):
194 shutil.copy2(os.path.join(root, f), os.path.join(exportpath, "oeqa/utils"))
195 # copy oeqa/runtime/files/*
196 for root, dirs, files in os.walk(os.path.join(oeqadir, "runtime/files")):
197 for f in files:
198 shutil.copy2(os.path.join(root, f), os.path.join(exportpath, "oeqa/runtime/files"))
199
200 bb.plain("Exported tests to: %s" % exportpath)
201
202def testimage_main(d): 108def testimage_main(d):
203 import unittest 109 import unittest
204 import os 110 import os
@@ -210,11 +116,7 @@ def testimage_main(d):
210 from oeqa.utils.dump import get_host_dumper 116 from oeqa.utils.dump import get_host_dumper
211 117
212 pn = d.getVar("PN", True) 118 pn = d.getVar("PN", True)
213 export = oe.utils.conditional("TEST_EXPORT_ONLY", "1", True, False, d)
214 bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True)) 119 bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True))
215 if export:
216 bb.utils.remove(d.getVar("TEST_EXPORT_DIR", True), recurse=True)
217 bb.utils.mkdirhier(d.getVar("TEST_EXPORT_DIR", True))
218 120
219 # we need the host dumper in test context 121 # we need the host dumper in test context
220 host_dumper = get_host_dumper(d) 122 host_dumper = get_host_dumper(d)
@@ -234,29 +136,24 @@ def testimage_main(d):
234 import traceback 136 import traceback
235 bb.fatal("Loading tests failed:\n%s" % traceback.format_exc()) 137 bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
236 138
237 if export: 139 target.deploy()
140 try:
141 target.start()
142 starttime = time.time()
143 result = tc.runTests()
144 stoptime = time.time()
145 if result.wasSuccessful():
146 bb.plain("%s - Ran %d test%s in %.3fs" % (pn, result.testsRun, result.testsRun != 1 and "s" or "", stoptime - starttime))
147 msg = "%s - OK - All required tests passed" % pn
148 skipped = len(result.skipped)
149 if skipped:
150 msg += " (skipped=%d)" % skipped
151 bb.plain(msg)
152 else:
153 raise bb.build.FuncFailed("%s - FAILED - check the task log and the ssh log" % pn )
154 finally:
238 signal.signal(signal.SIGTERM, tc.origsigtermhandler) 155 signal.signal(signal.SIGTERM, tc.origsigtermhandler)
239 tc.origsigtermhandler = None 156 target.stop()
240 exportTests(d,tc)
241 else:
242 target.deploy()
243 try:
244 target.start()
245 starttime = time.time()
246 result = tc.runTests()
247 stoptime = time.time()
248 if result.wasSuccessful():
249 bb.plain("%s - Ran %d test%s in %.3fs" % (pn, result.testsRun, result.testsRun != 1 and "s" or "", stoptime - starttime))
250 msg = "%s - OK - All required tests passed" % pn
251 skipped = len(result.skipped)
252 if skipped:
253 msg += " (skipped=%d)" % skipped
254 bb.plain(msg)
255 else:
256 raise bb.build.FuncFailed("%s - FAILED - check the task log and the ssh log" % pn )
257 finally:
258 signal.signal(signal.SIGTERM, tc.origsigtermhandler)
259 target.stop()
260 157
261testimage_main[vardepsexclude] =+ "BB_ORIGENV" 158testimage_main[vardepsexclude] =+ "BB_ORIGENV"
262 159