summaryrefslogtreecommitdiff
path: root/UnitTestFrameworkPkg/Include/Library
diff options
context:
space:
mode:
authorMichael D Kinney <michael.d.kinney@intel.com>2024-02-02 17:28:31 -0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2024-02-14 02:37:16 +0000
commit81b69f306fe801546786186e1e5ae5f79a2fde97 (patch)
tree139b513bab6fe3ce058a8d1bf14e49717de62e76 /UnitTestFrameworkPkg/Include/Library
parent46c6de57b0628567ed3e72a7c65d1e6c708312cc (diff)
downloadedk2-81b69f306fe801546786186e1e5ae5f79a2fde97.zip
edk2-81b69f306fe801546786186e1e5ae5f79a2fde97.tar.gz
edk2-81b69f306fe801546786186e1e5ae5f79a2fde97.tar.bz2
UnitTestFrameworkPkg: Expand host-based exception handling and gcov
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4683 Update MSFT CC_FLAGS for host-based unit tests to use /EHs instead of /EHsc to support building C functions with SEH (Structured Exception Handling) enabled. This is required to build UnitTestDebugAssertLibHost.inf. Update GCC CC_FLAGS for host-based unit tests to use -fexceptions to support catching exceptions. Update GoogleTestLib.h to include Throws() APIs that enable unit tests to use EXPECT_THAT() to check for expected ASSERT() conditions for a specific ASSERT() expression. Update GCC CC_FLAGS to add --coverage for host-based builds for all GCC tool chains. Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com>
Diffstat (limited to 'UnitTestFrameworkPkg/Include/Library')
-rw-r--r--UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h20
1 files changed, 20 insertions, 0 deletions
diff --git a/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h b/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h
index c723b5c..b8405ce 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>
}