Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # Copyright (C) 2013 Intel Corporation |
| 2 | # |
| 3 | # Released under the MIT license (see COPYING.MIT) |
| 4 | |
| 5 | |
| 6 | # testimage.bbclass enables testing of qemu images using python unittests. |
| 7 | # Most of the tests are commands run on target image over ssh. |
| 8 | # To use it add testimage to global inherit and call your target image with -c testimage |
| 9 | # You can try it out like this: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 10 | # - first add IMAGE_CLASSES += "testimage" in local.conf |
| 11 | # - build a qemu core-image-sato |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 12 | # - then bitbake core-image-sato -c testimage. That will run a standard suite of tests. |
| 13 | |
| 14 | # You can set (or append to) TEST_SUITES in local.conf to select the tests |
| 15 | # which you want to run for your target. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 16 | # The test names are the module names in meta/lib/oeqa/runtime/cases. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 17 | # Each name in TEST_SUITES represents a required test for the image. (no skipping allowed) |
| 18 | # Appending "auto" means that it will try to run all tests that are suitable for the image (each test decides that on it's own). |
| 19 | # Note that order in TEST_SUITES is relevant: tests are run in an order such that |
| 20 | # tests mentioned in @skipUnlessPassed run before the tests that depend on them, |
| 21 | # but without such dependencies, tests run in the order in which they are listed |
| 22 | # in TEST_SUITES. |
| 23 | # |
| 24 | # A layer can add its own tests in lib/oeqa/runtime, provided it extends BBPATH as normal in its layer.conf. |
| 25 | |
| 26 | # TEST_LOG_DIR contains a command ssh log and may contain infromation about what command is running, output and return codes and for qemu a boot log till login. |
| 27 | # Booting is handled by this class, and it's not a test in itself. |
| 28 | # TEST_QEMUBOOT_TIMEOUT can be used to set the maximum time in seconds the launch code will wait for the login prompt. |
| 29 | |
| 30 | TEST_LOG_DIR ?= "${WORKDIR}/testimage" |
| 31 | |
| 32 | TEST_EXPORT_DIR ?= "${TMPDIR}/testimage/${PN}" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 33 | TEST_INSTALL_TMP_DIR ?= "${WORKDIR}/testimage/install_tmp" |
| 34 | TEST_NEEDED_PACKAGES_DIR ?= "${WORKDIR}/testimage/packages" |
| 35 | TEST_EXTRACTED_DIR ?= "${TEST_NEEDED_PACKAGES_DIR}/extracted" |
| 36 | TEST_PACKAGED_DIR ?= "${TEST_NEEDED_PACKAGES_DIR}/packaged" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 38 | RPMTESTSUITE = "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'dnf rpm', '', d)}" |
| 39 | SYSTEMDSUITE = "${@bb.utils.filter('DISTRO_FEATURES', 'systemd', d)}" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 40 | MINTESTSUITE = "ping" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 41 | NETTESTSUITE = "${MINTESTSUITE} ssh df date scp oe_syslog ${SYSTEMDSUITE}" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 42 | DEVTESTSUITE = "gcc kernelmodule ldd" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 43 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 44 | DEFAULT_TEST_SUITES = "${MINTESTSUITE} auto" |
| 45 | DEFAULT_TEST_SUITES_pn-core-image-minimal = "${MINTESTSUITE}" |
| 46 | DEFAULT_TEST_SUITES_pn-core-image-minimal-dev = "${MINTESTSUITE}" |
| 47 | DEFAULT_TEST_SUITES_pn-core-image-full-cmdline = "${NETTESTSUITE} perl python logrotate" |
| 48 | DEFAULT_TEST_SUITES_pn-core-image-x11 = "${MINTESTSUITE}" |
| 49 | DEFAULT_TEST_SUITES_pn-core-image-lsb = "${NETTESTSUITE} pam parselogs ${RPMTESTSUITE}" |
| 50 | DEFAULT_TEST_SUITES_pn-core-image-sato = "${NETTESTSUITE} connman xorg parselogs ${RPMTESTSUITE} \ |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 51 | ${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'python', '', d)}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 52 | DEFAULT_TEST_SUITES_pn-core-image-sato-sdk = "${NETTESTSUITE} buildcpio buildlzip buildgalculator \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 53 | connman ${DEVTESTSUITE} logrotate perl parselogs python ${RPMTESTSUITE} xorg" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 54 | DEFAULT_TEST_SUITES_pn-core-image-lsb-dev = "${NETTESTSUITE} pam perl python parselogs ${RPMTESTSUITE}" |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 55 | DEFAULT_TEST_SUITES_pn-core-image-lsb-sdk = "${NETTESTSUITE} buildcpio buildlzip buildgalculator \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 56 | connman ${DEVTESTSUITE} logrotate pam parselogs perl python ${RPMTESTSUITE}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | DEFAULT_TEST_SUITES_pn-meta-toolchain = "auto" |
| 58 | |
| 59 | # aarch64 has no graphics |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 60 | DEFAULT_TEST_SUITES_remove_aarch64 = "xorg" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 62 | # qemumips is quite slow and has reached the timeout limit several times on the YP build cluster, |
| 63 | # mitigate this by removing build tests for qemumips machines. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 64 | MIPSREMOVE ??= "buildcpio buildlzip buildgalculator" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 65 | DEFAULT_TEST_SUITES_remove_qemumips = "${MIPSREMOVE}" |
| 66 | DEFAULT_TEST_SUITES_remove_qemumips64 = "${MIPSREMOVE}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 67 | |
| 68 | TEST_SUITES ?= "${DEFAULT_TEST_SUITES}" |
| 69 | |
| 70 | TEST_QEMUBOOT_TIMEOUT ?= "1000" |
| 71 | TEST_TARGET ?= "qemu" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 72 | |
| 73 | TESTIMAGEDEPENDS = "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 74 | TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot qemu-helper-native:do_addto_recipe_sysroot" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 75 | TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}" |
| 76 | TESTIMAGEDEPENDS_qemuall += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 77 | TESTIMAGEDEPENDS_qemuall += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'createrepo-c-native:do_populate_sysroot', '', d)}" |
| 78 | TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'dnf-native:do_populate_sysroot', '', d)}" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 79 | TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'ipk', 'opkg-utils-native:do_populate_sysroot', '', d)}" |
| 80 | TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'deb', 'apt-native:do_populate_sysroot', '', d)}" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 81 | TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'createrepo-c-native:do_populate_sysroot', '', d)}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 82 | |
| 83 | TESTIMAGELOCK = "${TMPDIR}/testimage.lock" |
| 84 | TESTIMAGELOCK_qemuall = "" |
| 85 | |
| 86 | TESTIMAGE_DUMP_DIR ?= "/tmp/oe-saved-tests/" |
| 87 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 88 | TESTIMAGE_UPDATE_VARS ?= "DL_DIR WORKDIR DEPLOY_DIR" |
| 89 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 90 | testimage_dump_target () { |
| 91 | top -bn1 |
| 92 | ps |
| 93 | free |
| 94 | df |
| 95 | # The next command will export the default gateway IP |
| 96 | export DEFAULT_GATEWAY=$(ip route | awk '/default/ { print $3}') |
| 97 | ping -c3 $DEFAULT_GATEWAY |
| 98 | dmesg |
| 99 | netstat -an |
| 100 | ip address |
| 101 | # Next command will dump logs from /var/log/ |
| 102 | find /var/log/ -type f 2>/dev/null -exec echo "====================" \; -exec echo {} \; -exec echo "====================" \; -exec cat {} \; -exec echo "" \; |
| 103 | } |
| 104 | |
| 105 | testimage_dump_host () { |
| 106 | top -bn1 |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 107 | iostat -x -z -N -d -p ALL 20 2 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 108 | ps -ef |
| 109 | free |
| 110 | df |
| 111 | memstat |
| 112 | dmesg |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 113 | ip -s link |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | netstat -an |
| 115 | } |
| 116 | |
| 117 | python do_testimage() { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 118 | |
| 119 | testimage_sanity(d) |
| 120 | |
| 121 | if (d.getVar('IMAGE_PKGTYPE') == 'rpm' |
| 122 | and 'dnf' in d.getVar('TEST_SUITES')): |
| 123 | create_rpm_index(d) |
| 124 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 125 | testimage_main(d) |
| 126 | } |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 127 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 128 | addtask testimage |
| 129 | do_testimage[nostamp] = "1" |
| 130 | do_testimage[depends] += "${TESTIMAGEDEPENDS}" |
| 131 | do_testimage[lockfiles] += "${TESTIMAGELOCK}" |
| 132 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 133 | def testimage_sanity(d): |
| 134 | if (d.getVar('TEST_TARGET') == 'simpleremote' |
| 135 | and (not d.getVar('TEST_TARGET_IP') |
| 136 | or not d.getVar('TEST_SERVER_IP'))): |
| 137 | bb.fatal('When TEST_TARGET is set to "simpleremote" ' |
| 138 | 'TEST_TARGET_IP and TEST_SERVER_IP are needed too.') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 139 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 140 | def testimage_main(d): |
| 141 | import os |
| 142 | import json |
| 143 | import signal |
| 144 | import logging |
| 145 | |
| 146 | from bb.utils import export_proxies |
| 147 | from oeqa.core.utils.misc import updateTestData |
| 148 | from oeqa.runtime.context import OERuntimeTestContext |
| 149 | from oeqa.runtime.context import OERuntimeTestContextExecutor |
| 150 | from oeqa.core.target.qemu import supported_fstypes |
| 151 | from oeqa.core.utils.test import getSuiteCases |
| 152 | from oeqa.utils import make_logger_bitbake_compatible |
| 153 | |
| 154 | def sigterm_exception(signum, stackframe): |
| 155 | """ |
| 156 | Catch SIGTERM from worker in order to stop qemu. |
| 157 | """ |
| 158 | raise RuntimeError |
| 159 | |
| 160 | logger = make_logger_bitbake_compatible(logging.getLogger("BitBake")) |
| 161 | pn = d.getVar("PN") |
| 162 | |
| 163 | bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR")) |
| 164 | |
| 165 | image_name = ("%s/%s" % (d.getVar('DEPLOY_DIR_IMAGE'), |
| 166 | d.getVar('IMAGE_LINK_NAME'))) |
| 167 | |
| 168 | tdname = "%s.testdata.json" % image_name |
| 169 | try: |
| 170 | td = json.load(open(tdname, "r")) |
| 171 | except (FileNotFoundError) as err: |
| 172 | bb.fatal('File %s Not Found. Have you built the image with INHERIT+="testimage" in the conf/local.conf?' % tdname) |
| 173 | |
| 174 | # Some variables need to be updates (mostly paths) with the |
| 175 | # ones of the current environment because some tests require them. |
| 176 | updateTestData(d, td, d.getVar('TESTIMAGE_UPDATE_VARS').split()) |
| 177 | |
| 178 | image_manifest = "%s.manifest" % image_name |
| 179 | image_packages = OERuntimeTestContextExecutor.readPackagesManifest(image_manifest) |
| 180 | |
| 181 | extract_dir = d.getVar("TEST_EXTRACTED_DIR") |
| 182 | |
| 183 | # Get machine |
| 184 | machine = d.getVar("MACHINE") |
| 185 | |
| 186 | # Get rootfs |
| 187 | fstypes = [fs for fs in d.getVar('IMAGE_FSTYPES').split(' ') |
| 188 | if fs in supported_fstypes] |
| 189 | if not fstypes: |
| 190 | bb.fatal('Unsupported image type built. Add a comptible image to ' |
| 191 | 'IMAGE_FSTYPES. Supported types: %s' % |
| 192 | ', '.join(supported_fstypes)) |
| 193 | rootfs = '%s.%s' % (image_name, fstypes[0]) |
| 194 | |
| 195 | # Get tmpdir (not really used, just for compatibility) |
| 196 | tmpdir = d.getVar("TMPDIR") |
| 197 | |
| 198 | # Get deploy_dir_image (not really used, just for compatibility) |
| 199 | dir_image = d.getVar("DEPLOY_DIR_IMAGE") |
| 200 | |
| 201 | # Get bootlog |
| 202 | bootlog = os.path.join(d.getVar("TEST_LOG_DIR"), |
| 203 | 'qemu_boot_log.%s' % d.getVar('DATETIME')) |
| 204 | |
| 205 | # Get display |
| 206 | display = d.getVar("BB_ORIGENV").getVar("DISPLAY") |
| 207 | |
| 208 | # Get kernel |
| 209 | kernel_name = ('%s-%s.bin' % (d.getVar("KERNEL_IMAGETYPE"), machine)) |
| 210 | kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), kernel_name) |
| 211 | |
| 212 | # Get boottime |
| 213 | boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")) |
| 214 | |
| 215 | # Get use_kvm |
| 216 | qemu_use_kvm = d.getVar("QEMU_USE_KVM") |
| 217 | if qemu_use_kvm and \ |
| 218 | (qemu_use_kvm == 'True' and 'x86' in machine or \ |
| 219 | d.getVar('MACHINE') in qemu_use_kvm.split()): |
| 220 | kvm = True |
| 221 | else: |
| 222 | kvm = False |
| 223 | |
| 224 | # TODO: We use the current implementatin of qemu runner because of |
| 225 | # time constrains, qemu runner really needs a refactor too. |
| 226 | target_kwargs = { 'machine' : machine, |
| 227 | 'rootfs' : rootfs, |
| 228 | 'tmpdir' : tmpdir, |
| 229 | 'dir_image' : dir_image, |
| 230 | 'display' : display, |
| 231 | 'kernel' : kernel, |
| 232 | 'boottime' : boottime, |
| 233 | 'bootlog' : bootlog, |
| 234 | 'kvm' : kvm, |
| 235 | } |
| 236 | |
| 237 | # TODO: Currently BBPATH is needed for custom loading of targets. |
| 238 | # It would be better to find these modules using instrospection. |
| 239 | target_kwargs['target_modules_path'] = d.getVar('BBPATH') |
| 240 | |
| 241 | # runtime use network for download projects for build |
| 242 | export_proxies(d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 243 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 244 | # we need the host dumper in test context |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 245 | host_dumper = OERuntimeTestContextExecutor.getHostDumper( |
| 246 | d.getVar("testimage_dump_host"), |
| 247 | d.getVar("TESTIMAGE_DUMP_DIR")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 248 | |
| 249 | # the robot dance |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 250 | target = OERuntimeTestContextExecutor.getTarget( |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 251 | d.getVar("TEST_TARGET"), logger, d.getVar("TEST_TARGET_IP"), |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 252 | d.getVar("TEST_SERVER_IP"), **target_kwargs) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 253 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 254 | # test context |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 255 | tc = OERuntimeTestContext(td, logger, target, host_dumper, |
| 256 | image_packages, extract_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 257 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 258 | # Load tests before starting the target |
| 259 | test_paths = get_runtime_paths(d) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 260 | test_modules = d.getVar('TEST_SUITES').split() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 261 | tc.loadTests(test_paths, modules=test_modules) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 263 | if not getSuiteCases(tc.suites): |
| 264 | bb.fatal('Empty test suite, please verify TEST_SUITES variable') |
| 265 | |
| 266 | package_extraction(d, tc.suites) |
| 267 | |
| 268 | bootparams = None |
| 269 | if d.getVar('VIRTUAL-RUNTIME_init_manager', '') == 'systemd': |
| 270 | # Add systemd.log_level=debug to enable systemd debug logging |
| 271 | bootparams = 'systemd.log_target=console' |
| 272 | |
| 273 | results = None |
| 274 | orig_sigterm_handler = signal.signal(signal.SIGTERM, sigterm_exception) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 275 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 276 | # We need to check if runqemu ends unexpectedly |
| 277 | # or if the worker send us a SIGTERM |
| 278 | tc.target.start(extra_bootparams=bootparams) |
| 279 | results = tc.runTests() |
| 280 | except (RuntimeError, BlockingIOError) as err: |
| 281 | if isinstance(err, RuntimeError): |
| 282 | bb.error('testimage received SIGTERM, shutting down...') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 283 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 284 | bb.error('runqemu failed, shutting down...') |
| 285 | if results: |
| 286 | results.stop() |
| 287 | results = None |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 288 | finally: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 289 | signal.signal(signal.SIGTERM, orig_sigterm_handler) |
| 290 | tc.target.stop() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 291 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 292 | # Show results (if we have them) |
| 293 | if not results: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 294 | bb.fatal('%s - FAILED - tests were interrupted during execution' % pn, forcelog=True) |
| 295 | results.logDetails() |
| 296 | results.logSummary(pn) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 297 | if not results.wasSuccessful(): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 298 | bb.fatal('%s - FAILED - check the task log and the ssh log' % pn, forcelog=True) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 299 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 300 | def get_runtime_paths(d): |
| 301 | """ |
| 302 | Returns a list of paths where runtime test must reside. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 303 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 304 | Runtime tests are expected in <LAYER_DIR>/lib/oeqa/runtime/cases/ |
| 305 | """ |
| 306 | paths = [] |
| 307 | |
| 308 | for layer in d.getVar('BBLAYERS').split(): |
| 309 | path = os.path.join(layer, 'lib/oeqa/runtime/cases') |
| 310 | if os.path.isdir(path): |
| 311 | paths.append(path) |
| 312 | return paths |
| 313 | |
| 314 | def create_index(arg): |
| 315 | import subprocess |
| 316 | |
| 317 | index_cmd = arg |
| 318 | try: |
| 319 | bb.note("Executing '%s' ..." % index_cmd) |
| 320 | result = subprocess.check_output(index_cmd, |
| 321 | stderr=subprocess.STDOUT, |
| 322 | shell=True) |
| 323 | result = result.decode('utf-8') |
| 324 | except subprocess.CalledProcessError as e: |
| 325 | return("Index creation command '%s' failed with return code " |
| 326 | '%d:\n%s' % (e.cmd, e.returncode, e.output.decode("utf-8"))) |
| 327 | if result: |
| 328 | bb.note(result) |
| 329 | return None |
| 330 | |
| 331 | def create_rpm_index(d): |
| 332 | # Index RPMs |
| 333 | rpm_createrepo = bb.utils.which(os.getenv('PATH'), "createrepo_c") |
| 334 | index_cmds = [] |
| 335 | archs = (d.getVar('ALL_MULTILIB_PACKAGE_ARCHS') or '').replace('-', '_') |
| 336 | |
| 337 | for arch in archs.split(): |
| 338 | rpm_dir = os.path.join(d.getVar('DEPLOY_DIR_RPM'), arch) |
| 339 | idx_path = os.path.join(d.getVar('WORKDIR'), 'oe-testimage-repo', arch) |
| 340 | |
| 341 | if not os.path.isdir(rpm_dir): |
| 342 | continue |
| 343 | |
| 344 | lockfilename = os.path.join(d.getVar('DEPLOY_DIR_RPM'), 'rpm.lock') |
| 345 | lf = bb.utils.lockfile(lockfilename, False) |
| 346 | oe.path.copyhardlinktree(rpm_dir, idx_path) |
| 347 | # Full indexes overload a 256MB image so reduce the number of rpms |
| 348 | # in the feed. Filter to r* since we use the run-postinst packages and |
| 349 | # this leaves some allarch and machine arch packages too. |
| 350 | bb.utils.remove(idx_path + "*/[a-qs-z]*.rpm") |
| 351 | bb.utils.unlockfile(lf) |
| 352 | cmd = '%s --update -q %s' % (rpm_createrepo, idx_path) |
| 353 | |
| 354 | # Create repodata |
| 355 | result = create_index(cmd) |
| 356 | if result: |
| 357 | bb.fatal('%s' % ('\n'.join(result))) |
| 358 | |
| 359 | def package_extraction(d, test_suites): |
| 360 | from oeqa.utils.package_manager import find_packages_to_extract |
| 361 | from oeqa.utils.package_manager import extract_packages |
| 362 | |
| 363 | bb.utils.remove(d.getVar("TEST_NEEDED_PACKAGES_DIR"), recurse=True) |
| 364 | packages = find_packages_to_extract(test_suites) |
| 365 | if packages: |
| 366 | bb.utils.mkdirhier(d.getVar("TEST_INSTALL_TMP_DIR")) |
| 367 | bb.utils.mkdirhier(d.getVar("TEST_PACKAGED_DIR")) |
| 368 | bb.utils.mkdirhier(d.getVar("TEST_EXTRACTED_DIR")) |
| 369 | extract_packages(d, packages) |
| 370 | |
| 371 | testimage_main[vardepsexclude] += "BB_ORIGENV DATETIME" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 372 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 373 | inherit testsdk |