diff options
author | Stefan Stanacar <stefanx.stanacar@intel.com> | 2013-11-26 11:18:22 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2013-12-03 12:51:57 +0000 |
commit | a7820350fa3271d78ed7476e02f4aef593be1125 (patch) | |
tree | 20561420d3cd1a5607f6fafe2d0f5f58d3035d42 /meta/classes/testimage.bbclass | |
parent | b7a0e1c351e396af6470e59c428128789295bd96 (diff) | |
download | openembedded-core-contrib-a7820350fa3271d78ed7476e02f4aef593be1125.tar.gz |
testimage: use the new targetcontrol.py module for running tests
This patch makes the necessary changes for using the targetcontrol.py module
so that one can run the same tests on a qemu instance or a remote machine
based on the value of TEST_TARGET variable: "qemu" or "simpleremote".
The default value is "qemu" which starts a qemu instance and it's the
with what we currently have.
With "simpleremote", the remote machine must be up with network and ssh
and you need to set TEST_TARGET_IP with the IP address of the remote machine
(it can still be a qemu instance that was manually started).
Basically testimage.bbclass now does something along the lines of:
- load tests -> deploy (prepare) / start target -> run tests.
There were a couple of changes necessary for tests and
also some cleanups/renames that were needed to adjust this change. (use
ip everywhere when refering to target and server_ip when refering to host/build machine)
Also two unnecessary and unsed methods were dropped from sshcontrol.
[ YOCTO #5554 ]
Signed-off-by: Stefan Stanacar <stefanx.stanacar@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/testimage.bbclass')
-rw-r--r-- | meta/classes/testimage.bbclass | 104 |
1 files changed, 36 insertions, 68 deletions
diff --git a/meta/classes/testimage.bbclass b/meta/classes/testimage.bbclass index 5d61c2baee7..add8009d47a 100644 --- a/meta/classes/testimage.bbclass +++ b/meta/classes/testimage.bbclass @@ -34,13 +34,19 @@ TEST_SUITES ?= "${DEFAULT_TEST_SUITES}" TEST_QEMUBOOT_TIMEOUT ?= "1000" +TEST_TARGET ?= "qemu" +TEST_TARGET_IP ?= "" +TEST_SERVER_IP ?= "" + +TESTIMAGEDEPENDS = "" +TESTIMAGEDEPENDS_qemuall = "qemu-native:do_populate_sysroot qemu-helper-native:do_populate_sysroot" + python do_testimage() { testimage_main(d) } addtask testimage do_testimage[nostamp] = "1" -do_testimage[depends] += "qemu-native:do_populate_sysroot" -do_testimage[depends] += "qemu-helper-native:do_populate_sysroot" +do_testimage[depends] += "${TESTIMAGEDEPENDS}" def get_tests_list(d): @@ -83,15 +89,12 @@ def testimage_main(d): import unittest import os import oeqa.runtime - import re - import shutil import time - from oeqa.oetest import runTests - from oeqa.utils.sshcontrol import SSHControl - from oeqa.utils.qemurunner import QemuRunner + from oeqa.oetest import loadTests, runTests + from oeqa.targetcontrol import get_target_controller - testdir = d.getVar("TEST_LOG_DIR", True) - bb.utils.mkdirhier(testdir) + pn = d.getVar("PN", True) + bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True)) # tests in TEST_SUITES become required tests # they won't be skipped even if they aren't suitable for a image (like xorg for minimal) @@ -99,81 +102,46 @@ def testimage_main(d): testslist = get_tests_list(d) testsrequired = [t for t in d.getVar("TEST_SUITES", True).split() if t != "auto"] + # the robot dance + target = get_target_controller(d) + class TestContext: def __init__(self): self.d = d self.testslist = testslist self.testsrequired = testsrequired self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files") + self.target = target # test context tc = TestContext() - # prepare qemu instance - # and boot each supported fs type - machine=d.getVar("MACHINE", True) - #will handle fs type eventually, stick with ext3 for now - #make a copy of the original rootfs and use that for tests - origrootfs=os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME",True) + '.ext3') - testrootfs=os.path.join(testdir, d.getVar("IMAGE_LINK_NAME", True) + '-testimage.ext3') + # this is a dummy load of tests + # we are doing that to find compile errors in the tests themselves + # before booting the image try: - shutil.copyfile(origrootfs, testrootfs) + loadTests(tc) except Exception as e: - bb.fatal("Error copying rootfs: %s" % e) + bb.fatal("Loading tests failed:\n %s" % e) - try: - boottime = int(d.getVar("TEST_QEMUBOOT_TIMEOUT", True)) - except ValueError: - boottime = 1000 - - qemu = QemuRunner(machine=machine, rootfs=testrootfs, - tmpdir = d.getVar("TMPDIR", True), - deploy_dir_image = d.getVar("DEPLOY_DIR_IMAGE", True), - display = d.getVar("BB_ORIGENV", False).getVar("DISPLAY", True), - logfile = os.path.join(testdir, "qemu_boot_log.%s" % d.getVar('DATETIME', True)), - boottime = boottime) - - qemuloglink = os.path.join(testdir, "qemu_boot_log") - if os.path.islink(qemuloglink): - os.unlink(qemuloglink) - os.symlink(qemu.logfile, qemuloglink) - - sshlog = os.path.join(testdir, "ssh_target_log.%s" % d.getVar('DATETIME', True)) - sshloglink = os.path.join(testdir, "ssh_target_log") - if os.path.islink(sshloglink): - os.unlink(sshloglink) - os.symlink(sshlog, sshloglink) - - bb.note("DISPLAY value: %s" % qemu.display) - bb.note("rootfs file: %s" % qemu.rootfs) - bb.note("Qemu log file: %s" % qemu.logfile) - bb.note("SSH log file: %s" % sshlog) + target.deploy() - pn = d.getVar("PN", True) - #catch exceptions when loading or running tests (mostly our own errors) try: - if qemu.launch(): - - # set more context - ssh instance and qemu - # we do these here because we needed qemu to boot and get the ip - tc.qemu = qemu - tc.target = SSHControl(host=qemu.ip,logfile=sshlog) - # run tests and get the results - starttime = time.time() - result = runTests(tc) - stoptime = time.time() - 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: - raise bb.build.FuncFailed("%s - FAILED - check the task log and the ssh log" % pn ) + target.start() + # run tests and get the results + starttime = time.time() + result = runTests(tc) + stoptime = time.time() + 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: - raise bb.build.FuncFailed("%s - FAILED to start qemu - check the task log and the boot log" % pn) + raise bb.build.FuncFailed("%s - FAILED - check the task log and the ssh log" % pn ) finally: - qemu.kill() + target.stop() testimage_main[vardepsexclude] =+ "BB_ORIGENV" |