diff options
4 files changed, 29 insertions, 6 deletions
diff --git a/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h b/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h index c723b5c230..b8405cee8e 100644 --- a/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h +++ b/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h @@ -13,6 +13,26 @@ #include <gmock/gmock.h>
#include <cstring>
+using ::testing::Throws;
+using ::testing::ThrowsMessage;
+using ::testing::HasSubstr;
+
+//
+// Extended macros for testing exceptions with a specific description string
+// in the exception message. Typically used to check that the expression
+// that generates an ASSERT() matches the expected expression.
+//
+#define EXPECT_THROW_MESSAGE(statement, description) \
+ EXPECT_THAT ( \
+ []() { statement; }, \
+ ThrowsMessage<std::runtime_error>(HasSubstr (description)) \
+ )
+#define ASSERT_THROW_MESSAGE(statement, description) \
+ ASSERT_THAT ( \
+ []() { statement; }, \
+ ThrowsMessage<std::runtime_error>(HasSubstr (description)) \
+ )
+
extern "C" {
#include <Uefi.h>
}
diff --git a/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf b/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf index 83ab9f9b2a..0c522832e9 100644 --- a/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf +++ b/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf @@ -28,6 +28,6 @@ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
[BuildOptions]
- MSFT:*_*_*_CC_FLAGS == /c /EHsc /Zi /Od /MT
- GCC:*_*_IA32_CC_FLAGS == -g -c -fshort-wchar -O0 -m32
- GCC:*_*_X64_CC_FLAGS == -g -c -fshort-wchar -O0 -m64
+ MSFT:*_*_*_CC_FLAGS == /c /EHs /Zi /Od /MT
+ GCC:*_*_IA32_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m32 -malign-double -fno-pie
+ GCC:*_*_X64_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m64 -fno-pie "-DEFIAPI=__attribute__((ms_abi))"
diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml index 40a396dd9f..b61a6a0b07 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml @@ -102,6 +102,8 @@ "cobertura",
"DHAVE", # build flag for cmocka in the INF
"gtest", # file name in GoogleTestLib.inf
+ "defiapi", # build flag for gtest
+ "fexceptions", # build flag for gtest
"corthon", # Contact GitHub account in Readme
"mdkinney", # Contact GitHub account in Readme
"spbrogan" # Contact GitHub account in Readme
diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index 00f8d9a895..24a50a2210 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -31,13 +31,14 @@ GCC:*_*_*_CC_FLAGS = -D UNIT_TESTING_DEBUG=1
XCODE:*_*_*_CC_FLAGS = -D UNIT_TESTING_DEBUG=1
!endif
- GCC:*_GCC5_*_CC_FLAGS = --coverage
- GCC:*_GCC5_*_DLINK_FLAGS = --coverage
+ GCC:*_*_*_CC_FLAGS = -fexceptions
+ GCC:*_*_*_CC_FLAGS = --coverage
+ GCC:*_*_*_DLINK_FLAGS = --coverage
[BuildOptions.common.EDKII.HOST_APPLICATION]
#
# MSFT
#
- MSFT:*_*_*_CC_FLAGS = /EHsc
+ MSFT:*_*_*_CC_FLAGS = /EHs
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
|