summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
Diffstat (limited to 'meta')
-rw-r--r--meta/classes/testexport.bbclass215
1 files changed, 91 insertions, 124 deletions
diff --git a/meta/classes/testexport.bbclass b/meta/classes/testexport.bbclass
index 5398b3c767..56edda9943 100644
--- a/meta/classes/testexport.bbclass
+++ b/meta/classes/testexport.bbclass
@@ -33,113 +33,111 @@ TEST_EXPORT_DEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-nativ
33TEST_EXPORT_DEPENDS += "${@bb.utils.contains('TEST_EXPORT_SDK_ENABLED', '1', 'testexport-tarball:do_populate_sdk', '', d)}" 33TEST_EXPORT_DEPENDS += "${@bb.utils.contains('TEST_EXPORT_SDK_ENABLED', '1', 'testexport-tarball:do_populate_sdk', '', d)}"
34TEST_EXPORT_LOCK = "${TMPDIR}/testimage.lock" 34TEST_EXPORT_LOCK = "${TMPDIR}/testimage.lock"
35 35
36python do_testexport() {
37 testexport_main(d)
38}
39
40addtask testexport 36addtask testexport
41do_testexport[nostamp] = "1" 37do_testexport[nostamp] = "1"
42do_testexport[depends] += "${TEST_EXPORT_DEPENDS} ${TESTIMAGEDEPENDS}" 38do_testexport[depends] += "${TEST_EXPORT_DEPENDS} ${TESTIMAGEDEPENDS}"
43do_testexport[lockfiles] += "${TEST_EXPORT_LOCK}" 39do_testexport[lockfiles] += "${TEST_EXPORT_LOCK}"
44 40
45def exportTests(d,tc): 41python do_testexport() {
42 testexport_main(d)
43}
44
45def testexport_main(d):
46 import json 46 import json
47 import logging
48
49 from oeqa.runtime.context import OERuntimeTestContext
50 from oeqa.runtime.context import OERuntimeTestContextExecutor
51
52 image_name = ("%s/%s" % (d.getVar('DEPLOY_DIR_IMAGE'),
53 d.getVar('IMAGE_LINK_NAME')))
54
55 tdname = "%s.testdata.json" % image_name
56 td = json.load(open(tdname, "r"))
57
58 logger = logging.getLogger("BitBake")
59
60 target = OERuntimeTestContextExecutor.getTarget(
61 d.getVar("TEST_TARGET"), None, d.getVar("TEST_TARGET_IP"),
62 d.getVar("TEST_SERVER_IP"))
63
64 host_dumper = OERuntimeTestContextExecutor.getHostDumper(
65 d.getVar("testimage_dump_host"), d.getVar("TESTIMAGE_DUMP_DIR"))
66
67 image_manifest = "%s.manifest" % image_name
68 image_packages = OERuntimeTestContextExecutor.readPackagesManifest(image_manifest)
69
70 extract_dir = d.getVar("TEST_EXTRACTED_DIR")
71
72 tc = OERuntimeTestContext(td, logger, target, host_dumper,
73 image_packages, extract_dir)
74
75 copy_needed_files(d, tc)
76
77def copy_needed_files(d, tc):
47 import shutil 78 import shutil
48 import pkgutil
49 import re
50 import oe.path 79 import oe.path
51 80
52 exportpath = d.getVar("TEST_EXPORT_DIR") 81 from oeqa.utils.package_manager import _get_json_file
53 82 from oeqa.core.utils.test import getSuiteCasesFiles
54 savedata = {} 83
55 savedata["d"] = {} 84 export_path = d.getVar('TEST_EXPORT_DIR')
56 savedata["target"] = {} 85 corebase_path = d.getVar('COREBASE')
57 savedata["target"]["ip"] = tc.target.ip or d.getVar("TEST_TARGET_IP") 86
58 savedata["target"]["server_ip"] = tc.target.server_ip or d.getVar("TEST_SERVER_IP") 87 # Clean everything before starting
59 88 oe.path.remove(export_path)
60 keys = [ key for key in d.keys() if not key.startswith("_") and not key.startswith("BB") \ 89 bb.utils.mkdirhier(os.path.join(export_path, 'lib', 'oeqa'))
61 and not key.startswith("B_pn") and not key.startswith("do_") and not d.getVarFlag(key, "func")] 90
62 for key in keys: 91 # The source of files to copy are relative to 'COREBASE' directory
63 try: 92 # The destination is relative to 'TEST_EXPORT_DIR'
64 savedata["d"][key] = d.getVar(key) 93 # Because we are squashing the libraries, we need to remove
65 except bb.data_smart.ExpansionError: 94 # the layer/script directory
66 # we don't care about those anyway 95 files_to_copy = [ os.path.join('meta', 'lib', 'oeqa', 'core'),
67 pass 96 os.path.join('meta', 'lib', 'oeqa', 'runtime'),
68 97 os.path.join('meta', 'lib', 'oeqa', 'files'),
69 json_file = os.path.join(exportpath, "testdata.json") 98 os.path.join('meta', 'lib', 'oeqa', 'utils'),
70 with open(json_file, "w") as f: 99 os.path.join('scripts', 'oe-test'),
71 json.dump(savedata, f, skipkeys=True, indent=4, sort_keys=True) 100 os.path.join('scripts', 'lib', 'argparse_oe.py'),
72 101 os.path.join('scripts', 'lib', 'scriptutils.py'), ]
73 # Replace absolute path with relative in the file 102
74 exclude_path = os.path.join(d.getVar("COREBASE"),'meta','lib','oeqa') 103 for f in files_to_copy:
75 f1 = open(json_file,'r').read() 104 src = os.path.join(corebase_path, f)
76 f2 = open(json_file,'w') 105 dst = os.path.join(export_path, f.split('/', 1)[-1])
77 m = f1.replace(exclude_path,'oeqa') 106 if os.path.isdir(src):
78 f2.write(m) 107 oe.path.copytree(src, dst)
79 f2.close() 108 else:
80 109 shutil.copy2(src, dst)
81 # now start copying files 110
82 # we'll basically copy everything under meta/lib/oeqa, with these exceptions 111 # Remove cases and just copy the ones specified
83 # - oeqa/targetcontrol.py - not needed 112 cases_path = os.path.join(export_path, 'lib', 'oeqa', 'runtime', 'cases')
84 # - oeqa/selftest - something else 113 oe.path.remove(cases_path)
85 # That means: 114 bb.utils.mkdirhier(cases_path)
86 # - all tests from oeqa/runtime defined in TEST_SUITES (including from other layers) 115 test_paths = get_runtime_paths(d)
87 # - the contents of oeqa/utils and oeqa/runtime/files 116 test_modules = d.getVar('TEST_SUITES')
88 # - oeqa/oetest.py and oeqa/runexport.py (this will get copied to exportpath not exportpath/oeqa) 117 tc.loadTests(test_paths, modules=test_modules)
89 # - __init__.py files 118 for f in getSuiteCasesFiles(tc.suites):
90 bb.utils.mkdirhier(os.path.join(exportpath, "oeqa/files")) 119 shutil.copy2(f, cases_path)
91 bb.utils.mkdirhier(os.path.join(exportpath, "oeqa/runtime/files")) 120 json_file = _get_json_file(f)
92 bb.utils.mkdirhier(os.path.join(exportpath, "oeqa/utils")) 121 if json_file:
93 # copy test modules, this should cover tests in other layers too 122 shutil.copy2(json_file, cases_path)
94 bbpath = d.getVar("BBPATH").split(':') 123
95 for t in tc.testslist: 124 # Copy test data
96 isfolder = False 125 image_name = ("%s/%s" % (d.getVar('DEPLOY_DIR_IMAGE'),
97 if re.search("\w+\.\w+\.test_\S+", t): 126 d.getVar('IMAGE_LINK_NAME')))
98 t = '.'.join(t.split('.')[:3]) 127 image_manifest = "%s.manifest" % image_name
99 mod = pkgutil.get_loader(t) 128 tdname = "%s.testdata.json" % image_name
100 # More depth than usual? 129 test_data_path = os.path.join(export_path, 'data')
101 if (t.count('.') > 2): 130 bb.utils.mkdirhier(test_data_path)
102 for p in bbpath: 131 shutil.copy2(image_manifest, os.path.join(test_data_path, 'manifest'))
103 foldername = os.path.join(p, 'lib', os.sep.join(t.split('.')).rsplit(os.sep, 1)[0]) 132 shutil.copy2(tdname, os.path.join(test_data_path, 'testdata.json'))
104 if os.path.isdir(foldername):
105 isfolder = True
106 target_folder = os.path.join(exportpath, "oeqa", "runtime", os.path.basename(foldername))
107 if not os.path.exists(target_folder):
108 oe.path.copytree(foldername, target_folder)
109 if not isfolder:
110 shutil.copy2(mod.path, os.path.join(exportpath, "oeqa/runtime"))
111 json_file = "%s.json" % mod.path.rsplit(".", 1)[0]
112 if os.path.isfile(json_file):
113 shutil.copy2(json_file, os.path.join(exportpath, "oeqa/runtime"))
114 # Get meta layer
115 for layer in d.getVar("BBLAYERS").split():
116 if os.path.basename(layer) == "meta":
117 meta_layer = layer
118 break
119 # copy oeqa/oetest.py and oeqa/runexported.py
120 oeqadir = os.path.join(meta_layer, "lib/oeqa")
121 shutil.copy2(os.path.join(oeqadir, "oetest.py"), os.path.join(exportpath, "oeqa"))
122 shutil.copy2(os.path.join(oeqadir, "runexported.py"), exportpath)
123 # copy oeqa/utils/*.py
124 for root, dirs, files in os.walk(os.path.join(oeqadir, "utils")):
125 for f in files:
126 if f.endswith(".py"):
127 shutil.copy2(os.path.join(root, f), os.path.join(exportpath, "oeqa/utils"))
128 # copy oeqa/files/*
129 for root, dirs, files in os.walk(os.path.join(oeqadir, "files")):
130 for f in files:
131 shutil.copy2(os.path.join(root, f), os.path.join(exportpath, "oeqa/files"))
132 # copy oeqa/runtime/files/*
133 for root, dirs, files in os.walk(os.path.join(oeqadir, "runtime/files")):
134 for f in files:
135 shutil.copy2(os.path.join(root, f), os.path.join(exportpath, "oeqa/runtime/files"))
136 133
137 # Create tar file for common parts of testexport 134 # Create tar file for common parts of testexport
138 create_tarball(d, "testexport.tar.gz", d.getVar("TEST_EXPORT_DIR")) 135 create_tarball(d, "testexport.tar.gz", d.getVar("TEST_EXPORT_DIR"))
139 136
140 # Copy packages needed for runtime testing 137 # Copy packages needed for runtime testing
138 package_extraction(d, tc.suites)
141 test_pkg_dir = d.getVar("TEST_NEEDED_PACKAGES_DIR") 139 test_pkg_dir = d.getVar("TEST_NEEDED_PACKAGES_DIR")
142 if os.listdir(test_pkg_dir): 140 if os.path.isdir(test_pkg_dir) and os.listdir(test_pkg_dir):
143 export_pkg_dir = os.path.join(d.getVar("TEST_EXPORT_DIR"), "packages") 141 export_pkg_dir = os.path.join(d.getVar("TEST_EXPORT_DIR"), "packages")
144 oe.path.copytree(test_pkg_dir, export_pkg_dir) 142 oe.path.copytree(test_pkg_dir, export_pkg_dir)
145 # Create tar file for packages needed by the DUT 143 # Create tar file for packages needed by the DUT
@@ -158,35 +156,7 @@ def exportTests(d,tc):
158 # Create tar file for the sdk 156 # Create tar file for the sdk
159 create_tarball(d, "testexport_sdk_%s.tar.gz" % d.getVar("SDK_ARCH"), export_sdk_dir) 157 create_tarball(d, "testexport_sdk_%s.tar.gz" % d.getVar("SDK_ARCH"), export_sdk_dir)
160 158
161 bb.plain("Exported tests to: %s" % exportpath) 159 bb.plain("Exported tests to: %s" % export_path)
162
163def testexport_main(d):
164 from oeqa.oetest import ExportTestContext
165 from oeqa.targetcontrol import get_target_controller
166
167 test_create_extract_dirs(d)
168 export_dir = d.getVar("TEST_EXPORT_DIR")
169 bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR"))
170 bb.utils.remove(export_dir, recurse=True)
171 bb.utils.mkdirhier(export_dir)
172
173 # the robot dance
174 target = get_target_controller(d)
175
176 # test context
177 tc = ExportTestContext(d, target)
178
179 # this is a dummy load of tests
180 # we are doing that to find compile errors in the tests themselves
181 # before booting the image
182 try:
183 tc.loadTests()
184 except Exception as e:
185 import traceback
186 bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
187
188 tc.extract_packages()
189 exportTests(d,tc)
190 160
191def create_tarball(d, tar_name, src_dir): 161def create_tarball(d, tar_name, src_dir):
192 162
@@ -204,7 +174,4 @@ def create_tarball(d, tar_name, src_dir):
204 tar.close() 174 tar.close()
205 os.chdir(current_dir) 175 os.chdir(current_dir)
206 176
207
208testexport_main[vardepsexclude] =+ "BB_ORIGENV"
209
210inherit testimage 177inherit testimage