Skip to content

Commit

Permalink
Allow GoogleTest to Test STATIC Functions
Browse files Browse the repository at this point in the history
> 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.
  • Loading branch information
os-d authored and Flickdm committed Jun 6, 2024
1 parent d02852d commit bf1d74e
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit bf1d74e

Please sign in to comment.