]> git.proxmox.com Git - mirror_edk2.git/commitdiff
.pytool: Add CI support for host based unit tests with results
authorMichael D Kinney <michael.d.kinney@intel.com>
Wed, 22 Jan 2020 18:17:23 +0000 (10:17 -0800)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Fri, 7 Feb 2020 19:18:53 +0000 (19:18 +0000)
https://bugzilla.tianocore.org/show_bug.cgi?id=2505

* Add plugin to build and run host based unit tests
* Add plugin that performs a DSC complete check DSC files
  used to build host based tests
* Update DscCompleteCheck plugin to ignore module INFs with
  a MODULE_TYPE of HOST_APPLICATION and library INFs that
  only support a module type of HOST_APPLICATION.
* Fix issues in XML reports from checkers.

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Liming Gao <liming.gao@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Bret Barkelew <Bret.Barkelew@microsoft.com>
14 files changed:
.pytool/CISettings.py
.pytool/Plugin/CharEncodingCheck/CharEncodingCheck.py
.pytool/Plugin/CompilerPlugin/CompilerPlugin.py
.pytool/Plugin/DependencyCheck/DependencyCheck.py
.pytool/Plugin/DscCompleteCheck/DscCompleteCheck.py
.pytool/Plugin/DscCompleteCheck/Readme.md
.pytool/Plugin/GuidCheck/GuidCheck.py
.pytool/Plugin/HostUnitTestCompilerPlugin/HostUnitTestCompilerPlugin.py [new file with mode: 0644]
.pytool/Plugin/HostUnitTestCompilerPlugin/HostUnitTestCompiler_plug_in.yaml [new file with mode: 0644]
.pytool/Plugin/HostUnitTestCompilerPlugin/Readme.md [new file with mode: 0644]
.pytool/Plugin/HostUnitTestDscCompleteCheck/HostUnitTestDscCompleteCheck.py [new file with mode: 0644]
.pytool/Plugin/HostUnitTestDscCompleteCheck/HostUnitTestDscCompleteCheck_plug_in.yaml [new file with mode: 0644]
.pytool/Plugin/HostUnitTestDscCompleteCheck/Readme.md [new file with mode: 0644]
.pytool/Plugin/LibraryClassCheck/LibraryClassCheck.py

index ce177937e135f778cc811f1d53d88aa7c7b10fd5..79593d9dc514d6c99f859102028371ceea308d98 100644 (file)
@@ -48,7 +48,8 @@ class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManag
                 "FmpDevicePkg",\r
                 "ShellPkg",\r
                 "FatPkg",\r
-                "CryptoPkg"\r
+                "CryptoPkg",\r
+                "UnitTestFrameworkPkg"\r
                 )\r
 \r
     def GetArchitecturesSupported(self):\r
@@ -117,10 +118,13 @@ class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManag
 \r
     def GetActiveScopes(self):\r
         ''' return tuple containing scopes that should be active for this process '''\r
-        scopes = ("cibuild","edk2-build")\r
+        scopes = ("cibuild", "edk2-build", "host-based-test")\r
 \r
         self.ActualToolChainTag = shell_environment.GetBuildVars().GetValue("TOOL_CHAIN_TAG", "")\r
 \r
+        if GetHostInfo().os.upper() == "WINDOWS":\r
+            scopes += ('host-test-win',)\r
+\r
         if GetHostInfo().os.upper() == "LINUX" and self.ActualToolChainTag.upper().startswith("GCC"):\r
             if "AARCH64" in self.ActualArchitectures:\r
                 scopes += ("gcc_aarch64_linux",)\r
@@ -133,18 +137,21 @@ class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManag
         ''' return iterable containing RequiredSubmodule objects.\r
         If no RequiredSubmodules return an empty iterable\r
         '''\r
-        rs=[]\r
+        rs = []\r
         rs.append(RequiredSubmodule(\r
             "ArmPkg/Library/ArmSoftFloatLib/berkeley-softfloat-3", False))\r
         rs.append(RequiredSubmodule(\r
             "CryptoPkg/Library/OpensslLib/openssl", False))\r
