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