diff options
Diffstat (limited to 'yocto-poky/meta/classes/testimage.bbclass')
-rw-r--r-- | yocto-poky/meta/classes/testimage.bbclass | 259 |
1 files changed, 37 insertions, 222 deletions
diff --git a/yocto-poky/meta/classes/testimage.bbclass b/yocto-poky/meta/classes/testimage.bbclass index b4d4a69b0..e77bb1192 100644 --- a/yocto-poky/meta/classes/testimage.bbclass +++ b/yocto-poky/meta/classes/testimage.bbclass @@ -33,17 +33,27 @@ TEST_EXPORT_DIR ?= "${TMPDIR}/testimage/${PN}" TEST_EXPORT_ONLY ?= "0" RPMTESTSUITE = "${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'smart rpm', '', d)}" - -DEFAULT_TEST_SUITES = "ping auto" -DEFAULT_TEST_SUITES_pn-core-image-minimal = "ping" -DEFAULT_TEST_SUITES_pn-core-image-sato = "ping ssh df connman syslog xorg scp vnc date dmesg parselogs ${RPMTESTSUITE} \ +MINTESTSUITE = "ping" +NETTESTSUITE = "${MINTESTSUITE} ssh df date scp syslog" +DEVTESTSUITE = "gcc kernelmodule ldd" + +DEFAULT_TEST_SUITES = "${MINTESTSUITE} auto" +DEFAULT_TEST_SUITES_pn-core-image-minimal = "${MINTESTSUITE}" +DEFAULT_TEST_SUITES_pn-core-image-minimal-dev = "${MINTESTSUITE}" +DEFAULT_TEST_SUITES_pn-core-image-full-cmdline = "${NETTESTSUITE} perl python logrotate" +DEFAULT_TEST_SUITES_pn-core-image-x11 = "${MINTESTSUITE}" +DEFAULT_TEST_SUITES_pn-core-image-lsb = "${NETTESTSUITE} pam parselogs ${RPMTESTSUITE}" +DEFAULT_TEST_SUITES_pn-core-image-sato = "${NETTESTSUITE} connman xorg parselogs ${RPMTESTSUITE} \ ${@bb.utils.contains('IMAGE_PKGTYPE', 'rpm', 'python', '', d)}" -DEFAULT_TEST_SUITES_pn-core-image-sato-sdk = "ping ssh df connman syslog xorg scp vnc date perl ldd gcc kernelmodule dmesg python parselogs ${RPMTESTSUITE}" -DEFAULT_TEST_SUITES_pn-core-image-lsb-sdk = "ping buildcvs buildiptables buildsudoku connman date df gcc kernelmodule ldd pam parselogs perl python scp ${RPMTESTSUITE} ssh syslog logrotate" +DEFAULT_TEST_SUITES_pn-core-image-sato-sdk = "${NETTESTSUITE} connman xorg perl python \ + ${DEVTESTSUITE} parselogs ${RPMTESTSUITE}" +DEFAULT_TEST_SUITES_pn-core-image-lsb-dev = "${NETTESTSUITE} pam perl python parselogs ${RPMTESTSUITE}" +DEFAULT_TEST_SUITES_pn-core-image-lsb-sdk = "${NETTESTSUITE} buildcvs buildiptables buildsudoku \ + connman ${DEVTESTSUITE} pam perl python parselogs ${RPMTESTSUITE}" DEFAULT_TEST_SUITES_pn-meta-toolchain = "auto" # aarch64 has no graphics -DEFAULT_TEST_SUITES_remove_aarch64 = "xorg vnc" +DEFAULT_TEST_SUITES_remove_aarch64 = "xorg" #qemumips is too slow for buildsudoku DEFAULT_TEST_SUITES_remove_qemumips = "buildsudoku" @@ -98,82 +108,6 @@ do_testimage[nostamp] = "1" do_testimage[depends] += "${TESTIMAGEDEPENDS}" do_testimage[lockfiles] += "${TESTIMAGELOCK}" -python do_testsdk() { - testsdk_main(d) -} -addtask testsdk -do_testsdk[nostamp] = "1" -do_testsdk[depends] += "${TESTIMAGEDEPENDS}" -do_testsdk[lockfiles] += "${TESTIMAGELOCK}" - -# get testcase list from specified file -# if path is a relative path, then relative to build/conf/ -def read_testlist(d, fpath): - if not os.path.isabs(fpath): - builddir = d.getVar("TOPDIR", True) - fpath = os.path.join(builddir, "conf", fpath) - if not os.path.exists(fpath): - bb.fatal("No such manifest file: ", fpath) - tcs = [] - for line in open(fpath).readlines(): - line = line.strip() - if line and not line.startswith("#"): - tcs.append(line) - return " ".join(tcs) - -def get_tests_list(d, type="runtime"): - testsuites = [] - testslist = [] - manifests = d.getVar("TEST_SUITES_MANIFEST", True) - if manifests is not None: - manifests = manifests.split() - for manifest in manifests: - testsuites.extend(read_testlist(d, manifest).split()) - else: - testsuites = d.getVar("TEST_SUITES", True).split() - if type == "sdk": - testsuites = (d.getVar("TEST_SUITES_SDK", True) or "auto").split() - bbpath = d.getVar("BBPATH", True).split(':') - - # This relies on lib/ under each directory in BBPATH being added to sys.path - # (as done by default in base.bbclass) - for testname in testsuites: - if testname != "auto": - if testname.startswith("oeqa."): - testslist.append(testname) - continue - found = False - for p in bbpath: - if os.path.exists(os.path.join(p, 'lib', 'oeqa', type, testname + '.py')): - testslist.append("oeqa." + type + "." + testname) - found = True - break - elif os.path.exists(os.path.join(p, 'lib', 'oeqa', type, testname.split(".")[0] + '.py')): - testslist.append("oeqa." + type + "." + testname) - found = True - break - if not found: - bb.fatal('Test %s specified in TEST_SUITES could not be found in lib/oeqa/runtime under BBPATH' % testname) - - if "auto" in testsuites: - def add_auto_list(path): - if not os.path.exists(os.path.join(path, '__init__.py')): - bb.fatal('Tests directory %s exists but is missing __init__.py' % path) - files = sorted([f for f in os.listdir(path) if f.endswith('.py') and not f.startswith('_')]) - for f in files: - module = 'oeqa.' + type + '.' + f[:-3] - if module not in testslist: - testslist.append(module) - - for p in bbpath: - testpath = os.path.join(p, 'lib', 'oeqa', type) - bb.debug(2, 'Searching for tests in %s' % testpath) - if os.path.exists(testpath): - add_auto_list(testpath) - - return testslist - - def exportTests(d,tc): import json import shutil @@ -188,13 +122,13 @@ def exportTests(d,tc): savedata["host_dumper"] = {} for key in tc.__dict__: # special cases - if key != "d" and key != "target" and key != "host_dumper": + if key not in ['d', 'target', 'host_dumper', 'suite']: savedata[key] = getattr(tc, key) savedata["target"]["ip"] = tc.target.ip or d.getVar("TEST_TARGET_IP", True) savedata["target"]["server_ip"] = tc.target.server_ip or d.getVar("TEST_SERVER_IP", True) keys = [ key for key in d.keys() if not key.startswith("_") and not key.startswith("BB") \ - and not key.startswith("B_pn") and not key.startswith("do_") and not d.getVarFlag(key, "func")] + and not key.startswith("B_pn") and not key.startswith("do_") and not d.getVarFlag(key, "func", True)] for key in keys: try: savedata["d"][key] = d.getVar(key, True) @@ -229,11 +163,23 @@ def exportTests(d,tc): bb.utils.mkdirhier(os.path.join(exportpath, "oeqa/runtime/files")) bb.utils.mkdirhier(os.path.join(exportpath, "oeqa/utils")) # copy test modules, this should cover tests in other layers too + bbpath = d.getVar("BBPATH", True).split(':') for t in tc.testslist: + isfolder = False if re.search("\w+\.\w+\.test_\S+", t): t = '.'.join(t.split('.')[:3]) mod = pkgutil.get_loader(t) - shutil.copy2(mod.filename, os.path.join(exportpath, "oeqa/runtime")) + # More depth than usual? + if (t.count('.') > 2): + for p in bbpath: + foldername = os.path.join(p, 'lib', os.sep.join(t.split('.')).rsplit(os.sep, 1)[0]) + if os.path.isdir(foldername): + isfolder = True + target_folder = os.path.join(exportpath, "oeqa", "runtime", os.path.basename(foldername)) + if not os.path.exists(target_folder): + shutil.copytree(foldername, target_folder) + if not isfolder: + shutil.copy2(mod.filename, os.path.join(exportpath, "oeqa/runtime")) # copy __init__.py files oeqadir = pkgutil.get_loader("oeqa").filename shutil.copy2(os.path.join(oeqadir, "__init__.py"), os.path.join(exportpath, "oeqa")) @@ -253,14 +199,13 @@ def exportTests(d,tc): bb.plain("Exported tests to: %s" % exportpath) - def testimage_main(d): import unittest import os import oeqa.runtime import time import signal - from oeqa.oetest import loadTests, runTests + from oeqa.oetest import ImageTestContext from oeqa.targetcontrol import get_target_controller from oeqa.utils.dump import get_host_dumper @@ -271,65 +216,24 @@ def testimage_main(d): bb.utils.remove(d.getVar("TEST_EXPORT_DIR", True), recurse=True) bb.utils.mkdirhier(d.getVar("TEST_EXPORT_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) - # testslist is what we'll actually pass to the unittest loader - testslist = get_tests_list(d) - testsrequired = [t for t in d.getVar("TEST_SUITES", True).split() if t != "auto"] - - tagexp = d.getVar("TEST_SUITES_TAGS", True) - # we need the host dumper in test context host_dumper = get_host_dumper(d) # the robot dance target = get_target_controller(d) - class TestContext(object): - def __init__(self): - self.d = d - self.testslist = testslist - self.tagexp = tagexp - self.testsrequired = testsrequired - self.filesdir = os.path.join(os.path.dirname(os.path.abspath(oeqa.runtime.__file__)),"files") - self.target = target - self.host_dumper = host_dumper - self.imagefeatures = d.getVar("IMAGE_FEATURES", True).split() - self.distrofeatures = d.getVar("DISTRO_FEATURES", True).split() - manifest = os.path.join(d.getVar("DEPLOY_DIR_IMAGE", True), d.getVar("IMAGE_LINK_NAME", True) + ".manifest") - nomanifest = d.getVar("IMAGE_NO_MANIFEST", True) - - self.sigterm = False - self.origsigtermhandler = signal.getsignal(signal.SIGTERM) - signal.signal(signal.SIGTERM, self.sigterm_exception) - - if nomanifest is None or nomanifest != "1": - try: - with open(manifest) as f: - self.pkgmanifest = f.read() - except IOError as e: - bb.fatal("No package manifest file found. Did you build the image?\n%s" % e) - else: - self.pkgmanifest = "" - - def sigterm_exception(self, signum, stackframe): - bb.warn("TestImage received SIGTERM, shutting down...") - self.sigterm = True - self.target.stop() - # test context - tc = TestContext() + tc = ImageTestContext(d, target, host_dumper) # this is a dummy load of tests # we are doing that to find compile errors in the tests themselves # before booting the image try: - loadTests(tc) + tc.loadTests() except Exception as e: import traceback bb.fatal("Loading tests failed:\n%s" % traceback.format_exc()) - if export: signal.signal(signal.SIGTERM, tc.origsigtermhandler) tc.origsigtermhandler = None @@ -339,7 +243,7 @@ def testimage_main(d): try: target.start() starttime = time.time() - result = runTests(tc) + result = tc.runTests() 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)) @@ -356,93 +260,4 @@ def testimage_main(d): testimage_main[vardepsexclude] =+ "BB_ORIGENV" - -def testsdk_main(d): - import unittest - import os - import glob - import oeqa.runtime - import oeqa.sdk - import time - import subprocess - from oeqa.oetest import loadTests, runTests - - 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. - # testslist is what we'll actually pass to the unittest loader - testslist = get_tests_list(d, "sdk") - testsrequired = [t for t in (d.getVar("TEST_SUITES_SDK", True) or "auto").split() if t != "auto"] - - tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh") - if not os.path.exists(tcname): - bb.fatal("The toolchain is not built. Build it before running the tests: 'bitbake <image> -c populate_sdk' .") - - class TestContext(object): - 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.sdktestdir = sdktestdir - self.sdkenv = sdkenv - self.imagefeatures = d.getVar("IMAGE_FEATURES", True).split() - self.distrofeatures = d.getVar("DISTRO_FEATURES", True).split() - manifest = d.getVar("SDK_TARGET_MANIFEST", True) - try: - with open(manifest) as f: - self.pkgmanifest = f.read() - except IOError as e: - bb.fatal("No package manifest file found. Did you build the sdk image?\n%s" % e) - hostmanifest = d.getVar("SDK_HOST_MANIFEST", True) - try: - with open(hostmanifest) as f: - self.hostpkgmanifest = f.read() - except IOError as e: - bb.fatal("No host package manifest file found. Did you build the sdk image?\n%s" % e) - - sdktestdir = d.expand("${WORKDIR}/testimage-sdk/") - bb.utils.remove(sdktestdir, True) - bb.utils.mkdirhier(sdktestdir) - try: - subprocess.check_output("cd %s; %s <<EOF\n./tc\nY\nEOF" % (sdktestdir, tcname), shell=True) - except subprocess.CalledProcessError as e: - bb.fatal("Couldn't install the SDK:\n%s" % e.output) - - try: - targets = glob.glob(d.expand(sdktestdir + "/tc/environment-setup-*")) - bb.warn(str(targets)) - for sdkenv in targets: - bb.plain("Testing %s" % sdkenv) - # test context - tc = TestContext() - - # this is a dummy load of tests - # we are doing that to find compile errors in the tests themselves - # before booting the image - try: - loadTests(tc, "sdk") - except Exception as e: - import traceback - bb.fatal("Loading tests failed:\n%s" % traceback.format_exc()) - - - starttime = time.time() - result = runTests(tc, "sdk") - stoptime = time.time() - if result.wasSuccessful(): - bb.plain("%s SDK(%s):%s - Ran %d test%s in %.3fs" % (pn, os.path.basename(tcname), os.path.basename(sdkenv),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 commands log" % pn ) - finally: - bb.utils.remove(sdktestdir, True) - -testsdk_main[vardepsexclude] =+ "BB_ORIGENV" - +inherit testsdk |