From bf1d74e2ef1c56461000b4a705893eba58231b49 Mon Sep 17 00:00:00 2001 From: Oliver Smith-Denny Date: Fri, 26 Apr 2024 10:30:55 -0700 Subject: [PATCH] Allow GoogleTest to Test STATIC Functions > This is a cherry-pick to keep the -D GOOGLETEST_HOST_UNIT_TEST_BUILD=1 Cmocka is able to test STATIC functions by including the C file in the test file. However, in many scenarios, GoogleTest files cannot do this as the C++ compiler has stricter rules than the C compiler. This patch updates the UnitTestFrameworkPkgHost.dsc.in to add a new build flag GOOGLETEST_HOST_UNIT_TEST_BUILD for HOST_APPLICATIONS only. Base.h is then updated to undef STATIC if this flag is set. This allows for STATIC functions to be tested in GoogleTest. There is less danger of symbol collision here, because HOST_APPLICATIONS are running with the least amount of dependencies possible. This still allows for interfaces tests (where a Library Class is tested, not an instance, so the library is linked in to the test instead of compiled) as the library in this case will not be compiled as a HOST_APPLICATION and so the STATIC functions will remain STATIC. --- UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index 9c50e65dae..ea7974fa7a 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -43,7 +43,9 @@ # # MSFT # - MSFT:*_*_*_CC_FLAGS = /EHsc + # MU_CHANGE [BEGIN] - Allow GoogleTest to Test STATIC Functions + MSFT:*_*_*_CC_FLAGS = /EHsc -D GOOGLETEST_HOST_UNIT_TEST_BUILD=1 + # MU_CHANGE [END] - Allow GoogleTest to Test STATIC Functions MSFT:*_*_*_DLINK_FLAGS == /out:"$(BIN_DIR)\$(MODULE_NAME_GUID).exe" /pdb:"$(BIN_DIR)\$(MODULE_NAME_GUID).pdb" /IGNORE:4001 /NOLOGO /SUBSYSTEM:CONSOLE /DEBUG /STACK:0x40000,0x40000 /WHOLEARCHIVE MSFT:*_*_IA32_DLINK_FLAGS = /MACHINE:I386 MSFT:*_*_X64_DLINK_FLAGS = /MACHINE:AMD64