[OE-core] [PATCHv3 20/30] classes/testsdk: Migrates testsdk.bbclass to use new OESDKTestContext

Aníbal Limón anibal.limon at linux.intel.com
Thu Dec 8 16:20:48 UTC 2016


The functionality provided is the same with imporvements on code
reuse and better interfaces.

Signed-off-by: Aníbal Limón <anibal.limon at linux.intel.com>
---
 meta/classes/testsdk.bbclass | 67 ++++++++++++++++++++++++++++++++++++--------
 1 file changed, 55 insertions(+), 12 deletions(-)

diff --git a/meta/classes/testsdk.bbclass b/meta/classes/testsdk.bbclass
index 06b4c50..959fb38 100644
--- a/meta/classes/testsdk.bbclass
+++ b/meta/classes/testsdk.bbclass
@@ -50,30 +50,74 @@ def run_test_context(CTestContext, d, testdir, tcname, pn, *args):
 
 def testsdk_main(d):
     import os
-    import oeqa.sdk
     import subprocess
-    from oeqa.oetest import SDKTestContext
+    import json
+    import logging
+
+    from bb.utils import export_proxies
+    from oeqa.core.runner import OEStreamLogger
+    from oeqa.sdk.context import OESDKTestContext, OESDKTestContextExecutor
 
     pn = d.getVar("PN", True)
-    bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True))
+    logger = logging.getLogger("BitBake")
+
+    # sdk use network for download projects for build
+    export_proxies(d)
+
+    test_log_dir = d.getVar("TEST_LOG_DIR", True)
+
+    bb.utils.mkdirhier(test_log_dir)
 
     tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.sh")
     if not os.path.exists(tcname):
         bb.fatal("The toolchain %s is not built. Build it before running the tests: 'bitbake <image> -c populate_sdk' ." % tcname)
 
-    sdktestdir = d.expand("${WORKDIR}/testimage-sdk/")
-    bb.utils.remove(sdktestdir, True)
-    bb.utils.mkdirhier(sdktestdir)
+    tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.testdata.json")
+    test_data = json.load(open(tdname, "r"))
+    test_data['TEST_LOG_DIR'] = test_log_dir
+
+    target_pkg_manifest = OESDKTestContextExecutor._load_manifest(
+        d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.target.manifest"))
+    host_pkg_manifest = OESDKTestContextExecutor._load_manifest(
+        d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.host.manifest"))
+
+    sdk_dir = d.expand("${WORKDIR}/testimage-sdk/")
+    bb.utils.remove(sdk_dir, True)
+    bb.utils.mkdirhier(sdk_dir)
     try:
-        subprocess.check_output("cd %s; %s <<EOF\n./tc\nY\nEOF" % (sdktestdir, tcname), shell=True)
+        subprocess.check_output("cd %s; %s <<EOF\n./\nY\nEOF" % (sdk_dir, tcname), shell=True)
     except subprocess.CalledProcessError as e:
         bb.fatal("Couldn't install the SDK:\n%s" % e.output.decode("utf-8"))
 
-    try:
-        run_test_context(SDKTestContext, d, sdktestdir, tcname, pn)
-    finally:
-        bb.utils.remove(sdktestdir, True)
+    fail = False
+    sdk_envs = OESDKTestContextExecutor._get_sdk_environs(sdk_dir)
+    for s in sdk_envs:
+        sdk_env = sdk_envs[s]
+        bb.plain("SDK testing environment: %s" % s)
+        tc = OESDKTestContext(td=test_data, logger=logger, sdk_dir=sdk_dir,
+            sdk_env=sdk_env, target_pkg_manifest=target_pkg_manifest,
+            host_pkg_manifest=host_pkg_manifest)
 
+        try:
+            tc.loadTests(OESDKTestContextExecutor.default_cases)
+        except Exception as e:
+            import traceback
+            bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
+
+        result = tc.runTests()
+
+        component = "%s %s" % (pn, OESDKTestContextExecutor.name)
+        context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env))
+
+        tc.logSummary(result, component, context_msg)
+        tc.logDetails()
+
+        if not result.wasSuccessful():
+            fail = True
+
+    if fail:
+        bb.fatal("%s - FAILED - check the task log and the commands log" % pn)
+  
 testsdk_main[vardepsexclude] =+ "BB_ORIGENV"
 
 python do_testsdk() {
@@ -94,7 +138,6 @@ def testsdkext_main(d):
     from oeqa.oetest import SDKTestContext, SDKExtTestContext
     from oeqa.utils import avoid_paths_in_environ
 
-
     # extensible sdk use network
     export_proxies(d)
 
-- 
2.1.4




More information about the Openembedded-core mailing list