Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 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 | |
| 17 | TEST_LOG_DIR ?= "${WORKDIR}/testexport" |
| 18 | TEST_EXPORT_DIR ?= "${TMPDIR}/testexport/${PN}" |
| 19 | TEST_EXPORT_PACKAGED_DIR ?= "packages/packaged" |
| 20 | TEST_EXPORT_EXTRACTED_DIR ?= "packages/extracted" |
| 21 | |
| 22 | TEST_TARGET ?= "simpleremote" |
| 23 | TEST_TARGET_IP ?= "" |
| 24 | TEST_SERVER_IP ?= "" |
| 25 | |
| 26 | TEST_EXPORT_SDK_PACKAGES ?= "" |
| 27 | TEST_EXPORT_SDK_ENABLED ?= "0" |
| 28 | TEST_EXPORT_SDK_NAME ?= "testexport-tools-nativesdk" |
| 29 | TEST_EXPORT_SDK_DIR ?= "sdk" |
| 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 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 36 | addtask testexport |
| 37 | do_testexport[nostamp] = "1" |
| 38 | do_testexport[depends] += "${TEST_EXPORT_DEPENDS} ${TESTIMAGEDEPENDS}" |
| 39 | do_testexport[lockfiles] += "${TEST_EXPORT_LOCK}" |
| 40 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 41 | python do_testexport() { |
| 42 | testexport_main(d) |
| 43 | } |
| 44 | |
| 45 | def testexport_main(d): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 46 | import json |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 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): |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 78 | import shutil |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 79 | import oe.path |
| 80 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 81 | from oeqa.utils.package_manager import _get_json_file |
| 82 | from oeqa.core.utils.test import getSuiteCasesFiles |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 83 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 84 | export_path = d.getVar('TEST_EXPORT_DIR') |
| 85 | corebase_path = d.getVar('COREBASE') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 86 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 87 | # Clean everything before starting |
| 88 | oe.path.remove(export_path) |
| 89 | bb.utils.mkdirhier(os.path.join(export_path, 'lib', 'oeqa')) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 90 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 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'), ] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 102 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 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) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 110 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 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) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame^] | 116 | test_modules = d.getVar('TEST_SUITES').split() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 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')) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 133 | |
| 134 | # Create tar file for common parts of testexport |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 135 | create_tarball(d, "testexport.tar.gz", d.getVar("TEST_EXPORT_DIR")) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 136 | |
| 137 | # Copy packages needed for runtime testing |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 138 | package_extraction(d, tc.suites) |
| 139 | test_pkg_dir = d.getVar("TEST_NEEDED_PACKAGES_DIR") |
| 140 | if os.path.isdir(test_pkg_dir) and os.listdir(test_pkg_dir): |
| 141 | export_pkg_dir = os.path.join(d.getVar("TEST_EXPORT_DIR"), "packages") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 142 | oe.path.copytree(test_pkg_dir, export_pkg_dir) |
| 143 | # Create tar file for packages needed by the DUT |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 144 | create_tarball(d, "testexport_packages_%s.tar.gz" % d.getVar("MACHINE"), export_pkg_dir) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 145 | |
| 146 | # Copy SDK |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 147 | if d.getVar("TEST_EXPORT_SDK_ENABLED") == "1": |
| 148 | sdk_deploy = d.getVar("SDK_DEPLOY") |
| 149 | tarball_name = "%s.sh" % d.getVar("TEST_EXPORT_SDK_NAME") |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 150 | tarball_path = os.path.join(sdk_deploy, tarball_name) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 151 | export_sdk_dir = os.path.join(d.getVar("TEST_EXPORT_DIR"), |
| 152 | d.getVar("TEST_EXPORT_SDK_DIR")) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 153 | bb.utils.mkdirhier(export_sdk_dir) |
| 154 | shutil.copy2(tarball_path, export_sdk_dir) |
| 155 | |
| 156 | # Create tar file for the sdk |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 157 | create_tarball(d, "testexport_sdk_%s.tar.gz" % d.getVar("SDK_ARCH"), export_sdk_dir) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 158 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 159 | bb.plain("Exported tests to: %s" % export_path) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 160 | |
| 161 | def create_tarball(d, tar_name, src_dir): |
| 162 | |
| 163 | import tarfile |
| 164 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 165 | tar_path = os.path.join(d.getVar("TEST_EXPORT_DIR"), tar_name) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 166 | current_dir = os.getcwd() |
| 167 | src_dir = src_dir.rstrip('/') |
| 168 | dir_name = os.path.dirname(src_dir) |
| 169 | base_name = os.path.basename(src_dir) |
| 170 | |
| 171 | os.chdir(dir_name) |
| 172 | tar = tarfile.open(tar_path, "w:gz") |
| 173 | tar.add(base_name) |
| 174 | tar.close() |
| 175 | os.chdir(current_dir) |
| 176 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 177 | inherit testimage |