From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 8354A7803CC for ; Wed, 14 Feb 2024 00:32:35 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=ZIAIYvvDEUFAUx54m8whwNslvRAWz5Gb6QVssxMDsbQ=; c=relaxed/simple; d=groups.io; h=DKIM-Filter:Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From:In-Reply-To:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Language:Content-Type:Content-Transfer-Encoding; s=20140610; t=1707870754; v=1; b=P08rtlFLeYTl1gtwExktfQzEXBmnHw87iNqaj5/WOyzoWhVW8LBuIkiTPeAUtNoZ3W62Lid2 Ec5rfVPIxpNOMhuPAcQQ3DwSPb/+wXEb4byWYVthvDLeu3o4xzZYj9PLLSowo1hLsw8WvAe6q5d pioHa+UEihCzCy4OTj3hy0kI= X-Received: by 127.0.0.2 with SMTP id 3mOkYY7687511xPiVk6br4C3; Tue, 13 Feb 2024 16:32:34 -0800 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.31002.1707870753685261661 for ; Tue, 13 Feb 2024 16:32:33 -0800 X-Received: from [10.0.0.154] (unknown [20.39.63.11]) by linux.microsoft.com (Postfix) with ESMTPSA id D882620B2000; Tue, 13 Feb 2024 16:32:32 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com D882620B2000 Message-ID: <97d61ab5-f455-4d02-a782-25234c19c30c@linux.microsoft.com> Date: Tue, 13 Feb 2024 19:32:32 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [edk2-devel] [edk2-stable202402][Patch v4 3/7] UnitTestFrameworkPkg: Expand host-based exception handling and gcov To: Michael D Kinney , devel@edk2.groups.io Cc: Sean Brogan , Michael Kubacki References: <20240213172612.636-1-michael.d.kinney@intel.com> <20240213172612.636-4-michael.d.kinney@intel.com> From: "Michael Kubacki" In-Reply-To: <20240213172612.636-4-michael.d.kinney@intel.com> Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,mikuback@linux.microsoft.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: K62HTEWzs2kWeI92xtvulXHdx7686176AA= Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: quoted-printable X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=P08rtlFL; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=linux.microsoft.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io After further explanation from Mike: Reviewed-by: Michael Kubacki On 2/13/2024 12:26 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. >=20 > Update GCC CC_FLAGS for host-based unit tests to use -fexceptions > to support catching exceptions. >=20 > 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. >=20 > Update GCC CC_FLAGS to add --coverage for host-based builds > for all GCC tool chains. >=20 > Cc: Michael Kubacki > Cc: Sean Brogan > Signed-off-by: Michael D Kinney > Acked-by: Michael Kubacki > --- > .../Include/Library/GoogleTestLib.h | 20 +++++++++++++++++++ > .../Library/GoogleTestLib/GoogleTestLib.inf | 6 +++--- > .../UnitTestFrameworkPkg.ci.yaml | 2 ++ > .../UnitTestFrameworkPkgHost.dsc.inc | 7 ++++--- > 4 files changed, 29 insertions(+), 6 deletions(-) >=20 > diff --git a/UnitTestFrameworkPkg/Include/Library/GoogleTestLib.h b/UnitT= estFrameworkPkg/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 > #include > =20 > +using ::testing::Throws; > +using ::testing::ThrowsMessage; > +using ::testing::HasSubstr; > + > +// > +// Extended macros for testing exceptions with a specific description st= ring > +// in the exception message. Typically used to check that the expressio= n > +// that generates an ASSERT() matches the expected expression. > +// > +#define EXPECT_THROW_MESSAGE(statement, description) \ > + EXPECT_THAT ( \ > + []() { statement; }, \ > + ThrowsMessage(HasSubstr (description)) \ > + ) > +#define ASSERT_THROW_MESSAGE(statement, description) \ > + ASSERT_THAT ( \ > + []() { statement; }, \ > + ThrowsMessage(HasSubstr (description)) \ > + ) > + > extern "C" { > #include > } > diff --git a/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf= b/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf > index 83ab9f9b2af8..0c522832e9d8 100644 > --- a/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf > +++ b/UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf > @@ -28,6 +28,6 @@ [Packages] > UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec > =20 > [BuildOptions] > - MSFT:*_*_*_CC_FLAGS =3D=3D /c /EHsc /Zi /Od /MT > - GCC:*_*_IA32_CC_FLAGS =3D=3D -g -c -fshort-wchar -O0 -m32 > - GCC:*_*_X64_CC_FLAGS =3D=3D -g -c -fshort-wchar -O0 -m64 > + MSFT:*_*_*_CC_FLAGS =3D=3D /c /EHs /Zi /Od /MT > + GCC:*_*_IA32_CC_FLAGS =3D=3D -g -c -fshort-wchar -fexceptions -O0 -m32= -malign-double -fno-pie > + GCC:*_*_X64_CC_FLAGS =3D=3D -g -c -fshort-wchar -fexceptions -O0 -m64= -fno-pie "-DEFIAPI=3D__attribute__((ms_abi))" > diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml b/UnitTest= FrameworkPkg/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/Unit= TestFrameworkPkg/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 =3D -D UNIT_TESTING_DEBUG=3D1 > XCODE:*_*_*_CC_FLAGS =3D -D UNIT_TESTING_DEBUG=3D1 > !endif > - GCC:*_GCC5_*_CC_FLAGS =3D --coverage > - GCC:*_GCC5_*_DLINK_FLAGS =3D --coverage > + GCC:*_*_*_CC_FLAGS =3D -fexceptions > + GCC:*_*_*_CC_FLAGS =3D --coverage > + GCC:*_*_*_DLINK_FLAGS =3D --coverage > [BuildOptions.common.EDKII.HOST_APPLICATION] > # > # MSFT > # > - MSFT:*_*_*_CC_FLAGS =3D /EHsc > + MSFT:*_*_*_CC_FLAGS =3D /EHs > MSFT:*_*_*_DLINK_FLAGS =3D=3D /out:"$(BIN_DIR)\$(MODULE_NA= ME_GUID).exe" /pdb:"$(BIN_DIR)\$(MODULE_NAME_GUID).pdb" /IGNORE:4001 /NOLOG= O /SUBSYSTEM:CONSOLE /DEBUG /STACK:0x40000,0x40000 /WHOLEARCHIVE > MSFT:*_*_IA32_DLINK_FLAGS =3D /MACHINE:I386 > MSFT:*_*_X64_DLINK_FLAGS =3D /MACHINE:AMD64 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115423): https://edk2.groups.io/g/devel/message/115423 Mute This Topic: https://groups.io/mt/104336760/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-