diff --git a/.pytool/Plugin/HostUnitTestCompilerPlugin/HostUnitTestCompilerPlugin.py b/.pytool/Plugin/HostUnitTestCompilerPlugin/HostUnitTestCompilerPlugin.py index 2c12ae78cf..876db5cd96 100644 --- a/.pytool/Plugin/HostUnitTestCompilerPlugin/HostUnitTestCompilerPlugin.py +++ b/.pytool/Plugin/HostUnitTestCompilerPlugin/HostUnitTestCompilerPlugin.py @@ -6,11 +6,12 @@ import logging import os -import re +import sys from edk2toollib.uefi.edk2.parsers.dsc_parser import DscParser from edk2toolext.environment.plugintypes.ci_build_plugin import ICiBuildPlugin +from edk2toolext.environment.plugintypes.uefi_build_plugin import IUefiBuildPlugin +from edk2toolext.environment.plugin_manager import PluginDescriptor from edk2toolext.environment.uefi_build import UefiBuilder -from edk2toolext import edk2_logging from edk2toolext.environment.var_dict import VarDict from edk2toollib.utility_functions import GetHostInfo @@ -132,18 +133,32 @@ def RunBuildPlugin(self, packagename, Edk2pathObj, pkgconfig, environment, PLM, # Skip if there is no intersection between SUPPORTED_ARCHITECTURES and TARGET_ARCHITECTURES if len(set(SUPPORTED_ARCHITECTURES) & set(TARGET_ARCHITECTURES)) == 0: tc.SetSkipped() - tc.LogStdError("No supported architecutres to build for host unit tests") + tc.LogStdError("No supported architectures to build for host unit tests") return -1 uefiBuilder = UefiBuilder() + # do all the steps # WorkSpace, PackagesPath, PInHelper, PInManager + # Skip post build plugins and run only host-based-tests manually + uefiBuilder.SkipPostBuild = True ret = uefiBuilder.Go(Edk2pathObj.WorkspacePath, os.pathsep.join(Edk2pathObj.PackagePathList), PLMHelper, PLM) if ret != 0: # failure: tc.SetFailed("Compile failed for {0}".format(packagename), "Compile_FAILED") tc.LogStdError("{0} Compile failed with error code {1} ".format(AP_Path, ret)) return 1 - else: - tc.SetSuccess() - return 0 + def host_test_filter(plugin: PluginDescriptor) -> bool: + return plugin.descriptor['scope'] == 'host-based-test' + + build_plugins = PLM.GetPluginsOfClass(IUefiBuildPlugin) + host_test_plugins = filter(host_test_filter, build_plugins) + + for plugin in host_test_plugins: + if plugin.Obj.do_post_build(uefiBuilder) != 0: + tc.SetFailed("Host Based Unit Test failed for {0}".format(packagename), "HostUnitTest_FAILED") + tc.LogStdError("Host Based Unit Test failed for {0} ".format(packagename)) + return 1 + + tc.SetSuccess() + return 0 diff --git a/.pytool/Plugin/HostUnitTestCompilerPlugin/Readme.md b/.pytool/Plugin/HostUnitTestCompilerPlugin/Readme.md index 3eeebb4b16..f3811a929a 100644 --- a/.pytool/Plugin/HostUnitTestCompilerPlugin/Readme.md +++ b/.pytool/Plugin/HostUnitTestCompilerPlugin/Readme.md @@ -1,7 +1,10 @@ # Host UnitTest Compiler Plugin A CiBuildPlugin that compiles the dsc for host based unit test apps. -An IUefiBuildPlugin may be attached to this plugin that will run the unit tests and collect the results after successful compilation. + +To run the unit tests and collect the results after successful compilation, The +host UnitTest Compliler Plugin will execute any IUefiBuildPlugin that has the +scope 'host-based-test'. ## Configuration