summaryrefslogtreecommitdiffstats
path: root/meta/classes/imagetest-qemu.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/imagetest-qemu.bbclass')
-rw-r--r--meta/classes/imagetest-qemu.bbclass137
1 files changed, 137 insertions, 0 deletions
diff --git a/meta/classes/imagetest-qemu.bbclass b/meta/classes/imagetest-qemu.bbclass
new file mode 100644
index 0000000000..742b759208
--- /dev/null
+++ b/meta/classes/imagetest-qemu.bbclass
@@ -0,0 +1,137 @@
1addtask qemuimagetest before do_build
2# after do_rootfs
3do_qemuimagetest[nostamp] = "1"
4do_qemuimagetest[depends] += "qemu-native:do_populate_sysroot"
5
6# Test related variables
7# By default, TEST_DIR is created under WORKDIR
8TEST_DIR ?= "${WORKDIR}/qemuimagetest"
9TEST_LOG ?= "${LOG_DIR}/qemuimagetests"
10TEST_RESULT ?= "${TEST_DIR}/result"
11TEST_LIST ?= "${TEST_DIR}/list"
12TEST_TMP ?= "${TEST_DIR}/tmp"
13TEST_SCEN ?= "sanity"
14
15python do_qemuimagetest() {
16 import sys
17 import re
18 import os
19
20 """
21 Test Controller for Poky Testing.
22 """
23
24 casestr = re.compile(r'(?P<scen>\w+\b)\s*(?P<case>\w+$)')
25 resultstr = re.compile(r'\s*(?P<case>\w+)\s*(?P<pass>\d+)\s*(?P<fail>\d+)\s*(?P<noresult>\d+)')
26
27 """funtion to run each case under scenario"""
28 def runtest(scen, case, fulltestpath):
29 resultpath = bb.data.getVar('TEST_RESULT', d, 1)
30 machine = bb.data.getVar('MACHINE', d, 1)
31 pname = bb.data.getVar('PN', d, 1)
32
33 testpath = bb.data.getVar('TEST_DIR', d, 1)
34
35 """initialize log file for testcase"""
36 logpath = bb.data.getVar('TEST_LOG', d, 1)
37 bb.utils.mkdirhier("%s/%s" % (logpath, scen))
38 caselog = os.path.join(logpath, "%s/log_%s.%s" % (scen, case, bb.data.getVar('DATETIME', d, 1)))
39 os.system("touch %s" % caselog)
40
41
42 """export TEST_TMP, TEST_RESULT, DEPLOY_DIR and QEMUARCH"""
43 os.environ["PATH"] = bb.data.getVar("PATH", d, True)
44 os.environ["TEST_TMP"] = testpath
45 os.environ["TEST_RESULT"] = resultpath
46 os.environ["DEPLOY_DIR"] = bb.data.getVar("DEPLOY_DIR", d, True)
47 os.environ["QEMUARCH"] = machine
48 os.environ["QEMUTARGET"] = pname
49 os.environ["DISPLAY"] = bb.data.getVar("DISPLAY", d, True)
50
51 """run Test Case"""
52 bb.note("Run %s test in scenario %s" % (case, scen))
53 os.system("%s | tee -a %s" % (fulltestpath, caselog))
54
55 """Generate testcase list in runtime"""
56 def generate_list(testfile, testlist):
57 list = []
58 if len(testlist) == 0:
59 raise bb.build.FuncFailed("No testcase defined in TEST_SCEN")
60
61 """remove old testcase list file"""
62 if os.path.exists(testfile):
63 os.remove(testfile)
64 os.system("touch %s" % testfile)
65
66 """check testcase folder and add case to TEST_LIST"""
67 for item in testlist.split(" "):
68 found = False
69 for dir in bb.data.getVar("QEMUIMAGETESTS", d, True).split():
70 casepath = os.path.join(dir, item)
71 if not os.path.isdir(casepath):
72 continue
73 files = os.listdir(casepath)
74 for casefile in files:
75 fulltestcase = "%s/%s" % (casepath, casefile)
76 if os.path.isfile(fulltestcase):
77 list.append((item, casefile, fulltestcase))
78 found = True
79 if not found:
80 raise bb.build.FuncFailed("Testcase folder not found for test %s" % item)
81 return list
82
83 """check testcase folder and create test log folder"""
84 testpath = bb.data.getVar('TEST_DIR', d, 1)
85 bb.utils.mkdirhier(testpath)
86
87 logpath = bb.data.getVar('TEST_LOG', d, 1)
88 bb.utils.mkdirhier(logpath)
89
90 tmppath = bb.data.getVar('TEST_TMP', d, 1)
91 bb.utils.mkdirhier(tmppath)
92
93 """initialize result file"""
94 resultpath = bb.data.getVar('TEST_RESULT', d, 1)
95 bb.utils.mkdirhier(resultpath)
96 resultfile = os.path.join(resultpath, "testresult.%s" % bb.data.getVar('DATETIME', d, 1))
97 sresultfile = os.path.join(resultpath, "testresult.log")
98
99 machine = bb.data.getVar('MACHINE', d, 1)
100
101 if os.path.exists(sresultfile):
102 os.remove(sresultfile)
103 os.system("touch %s" % resultfile)
104 os.symlink(resultfile, sresultfile)
105 f = open(sresultfile, "a")
106 f.write("\tTest Result for %s\n" % machine)
107 f.write("\tTestcase\tPASS\tFAIL\tNORESULT\n")
108 f.close()
109
110 """generate pre-defined testcase list"""
111 testfile = bb.data.getVar('TEST_LIST', d, 1)
112 testlist = bb.data.getVar('TEST_SCEN', d, 1)
113 fulllist = generate_list(testfile, testlist)
114
115 """Begin testing"""
116 for test in fulllist:
117 (scen, case, fullpath) = test
118 runtest(scen, case, fullpath)
119
120 """Print Test Result"""
121 ret = 0
122 f = open(sresultfile, "r")
123 for line in f:
124 m = resultstr.match(line)
125 if m:
126 if m.group('fail') == "1":
127 ret = 1
128 elif m.group('noresult') == "1":
129 ret = 2
130 print line,
131 else:
132 print line,
133 f.close()
134
135 if ret != 0:
136 raise bb.build.FuncFailed("Some testcases fail, pls. check test result and test log!!!")
137}