]> git.proxmox.com Git - mirror_edk2.git/blobdiff - BaseTools/Plugin/HostBasedUnitTestRunner/HostBasedUnitTestRunner.py
BaseTools/Plugin: Update HostBasedUnitTestRunner to support Linux
[mirror_edk2.git] / BaseTools / Plugin / HostBasedUnitTestRunner / HostBasedUnitTestRunner.py
index 92426760ae0f67f9cb1cd6df4258939963693bb6..c1eeaf26251eeb0a79a8cbe14494d0cb88bc739a 100644 (file)
@@ -8,47 +8,23 @@
 import os\r
 import logging\r
 import glob\r
+import stat\r
 import xml.etree.ElementTree\r
 from edk2toolext.environment.plugintypes.uefi_build_plugin import IUefiBuildPlugin\r
 from edk2toolext import edk2_logging\r
 import edk2toollib.windows.locate_tools as locate_tools\r
 from edk2toolext.environment import shell_environment\r
 from edk2toollib.utility_functions import RunCmd\r
+from edk2toollib.utility_functions import GetHostInfo\r
 \r
 \r
 class HostBasedUnitTestRunner(IUefiBuildPlugin):\r
 \r
     def do_pre_build(self, thebuilder):\r
         '''\r
-        Works with the compiler (either the HostBasedCompilerPlugin or an other Builder) to set\r
-        up the environment that will be needed to build host-based unit tests.\r
-\r
-        EXPECTS:\r
-        - Build Var 'CI_BUILD_TYPE' - If not set to 'host_unit_test', will not do anything.\r
-\r
-        UPDATES:\r
-        - Shell Var (Several) - Updates the shell with all vars listed in interesting_keys.\r
-        - Shell Path - Updated from QueryVcVariables()\r
-        - Shell Var 'CMOCKA_MESSAGE_OUTPUT'\r
+        Run Prebuild\r
         '''\r
-        ci_type = thebuilder.env.GetValue('CI_BUILD_TYPE')\r
-        if ci_type != 'host_unit_test':\r
-            return 0\r
-\r
-        shell_env = shell_environment.GetEnvironment()\r
-        # Use the tools lib to determine the correct values for the vars that interest us.\r
-        interesting_keys = ["ExtensionSdkDir", "INCLUDE", "LIB", "LIBPATH", "UniversalCRTSdkDir",\r
-                            "UCRTVersion", "WindowsLibPath", "WindowsSdkBinPath", "WindowsSdkDir", "WindowsSdkVerBinPath",\r
-                            "WindowsSDKVersion", "VCToolsInstallDir"]\r
-        vs_vars = locate_tools.QueryVcVariables(interesting_keys, "amd64")\r
-        for (k, v) in vs_vars.items():\r
-            if k.upper() == "PATH":\r
-                shell_env.append_path(v)\r
-            else:\r
-                shell_env.set_shell_var(k, v)\r
 \r
-        # Set up the reporting type for Cmocka.\r
-        shell_env.set_shell_var('CMOCKA_MESSAGE_OUTPUT', 'xml')\r
         return 0\r
 \r
     def do_post_build(self, thebuilder):\r
@@ -73,6 +49,9 @@ class HostBasedUnitTestRunner(IUefiBuildPlugin):
 \r
         failure_count = 0\r
 \r
+        # Set up the reporting type for Cmocka.\r
+        shell_env.set_shell_var('CMOCKA_MESSAGE_OUTPUT', 'xml')\r
+\r
         for arch in thebuilder.env.GetValue("TARGET_ARCH").split():\r
             logging.log(edk2_logging.get_subsection_level(),\r
                         "Testing for architecture: " + arch)\r
@@ -82,8 +61,29 @@ class HostBasedUnitTestRunner(IUefiBuildPlugin):
             for old_result in glob.iglob(os.path.join(cp, "*.result.xml")):\r
                 os.remove(old_result)\r
 \r
-            # Determine whether any tests exist.\r
-            testList = glob.glob(os.path.join(cp, "*Test*.exe"))\r
+            # Find and Run any Host Tests\r
+            if GetHostInfo().os.upper() == "LINUX":\r
+                testList = glob.glob(os.path.join(cp, "*Test*"))\r
+                for a in testList[:]:\r
+                    p = os.path.join(cp, a)\r
+                    # It must be a file\r
+                    if not os.path.isfile(p):\r
+                        testList.remove(a)\r
+                        logging.debug(f"Remove directory file: {p}")\r
+                        continue\r
+                    # It must be executable\r
+                    if os.stat(p).st_mode & (stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH) == 0:\r
+                        testList.remove(a)\r
+                        logging.debug(f"Remove non-executable file: {p}")\r
+                        continue\r
+\r
+                    logging.info(f"Test file found: {p}")\r
+\r
+            elif GetHostInfo().os.upper() == "WINDOWS":\r
+                testList = glob.glob(os.path.join(cp, "*Test*.exe"))\r
+            else:\r
+                raise NotImplementedError("Unsupported Operating System")\r
+\r
             for test in testList:\r
                 # Configure output name.\r
                 shell_env.set_shell_var(\r