summaryrefslogtreecommitdiffstats
path: root/meta/classes/imagetest-qemu.bbclass
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2013-09-19 13:18:06 +0100
committerRichard Purdie <richard.purdie@linuxfoundation.org>2013-09-22 12:19:41 +0100
commitd6529876129a6932b6d2e369b3fd6ca40d342add (patch)
tree82b62115b0f4ba9701c823988472884c735872b7 /meta/classes/imagetest-qemu.bbclass
parent595321a62669e90bed5f459a9d926a68988086a9 (diff)
downloadpoky-d6529876129a6932b6d2e369b3fd6ca40d342add.tar.gz
classes/imagetest-qemu: remove old image testing class
This has now been superseded by testimage. (From OE-Core rev: d469c92394a1a95ae7a45b8b80dc4c2918e0e9a6) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/imagetest-qemu.bbclass')
-rw-r--r--meta/classes/imagetest-qemu.bbclass238
1 files changed, 0 insertions, 238 deletions
diff --git a/meta/classes/imagetest-qemu.bbclass b/meta/classes/imagetest-qemu.bbclass
deleted file mode 100644
index 7083a99381..0000000000
--- a/meta/classes/imagetest-qemu.bbclass
+++ /dev/null
@@ -1,238 +0,0 @@
1# Test related variables
2# By default, TEST_DIR is created under WORKDIR
3TEST_DIR ?= "${WORKDIR}/qemuimagetest"
4TEST_LOG ?= "${LOG_DIR}/qemuimagetests"
5TEST_RESULT ?= "${TEST_DIR}/result"
6TEST_TMP ?= "${TEST_DIR}/tmp"
7TEST_SCEN ?= "sanity"
8TEST_STATUS ?= "${TEST_TMP}/status"
9TARGET_IPSAVE ?= "${TEST_TMP}/target_ip"
10TEST_SERIALIZE ?= "1"
11
12python do_qemuimagetest() {
13 qemuimagetest_main(d)
14}
15addtask qemuimagetest before do_build after do_rootfs
16do_qemuimagetest[nostamp] = "1"
17do_qemuimagetest[depends] += "qemu-native:do_populate_sysroot"
18
19python do_qemuimagetest_standalone() {
20 qemuimagetest_main(d)
21}
22addtask qemuimagetest_standalone
23do_qemuimagetest_standalone[nostamp] = "1"
24do_qemuimagetest_standalone[depends] += "qemu-native:do_populate_sysroot"
25
26def qemuimagetest_main(d):
27 import sys
28 import re
29 import shutil
30 import subprocess
31
32 """
33 Test Controller for automated testing.
34 """
35
36 casestr = re.compile(r'(?P<scen>\w+\b):(?P<case>\S+$)')
37 resultstr = re.compile(r'\s*(?P<case>\w+)\s*(?P<pass>\d+)\s*(?P<fail>\d+)\s*(?P<noresult>\d+)')
38 machine = d.getVar('MACHINE', True)
39 pname = d.getVar('PN', True)
40 allfstypes = d.getVar("IMAGE_FSTYPES", True).split()
41 testfstypes = [ "ext2", "ext3", "ext4", "jffs2", "btrfs" ]
42
43 """function to save test cases running status"""
44 def teststatus(test, status, index, length):
45 test_status = d.getVar('TEST_STATUS', True)
46 if not os.path.exists(test_status):
47 raise bb.build.FuncFailed("No test status file existing under TEST_TMP")
48
49 f = open(test_status, "w")
50 f.write("\t%-15s%-15s%-15s%-15s\n" % ("Case", "Status", "Number", "Total"))
51 f.write("\t%-15s%-15s%-15s%-15s\n" % (case, status, index, length))
52 f.close()
53
54 """funtion to run each case under scenario"""
55 def runtest(scen, case, fulltestpath, fstype):
56 resultpath = d.getVar('TEST_RESULT', True)
57 tmppath = d.getVar('TEST_TMP', True)
58
59 """initialize log file for testcase"""
60 logpath = d.getVar('TEST_LOG', True)
61 bb.utils.mkdirhier("%s/%s" % (logpath, scen))
62 caselog = os.path.join(logpath, "%s/log_%s.%s" % (scen, case, d.getVar('DATETIME', True)))
63 subprocess.call("touch %s" % caselog, shell=True)
64
65 """export TEST_TMP, TEST_RESULT, DEPLOY_DIR and QEMUARCH"""
66 os.environ["PATH"] = d.getVar("PATH", True)
67 os.environ["TEST_TMP"] = tmppath
68 os.environ["TEST_RESULT"] = resultpath
69 os.environ["DEPLOY_DIR"] = d.getVar("DEPLOY_DIR", True)
70 os.environ["QEMUARCH"] = machine
71 os.environ["QEMUTARGET"] = pname
72 os.environ["COREBASE"] = d.getVar("COREBASE", True)
73 os.environ["TOPDIR"] = d.getVar("TOPDIR", True)
74 os.environ["OE_TMPDIR"] = d.getVar("TMPDIR", True)
75 os.environ["TEST_STATUS"] = d.getVar("TEST_STATUS", True)
76 os.environ["TARGET_IPSAVE"] = d.getVar("TARGET_IPSAVE", True)
77 os.environ["TEST_SERIALIZE"] = d.getVar("TEST_SERIALIZE", True)
78 os.environ["SDK_NAME"] = d.getVar("SDK_NAME", True)
79 os.environ["RUNQEMU_LOGFILE"] = d.expand("${T}/log.runqemutest.%s" % os.getpid())
80 os.environ["ROOTFS_EXT"] = fstype
81
82 # Add in all variables from the user's original environment which
83 # haven't subsequntly been set/changed
84 origbbenv = d.getVar("BB_ORIGENV", False) or {}
85 for key in origbbenv:
86 if key in os.environ:
87 continue
88 value = origbbenv.getVar(key, True)
89 if value is not None:
90 os.environ[key] = str(value)
91
92 """run Test Case"""
93 bb.note("Run %s test in scenario %s" % (case, scen))
94 subprocess.call("%s" % fulltestpath, shell=True)
95
96 """function to check testcase list and remove inappropriate cases"""
97 def check_list(list):
98 final_list = []
99 for test in list:
100 (scen, case, fullpath) = test
101
102 """Skip rpm/smart if package_rpm not set for PACKAGE_CLASSES"""
103 if case.find("smart") != -1 or case.find("rpm") != -1:
104 if d.getVar("PACKAGE_CLASSES", True).find("rpm", 0, 11) == -1:
105 bb.note("skip rpm/smart cases since package_rpm not set in PACKAGE_CLASSES")
106 continue
107 else:
108 final_list.append((scen, case, fullpath))
109 else:
110 final_list.append((scen, case, fullpath))
111
112 if not final_list:
113 raise bb.build.FuncFailed("There is no suitable testcase for this target")
114
115 return final_list
116
117 """Generate testcase list in runtime"""
118 def generate_list(testlist):
119 list = []
120 final_list = []
121 if len(testlist) == 0:
122 raise bb.build.FuncFailed("No testcase defined in TEST_SCEN")
123
124 """check testcase folder and add case list according to TEST_SCEN"""
125 for item in testlist.split(" "):
126 n = casestr.match(item)
127 if n:
128 item = n.group('scen')
129 casefile = n.group('case')
130 for dir in d.getVar("QEMUIMAGETESTS", True).split():
131 fulltestcase = os.path.join(dir, item, casefile)
132 if not os.path.isfile(fulltestcase):
133 raise bb.build.FuncFailed("Testcase %s not found" % fulltestcase)
134 list.append((item, casefile, fulltestcase))
135 else:
136 for dir in d.getVar("QEMUIMAGETESTS", True).split():
137 scenlist = os.path.join(dir, "scenario", machine, pname)
138 if not os.path.isfile(scenlist):
139 raise bb.build.FuncFailed("No scenario list file named %s found" % scenlist)
140
141 f = open(scenlist, "r")
142 for line in f:
143 if item != line.split()[0]:
144 continue
145 else:
146 casefile = line.split()[1]
147
148 fulltestcase = os.path.join(dir, item, casefile)
149 if not os.path.isfile(fulltestcase):
150 raise bb.build.FuncFailed("Testcase %s not found" % fulltestcase)
151 list.append((item, casefile, fulltestcase))
152 f.close()
153 final_list = check_list(list)
154 return final_list
155
156 """Clean tmp folder for testing"""
157 def clean_tmp():
158 tmppath = d.getVar('TEST_TMP', True)
159
160 if os.path.isdir(tmppath):
161 for f in os.listdir(tmppath):
162 tmpfile = os.path.join(tmppath, f)
163 if os.path.isfile(tmpfile):
164 os.remove(tmpfile)
165 elif os.path.isdir(tmpfile):
166 shutil.rmtree(tmpfile, True)
167
168 """Before running testing, clean temp folder first"""
169 clean_tmp()
170
171 """check testcase folder and create test log folder"""
172 testpath = d.getVar('TEST_DIR', True)
173 bb.utils.mkdirhier(testpath)
174
175 logpath = d.getVar('TEST_LOG', True)
176 bb.utils.mkdirhier(logpath)
177
178 tmppath = d.getVar('TEST_TMP', True)
179 bb.utils.mkdirhier(tmppath)
180
181 """initialize test status file"""
182 test_status = d.getVar('TEST_STATUS', True)
183 if os.path.exists(test_status):
184 os.remove(test_status)
185 subprocess.call("touch %s" % test_status, shell=True)
186
187 """initialize result file"""
188 resultpath = d.getVar('TEST_RESULT', True)
189 bb.utils.mkdirhier(resultpath)
190 resultfile = os.path.join(resultpath, "testresult.%s" % d.getVar('DATETIME', True))
191 sresultfile = os.path.join(resultpath, "testresult.log")
192
193 machine = d.getVar('MACHINE', True)
194
195 if os.path.exists(sresultfile):
196 os.remove(sresultfile)
197 subprocess.call("touch %s" % resultfile, shell=True)
198 os.symlink(resultfile, sresultfile)
199
200 """generate pre-defined testcase list"""
201 testlist = d.getVar('TEST_SCEN', True)
202 fulllist = generate_list(testlist)
203
204 """Begin testing"""
205 for fstype in allfstypes:
206 if fstype in testfstypes:
207 with open(sresultfile, "a") as f:
208 f.write("\tTest Result for %s %s %s\n" % (machine, pname, fstype))
209 f.write("\t%-15s%-15s%-15s%-15s\n" % ("Testcase", "PASS", "FAIL", "NORESULT"))
210 for index,test in enumerate(fulllist):
211 (scen, case, fullpath) = test
212 teststatus(case, "running", index, (len(fulllist) - 1))
213 runtest(scen, case, fullpath, fstype)
214 teststatus(case, "finished", index, (len(fulllist) - 1))
215
216 """Print Test Result"""
217 ret = 0
218 f = open(sresultfile, "r")
219 for line in f:
220 m = resultstr.match(line)
221 if m:
222 if m.group('fail') == "1":
223 ret = 1
224 elif m.group('noresult') == "1":
225 ret = 2
226 line = line.strip('\n')
227 bb.note(line)
228 else:
229 line = line.strip('\n')
230 bb.note(line)
231 f.close()
232
233 """Clean temp files for testing"""
234 clean_tmp()
235
236 if ret != 0:
237 raise bb.build.FuncFailed("Some tests failed. Please check the results file: %s and the log files found in: %s." % (resultfile, d.getVar('TEST_LOG', True)))
238