diff options
| author | Ross Burton <ross.burton@arm.com> | 2022-11-09 19:31:35 +0000 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2022-11-11 13:43:40 +0000 |
| commit | c3ad78032870f0f30ac8f85e220f7a0f768715cc (patch) | |
| tree | bd91f3479209bcf98ca89a34994a361ab72bf5e4 /meta/classes-recipe/testexport.bbclass | |
| parent | 33b4cd0c00618fad170db13a25f96de9bb1c5863 (diff) | |
| download | poky-c3ad78032870f0f30ac8f85e220f7a0f768715cc.tar.gz | |
classes/testexport: move to classes-recipe
This class should be in classes-recipe as, like testimage, it is specific
to image recipes.
This also solves a regression where simply IMAGE_CLASSES += "testexport"
doesn't work if testimage isn't already in IMAGE_CLASSES. The testexport
class adds testimage to IMAGE_CLASSES, but by this point it's too late.
Now that the class can only be inherited via IMAGE_CLASSES, we can
simply inherit testimage directly.
(From OE-Core rev: 87fcee9fed915ff3af528b976d7d44737f9f1a95)
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes-recipe/testexport.bbclass')
| -rw-r--r-- | meta/classes-recipe/testexport.bbclass | 180 |
1 files changed, 180 insertions, 0 deletions
diff --git a/meta/classes-recipe/testexport.bbclass b/meta/classes-recipe/testexport.bbclass new file mode 100644 index 0000000000..0f0c56107f --- /dev/null +++ b/meta/classes-recipe/testexport.bbclass | |||
| @@ -0,0 +1,180 @@ | |||
| 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 IMAGE_CLASSES += "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 | inherit testimage | ||
| 17 | |||
| 18 | TEST_LOG_DIR ?= "${WORKDIR}/testexport" | ||
| 19 | TEST_EXPORT_DIR ?= "${TMPDIR}/testexport/${PN}" | ||
| 20 | TEST_EXPORT_PACKAGED_DIR ?= "packages/packaged" | ||
| 21 | TEST_EXPORT_EXTRACTED_DIR ?= "packages/extracted" | ||
| 22 | |||
| 23 | TEST_TARGET ?= "simpleremote" | ||
| 24 | TEST_TARGET_IP ?= "" | ||
| 25 | TEST_SERVER_IP ?= "" | ||
| 26 | |||
| 27 | require conf/testexport.conf | ||
| 28 | |||
| 29 | TEST_EXPORT_SDK_ENABLED ?= "0" | ||
| 30 | |||
| 31 | TEST_EXPORT_DEPENDS = "" | ||
| 32 | TEST_EXPORT_DEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}" | ||
| 33 | TEST_EXPORT_DEPENDS += "${@bb.utils.contains('TEST_EXPORT_SDK_ENABLED', '1', 'testexport-tarball:do_populate_sdk', '', d)}" | ||
| 34 | TEST_EXPORT_LOCK = "${TMPDIR}/testimage.lock" | ||
| 35 | |||
| 36 | addtask testexport | ||
| 37 | do_testexport[nostamp] = "1" | ||
| 38 | do_testexport[depends] += "${TEST_EXPORT_DEPENDS} ${TESTIMAGEDEPENDS}" | ||
| 39 | do_testexport[lockfiles] += "${TEST_EXPORT_LOCK}" | ||
| 40 | |||
| 41 | python do_testexport() { | ||
| 42 | testexport_main(d) | ||
| 43 | } | ||
| 44 | |||
| 45 | def testexport_main(d): | ||
| 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 | |||
| 77 | def copy_needed_files(d, tc): | ||
| 78 | import shutil | ||
| 79 | import oe.path | ||
| 80 | |||
| 81 | from oeqa.utils.package_manager import _get_json_file | ||
| 82 | from oeqa.core.utils.test import getSuiteCasesFiles | ||
| 83 | |||
| 84 | export_path = d.getVar('TEST_EXPORT_DIR') | ||
| 85 | corebase_path = d.getVar('COREBASE') | ||
| 86 | |||
| 87 | # Clean everything before starting | ||
| 88 | oe.path.remove(export_path) | ||
| 89 | bb.utils.mkdirhier(os.path.join(export_path, 'lib', 'oeqa')) | ||
| 90 | |||
| 91 | # The source of files to copy are relative to 'COREBASE' directory | ||
| 92 | # The destination is relative to 'TEST_EXPORT_DIR' | ||
| 93 | # Because we are squashing the libraries, we need to remove | ||
| 94 | # the layer/script directory | ||
| 95 | files_to_copy = [ os.path.join('meta', 'lib', 'oeqa', 'core'), | ||
| 96 | os.path.join('meta', 'lib', 'oeqa', 'runtime'), | ||
| 97 | os.path.join('meta', 'lib', 'oeqa', 'files'), | ||
| 98 | os.path.join('meta', 'lib', 'oeqa', 'utils'), | ||
| 99 | os.path.join('scripts', 'oe-test'), | ||
| 100 | os.path.join('scripts', 'lib', 'argparse_oe.py'), | ||
| 101 | os.path.join('scripts', 'lib', 'scriptutils.py'), ] | ||
| 102 | |||
| 103 | for f in files_to_copy: | ||
| 104 | src = os.path.join(corebase_path, f) | ||
| 105 | dst = os.path.join(export_path, f.split('/', 1)[-1]) | ||
| 106 | if os.path.isdir(src): | ||
| 107 | oe.path.copytree(src, dst) | ||
| 108 | else: | ||
| 109 | shutil.copy2(src, dst) | ||
| 110 | |||
| 111 | # Remove cases and just copy the ones specified | ||
| 112 | cases_path = os.path.join(export_path, 'lib', 'oeqa', 'runtime', 'cases') | ||
| 113 | oe.path.remove(cases_path) | ||
| 114 | bb.utils.mkdirhier(cases_path) | ||
| 115 | test_paths = get_runtime_paths(d) | ||
| 116 | test_modules = d.getVar('TEST_SUITES').split() | ||
| 117 | tc.loadTests(test_paths, modules=test_modules) | ||
| 118 | for f in getSuiteCasesFiles(tc.suites): | ||
| 119 | shutil.copy2(f, cases_path) | ||
| 120 | json_file = _get_json_file(f) | ||
| 121 | if json_file: | ||
| 122 | shutil.copy2(json_file, cases_path) | ||
| 123 | |||
| 124 | # Copy test data | ||
| 125 | image_name = ("%s/%s" % (d.getVar('DEPLOY_DIR_IMAGE'), | ||
| 126 | d.getVar('IMAGE_LINK_NAME'))) | ||
| 127 | image_manifest = "%s.manifest" % image_name | ||
| 128 | tdname = "%s.testdata.json" % image_name | ||
| 129 | test_data_path = os.path.join(export_path, 'data') | ||
| 130 | bb.utils.mkdirhier(test_data_path) | ||
| 131 | shutil.copy2(image_manifest, os.path.join(test_data_path, 'manifest')) | ||
| 132 | shutil.copy2(tdname, os.path.join(test_data_path, 'testdata.json')) | ||
| 133 | |||
| 134 | for subdir, dirs, files in os.walk(export_path): | ||
| 135 | for dir in dirs: | ||
| 136 | if dir == '__pycache__': | ||
| 137 | shutil.rmtree(os.path.join(subdir, dir)) | ||
| 138 | |||
| 139 | # Create tar file for common parts of testexport | ||
| 140 | testexport_create_tarball(d, "testexport.tar.gz", d.getVar("TEST_EXPORT_DIR")) | ||
| 141 | |||
| 142 | # Copy packages needed for runtime testing | ||
| 143 | package_extraction(d, tc.suites) | ||
| 144 | test_pkg_dir = d.getVar("TEST_NEEDED_PACKAGES_DIR") | ||
| 145 | if os.path.isdir(test_pkg_dir) and os.listdir(test_pkg_dir): | ||
| 146 | export_pkg_dir = os.path.join(d.getVar("TEST_EXPORT_DIR"), "packages") | ||
| 147 | oe.path.copytree(test_pkg_dir, export_pkg_dir) | ||
| 148 | # Create tar file for packages needed by the DUT | ||
| 149 | testexport_create_tarball(d, "testexport_packages_%s.tar.gz" % d.getVar("MACHINE"), export_pkg_dir) | ||
| 150 | |||
| 151 | # Copy SDK | ||
| 152 | if d.getVar("TEST_EXPORT_SDK_ENABLED") == "1": | ||
| 153 | sdk_deploy = d.getVar("SDK_DEPLOY") | ||
| 154 | tarball_name = "%s.sh" % d.getVar("TEST_EXPORT_SDK_NAME") | ||
| 155 | tarball_path = os.path.join(sdk_deploy, tarball_name) | ||
| 156 | export_sdk_dir = os.path.join(d.getVar("TEST_EXPORT_DIR"), | ||
| 157 | d.getVar("TEST_EXPORT_SDK_DIR")) | ||
| 158 | bb.utils.mkdirhier(export_sdk_dir) | ||
| 159 | shutil.copy2(tarball_path, export_sdk_dir) | ||
| 160 | |||
| 161 | # Create tar file for the sdk | ||
| 162 | testexport_create_tarball(d, "testexport_sdk_%s.tar.gz" % d.getVar("SDK_ARCH"), export_sdk_dir) | ||
| 163 | |||
| 164 | bb.plain("Exported tests to: %s" % export_path) | ||
| 165 | |||
| 166 | def testexport_create_tarball(d, tar_name, src_dir): | ||
| 167 | |||
| 168 | import tarfile | ||
| 169 | |||
| 170 | tar_path = os.path.join(d.getVar("TEST_EXPORT_DIR"), tar_name) | ||
| 171 | current_dir = os.getcwd() | ||
| 172 | src_dir = src_dir.rstrip('/') | ||
| 173 | dir_name = os.path.dirname(src_dir) | ||
| 174 | base_name = os.path.basename(src_dir) | ||
| 175 | |||
| 176 | os.chdir(dir_name) | ||
| 177 | tar = tarfile.open(tar_path, "w:gz") | ||
| 178 | tar.add(base_name) | ||
| 179 | tar.close() | ||
| 180 | os.chdir(current_dir) | ||
