Yocto 2.3

Move OpenBMC to Yocto 2.3(pyro).

Tested: Built and verified Witherspoon and Palmetto images
Change-Id: I50744030e771f4850afc2a93a10d3507e76d36bc
Signed-off-by: Brad Bishop <bradleyb@fuzziesquirrel.com>
Resolves: openbmc/openbmc#2461
diff --git a/import-layers/yocto-poky/meta/classes/testsdk.bbclass b/import-layers/yocto-poky/meta/classes/testsdk.bbclass
index 43342b1..6a201aa 100644
--- a/import-layers/yocto-poky/meta/classes/testsdk.bbclass
+++ b/import-layers/yocto-poky/meta/classes/testsdk.bbclass
@@ -14,66 +14,72 @@
 #
 # where "<image-name>" is an image like core-image-sato.
 
-TEST_LOG_DIR ?= "${WORKDIR}/testimage"
-TESTSDKLOCK = "${TMPDIR}/testsdk.lock"
+def testsdk_main(d):
+    import os
+    import subprocess
+    import json
+    import logging
 
-def run_test_context(CTestContext, d, testdir, tcname, pn, *args):
-    import glob
-    import time
+    from bb.utils import export_proxies
+    from oeqa.core.runner import OEStreamLogger
+    from oeqa.sdk.context import OESDKTestContext, OESDKTestContextExecutor
+    from oeqa.utils import make_logger_bitbake_compatible
 
-    targets = glob.glob(d.expand(testdir + "/tc/environment-setup-*"))
-    for sdkenv in targets:
-        bb.plain("Testing %s" % sdkenv)
-        tc = CTestContext(d, testdir, sdkenv, tcname, args)
+    pn = d.getVar("PN")
+    logger = make_logger_bitbake_compatible(logging.getLogger("BitBake"))
 
-        # this is a dummy load of tests
-        # we are doing that to find compile errors in the tests themselves
-        # before booting the image
+    # sdk use network for download projects for build
+    export_proxies(d)
+
+    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)
+
+    tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAIN_OUTPUTNAME}.testdata.json")
+    test_data = json.load(open(tdname, "r"))
+
+    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./\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"))
+
+    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()
+            tc.loadTests(OESDKTestContextExecutor.default_cases)
         except Exception as e:
             import traceback
             bb.fatal("Loading tests failed:\n%s" % traceback.format_exc())
 
-        starttime = time.time()
         result = tc.runTests()
-        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:
-            bb.fatal("%s - FAILED - check the task log and the commands log" % pn)
 
-def testsdk_main(d):
-    import os
-    import oeqa.sdk
-    import subprocess
-    from oeqa.oetest import SDKTestContext
+        component = "%s %s" % (pn, OESDKTestContextExecutor.name)
+        context_msg = "%s:%s" % (os.path.basename(tcname), os.path.basename(sdk_env))
 
-    pn = d.getVar("PN", True)
-    bb.utils.mkdirhier(d.getVar("TEST_LOG_DIR", True))
+        tc.logSummary(result, component, context_msg)
+        tc.logDetails()
 
-    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' .")
+        if not result.wasSuccessful():
+            fail = True
 
-    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.decode("utf-8"))
-
-    try:
-        run_test_context(SDKTestContext, d, sdktestdir, tcname, pn)
-    finally:
-        bb.utils.remove(sdktestdir, True)
-
+    if fail:
+        bb.fatal("%s - FAILED - check the task log and the commands log" % pn)
+  
 testsdk_main[vardepsexclude] =+ "BB_ORIGENV"
 
 python do_testsdk() {
@@ -81,46 +87,52 @@
 }
 addtask testsdk
 do_testsdk[nostamp] = "1"
-do_testsdk[lockfiles] += "${TESTSDKLOCK}"
-
-TEST_LOG_SDKEXT_DIR ?= "${WORKDIR}/testsdkext"
-TESTSDKEXTLOCK = "${TMPDIR}/testsdkext.lock"
 
 def testsdkext_main(d):
     import os
-    import oeqa.sdkext
+    import json
     import subprocess
-    from bb.utils import export_proxies
-    from oeqa.oetest import SDKTestContext, SDKExtTestContext
-    from oeqa.utils import avoid_paths_in_environ
+    import logging
 
+    from bb.utils import export_proxies
+    from oeqa.utils import avoid_paths_in_environ, make_logger_bitbake_compatible, subprocesstweak
+    from oeqa.sdkext.context import OESDKExtTestContext, OESDKExtTestContextExecutor
+
+    pn = d.getVar("PN")
+    logger = make_logger_bitbake_compatible(logging.getLogger("BitBake"))
 
     # extensible sdk use network
     export_proxies(d)
 
