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 | |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 5 | inherit metadata_scm |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 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}" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 47 | DEFAULT_TEST_SUITES_pn-core-image-full-cmdline = "${NETTESTSUITE} perl python logrotate ptest" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 48 | DEFAULT_TEST_SUITES_pn-core-image-x11 = "${MINTESTSUITE}" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 49 | DEFAULT_TEST_SUITES_pn-core-image-lsb = "${NETTESTSUITE} pam parselogs ${RPMTESTSUITE} ptest" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 50 | DEFAULT_TEST_SUITES_pn-core-image-sato = "${NETTESTSUITE} connman xorg parselogs ${RPMTESTSUITE} \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 51 | ${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'python', '', d)} ptest gi" |
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 | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 53 | connman ${DEVTESTSUITE} logrotate perl parselogs python ${RPMTESTSUITE} xorg ptest gi stap" |
| 54 | DEFAULT_TEST_SUITES_pn-core-image-lsb-dev = "${NETTESTSUITE} pam perl python parselogs ${RPMTESTSUITE} ptest gi" |
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 | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 56 | connman ${DEVTESTSUITE} logrotate pam parselogs perl python ${RPMTESTSUITE} ptest gi stap" |
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" |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 61 | # musl doesn't support systemtap |
| 62 | DEFAULT_TEST_SUITES_remove_libc-musl = "stap" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 64 | # qemumips is quite slow and has reached the timeout limit several times on the YP build cluster, |
| 65 | # mitigate this by removing build tests for qemumips machines. |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 66 | MIPSREMOVE ??= "buildcpio buildlzip buildgalculator" |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 67 | DEFAULT_TEST_SUITES_remove_qemumips = "${MIPSREMOVE}" |
| 68 | DEFAULT_TEST_SUITES_remove_qemumips64 = "${MIPSREMOVE}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 69 | |
| 70 | TEST_SUITES ?= "${DEFAULT_TEST_SUITES}" |
| 71 | |
| 72 | TEST_QEMUBOOT_TIMEOUT ?= "1000" |
| 73 | TEST_TARGET ?= "qemu" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 74 | |
| 75 | TESTIMAGEDEPENDS = "" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 76 | 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] | 77 | TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}" |
| 78 | 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] | 79 | TESTIMAGEDEPENDS_qemuall += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'createrepo-c-native:do_populate_sysroot', '', d)}" |
| 80 | 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] | 81 | TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'ipk', 'opkg-utils-native:do_populate_sysroot', '', d)}" |
| 82 | 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] | 83 | 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] | 84 | |
| 85 | TESTIMAGELOCK = "${TMPDIR}/testimage.lock" |
| 86 | TESTIMAGELOCK_qemuall = "" |
| 87 | |
| 88 | TESTIMAGE_DUMP_DIR ?= "/tmp/oe-saved-tests/" |
| 89 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 90 | TESTIMAGE_UPDATE_VARS ?= "DL_DIR WORKDIR DEPLOY_DIR" |
| 91 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 92 | testimage_dump_target () { |
| 93 | top -bn1 |
| 94 | ps |
| 95 | free |
| 96 | df |
| 97 | # The next command will export the default gateway IP |
| 98 | export DEFAULT_GATEWAY=$(ip route | awk '/default/ { print $3}') |
| 99 | ping -c3 $DEFAULT_GATEWAY |
| 100 | dmesg |
| 101 | netstat -an |
| 102 | ip address |
| 103 | # Next command will dump logs from /var/log/ |
| 104 | find /var/log/ -type f 2>/dev/null -exec echo "====================" \; -exec echo {} \; -exec echo "====================" \; -exec cat {} \; -exec echo "" \; |
| 105 | } |
| 106 | |
| 107 | testimage_dump_host () { |
| 108 | top -bn1 |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 109 | iostat -x -z -N -d -p ALL 20 2 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 110 | ps -ef |
| 111 | free |
| 112 | df |
| 113 | memstat |
| 114 | dmesg |
Patrick Williams | f1e5d69 | 2016-03-30 15:21:19 -0500 | [diff] [blame] | 115 | ip -s link |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 116 | netstat -an |
| 117 | } |
| 118 | |
| 119 | python do_testimage() { |
| 120 | testimage_main(d) |
| 121 | } |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 122 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 123 | addtask testimage |
| 124 | do_testimage[nostamp] = "1" |
| 125 | do_testimage[depends] += "${TESTIMAGEDEPENDS}" |
| 126 | do_testimage[lockfiles] += "${TESTIMAGELOCK}" |
| 127 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 128 | def testimage_sanity(d): |
| 129 | if (d.getVar('TEST_TARGET') == 'simpleremote' |
| 130 | and (not d.getVar('TEST_TARGET_IP') |
| 131 | or not d.getVar('TEST_SERVER_IP'))): |
| 132 | bb.fatal('When TEST_TARGET is set to "simpleremote" ' |
| 133 | 'TEST_TARGET_IP and TEST_SERVER_IP are needed too.') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 134 | |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 135 | def get_testimage_configuration(d, test_type, machine): |
| 136 | import platform |
| 137 | from oeqa.utils.metadata import get_layers |
| 138 | configuration = {'TEST_TYPE': test_type, |
| 139 | 'MACHINE': machine, |
| 140 | 'DISTRO': d.getVar("DISTRO"), |
| 141 | 'IMAGE_BASENAME': d.getVar("IMAGE_BASENAME"), |
| 142 | 'IMAGE_PKGTYPE': d.getVar("IMAGE_PKGTYPE"), |
| 143 | 'STARTTIME': d.getVar("DATETIME"), |
| 144 | 'HOST_DISTRO': ('-'.join(platform.linux_distribution())).replace(' ', '-'), |
| 145 | 'LAYERS': get_layers(d.getVar("BBLAYERS"))} |
| 146 | return configuration |
| 147 | get_testimage_configuration[vardepsexclude] = "DATETIME" |
| 148 | |
| 149 | def get_testimage_json_result_dir(d): |
| 150 | json_result_dir = os.path.join(d.getVar("LOG_DIR"), 'oeqa') |
| 151 | custom_json_result_dir = d.getVar("OEQA_JSON_RESULT_DIR") |
| 152 | if custom_json_result_dir: |
| 153 | json_result_dir = custom_json_result_dir |
| 154 | return json_result_dir |
| 155 | |
| 156 | def get_testimage_result_id(configuration): |
| 157 | return '%s_%s_%s_%s' % (configuration['TEST_TYPE'], configuration['IMAGE_BASENAME'], configuration['MACHINE'], configuration['STARTTIME']) |
| 158 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 159 | def testimage_main(d): |
| 160 | import os |
| 161 | import json |
| 162 | import signal |
| 163 | import logging |
| 164 | |
| 165 | from bb.utils import export_proxies |
| 166 | from oeqa.core.utils.misc import updateTestData |
| 167 | from oeqa.runtime.context import OERuntimeTestContext |
| 168 | from oeqa.runtime.context import OERuntimeTestContextExecutor |
| 169 | from oeqa.core.target.qemu import supported_fstypes |
| 170 | from oeqa.core.utils.test import getSuiteCases |
| 171 | from oeqa.utils import make_logger_bitbake_compatible |
| 172 | |
| 173 | def sigterm_exception(signum, stackframe): |
| 174 | """ |
| 175 | Catch SIGTERM from worker in order to stop qemu. |
| 176 | """ |
| 177 | raise RuntimeError |
| 178 | |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 179 | testimage_sanity(d) |
| 180 | |
| 181 | if (d.getVar('IMAGE_PKGTYPE') == 'rpm' |
| 182 | and ('dnf' in d.getVar('TEST_SUITES') or 'auto' in d.getVar('TEST_SUITES'))): |
| 183 | create_rpm_index(d) |
| 184 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 185 | logger = make_logger_bitbake_compatible(logging.getLogger("BitBake")) |
| 186 | pn = d.getVar("PN") |
| 187 | |
| 188 | bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR")) |
| 189 | |
| 190 | image_name = ("%s/%s" % (d.getVar('DEPLOY_DIR_IMAGE'), |
| 191 | d.getVar('IMAGE_LINK_NAME'))) |
| 192 | |
| 193 | tdname = "%s.testdata.json" % image_name |
| 194 | try: |
| 195 | td = json.load(open(tdname, "r")) |
| 196 | except (FileNotFoundError) as err: |
| 197 | bb.fatal('File %s Not Found. Have you built the image with INHERIT+="testimage" in the conf/local.conf?' % tdname) |
| 198 | |
| 199 | # Some variables need to be updates (mostly paths) with the |
| 200 | # ones of the current environment because some tests require them. |
| 201 | updateTestData(d, td, d.getVar('TESTIMAGE_UPDATE_VARS').split()) |
| 202 | |
| 203 | image_manifest = "%s.manifest" % image_name |
| 204 | image_packages = OERuntimeTestContextExecutor.readPackagesManifest(image_manifest) |
| 205 | |
| 206 | extract_dir = d.getVar("TEST_EXTRACTED_DIR") |
| 207 | |
| 208 | # Get machine |
| 209 | machine = d.getVar("MACHINE") |
| 210 | |
| 211 | # Get rootfs |
| 212 | fstypes = [fs for fs in d.getVar('IMAGE_FSTYPES').split(' ') |
| 213 | if fs in supported_fstypes] |
| 214 | if not fstypes: |
| 215 | bb.fatal('Unsupported image type built. Add a comptible image to ' |
| 216 | 'IMAGE_FSTYPES. Supported types: %s' % |
| 217 | ', '.join(supported_fstypes)) |
| 218 | rootfs = '%s.%s' % (image_name, fstypes[0]) |
| 219 | |
| 220 | # Get tmpdir (not really used, just for compatibility) |
| 221 | tmpdir = d.getVar("TMPDIR") |
| 222 | |
| 223 | # Get deploy_dir_image (not really used, just for compatibility) |
| 224 | dir_image = d.getVar("DEPLOY_DIR_IMAGE") |
| 225 | |
| 226 | # Get bootlog |
| 227 | bootlog = os.path.join(d.getVar("TEST_LOG_DIR"), |
| 228 | 'qemu_boot_log.%s' % d.getVar('DATETIME')) |
| 229 | |
| 230 | # Get display |
| 231 | display = d.getVar("BB_ORIGENV").getVar("DISPLAY") |
| 232 | |
| 233 | # Get kernel |
| 234 | kernel_name = ('%s-%s.bin' % (d.getVar("KERNEL_IMAGETYPE"), machine)) |
| 235 | kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), kernel_name) |
| 236 | |
| 237 | # Get boottime |
| 238 | boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT")) |
| 239 | |
| 240 | # Get use_kvm |
| 241 | qemu_use_kvm = d.getVar("QEMU_USE_KVM") |
| 242 | if qemu_use_kvm and \ |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 243 | (oe.types.boolean(qemu_use_kvm) and 'x86' in machine or \ |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 244 | d.getVar('MACHINE') in qemu_use_kvm.split()): |
| 245 | kvm = True |
| 246 | else: |
| 247 | kvm = False |
| 248 | |
| 249 | # TODO: We use the current implementatin of qemu runner because of |
| 250 | # time constrains, qemu runner really needs a refactor too. |
| 251 | target_kwargs = { 'machine' : machine, |
| 252 | 'rootfs' : rootfs, |
| 253 | 'tmpdir' : tmpdir, |
| 254 | 'dir_image' : dir_image, |
| 255 | 'display' : display, |
| 256 | 'kernel' : kernel, |
| 257 | 'boottime' : boottime, |
| 258 | 'bootlog' : bootlog, |
| 259 | 'kvm' : kvm, |
| 260 | } |
| 261 | |
| 262 | # TODO: Currently BBPATH is needed for custom loading of targets. |
| 263 | # It would be better to find these modules using instrospection. |
| 264 | target_kwargs['target_modules_path'] = d.getVar('BBPATH') |
| 265 | |
| 266 | # runtime use network for download projects for build |
| 267 | export_proxies(d) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 268 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 269 | # we need the host dumper in test context |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 270 | host_dumper = OERuntimeTestContextExecutor.getHostDumper( |
| 271 | d.getVar("testimage_dump_host"), |
| 272 | d.getVar("TESTIMAGE_DUMP_DIR")) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 273 | |
| 274 | # the robot dance |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 275 | target = OERuntimeTestContextExecutor.getTarget( |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 276 | d.getVar("TEST_TARGET"), logger, d.getVar("TEST_TARGET_IP"), |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 277 | d.getVar("TEST_SERVER_IP"), **target_kwargs) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 278 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 279 | # test context |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 280 | tc = OERuntimeTestContext(td, logger, target, host_dumper, |
| 281 | image_packages, extract_dir) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 282 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 283 | # Load tests before starting the target |
| 284 | test_paths = get_runtime_paths(d) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 285 | test_modules = d.getVar('TEST_SUITES').split() |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 286 | if not test_modules: |
| 287 | bb.fatal('Empty test suite, please verify TEST_SUITES variable') |
| 288 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 289 | tc.loadTests(test_paths, modules=test_modules) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 290 | |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 291 | suitecases = getSuiteCases(tc.suites) |
| 292 | if not suitecases: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 293 | bb.fatal('Empty test suite, please verify TEST_SUITES variable') |
Brad Bishop | d5ae7d9 | 2018-06-14 09:52:03 -0700 | [diff] [blame] | 294 | else: |
| 295 | bb.debug(2, 'test suites:\n\t%s' % '\n\t'.join([str(c) for c in suitecases])) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 296 | |
| 297 | package_extraction(d, tc.suites) |
| 298 | |
| 299 | bootparams = None |
| 300 | if d.getVar('VIRTUAL-RUNTIME_init_manager', '') == 'systemd': |
| 301 | # Add systemd.log_level=debug to enable systemd debug logging |
| 302 | bootparams = 'systemd.log_target=console' |
| 303 | |
| 304 | results = None |
| 305 | orig_sigterm_handler = signal.signal(signal.SIGTERM, sigterm_exception) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 306 | try: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 307 | # We need to check if runqemu ends unexpectedly |
| 308 | # or if the worker send us a SIGTERM |
| 309 | tc.target.start(extra_bootparams=bootparams) |
| 310 | results = tc.runTests() |
| 311 | except (RuntimeError, BlockingIOError) as err: |
| 312 | if isinstance(err, RuntimeError): |
| 313 | bb.error('testimage received SIGTERM, shutting down...') |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 314 | else: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 315 | bb.error('runqemu failed, shutting down...') |
| 316 | if results: |
| 317 | results.stop() |
| 318 | results = None |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 319 | finally: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 320 | signal.signal(signal.SIGTERM, orig_sigterm_handler) |
| 321 | tc.target.stop() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 322 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 323 | # Show results (if we have them) |
| 324 | if not results: |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 325 | bb.fatal('%s - FAILED - tests were interrupted during execution' % pn, forcelog=True) |
Brad Bishop | f86d055 | 2018-12-04 14:18:15 -0800 | [diff] [blame] | 326 | configuration = get_testimage_configuration(d, 'runtime', machine) |
| 327 | results.logDetails(get_testimage_json_result_dir(d), |
| 328 | configuration, |
| 329 | get_testimage_result_id(configuration)) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 330 | results.logSummary(pn) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 331 | if not results.wasSuccessful(): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 332 | 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] | 333 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 334 | def get_runtime_paths(d): |
| 335 | """ |
| 336 | Returns a list of paths where runtime test must reside. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 337 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 338 | Runtime tests are expected in <LAYER_DIR>/lib/oeqa/runtime/cases/ |
| 339 | """ |
| 340 | paths = [] |
| 341 | |
| 342 | for layer in d.getVar('BBLAYERS').split(): |
| 343 | path = os.path.join(layer, 'lib/oeqa/runtime/cases') |
| 344 | if os.path.isdir(path): |
| 345 | paths.append(path) |
| 346 | return paths |
| 347 | |
| 348 | def create_index(arg): |
| 349 | import subprocess |
| 350 | |
| 351 | index_cmd = arg |
| 352 | try: |
| 353 | bb.note("Executing '%s' ..." % index_cmd) |
| 354 | result = subprocess.check_output(index_cmd, |
| 355 | stderr=subprocess.STDOUT, |
| 356 | shell=True) |
| 357 | result = result.decode('utf-8') |
| 358 | except subprocess.CalledProcessError as e: |
| 359 | return("Index creation command '%s' failed with return code " |
| 360 | '%d:\n%s' % (e.cmd, e.returncode, e.output.decode("utf-8"))) |
| 361 | if result: |
| 362 | bb.note(result) |
| 363 | return None |
| 364 | |
| 365 | def create_rpm_index(d): |
| 366 | # Index RPMs |
| 367 | rpm_createrepo = bb.utils.which(os.getenv('PATH'), "createrepo_c") |
| 368 | index_cmds = [] |
| 369 | archs = (d.getVar('ALL_MULTILIB_PACKAGE_ARCHS') or '').replace('-', '_') |
| 370 | |
| 371 | for arch in archs.split(): |
| 372 | rpm_dir = os.path.join(d.getVar('DEPLOY_DIR_RPM'), arch) |
| 373 | idx_path = os.path.join(d.getVar('WORKDIR'), 'oe-testimage-repo', arch) |
| 374 | |
| 375 | if not os.path.isdir(rpm_dir): |
| 376 | continue |
| 377 | |
| 378 | lockfilename = os.path.join(d.getVar('DEPLOY_DIR_RPM'), 'rpm.lock') |
| 379 | lf = bb.utils.lockfile(lockfilename, False) |
| 380 | oe.path.copyhardlinktree(rpm_dir, idx_path) |
| 381 | # Full indexes overload a 256MB image so reduce the number of rpms |
| 382 | # in the feed. Filter to r* since we use the run-postinst packages and |
| 383 | # this leaves some allarch and machine arch packages too. |
| 384 | bb.utils.remove(idx_path + "*/[a-qs-z]*.rpm") |
| 385 | bb.utils.unlockfile(lf) |
| 386 | cmd = '%s --update -q %s' % (rpm_createrepo, idx_path) |
| 387 | |
| 388 | # Create repodata |
| 389 | result = create_index(cmd) |
| 390 | if result: |
| 391 | bb.fatal('%s' % ('\n'.join(result))) |
| 392 | |
| 393 | def package_extraction(d, test_suites): |
| 394 | from oeqa.utils.package_manager import find_packages_to_extract |
| 395 | from oeqa.utils.package_manager import extract_packages |
| 396 | |
| 397 | bb.utils.remove(d.getVar("TEST_NEEDED_PACKAGES_DIR"), recurse=True) |
| 398 | packages = find_packages_to_extract(test_suites) |
| 399 | if packages: |
| 400 | bb.utils.mkdirhier(d.getVar("TEST_INSTALL_TMP_DIR")) |
| 401 | bb.utils.mkdirhier(d.getVar("TEST_PACKAGED_DIR")) |
| 402 | bb.utils.mkdirhier(d.getVar("TEST_EXTRACTED_DIR")) |
| 403 | extract_packages(d, packages) |
| 404 | |
| 405 | testimage_main[vardepsexclude] += "BB_ORIGENV DATETIME" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 406 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 407 | inherit testsdk |