+        rs.append(RequiredSubmodule(\r
+            "UnitTestFrameworkPkg/Library/CmockaLib/cmocka", False))\r
         return rs\r
 \r
     def GetName(self):\r
         return "Edk2"\r
 \r
     def GetDependencies(self):\r
-        return []\r
+        return [\r
+        ]\r
 \r
     def GetPackagesPath(self):\r
         return ()\r
@@ -155,10 +162,11 @@ class Settings(CiBuildSettingsManager, UpdateSettingsManager, SetupSettingsManag
 \r
     def FilterPackagesToTest(self, changedFilesList: list, potentialPackagesList: list) -> list:\r
         ''' Filter potential packages to test based on changed files. '''\r
-        build_these_packages=[]\r
-        possible_packages=potentialPackagesList.copy()\r
+        build_these_packages = []\r
+        possible_packages = potentialPackagesList.copy()\r
         for f in changedFilesList:\r
-            nodes=f.split("/")  # split each part of path for comparison later\r
+            # split each part of path for comparison later\r
+            nodes = f.split("/")\r
 \r
             # python file change in .pytool folder causes building all\r
             if f.endswith(".py") and ".pytool" in nodes:\r
index 02f25ab19fd747b1429db7d0a63e6f36caa143b8..1496e1f24934187cedd080caddbb4883857c9a37 100644 (file)
@@ -100,7 +100,7 @@ class CharEncodingCheck(ICiBuildPlugin):
                     overall_status += 1\r
 \r
         tc.LogStdOut("Tested Encoding on {0} files".format(files_tested))\r
-        if overall_status is not 0:\r
+        if overall_status != 0:\r
             tc.SetFailed("CharEncoding {0} Failed.  Errors {1}".format(packagename, overall_status), "CHAR_ENCODING_CHECK_FAILED")\r
         else:\r
             tc.SetSuccess()\r
index 3b6f7c769882127c92f0af7c2ff79985ddf76d2d..e8657940d71bae72d9c2b34f615ebc8fd9611849 100644 (file)
@@ -1,4 +1,4 @@
-# @file HostUnitTestCompiler_plugin.py\r
+# @file CompilerPlugin.py\r
 ##\r
 # Copyright (c) Microsoft Corporation.\r
 # SPDX-License-Identifier: BSD-2-Clause-Patent\r
@@ -42,7 +42,7 @@ class CompilerPlugin(ICiBuildPlugin):
         return ["DEBUG", "RELEASE"]\r
 \r
     ##\r
-    # External function of plugin.  This function is used to perform the task of the MuBuild Plugin\r
+    # External function of plugin.  This function is used to perform the task of the ICiBuildPlugin Plugin\r
     #\r
     #   - package is the edk2 path to package.  This means workspace/packagepath relative.\r
     #   - edk2path object configured with workspace and packages path\r
index 2c3d8baf6984e9849ae6d03203fca3faead56faf..db154d769a3909eeacb4781322a43b65a06ffa46 100644 (file)
@@ -113,7 +113,7 @@ class DependencyCheck(ICiBuildPlugin):
                     overall_status += 1\r
 \r
         # If XML object exists, add results\r
-        if overall_status is not 0:\r
+        if overall_status != 0:\r
             tc.SetFailed("Failed with {0} errors".format(overall_status), "DEPENDENCYCHECK_FAILED")\r
         else:\r
             tc.SetSuccess()\r
index 9af4f72c8de3a2a0dff462cfdca822be8cab6772..c613cd52334cd1bea7093cf77c3680258409e49d 100644 (file)
@@ -54,12 +54,15 @@ class DscCompleteCheck(ICiBuildPlugin):
         # Parse the config for required DscPath element\r
         if "DscPath" not in pkgconfig:\r
             tc.SetSkipped()\r
-            tc.LogStdError("DscPath not found in config file.  Nothing to check.")\r
+            tc.LogStdError(\r
+                "DscPath not found in config file.  Nothing to check.")\r
             return -1\r
 \r
-        abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(packagename)\r
+        abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(\r
+            packagename)\r
         abs_dsc_path = os.path.join(abs_pkg_path, pkgconfig["DscPath"].strip())\r
-        wsr_dsc_path = Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(abs_dsc_path)\r
+        wsr_dsc_path = Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(\r
+            abs_dsc_path)\r
 \r
         if abs_dsc_path is None or wsr_dsc_path == "" or not os.path.isfile(abs_dsc_path):\r
             tc.SetSkipped()\r
@@ -68,7 +71,8 @@ class DscCompleteCheck(ICiBuildPlugin):
 \r
         # Get INF Files\r
         INFFiles = self.WalkDirectoryForExtension([".inf"], abs_pkg_path)\r
-        INFFiles = [Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(x) for x in INFFiles]  # make edk2relative path so can compare with DSC\r
+        INFFiles = [Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(\r
+            x) for x in INFFiles]  # make edk2relative path so can compare with DSC\r
 \r
         # remove ignores\r
 \r
@@ -79,8 +83,10 @@ class DscCompleteCheck(ICiBuildPlugin):
                     tc.LogStdOut("Ignoring INF {0}".format(a))\r
                     INFFiles.remove(a)\r
                 except:\r
-                    tc.LogStdError("DscCompleteCheck.IgnoreInf -> {0} not found in filesystem.  Invalid ignore file".format(a))\r
-                    logging.info("DscCompleteCheck.IgnoreInf -> {0} not found in filesystem.  Invalid ignore file".format(a))\r
+                    tc.LogStdError(\r
+                        "DscCompleteCheck.IgnoreInf -> {0} not found in filesystem.  Invalid ignore file".format(a))\r
+                    logging.info(\r
+                        "DscCompleteCheck.IgnoreInf -> {0} not found in filesystem.  Invalid ignore file".format(a))\r
 \r
         # DSC Parser\r
         dp = DscParser()\r
@@ -99,11 +105,19 @@ class DscCompleteCheck(ICiBuildPlugin):
                 infp.SetPackagePaths(Edk2pathObj.PackagePathList)\r
                 infp.ParseFile(INF)\r
                 if("MODULE_TYPE" not in infp.Dict):\r
-                    tc.LogStdOut("Ignoring INF. Missing key for MODULE_TYPE {0}".format(INF))\r
+                    tc.LogStdOut(\r
+                        "Ignoring INF. Missing key for MODULE_TYPE {0}".format(INF))\r
                     continue\r
 \r
                 if(infp.Dict["MODULE_TYPE"] == "HOST_APPLICATION"):\r
-                    tc.LogStdOut("Ignoring INF.  Module type is HOST_APPLICATION {0}".format(INF))\r
+                    tc.LogStdOut(\r
+                        "Ignoring INF.  Module type is HOST_APPLICATION {0}".format(INF))\r
+                    continue\r
+\r
+                if len(infp.SupportedPhases) == 1 and \\r
+                   "HOST_APPLICATION" in infp.SupportedPhases:\r
+                    tc.LogStdOut(\r
+                        "Ignoring Library INF due to only supporting type HOST_APPLICATION {0}".format(INF))\r
                     continue\r
 \r
                 logging.critical(INF + " not in " + wsr_dsc_path)\r
@@ -111,8 +125,9 @@ class DscCompleteCheck(ICiBuildPlugin):
                 overall_status = overall_status + 1\r
 \r
         # If XML object exists, add result\r
-        if overall_status is not 0:\r
-            tc.SetFailed("DscCompleteCheck {0} Failed.  Errors {1}".format(wsr_dsc_path, overall_status), "CHECK_FAILED")\r
+        if overall_status != 0:\r
+            tc.SetFailed("DscCompleteCheck {0} Failed.  Errors {1}".format(\r
+                wsr_dsc_path, overall_status), "CHECK_FAILED")\r
         else:\r
             tc.SetSuccess()\r
         return overall_status\r
index eefbb9894d5f4262b1a6bb62cc4d2fd5b2cd98f5..8aaa4f76ee0a96aedf7461b54c9582d8ecb7f9a1 100644 (file)
@@ -7,6 +7,11 @@ that it would not be built if the package were built). This is critical because
 much of the CI infrastructure assumes that all modules will be listed in the DSC\r
 and compiled.\r
 \r
