From: "Michael Kubacki" <mikuback@linux.microsoft.com>
To: devel@edk2.groups.io, michael.d.kinney@intel.com
Cc: Sean Brogan <sean.brogan@microsoft.com>
Subject: Re: [edk2-devel] [edk2-stable202402][Patch V3 3/7] UnitTestFrameworkPkg: Expand host-based exception handling and gcov
Date: Mon, 12 Feb 2024 11:25:26 -0500 [thread overview]
Message-ID: <3a96265b-786b-4cb7-80ab-a74d044ccb29@linux.microsoft.com> (raw)
In-Reply-To: <20240209203253.488-4-michael.d.kinney@intel.com>
Acked-by: Michael Kubacki <michael.kubacki@microsoft.com>
On 2/9/2024 3:32 PM, Michael D Kinney wrote:
> 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>
> ---
> .../Include/Library/GoogleTestLib.h | 20 +++++++++++++++++++
> .../Library/GoogleTestLib/GoogleTestLib.inf | 4 ++--
> .../UnitTestFrameworkPkg.ci.yaml | 2 ++
> .../UnitTestFrameworkPkgHost.dsc.inc | 7 ++++---
> 4 files changed, 28 insertions(+), 5 deletions(-)
>
> diff --git a/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h b/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h
> index c723b5c23050..b8405cee8ee1 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 bdab98a54f0e..0c522832e9d8 100644
> --- a/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf
> +++ b/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf
> @@ -29,5 +29,5 @@ [Packages]
>
> [BuildOptions]
> MSFT:*_*_*_CC_FLAGS == /c /EHs /Zi /Od /MT
> - GCC:*_*_IA32_CC_FLAGS == -g -c -fshort-wchar -O0 -m32
> - GCC:*_*_X64_CC_FLAGS == -g -c -fshort-wchar -O0 -m64
> + 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 40a396dd9f71..b61a6a0b0717 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 00f8d9a895be..24a50a22106f 100644
> --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
> +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
> @@ -31,13 +31,14 @@ [BuildOptions]
> 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
-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115355): https://edk2.groups.io/g/devel/message/115355
Mute This Topic: https://groups.io/mt/104267258/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-
next prev parent reply other threads:[~2024-02-12 16:25 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-09 20:32 [edk2-devel] [edk2-stable202402][Patch V3 0/7] EDK II CI misses UnitTestFrameworkPkg failures Michael D Kinney
2024-02-09 20:32 ` [edk2-devel] [edk2-stable202402][Patch V3 1/7] MdePkg/Include: Rename _DEBUG() to address name collision Michael D Kinney
2024-02-13 11:57 ` Leif Lindholm
2024-02-09 20:32 ` [edk2-devel] [edk2-stable202402][Patch V3 2/7] UnitTestFrameworkPkg: MSFT CC_FLAGS add /MT to for host builds Michael D Kinney
2024-02-10 2:26 ` Michael Kubacki
2024-02-10 4:03 ` Michael D Kinney
2024-02-12 16:25 ` Michael Kubacki
2024-02-09 20:32 ` [edk2-devel] [edk2-stable202402][Patch V3 3/7] UnitTestFrameworkPkg: Expand host-based exception handling and gcov Michael D Kinney
2024-02-12 16:25 ` Michael Kubacki [this message]
2024-02-09 20:32 ` [edk2-devel] [edk2-stable202402][Patch V3 4/7] UnitTestFrameworkPkg/UnitTestLib: GetActiveFrameworkHandle() no ASSERT() Michael D Kinney
2024-02-12 16:25 ` Michael Kubacki
2024-02-09 20:32 ` [edk2-devel] [edk2-stable202402][Patch V3 5/7] UnitTestFrameworkPkg/UnitTestDebugAssertLib: Add GoogleTest support Michael D Kinney
2024-02-12 16:25 ` Michael Kubacki
2024-02-09 20:32 ` [edk2-devel] [edk2-stable202402][Patch V3 6/7] UnitTestFrameworkPkg/SampleGoogleTest: Use EXPECT_ANY_THROW() Michael D Kinney
2024-02-12 16:25 ` Michael Kubacki
2024-02-09 20:32 ` [edk2-devel] [edk2-stable202402][Patch V3 7/7] UnitTestFrameworkPkg: Add DSC and host tests that always fail Michael D Kinney
2024-02-12 16:26 ` Michael Kubacki
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=3a96265b-786b-4cb7-80ab-a74d044ccb29@linux.microsoft.com \
--to=devel@edk2.groups.io \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox