diff options
Diffstat (limited to 'meta/classes')
-rw-r--r-- | meta/classes/testexport.bbclass | 180 |
1 files changed, 0 insertions, 180 deletions
diff --git a/meta/classes/testexport.bbclass b/meta/classes/testexport.bbclass deleted file mode 100644 index f7c5242dc5..0000000000 --- a/meta/classes/testexport.bbclass +++ /dev/null | |||
@@ -1,180 +0,0 @@ | |||
1 | # Copyright (C) 2016 Intel Corporation | ||
2 | # | ||
3 | # SPDX-License-Identifier: MIT | ||
4 | # | ||
5 | # testexport.bbclass allows to execute runtime test outside OE environment. | ||
6 | # Most of the tests are commands run on target image over ssh. | ||
7 | # To use it add testexport to global inherit and call your target image with -c testexport | ||
8 | # You can try it out like this: | ||
9 | # - First build an image. i.e. core-image-sato | ||
10 | # - Add INHERIT += "testexport" in local.conf | ||
11 | # - Then bitbake core-image-sato -c testexport. That will generate the directory structure | ||
12 | # to execute the runtime tests using runexported.py. | ||
13 | # | ||
14 | # For more information on TEST_SUITES check testimage class. | ||
15 | |||
16 | TEST_LOG_DIR ?= "${WORKDIR}/testexport" | ||
17 | TEST_EXPORT_DIR ?= "${TMPDIR}/testexport/${PN}" | ||
18 | TEST_EXPORT_PACKAGED_DIR ?= "packages/packaged" | ||
19 | TEST_EXPORT_EXTRACTED_DIR ?= "packages/extracted" | ||
20 | |||
21 | TEST_TARGET ?= "simpleremote" | ||
22 | TEST_TARGET_IP ?= "" | ||
23 | TEST_SERVER_IP ?= "" | ||
24 | |||
25 | require conf/testexport.conf | ||
26 | |||
27 | TEST_EXPORT_SDK_ENABLED ?= "0" | ||
28 | |||
29 | TEST_EXPORT_DEPENDS = "" | ||
30 | TEST_EXPORT_DEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}" | ||
31 | TEST_EXPORT_DEPENDS += "${@bb.utils.contains('TEST_EXPORT_SDK_ENABLED', '1', 'testexport-tarball:do_populate_sdk', '', d)}" | ||
32 | TEST_EXPORT_LOCK = "${TMPDIR}/testimage.lock" | ||
33 | |||
34 | addtask testexport | ||
35 | do_testexport[nostamp] = "1" | ||
36 | do_testexport[depends] += "${TEST_EXPORT_DEPENDS} ${TESTIMAGEDEPENDS}" | ||
37 | do_testexport[lockfiles] += "${TEST_EXPORT_LOCK}" | ||
38 | |||
39 | python do_testexport() { | ||
40 | testexport_main(d) | ||
41 | } | ||
42 | |||
43 | def testexport_main(d): | ||
44 | import json | ||
45 | import logging | ||
46 | |||
47 | from oeqa.runtime.context import OERuntimeTestContext | ||
48 | from oeqa.runtime.context import OERuntimeTestContextExecutor | ||
49 | |||
50 | image_name = ("%s/%s" % (d.getVar('DEPLOY_DIR_IMAGE'), | ||
51 | d.getVar('IMAGE_LINK_NAME'))) | ||
52 | |||
53 | tdname = "%s.testdata.json" % image_name | ||
54 | td = json.load(open(tdname, "r")) | ||
55 | |||
56 | logger = logging.getLogger("BitBake") | ||
57 | |||
58 | target = OERuntimeTestContextExecutor.getTarget( | ||
59 | d.getVar("TEST_TARGET"), None, d.getVar("TEST_TARGET_IP"), | ||
60 | d.getVar("TEST_SERVER_IP")) | ||
61 | |||
62 | host_dumper = OERuntimeTestContextExecutor.getHostDumper( | ||
63 | d.getVar("testimage_dump_host"), d.getVar("TESTIMAGE_DUMP_DIR")) | ||
64 | |||
65 | image_manifest = "%s.manifest" % image_name | ||
66 | image_packages = OERuntimeTestContextExecutor.readPackagesManifest(image_manifest) | ||
67 | |||
68 | extract_dir = d.getVar("TEST_EXTRACTED_DIR") | ||
69 | |||
70 | tc = OERuntimeTestContext(td, logger, target, host_dumper, | ||
71 | image_packages, extract_dir) | ||
72 | |||
73 | copy_needed_files(d, tc) | ||
74 | |||
75 | def copy_needed_files(d, tc): | ||
76 | import shutil | ||
77 | import oe.path | ||
78 | |||
79 | from oeqa.utils.package_manager import _get_json_file | ||
80 | from oeqa.core.utils.test import getSuiteCasesFiles | ||
81 | |||
82 | export_path = d.getVar('TEST_EXPORT_DIR') | ||
83 | corebase_path = d.getVar('COREBASE') | ||
84 | |||
85 | # Clean everything before starting | ||
86 | oe.path.remove(export_path) | ||
87 | bb.utils.mkdirhier(os.path.join(export_path, 'lib', 'oeqa')) | ||
88 | |||
89 | # The source of files to copy are relative to 'COREBASE' directory | ||
90 | # The destination is relative to 'TEST_EXPORT_DIR' | ||
91 | # Because we are squashing the libraries, we need to remove | ||
92 | # the layer/script directory | ||
93 | files_to_copy = [ os.path.join('meta', 'lib', 'oeqa', 'core'), | ||
94 | os.path.join('meta', 'lib', 'oeqa', 'runtime'), | ||
95 | os.path.join('meta', 'lib', 'oeqa', 'files'), | ||
96 | os.path.join('meta', 'lib', 'oeqa', 'utils'), | ||
97 | os.path.join('scripts', 'oe-test'), | ||
98 | os.path.join('scripts', 'lib', 'argparse_oe.py'), | ||
99 | os.path.join('scripts', 'lib', 'scriptutils.py'), ] | ||
100 | |||
101 | for f in files_to_copy: | ||
102 | src = os.path.join(corebase_path, f) | ||
103 | dst = os.path.join(export_path, f.split('/', 1)[-1]) | ||
104 | if os.path.isdir(src): | ||
105 | oe.path.copytree(src, dst) | ||
106 | else: | ||
107 | shutil.copy2(src, dst) | ||
108 | |||
109 | # Remove cases and just copy the ones specified | ||
110 | cases_path = os.path.join(export_path, 'lib', 'oeqa', 'runtime', 'cases') | ||
111 | oe.path.remove(cases_path) | ||
112 | bb.utils.mkdirhier(cases_path) | ||
113 | test_paths = get_runtime_paths(d) | ||
114 | test_modules = d.getVar('TEST_SUITES').split() | ||
115 | tc.loadTests(test_paths, modules=test_modules) | ||
116 | for f in getSuiteCasesFiles(tc.suites): | ||
117 | shutil.copy2(f, cases_path) | ||
118 | json_file = _get_json_file(f) | ||
119 | if json_file: | ||
120 | shutil.copy2(json_file, cases_path) | ||
121 | |||
122 | # Copy test data | ||
123 | image_name = ("%s/%s" % (d.getVar('DEPLOY_DIR_IMAGE'), | ||
124 | d.getVar('IMAGE_LINK_NAME'))) | ||
125 | image_manifest = "%s.manifest" % image_name | ||
126 | tdname = "%s.testdata.json" % image_name | ||
127 | test_data_path = os.path.join(export_path, 'data') | ||
128 | bb.utils.mkdirhier(test_data_path) | ||
129 | shutil.copy2(image_manifest, os.path.join(test_data_path, 'manifest')) | ||
130 | shutil.copy2(tdname, os.path.join(test_data_path, 'testdata.json')) | ||
131 | |||
132 | for subdir, dirs, files in os.walk(export_path): | ||
133 | for dir in dirs: | ||
134 | if dir == '__pycache__': | ||
135 | shutil.rmtree(os.path.join(subdir, dir)) | ||
136 | |||
137 | # Create tar file for common parts of testexport | ||
138 | testexport_create_tarball(d, "testexport.tar.gz", d.getVar("TEST_EXPORT_DIR")) | ||
139 | |||
140 | # Copy packages needed for runtime testing | ||
141 | package_extraction(d, tc.suites) | ||
142 | test_pkg_dir = d.getVar("TEST_NEEDED_PACKAGES_DIR") | ||
143 | if os.path.isdir(test_pkg_dir) and os.listdir(test_pkg_dir): | ||
144 | export_pkg_dir = os.path.join(d.getVar("TEST_EXPORT_DIR"), "packages") | ||
145 | oe.path.copytree(test_pkg_dir, export_pkg_dir) | ||
146 | # Create tar file for packages needed by the DUT | ||
147 | testexport_create_tarball(d, "testexport_packages_%s.tar.gz" % d.getVar("MACHINE"), export_pkg_dir) | ||
148 | |||
149 | # Copy SDK | ||
150 | if d.getVar("TEST_EXPORT_SDK_ENABLED") == "1": | ||
151 | sdk_deploy = d.getVar("SDK_DEPLOY") | ||
152 | tarball_name = "%s.sh" % d.getVar("TEST_EXPORT_SDK_NAME") | ||
153 | tarball_path = os.path.join(sdk_deploy, tarball_name) | ||
154 | export_sdk_dir = os.path.join(d.getVar("TEST_EXPORT_DIR"), | ||
155 | d.getVar("TEST_EXPORT_SDK_DIR")) | ||
156 | bb.utils.mkdirhier(export_sdk_dir) | ||
157 | shutil.copy2(tarball_path, export_sdk_dir) | ||
158 | |||
159 | # Create tar file for the sdk | ||
160 | testexport_create_tarball(d, "testexport_sdk_%s.tar.gz" % d.getVar("SDK_ARCH"), export_sdk_dir) | ||
161 | |||
162 | bb.plain("Exported tests to: %s" % export_path) | ||
163 | |||
164 | def testexport_create_tarball(d, tar_name, src_dir): | ||
165 | |||
166 | import tarfile | ||
167 | |||
168 | tar_path = os.path.join(d.getVar("TEST_EXPORT_DIR"), tar_name) | ||
169 | current_dir = os.getcwd() | ||
170 | src_dir = src_dir.rstrip('/') | ||
171 | dir_name = os.path.dirname(src_dir) | ||
172 | base_name = os.path.basename(src_dir) | ||
173 | |||
174 | os.chdir(dir_name) | ||
175 | tar = tarfile.open(tar_path, "w:gz") | ||
176 | tar.add(base_name) | ||
177 | tar.close() | ||
178 | os.chdir(current_dir) | ||
179 | |||
180 | IMAGE_CLASSES += "testimage" | ||