+This test will ignore INFs in the following cases:\r
+\r
+1. When MODULE_TYPE = HOST_APPLICATION\r
+2. When a Library instance **only** supports the HOST_APPLICATION environment\r
+\r
 ## Configuration\r
 \r
 The plugin has a few configuration options to support the UEFI codebase.\r
@@ -14,7 +19,7 @@ The plugin has a few configuration options to support the UEFI codebase.
 ``` yaml\r
 "DscCompleteCheck": {\r
         "DscPath": "",   # Path to dsc from root of package\r
-        "IgnoreInf": []  # Ignore INF if found in filesystem by not dsc\r
+        "IgnoreInf": []  # Ignore INF if found in filesystem but not dsc\r
     }\r
 ```\r
 \r
index f0b10beb1e8f09181fd856297f65b9afa8b0a5f4..61fdc7791128584df2143af9fd9bc8df13d3147d 100644 (file)
@@ -221,7 +221,7 @@ class GuidCheck(ICiBuildPlugin):
 \r
         # add result to test case\r
         overall_status = len(Errors)\r
-        if overall_status is not 0:\r
+        if overall_status != 0:\r
             tc.SetFailed("GuidCheck {0} Failed.  Errors {1}".format(\r
                 packagename, overall_status), "CHECK_FAILED")\r
         else:\r