+    subprocesstweak.errors_have_output()
+
     # extensible sdk can be contaminated if native programs are
     # in PATH, i.e. use perl-native instead of eSDK one.
-    paths_to_avoid = [d.getVar('STAGING_DIR', True),
-                      d.getVar('BASE_WORKDIR', True)]
+    paths_to_avoid = [d.getVar('STAGING_DIR'),
+                      d.getVar('BASE_WORKDIR')]
     os.environ['PATH'] = avoid_paths_in_environ(paths_to_avoid)
 
-    pn = d.getVar("PN", True)
-    bb.utils.mkdirhier(d.getVar("TEST_LOG_SDKEXT_DIR", True))
-
     tcname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.sh")
     if not os.path.exists(tcname):
-        bb.fatal("The toolchain ext is not built. Build it before running the" \
-                 " tests: 'bitbake <image> -c populate_sdk_ext' .")
+        bb.fatal("The toolchain ext %s is not built. Build it before running the" \
+                 " tests: 'bitbake <image> -c populate_sdk_ext' ." % tcname)
 
-    testdir = d.expand("${WORKDIR}/testsdkext/")
-    bb.utils.remove(testdir, True)
-    bb.utils.mkdirhier(testdir)
-    sdkdir = os.path.join(testdir, 'tc')
+    tdname = d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.testdata.json")
+    test_data = json.load(open(tdname, "r"))
+
+    target_pkg_manifest = OESDKExtTestContextExecutor._load_manifest(
+        d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.target.manifest"))
+    host_pkg_manifest = OESDKExtTestContextExecutor._load_manifest(
+        d.expand("${SDK_DEPLOY}/${TOOLCHAINEXT_OUTPUTNAME}.host.manifest"))
+
+    sdk_dir = d.expand("${WORKDIR}/testsdkext/")
+    bb.utils.remove(sdk_dir, True)
+    bb.utils.mkdirhier(sdk_dir)
     try:
-        subprocess.check_output("%s -y -d %s" % (tcname, sdkdir), shell=True)
+        subprocess.check_output("%s -y -d %s" % (tcname, sdk_dir), shell=True)
     except subprocess.CalledProcessError as e:
         msg = "Couldn't install the extensible SDK:\n%s" % e.output.decode("utf-8")
-        logfn = os.path.join(sdkdir, 'preparing_build_system.log')
+        logfn = os.path.join(sdk_dir, 'preparing_build_system.log')
         if os.path.exists(logfn):
             msg += '\n\nContents of preparing_build_system.log:\n'
             with open(logfn, 'r') as f:
@@ -128,19 +140,47 @@
                     msg += line
         bb.fatal(msg)
 
-    try:
-        bb.plain("Running SDK Compatibility tests ...")
-        run_test_context(SDKExtTestContext, d, testdir, tcname, pn, True)
-    finally:
-        pass
+    fail = False
+    sdk_envs = OESDKExtTestContextExecutor._get_sdk_environs(sdk_dir)
+    for s in sdk_envs:
+        bb.plain("Extensible SDK testing environment: %s" % s)
 
-    try:
-        bb.plain("Running Extensible SDK tests ...")
-        run_test_context(SDKExtTestContext, d, testdir, tcname, pn)
-    finally:
-        pass
+        sdk_env = sdk_envs[s]
 
-    bb.utils.remove(testdir, True)
+        # Use our own SSTATE_DIR and DL_DIR so that updates to the eSDK come from our sstate cache
+        # and we don't spend hours downloading kernels for the kernel module test
+        # Abuse auto.conf since local.conf would be overwritten by the SDK
+        with open(os.path.join(sdk_dir, 'conf', 'auto.conf'), 'a+') as f:
+            f.write('SSTATE_MIRRORS += " \\n file://.* file://%s/PATH"\n' % test_data.get('SSTATE_DIR'))
+            f.write('SOURCE_MIRROR_URL = "file://%s"\n' % test_data.get('DL_DIR'))
+            f.write('INHERIT += "own-mirrors"')
+
+        # We need to do this in case we have a minimal SDK
+        subprocess.check_output(". %s > /dev/null; devtool sdk-install meta-extsdk-toolchain" % sdk_env, cwd=sdk_dir, shell=True)
+
+        tc = OESDKExtTestContext(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(OESDKExtTestContextExecutor.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, OESDKExtTestContextExecutor.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)
 
 testsdkext_main[vardepsexclude] =+ "BB_ORIGENV"
 
@@ -149,4 +189,4 @@
 }
 addtask testsdkext
 do_testsdkext[nostamp] = "1"
-do_testsdkext[lockfiles] += "${TESTSDKEXTLOCK}"
+