summaryrefslogtreecommitdiffstats
path: root/meta/classes/testexport.bbclass
diff options
context:
space:
mode:
authorMariano Lopez <mariano.lopez@linux.intel.com>2016-05-02 13:19:15 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-05-19 09:05:18 +0100
commitb3a656374b2fce0a1ac236fab80998ac5d3a1726 (patch)
treee2f76aea9216e67836f8a6cc10fb55788ce8c2b1 /meta/classes/testexport.bbclass
parenta9eb22e3d30b9bfd06eea55556894c256be3a4b0 (diff)
downloadpoky-b3a656374b2fce0a1ac236fab80998ac5d3a1726.tar.gz
testexport.bbclass: Split testimage class
This adds a new class that only export tests of images, the code was taken from testimage class and most of it wasn't modified. Just add some vars for the new class. testexport class require testimage class to get the test suites defined for all the images. (From OE-Core rev: 3e4c429337966eea263b4258700843c909f496ec) Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/testexport.bbclass')
-rw-r--r--meta/classes/testexport.bbclass150
1 files changed, 150 insertions, 0 deletions
diff --git a/meta/classes/testexport.bbclass b/meta/classes/testexport.bbclass
new file mode 100644
index 0000000000..0aac030931
--- /dev/null
+++ b/meta/classes/testexport.bbclass
@@ -0,0 +1,150 @@
1# Copyright (C) 2016 Intel Corporation
2#
3# Released under the MIT license (see COPYING.MIT)
4#
5#
6# testexport.bbclass allows to execute runtime test outside OE environment.
7# Most of the tests are commands run on target image over ssh.
8# To use it add testexport to global inherit and call your target image with -c testexport
9# You can try it out like this:
10# - First build an image. i.e. core-image-sato
11# - Add INHERIT += "testexport" in local.conf
12# - Then bitbake core-image-sato -c testexport. That will generate the directory structure
13# to execute the runtime tests using runexported.py.
14#
15# For more information on TEST_SUITES check testimage class.
16
17TEST_LOG_DIR ?= "${WORKDIR}/testexport"
18TEST_EXPORT_DIR ?= "${TMPDIR}/testexport/${PN}"
19TEST_TARGET ?= "simpleremote"
20TEST_TARGET_IP ?= ""
21TEST_SERVER_IP ?= ""
22
23TEST_EXPORT_DEPENDS = ""
24TEST_EXPORT_LOCK = "${TMPDIR}/testimage.lock"
25
26python do_testexport() {
27 testexport_main(d)
28}
29
30addtask testexport
31do_testimage[nostamp] = "1"
32do_testimage[depends] += "${TEST_EXPORT_DEPENDS}"
33do_testimage[lockfiles] += "${TEST_EXPORT_LOCK}"
34
35def exportTests(d,tc):
36 import json
37 import shutil
38 import pkgutil
39 import re
40
41 exportpath = d.getVar("TEST_EXPORT_DIR", True)
42
43 savedata = {}
44 savedata["d"] = {}
45 savedata["target"] = {}
46 for key in tc.__dict__:
47 # special cases
48 if key not in ['d', 'target', 'suite']:
49 savedata[key] = getattr(tc, key)
50 savedata["target"]["ip"] = tc.target.ip or d.getVar("TEST_TARGET_IP", True)
51 savedata["target"]["server_ip"] = tc.target.server_ip or d.getVar("TEST_SERVER_IP", True)
52
53 keys = [ key for key in d.keys() if not key.startswith("_") and not key.startswith("BB") \
54 and not key.startswith("B_pn") and not key.startswith("do_") and not d.getVarFlag(key, "func", True)]
55 for key in keys:
56 try:
57 savedata["d"][key] = d.getVar(key, True)
58 except bb.data_smart.ExpansionError:
59 # we don't care about those anyway
60 pass
61
62 json_file = os.path.join(exportpath, "testdata.json")
63 with open(json_file, "w") as f:
64 json.dump(savedata, f, skipkeys=True, indent=4, sort_keys=True)
65
66 # Replace absolute path with relative in the file
67 exclude_path = os.path.join(d.getVar("COREBASE", True),'meta','lib','oeqa')
68 f1 = open(json_file,'r').read()
69 f2 = open(json_file,'w')
70 m = f1.replace(exclude_path,'oeqa')
71 f2.write(m)
72 f2.close()
73
74 # now start copying files
75 # we'll basically copy everything under meta/lib/oeqa, with these exceptions
76 # - oeqa/targetcontrol.py - not needed
77 # - oeqa/selftest - something else
78 # That means:
79 # - all tests from oeqa/runtime defined in TEST_SUITES (including from other layers)
80 # - the contents of oeqa/utils and oeqa/runtime/files
81 # - oeqa/oetest.py and oeqa/runexport.py (this will get copied to exportpath not exportpath/oeqa)
82 # - __init__.py files
83 bb.utils.mkdirhier(os.path.join(exportpath, "oeqa/runtime/files"))
84 bb.utils.mkdirhier(os.path.join(exportpath, "oeqa/utils"))
85 # copy test modules, this should cover tests in other layers too
86 bbpath = d.getVar("BBPATH", True).split(':')
87 for t in tc.testslist:
88 isfolder = False
89 if re.search("\w+\.\w+\.test_\S+", t):
90 t = '.'.join(t.split('.')[:3])
91 mod = pkgutil.get_loader(t)
92 # More depth than usual?
93 if (t.count('.') > 2):
94 for p in bbpath:
95 foldername = os.path.join(p, 'lib', os.sep.join(t.split('.')).rsplit(os.sep, 1)[0])
96 if os.path.isdir(foldername):
97 isfolder = True
98 target_folder = os.path.join(exportpath, "oeqa", "runtime", os.path.basename(foldername))
99 if not os.path.exists(target_folder):
100 shutil.copytree(foldername, target_folder)
101 if not isfolder:
102 shutil.copy2(mod.filename, os.path.join(exportpath, "oeqa/runtime"))
103 # copy __init__.py files
104 oeqadir = pkgutil.get_loader("oeqa").filename
105 shutil.copy2(os.path.join(oeqadir, "__init__.py"), os.path.join(exportpath, "oeqa"))
106 shutil.copy2(os.path.join(oeqadir, "runtime/__init__.py"), os.path.join(exportpath, "oeqa/runtime"))
107 # copy oeqa/oetest.py and oeqa/runexported.py
108 shutil.copy2(os.path.join(oeqadir, "oetest.py"), os.path.join(exportpath, "oeqa"))
109 shutil.copy2(os.path.join(oeqadir, "runexported.py"), exportpath)
110 # copy oeqa/utils/*.py
111 for root, dirs, files in os.walk(os.path.join(oeqadir, "utils")):
112 for f in files:
113 if f.endswith(".py"):
114 shutil.copy2(os.path.join(root, f), os.path.join(exportpath, "oeqa/utils"))
115 # copy oeqa/runtime/files/*
116 for root, dirs, files in os.walk(os.path.join(oeqadir, "runtime/files")):
117 for f in files:
118 shutil.copy2(os.path.join(root, f), os.path.join(exportpath, "oeqa/runtime/files"))
119
120 bb.plain("Exported tests to: %s" % exportpath)
121
122def testexport_main(d):
123 from oeqa.oetest import ExportTestContext
124 from oeqa.targetcontrol import get_target_controller
125 from oeqa.utils.dump import get_host_dumper
126
127 bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True))
128 bb.utils.remove(d.getVar("TEST_EXPORT_DIR", True), recurse=True)
129 bb.utils.mkdirhier(d.getVar("TEST_EXPORT_DIR", True))
130
131 # the robot dance
132 target = get_target_controller(d)
133
134 # test context
135 tc = ExportTestContext(d, target)
136
137 # this is a dummy load of tests
138 # we are doing that to find compile errors in the tests themselves
139 # before booting the image
140 try:
141 tc.loadTests()
142 except Exception as e:
143 import traceback
144 bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
145
146 exportTests(d,tc)
147
148testexport_main[vardepsexclude] =+ "BB_ORIGENV"
149
150inherit testimage