diff --git a/.pytool/Plugin/HostUnitTestCompilerPlugin/HostUnitTestCompilerPlugin.py b/.pytool/Plugin/HostUnitTestCompilerPlugin/HostUnitTestCompilerPlugin.py
new file mode 100644 (file)
index 0000000..f21b40c
--- /dev/null
@@ -0,0 +1,149 @@
+# @file HostUnitTestCompilerPlugin.py\r
+##\r
+# Copyright (c) Microsoft Corporation.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+##\r
+\r
+import logging\r
+import os\r
+import re\r
+from edk2toollib.uefi.edk2.parsers.dsc_parser import DscParser\r
+from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin\r
+from edk2toolext.environment.uefi_build import UefiBuilder\r
+from edk2toolext import edk2_logging\r
+from edk2toolext.environment.var_dict import VarDict\r
+from edk2toollib.utility_functions import GetHostInfo\r
+\r
+\r
+class HostUnitTestCompilerPlugin(ICiBuildPlugin):\r
+    """\r
+    A CiBuildPlugin that compiles the dsc for host based unit test apps.\r
+    An IUefiBuildPlugin may be attached to this plugin that will run the\r
+    unit tests and collect the results after successful compilation.\r
+\r
+    Configuration options:\r
+    "HostUnitTestCompilerPlugin": {\r
+        "DscPath": "<path to dsc from root of pkg>"\r
+    }\r
+    """\r
+\r
+    def GetTestName(self, packagename: str, environment: VarDict) -> tuple:\r
+        """ Provide the testcase name and classname for use in reporting\r
+            testclassname: a descriptive string for the testcase can include whitespace\r
+            classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>\r
+\r
+            Args:\r
+              packagename: string containing name of package to build\r
+              environment: The VarDict for the test to run in\r
+            Returns:\r
+                a tuple containing the testcase name and the classname\r
+                (testcasename, classname)\r
+        """\r
+        num,types = self.__GetHostUnitTestArch(environment)\r
+        types = types.replace(" ", "_")\r
+\r
+        return ("Compile and Run Host-Based UnitTests for " + packagename + " on arch " + types,\r
+                packagename + ".HostUnitTestCompiler." + types)\r
+\r
+    def RunsOnTargetList(self):\r
+        return ["NOOPT"]\r
+\r
+    #\r
+    # Find the intersection of application types that can run on this host\r
+    # and the TARGET_ARCH being build in this request.\r
+    #\r
+    # return tuple with (number of UEFI arch types, space separated string)\r
+    def __GetHostUnitTestArch(self, environment):\r
+        requested = environment.GetValue("TARGET_ARCH").split(' ')\r
+        host = []\r
+        if GetHostInfo().arch == 'x86':\r
+            #assume 64bit can handle 64 and 32\r
+            #assume 32bit can only handle 32\r
+            ## change once IA32 issues resolved host.append("IA32")\r
+            if GetHostInfo().bit == '64':\r
+                host.append("X64")\r
+        elif GetHostInfo().arch == 'ARM':\r
+            if GetHostInfo().bit == '64':\r
+                host.append("AARCH64")\r
+            elif GetHostInfo().bit == '32':\r
+                host.append("ARM")\r
+\r
+        willrun = set(requested) & set(host)\r
+        return (len(willrun), " ".join(willrun))\r
+\r
+\r
+    ##\r
+    # External function of plugin.  This function is used to perform the task of the ICiBuildPlugin Plugin\r
+    #\r
+    #   - package is the edk2 path to package.  This means workspace/packagepath relative.\r
+    #   - edk2path object configured with workspace and packages path\r
+    #   - PkgConfig Object (dict) for the pkg\r
+    #   - EnvConfig Object\r
+    #   - Plugin Manager Instance\r
+    #   - Plugin Helper Obj Instance\r
+    #   - Junit Logger\r
+    #   - output_stream the StringIO output stream from this plugin via logging\r
+    def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):\r
+        self._env = environment\r
+        environment.SetValue("CI_BUILD_TYPE", "host_unit_test", "Set in HostUnitTestCompilerPlugin")\r
+\r
+        # Parse the config for required DscPath element\r
+        if "DscPath" not in pkgconfig:\r
+            tc.SetSkipped()\r
+            tc.LogStdError("DscPath not found in config file.  Nothing to compile for HostBasedUnitTests.")\r
+            return -1\r
+\r
+        AP = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(packagename)\r
+\r
+        APDSC = os.path.join(AP, pkgconfig["DscPath"].strip())\r
+        AP_Path = Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(APDSC)\r
+        if AP is None or AP_Path is None or not os.path.isfile(APDSC):\r
+            tc.SetSkipped()\r
+            tc.LogStdError("Package HostBasedUnitTest Dsc not found.")\r
+            return -1\r
+\r
+        logging.info("Building {0}".format(AP_Path))\r
+        self._env.SetValue("ACTIVE_PLATFORM", AP_Path, "Set in Compiler Plugin")\r
+        num, RUNNABLE_ARCHITECTURES = self.__GetHostUnitTestArch(environment)\r
+        if(num == 0):\r
+            tc.SetSkipped()\r
+            tc.LogStdError("No host architecture compatibility")\r
+            return -1\r
+\r
+        if not environment.SetValue("TARGET_ARCH",\r
+                                    RUNNABLE_ARCHITECTURES,\r
+                                    "Update Target Arch based on Host Support"):\r
+            #use AllowOverride function since this is a controlled attempt to change\r
+            environment.AllowOverride("TARGET_ARCH")\r
+            if not environment.SetValue("TARGET_ARCH",\r
+                                        RUNNABLE_ARCHITECTURES,\r
+                                        "Update Target Arch based on Host Support"):\r
+                raise RuntimeError("Can't Change TARGET_ARCH as required")\r
+\r
+        # Parse DSC to check for SUPPORTED_ARCHITECTURES\r
+        dp = DscParser()\r
+        dp.SetBaseAbsPath(Edk2pathObj.WorkspacePath)\r
+        dp.SetPackagePaths(Edk2pathObj.PackagePathList)\r
+        dp.ParseFile(AP_Path)\r
+        if "SUPPORTED_ARCHITECTURES" in dp.LocalVars:\r
+            SUPPORTED_ARCHITECTURES = dp.LocalVars["SUPPORTED_ARCHITECTURES"].split('|')\r
+            TARGET_ARCHITECTURES = environment.GetValue("TARGET_ARCH").split(' ')\r
+\r
+            # Skip if there is no intersection between SUPPORTED_ARCHITECTURES and TARGET_ARCHITECTURES\r
+            if len(set(SUPPORTED_ARCHITECTURES) & set(TARGET_ARCHITECTURES)) == 0:\r
+                tc.SetSkipped()\r
+                tc.LogStdError("No supported architecutres to build for host unit tests")\r
+                return -1\r
+\r
+        uefiBuilder = UefiBuilder()\r
+        # do all the steps\r
+        # WorkSpace, PackagesPath, PInHelper, PInManager\r
+        ret = uefiBuilder.Go(Edk2pathObj.WorkspacePath, os.pathsep.join(Edk2pathObj.PackagePathList), PLMHelper, PLM)\r
+        if ret != 0:  # failure:\r
+            tc.SetFailed("Compile failed for {0}".format(packagename), "Compile_FAILED")\r
+            tc.LogStdError("{0} Compile failed with error code {1} ".format(AP_Path, ret))\r
+            return 1\r
+\r
+        else:\r
+            tc.SetSuccess()\r
+            return 0\r
diff --git a/.pytool/Plugin/HostUnitTestCompilerPlugin/HostUnitTestCompiler_plug_in.yaml b/.pytool/Plugin/HostUnitTestCompilerPlugin/HostUnitTestCompiler_plug_in.yaml
new file mode 100644 (file)
index 0000000..3cecf0a
--- /dev/null
@@ -0,0 +1,12 @@
+##\r
+# CiBuildPlugin used to build anything that identifies\r
+# as a unit test.\r
+#\r
+# Copyright (c) Microsoft Corporation.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+##\r
+{\r
+  "scope": "host-based-test",\r
+  "name": "Host Unit Test Compiler Plugin",\r
+  "module": "HostUnitTestCompilerPlugin"\r
+}\r
diff --git a/.pytool/Plugin/HostUnitTestCompilerPlugin/Readme.md b/.pytool/Plugin/HostUnitTestCompilerPlugin/Readme.md
new file mode 100644 (file)
index 0000000..3eeebb4
--- /dev/null
@@ -0,0 +1,24 @@
+# Host UnitTest Compiler Plugin\r
+\r
+A CiBuildPlugin that compiles the dsc for host based unit test apps.\r
+An IUefiBuildPlugin may be attached to this plugin that will run the unit tests and collect the results after successful compilation.\r
+\r
+## Configuration\r
+\r
+The package relative path of the DSC file to build.\r
+\r
+``` yaml\r
+"HostUnitTestCompilerPlugin": {\r
+    "DscPath": "<path to dsc from root of pkg>"\r
+}\r
+```\r
+\r
+### DscPath\r
+\r
+Package relative path to the DSC file to build.\r
+\r
+## Copyright\r
+\r
+Copyright (c) Microsoft Corporation.\r
+SPDX-License-Identifier: BSD-2-Clause-Patent\r
+\r
diff --git a/.pytool/Plugin/HostUnitTestDscCompleteCheck/HostUnitTestDscCompleteCheck.py b/.pytool/Plugin/HostUnitTestDscCompleteCheck/HostUnitTestDscCompleteCheck.py
new file mode 100644 (file)
index 0000000..66bdeca
--- /dev/null
@@ -0,0 +1,140 @@
+# @file HostUnitTestDscCompleteCheck.py\r
+#\r
+# This is a copy of DscCompleteCheck with different filtering logic.\r
+# It should be discussed if this should be one plugin\r
+#\r
+# Copyright (c) Microsoft Corporation.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+##\r
+import logging\r
+import os\r
+from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin\r
+from edk2toollib.uefi.edk2.parsers.dsc_parser import DscParser\r
+from edk2toollib.uefi.edk2.parsers.inf_parser import InfParser\r
+from edk2toolext.environment.var_dict import VarDict\r
+\r
+\r
+class HostUnitTestDscCompleteCheck(ICiBuildPlugin):\r
+    """\r
+    A CiBuildPlugin that scans the package Host Unit Test dsc file and confirms all Host application modules (inf files) are\r
+    listed in the components sections.\r
+\r
+    Configuration options:\r
+    "HostUnitTestDscCompleteCheck": {\r
+        "DscPath": "", # Path to Host based unit test DSC file\r
+        "IgnoreInf": []  # Ignore INF if found in filesystem but not dsc\r
+    }\r
+    """\r
+\r
+    def GetTestName(self, packagename: str, environment: VarDict) -> tuple:\r
+        """ Provide the testcase name and classname for use in reporting\r
+\r
+            Args:\r
+              packagename: string containing name of package to build\r
+              environment: The VarDict for the test to run in\r
+            Returns:\r
+                a tuple containing the testcase name and the classname\r
+                (testcasename, classname)\r
+                testclassname: a descriptive string for the testcase can include whitespace\r
+                classname: should be patterned <packagename>.<plugin>.<optionally any unique condition>\r
+        """\r
+        return ("Check the " + packagename + " Host Unit Test DSC for a being complete", packagename + ".HostUnitTestDscCompleteCheck")\r
+\r
+    ##\r
+    # External function of plugin.  This function is used to perform the task of the MuBuild Plugin\r
+    #\r
+    #   - package is the edk2 path to package.  This means workspace/packagepath relative.\r
+    #   - edk2path object configured with workspace and packages path\r
+    #   - PkgConfig Object (dict) for the pkg\r
+    #   - VarDict containing the shell environment Build Vars\r
+    #   - Plugin Manager Instance\r
+    #   - Plugin Helper Obj Instance\r
+    #   - Junit Logger\r
+    #   - output_stream the StringIO output stream from this plugin via logging\r
+    def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, PLMHelper, tc, output_stream=None):\r
+        overall_status = 0\r
+\r
+        # Parse the config for required DscPath element\r
+        if "DscPath" not in pkgconfig:\r
+            tc.SetSkipped()\r
+            tc.LogStdError(\r
+                "DscPath not found in config file.  Nothing to check.")\r
+            return -1\r
+\r
+        abs_pkg_path = Edk2pathObj.GetAbsolutePathOnThisSytemFromEdk2RelativePath(\r
+            packagename)\r
+        abs_dsc_path = os.path.join(abs_pkg_path, pkgconfig["DscPath"].strip())\r
+        wsr_dsc_path = Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(\r
+            abs_dsc_path)\r
+\r
+        if abs_dsc_path is None or wsr_dsc_path == "" or not os.path.isfile(abs_dsc_path):\r
+            tc.SetSkipped()\r
+            tc.LogStdError("Package Host Unit Test Dsc not found")\r
+            return 0\r
+\r
+        # Get INF Files\r
+        INFFiles = self.WalkDirectoryForExtension([".inf"], abs_pkg_path)\r
+        INFFiles = [Edk2pathObj.GetEdk2RelativePathFromAbsolutePath(\r
+            x) for x in INFFiles]  # make edk2relative path so can compare with DSC\r
+\r
+        # remove ignores\r
+\r
+        if "IgnoreInf" in pkgconfig:\r
+            for a in pkgconfig["IgnoreInf"]:\r
+                a = a.replace(os.sep, "/")\r
+                try:\r
+                    tc.LogStdOut("Ignoring INF {0}".format(a))\r
+                    INFFiles.remove(a)\r
+                except:\r
+                    tc.LogStdError(\r
+                        "HostUnitTestDscCompleteCheck.IgnoreInf -> {0} not found in filesystem.  Invalid ignore file".format(a))\r
+                    logging.info(\r
+                        "HostUnitTestDscCompleteCheck.IgnoreInf -> {0} not found in filesystem.  Invalid ignore file".format(a))\r
+\r
+        # DSC Parser\r
+        dp = DscParser()\r
+        dp.SetBaseAbsPath(Edk2pathObj.WorkspacePath)\r
+        dp.SetPackagePaths(Edk2pathObj.PackagePathList)\r
+        dp.SetInputVars(environment.GetAllBuildKeyValues())\r
+        dp.ParseFile(wsr_dsc_path)\r
+\r
+        # Check if INF in component section\r
+        for INF in INFFiles:\r
+            if not any(INF.strip() in x for x in dp.ThreeMods) and \\r
+               not any(INF.strip() in x for x in dp.SixMods) and \\r
+               not any(INF.strip() in x for x in dp.OtherMods):\r
+\r
+                infp = InfParser().SetBaseAbsPath(Edk2pathObj.WorkspacePath)\r
+                infp.SetPackagePaths(Edk2pathObj.PackagePathList)\r
+                infp.ParseFile(INF)\r
+                if("MODULE_TYPE" not in infp.Dict):\r
+                    tc.LogStdOut(\r
+                        "Ignoring INF. Missing key for MODULE_TYPE {0}".format(INF))\r
+                    continue\r
+\r
+                if(infp.Dict["MODULE_TYPE"] == "HOST_APPLICATION"):\r
+                    # should compile test a library that is declared type HOST_APPLICATION\r
+                    pass\r
+\r
+                elif len(infp.SupportedPhases) > 0 and \\r
+                        "HOST_APPLICATION" in infp.SupportedPhases:\r
+                    # should compile test a library that supports HOST_APPLICATION but\r
+                    # require it to be an explicit opt-in\r
+                    pass\r
+\r
+                else:\r
+                    tc.LogStdOut(\r
+                        "Ignoring INF. MODULE_TYPE or suppored phases not HOST_APPLICATION {0}".format(INF))\r
+                    continue\r
+\r
+                logging.critical(INF + " not in " + wsr_dsc_path)\r
+                tc.LogStdError("{0} not in {1}".format(INF, wsr_dsc_path))\r
+                overall_status = overall_status + 1\r
+\r
+        # If XML object exists, add result\r
+        if overall_status != 0:\r
+            tc.SetFailed("HostUnitTestDscCompleteCheck {0} Failed.  Errors {1}".format(\r
+                wsr_dsc_path, overall_status), "CHECK_FAILED")\r
+        else:\r
+            tc.SetSuccess()\r
+        return overall_status\r
diff --git a/.pytool/Plugin/HostUnitTestDscCompleteCheck/HostUnitTestDscCompleteCheck_plug_in.yaml b/.pytool/Plugin/HostUnitTestDscCompleteCheck/HostUnitTestDscCompleteCheck_plug_in.yaml
new file mode 100644 (file)
index 0000000..82cebd7
--- /dev/null
@@ -0,0 +1,12 @@
+##\r
+# CiBuildPlugin used to confirm all INFs are listed in\r
+# the components section of package dsc\r
+#\r
+# Copyright (c) Microsoft Corporation.\r
+# SPDX-License-Identifier: BSD-2-Clause-Patent\r
+##\r
+{\r
+    "scope": "host-based-test",\r
+    "name": "Host Unit Test Dsc Complete Check Test",\r
+    "module": "HostUnitTestDscCompleteCheck"\r
+  }\r
diff --git a/.pytool/Plugin/HostUnitTestDscCompleteCheck/Readme.md b/.pytool/Plugin/HostUnitTestDscCompleteCheck/Readme.md
new file mode 100644 (file)
index 0000000..d77a1f2
--- /dev/null
@@ -0,0 +1,32 @@
+# Host Unit Test Dsc Complete Check Plugin\r
+\r
+This CiBuildPlugin scans all INF files from a package for those related to host\r
+based unit tests confirms they are listed in the unit test DSC file for the package.\r
+The test considers it an error if any INF meeting the requirements does not appear\r
+in the `Components` section of the unit test DSC. This is critical because\r
+much of the CI infrastructure assumes that  modules will be listed in the DSC\r
+and compiled.\r
+\r
+This test will only require INFs in the following cases:\r
+\r
+1. When MODULE_TYPE = HOST_APPLICATION\r
+2. When a Library instance supports the HOST_APPLICATION environment\r
+\r
+## Configuration\r
+\r
+The plugin has a few configuration options to support the UEFI codebase.\r
+\r
+``` yaml\r
+"HostUnitTestDscCompleteCheck": {\r
+    "DscPath": "", # Path to Host based unit test DSC file\r
+    "IgnoreInf": []  # Ignore INF if found in filesystem but not dsc\r
+}\r
+```\r
+\r
+### DscPath\r
+\r
+Path to DSC to consider platform dsc\r
+\r
+### IgnoreInf\r
+\r
+Ignore error if Inf file is not listed in DSC file\r
index a62a7e912b15546e5de39f76b405ab66bfb9a143..20d87f13f5240613bc47b9d98339ac4f24545ac3 100644 (file)
@@ -146,7 +146,7 @@ class LibraryClassCheck(ICiBuildPlugin):
 \r
 \r
         # If XML object exists, add result\r
-        if overall_status is not 0:\r
+        if overall_status != 0:\r
             tc.SetFailed("LibraryClassCheck {0} Failed.  Errors {1}".format(wsr_dec_path, overall_status), "CHECK_FAILED")\r
         else:\r
             tc.SetSuccess()\r