blob: f2ff91da9dcf0a99236ba15d0ab222f7892f8b5c [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001# Copyright (C) 2013 Intel Corporation
2#
3# Released under the MIT license (see COPYING.MIT)
4
Brad Bishopf86d0552018-12-04 14:18:15 -08005inherit metadata_scm
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006# 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 Bishopd7bf8c12018-02-25 22:55:05 -050010# - first add IMAGE_CLASSES += "testimage" in local.conf
11# - build a qemu core-image-sato
Patrick Williamsc124f4f2015-09-15 14:41:29 -050012# - then bitbake core-image-sato -c testimage. That will run a standard suite of tests.
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080013#
14# The tests can be run automatically each time an image is built if you set
15# TESTIMAGE_AUTO = "1"
16
17TESTIMAGE_AUTO ??= "0"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050018
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 Bishopd7bf8c12018-02-25 22:55:05 -050021# The test names are the module names in meta/lib/oeqa/runtime/cases.
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022# 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
35TEST_LOG_DIR ?= "${WORKDIR}/testimage"
36
37TEST_EXPORT_DIR ?= "${TMPDIR}/testimage/${PN}"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060038TEST_INSTALL_TMP_DIR ?= "${WORKDIR}/testimage/install_tmp"
39TEST_NEEDED_PACKAGES_DIR ?= "${WORKDIR}/testimage/packages"
40TEST_EXTRACTED_DIR ?= "${TEST_NEEDED_PACKAGES_DIR}/extracted"
41TEST_PACKAGED_DIR ?= "${TEST_NEEDED_PACKAGES_DIR}/packaged"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050042
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080043PKGMANTESTSUITE = "\
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 Bishop6e60e8b2018-02-01 10:27:11 -050048SYSTEMDSUITE = "${@bb.utils.filter('DISTRO_FEATURES', 'systemd', d)}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050049MINTESTSUITE = "ping"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050050NETTESTSUITE = "${MINTESTSUITE} ssh df date scp oe_syslog ${SYSTEMDSUITE}"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050051DEVTESTSUITE = "gcc kernelmodule ldd"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080052PTESTTESTSUITE = "${MINTESTSUITE} ssh scp ptest"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050053
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050054DEFAULT_TEST_SUITES = "${MINTESTSUITE} auto"
55DEFAULT_TEST_SUITES_pn-core-image-minimal = "${MINTESTSUITE}"
56DEFAULT_TEST_SUITES_pn-core-image-minimal-dev = "${MINTESTSUITE}"
Brad Bishop316dfdd2018-06-25 12:45:53 -040057DEFAULT_TEST_SUITES_pn-core-image-full-cmdline = "${NETTESTSUITE} perl python logrotate ptest"
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050058DEFAULT_TEST_SUITES_pn-core-image-x11 = "${MINTESTSUITE}"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080059DEFAULT_TEST_SUITES_pn-core-image-lsb = "${NETTESTSUITE} pam parselogs ${PKGMANTESTSUITE} ptest"
60DEFAULT_TEST_SUITES_pn-core-image-sato = "${NETTESTSUITE} connman xorg parselogs ${PKGMANTESTSUITE} \
Brad Bishop316dfdd2018-06-25 12:45:53 -040061 ${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'python', '', d)} ptest gi"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050062DEFAULT_TEST_SUITES_pn-core-image-sato-sdk = "${NETTESTSUITE} buildcpio buildlzip buildgalculator \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080063 connman ${DEVTESTSUITE} logrotate perl parselogs python ${PKGMANTESTSUITE} xorg ptest gi stap"
64DEFAULT_TEST_SUITES_pn-core-image-lsb-dev = "${NETTESTSUITE} pam perl python parselogs ${PKGMANTESTSUITE} ptest gi"
Brad Bishopd7bf8c12018-02-25 22:55:05 -050065DEFAULT_TEST_SUITES_pn-core-image-lsb-sdk = "${NETTESTSUITE} buildcpio buildlzip buildgalculator \
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080066 connman ${DEVTESTSUITE} logrotate pam parselogs perl python ${PKGMANTESTSUITE} ptest gi stap"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050067DEFAULT_TEST_SUITES_pn-meta-toolchain = "auto"
68
69# aarch64 has no graphics
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050070DEFAULT_TEST_SUITES_remove_aarch64 = "xorg"
Brad Bishop316dfdd2018-06-25 12:45:53 -040071# musl doesn't support systemtap
72DEFAULT_TEST_SUITES_remove_libc-musl = "stap"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050073
Patrick Williamsc0f7c042017-02-23 20:41:17 -060074# 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 Bishopd7bf8c12018-02-25 22:55:05 -050076MIPSREMOVE ??= "buildcpio buildlzip buildgalculator"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060077DEFAULT_TEST_SUITES_remove_qemumips = "${MIPSREMOVE}"
78DEFAULT_TEST_SUITES_remove_qemumips64 = "${MIPSREMOVE}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050079
80TEST_SUITES ?= "${DEFAULT_TEST_SUITES}"
81
82TEST_QEMUBOOT_TIMEOUT ?= "1000"
83TEST_TARGET ?= "qemu"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050084
85TESTIMAGEDEPENDS = ""
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080086TESTIMAGEDEPENDS_append_qemuall = " qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot qemu-helper-native:do_addto_recipe_sysroot"
Patrick Williamsc0f7c042017-02-23 20:41:17 -060087TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080088TESTIMAGEDEPENDS_append_qemuall = " ${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'cpio-native:do_populate_sysroot', '', d)}"
89TESTIMAGEDEPENDS_append_qemuall = " ${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'createrepo-c-native:do_populate_sysroot', '', d)}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050090TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'dnf-native:do_populate_sysroot', '', d)}"
Brad Bishop1a4b7ee2018-12-16 17:11:34 -080091TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'ipk', 'opkg-utils-native:do_populate_sysroot package-index:do_package_index', '', d)}"
92TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'deb', 'apt-native:do_populate_sysroot package-index:do_package_index', '', d)}"
Brad Bishop6e60e8b2018-02-01 10:27:11 -050093TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'createrepo-c-native:do_populate_sysroot', '', d)}"
Patrick Williamsc124f4f2015-09-15 14:41:29 -050094
95TESTIMAGELOCK = "${TMPDIR}/testimage.lock"
96TESTIMAGELOCK_qemuall = ""
97
98TESTIMAGE_DUMP_DIR ?= "/tmp/oe-saved-tests/"
99
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500100TESTIMAGE_UPDATE_VARS ?= "DL_DIR WORKDIR DEPLOY_DIR"
101
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500102testimage_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
117testimage_dump_host () {
118 top -bn1
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500119 iostat -x -z -N -d -p ALL 20 2
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500120 ps -ef
121 free
122 df
123 memstat
124 dmesg
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500125 ip -s link
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500126 netstat -an
127}
128
129python do_testimage() {
130 testimage_main(d)
131}
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600132
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500133addtask testimage
134do_testimage[nostamp] = "1"
135do_testimage[depends] += "${TESTIMAGEDEPENDS}"
136do_testimage[lockfiles] += "${TESTIMAGELOCK}"
137
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500138def 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 Williamsc124f4f2015-09-15 14:41:29 -0500144
Brad Bishopf86d0552018-12-04 14:18:15 -0800145def 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 Bishop1a4b7ee2018-12-16 17:11:34 -0800154 'HOST_DISTRO': oe.lsb.distro_identifier().replace(' ', '-'),
Brad Bishopf86d0552018-12-04 14:18:15 -0800155 'LAYERS': get_layers(d.getVar("BBLAYERS"))}
156 return configuration
157get_testimage_configuration[vardepsexclude] = "DATETIME"
158
159def 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
166def get_testimage_result_id(configuration):
167 return '%s_%s_%s_%s' % (configuration['TEST_TYPE'], configuration['IMAGE_BASENAME'], configuration['MACHINE'], configuration['STARTTIME'])
168
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500169def 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 Bishopd5ae7d92018-06-14 09:52:03 -0700189 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 Bishop6e60e8b2018-02-01 10:27:11 -0500195 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 Bishop1a4b7ee2018-12-16 17:11:34 -0800253 (d.getVar('MACHINE') in qemu_use_kvm.split() or \
254 oe.types.boolean(qemu_use_kvm) and 'x86' in machine):
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500255 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 Williamsc124f4f2015-09-15 14:41:29 -0500278
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500279 # we need the host dumper in test context
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500280 host_dumper = OERuntimeTestContextExecutor.getHostDumper(
281 d.getVar("testimage_dump_host"),
282 d.getVar("TESTIMAGE_DUMP_DIR"))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500283
284 # the robot dance
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500285 target = OERuntimeTestContextExecutor.getTarget(
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500286 d.getVar("TEST_TARGET"), logger, d.getVar("TEST_TARGET_IP"),
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500287 d.getVar("TEST_SERVER_IP"), **target_kwargs)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500288
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500289 # test context
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500290 tc = OERuntimeTestContext(td, logger, target, host_dumper,
291 image_packages, extract_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500292
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500293 # Load tests before starting the target
294 test_paths = get_runtime_paths(d)
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500295 test_modules = d.getVar('TEST_SUITES').split()
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700296 if not test_modules:
297 bb.fatal('Empty test suite, please verify TEST_SUITES variable')
298
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500299 tc.loadTests(test_paths, modules=test_modules)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500300
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700301 suitecases = getSuiteCases(tc.suites)
302 if not suitecases:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500303 bb.fatal('Empty test suite, please verify TEST_SUITES variable')
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700304 else:
305 bb.debug(2, 'test suites:\n\t%s' % '\n\t'.join([str(c) for c in suitecases]))
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500306
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 Williamsc0f7c042017-02-23 20:41:17 -0600316 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500317 # 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 Williamsc0f7c042017-02-23 20:41:17 -0600324 else:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500325 bb.error('runqemu failed, shutting down...')
326 if results:
327 results.stop()
328 results = None
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600329 finally:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500330 signal.signal(signal.SIGTERM, orig_sigterm_handler)
331 tc.target.stop()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600332
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500333 # Show results (if we have them)
334 if not results:
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500335 bb.fatal('%s - FAILED - tests were interrupted during execution' % pn, forcelog=True)
Brad Bishopf86d0552018-12-04 14:18:15 -0800336 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 Bishopd7bf8c12018-02-25 22:55:05 -0500340 results.logSummary(pn)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500341 if not results.wasSuccessful():
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500342 bb.fatal('%s - FAILED - check the task log and the ssh log' % pn, forcelog=True)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600343
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500344def get_runtime_paths(d):
345 """
346 Returns a list of paths where runtime test must reside.
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500347
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500348 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
358def 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
375def create_rpm_index(d):
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800376 import glob
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500377 # 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 Bishop1a4b7ee2018-12-16 17:11:34 -0800393 # 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 Bishop6e60e8b2018-02-01 10:27:11 -0500400 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
408def 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
420testimage_main[vardepsexclude] += "BB_ORIGENV DATETIME"
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500421
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800422python () {
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 Williamsd8c66bc2016-06-20 12:57:21 -0500427inherit testsdk