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