1
0
mirror of https://git.yoctoproject.org/poky synced 2026-06-08 03:20:47 +00:00

testimage.bbclass: Migrate class to use new runtime framework

This migrates testimage class to use the new framework. Most of
the code added here is to get rid off the data store dependency.

[YOCTO #10234]

(From OE-Core rev: 2aa5a4954d7610f31875ba7e655f25f8892517b6)

Signed-off-by: Mariano Lopez <mariano.lopez@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Mariano Lopez
2017-01-05 13:33:07 +00:00
committed by Richard Purdie
parent 211c5be54c
commit 3857e5c91d
+147 -45
View File
@@ -77,6 +77,7 @@ TESTIMAGEDEPENDS_qemuall += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'creat
TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'python-smartpm-native:do_populate_sysroot', '', d)}" TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'python-smartpm-native:do_populate_sysroot', '', d)}"
TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'ipk', 'opkg-utils-native:do_populate_sysroot', '', d)}" TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'ipk', 'opkg-utils-native:do_populate_sysroot', '', d)}"
TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'deb', 'apt-native:do_populate_sysroot', '', d)}" TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'deb', 'apt-native:do_populate_sysroot', '', d)}"
TESTIMAGEDEPENDS += "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'python-smartpm-native:do_populate_sysroot', '', d)}"
TESTIMAGELOCK = "${TMPDIR}/testimage.lock" TESTIMAGELOCK = "${TMPDIR}/testimage.lock"
@@ -112,6 +113,9 @@ testimage_dump_host () {
} }
python do_testimage() { python do_testimage() {
testimage_sanity(d)
testimage_main(d) testimage_main(d)
} }
@@ -120,67 +124,165 @@ do_testimage[nostamp] = "1"
do_testimage[depends] += "${TESTIMAGEDEPENDS}" do_testimage[depends] += "${TESTIMAGEDEPENDS}"
do_testimage[lockfiles] += "${TESTIMAGELOCK}" do_testimage[lockfiles] += "${TESTIMAGELOCK}"
def testimage_main(d): def testimage_sanity(d):
import unittest if (d.getVar('TEST_TARGET') == 'simpleremote'
import os and (not d.getVar('TEST_TARGET_IP')
import oeqa.runtime or not d.getVar('TEST_SERVER_IP'))):
import time bb.fatal('When TEST_TARGET is set to "simpleremote" '
import signal 'TEST_TARGET_IP and TEST_SERVER_IP are needed too.')
from oeqa.oetest import ImageTestContext
from oeqa.targetcontrol import get_target_controller
from bb.utils import export_proxies
from oeqa.utils.dump import HostDumper
def testimage_main(d):
import os
import signal
import json
import sys
import logging
import time
from bb.utils import export_proxies
from oeqa.runtime.context import OERuntimeTestContext
from oeqa.runtime.context import OERuntimeTestContextExecutor
from oeqa.core.target.qemu import supported_fstypes
from oeqa.utils import make_logger_bitbake_compatible
def sigterm_exception(signum, stackframe):
"""
Catch SIGTERM from worker in order to stop qemu.
"""
raise RuntimeError
logger = make_logger_bitbake_compatible(logging.getLogger("BitBake"))
pn = d.getVar("PN") pn = d.getVar("PN")
bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR")) bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR"))
test_create_extract_dirs(d) #test_create_extract_dirs(d)
image_name = ("%s/%s" % (d.getVar('DEPLOY_DIR_IMAGE'),
d.getVar('IMAGE_LINK_NAME')))
tdname = "%s.testdata.json" % image_name
td = json.load(open(tdname, "r"))
image_manifest = "%s.manifest" % image_name
image_packages = OERuntimeTestContextExecutor.readPackagesManifest(image_manifest)
# Get machine
machine = d.getVar("MACHINE")
# Get rootfs
fstypes = [fs for fs in d.getVar('IMAGE_FSTYPES').split(' ')
if fs in supported_fstypes]
if not fstypes:
bb.fatal('Unsupported image type built. Add a comptible image to '
'IMAGE_FSTYPES. Supported types: %s' %
', '.join(supported_fstypes))
rootfs = '%s.%s' % (image_name, fstypes[0])
# Get tmpdir (not really used, just for compatibility)
tmpdir = d.getVar("TMPDIR")
# Get deploy_dir_image (not really used, just for compatibility)
dir_image = d.getVar("DEPLOY_DIR_IMAGE")
# Get bootlog
bootlog = os.path.join(d.getVar("TEST_LOG_DIR"),
'qemu_boot_log.%s' % d.getVar('DATETIME'))
# Get display
display = d.getVar("BB_ORIGENV").getVar("DISPLAY")
# Get kernel
kernel_name = ('%s-%s.bin' % (d.getVar("KERNEL_IMAGETYPE"), machine))
kernel = os.path.join(d.getVar("DEPLOY_DIR_IMAGE"), kernel_name)
# Get boottime
boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT"))
# Get use_kvm
qemu_use_kvm = d.getVar("QEMU_USE_KVM")
if qemu_use_kvm and qemu_use_kvm == 'True' and 'x86' in machine:
kvm = True
else:
kvm = False
# TODO: We use the current implementatin of qemu runner because of
# time constrains, qemu runner really needs a refactor too.
target_kwargs = { 'machine' : machine,
'rootfs' : rootfs,
'tmpdir' : tmpdir,
'dir_image' : dir_image,
'display' : display,
'kernel' : kernel,
'boottime' : boottime,
'bootlog' : bootlog,
'kvm' : kvm,
}
# runtime use network for download projects for build # runtime use network for download projects for build
export_proxies(d) export_proxies(d)
# we need the host dumper in test context # we need the host dumper in test context
host_dumper = HostDumper(d.getVar("testimage_dump_host", True), host_dumper = OERuntimeTestContextExecutor.getHostDumper(
d.getVar("TESTIMAGE_DUMP_DIR", True)) d.getVar("testimage_dump_host"),
d.getVar("TESTIMAGE_DUMP_DIR"))
# the robot dance # the robot dance
target = get_target_controller(d) target = OERuntimeTestContextExecutor.getTarget(
d.getVar("TEST_TARGET"), None, d.getVar("TEST_TARGET_IP"),
d.getVar("TEST_SERVER_IP"), **target_kwargs)
# test context # test context
tc = ImageTestContext(d, target, host_dumper) tc = OERuntimeTestContext(td, logger, target, host_dumper, image_packages)
# this is a dummy load of tests # Load tests before starting the target
# we are doing that to find compile errors in the tests themselves test_paths = get_runtime_paths(d)
# before booting the image test_modules = d.getVar('TEST_SUITES')
try: tc.loadTests(test_paths, modules=test_modules)
tc.loadTests()
except Exception as e:
import traceback
bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
tc.extract_packages() bootparams = None
target.deploy() if d.getVar('VIRTUAL-RUNTIME_init_manager', '') == 'systemd':
bootparams = 'systemd.log_level=debug systemd.log_target=console'
results = None
orig_sigterm_handler = signal.signal(signal.SIGTERM, sigterm_exception)
try: try:
bootparams = None # We need to check if runqemu ends unexpectedly
if d.getVar('VIRTUAL-RUNTIME_init_manager', '') == 'systemd': # or if the worker send us a SIGTERM
bootparams = 'systemd.log_level=debug systemd.log_target=console' tc.target.start(extra_bootparams=bootparams)
target.start(extra_bootparams=bootparams) results = tc.runTests()
starttime = time.time() except (RuntimeError, BlockingIOError) as err:
result = tc.runTests() if isinstance(err, RuntimeError):
stoptime = time.time() bb.error('testimage received SIGTERM, shutting down...')
if result.wasSuccessful():
bb.plain("%s - Ran %d test%s in %.3fs" % (pn, result.testsRun, result.testsRun != 1 and "s" or "", stoptime - starttime))
msg = "%s - OK - All required tests passed" % pn
skipped = len(result.skipped)
if skipped:
msg += " (skipped=%d)" % skipped
bb.plain(msg)
else: else:
bb.fatal("%s - FAILED - check the task log and the ssh log" % pn) bb.error('runqemu failed, shutting down...')
except BlockingIOError as err: if results:
bb.error('runqemu failed, shutting down...') results.stop()
results = None
finally: finally:
signal.signal(signal.SIGTERM, tc.origsigtermhandler) signal.signal(signal.SIGTERM, orig_sigterm_handler)
target.stop() tc.target.stop()
# Show results (if we have them)
if not results:
bb.fatal('%s - FAILED - tests were interrupted during execution' % pn)
tc.logSummary(results, pn)
tc.logDetails()
if not results.wasSuccessful():
bb.fatal('%s - FAILED - check the task log and the ssh log' % pn)
def get_runtime_paths(d):
"""
Returns a list of paths where runtime test must reside.
Runtime tests are expected in <LAYER_DIR>/lib/oeqa/runtime/cases/
"""
paths = []
for layer in d.getVar('BBLAYERS').split():
path = os.path.join(layer, 'lib/oeqa/runtime/cases')
if os.path.isdir(path):
paths.append(path)
return paths
def test_create_extract_dirs(d): def test_create_extract_dirs(d):
install_path = d.getVar("TEST_INSTALL_TMP_DIR") install_path = d.getVar("TEST_INSTALL_TMP_DIR")
@@ -193,6 +295,6 @@ def test_create_extract_dirs(d):
bb.utils.mkdirhier(extracted_path) bb.utils.mkdirhier(extracted_path)
testimage_main[vardepsexclude] =+ "BB_ORIGENV" testimage_main[vardepsexclude] += "BB_ORIGENV DATETIME"
inherit testsdk inherit testsdk