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 A1ECB941D48 for ; Tue, 13 Feb 2024 17:26:21 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=EbuKFynP2u3V3E5qOkjouX7Jl8e9zMAoe+8KyRIF86M=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1707845180; v=1; b=bPLIVGrY5qn/CX4zUSsDMy/5K731NycgEDtdi4JmsweDEpqYYIU/7wVv73+cuNvhwJUzVhnY 3CpmiX4pi40g+gxQNmE16h7RaQvjXvCfbeFimUhLkkjOBJZyBrcRBm0NGDuFWQNkYFdxoRt+M04 3ftSzKF1pNHtppDBVNmb5uK0= X-Received: by 127.0.0.2 with SMTP id FSevYY7687511xCJbcxm5VQ4; Tue, 13 Feb 2024 09:26:20 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by mx.groups.io with SMTP id smtpd.web11.17844.1707845177295409701 for ; Tue, 13 Feb 2024 09:26:17 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10982"; a="1733185" X-IronPort-AV: E=Sophos;i="6.06,157,1705392000"; d="scan'208";a="1733185" X-Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2024 09:26:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,157,1705392000"; d="scan'208";a="7698059" X-Received: from mdkinney-mobl.amr.corp.intel.com ([10.209.108.163]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2024 09:26:17 -0800 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Michael Kubacki , Sean Brogan , Michael Kubacki Subject: [edk2-devel] [edk2-stable202402][Patch v4 3/7] UnitTestFrameworkPkg: Expand host-based exception handling and gcov Date: Tue, 13 Feb 2024 09:26:08 -0800 Message-Id: <20240213172612.636-4-michael.d.kinney@intel.com> In-Reply-To: <20240213172612.636-1-michael.d.kinney@intel.com> References: <20240213172612.636-1-michael.d.kinney@intel.com> MIME-Version: 1.0 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,michael.d.kinney@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: Xz5VpT42NIDG9nyY13L1wEXGx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=bPLIVGrY; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.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 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 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(-) 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 #include +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(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 [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 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 -- 2.40.1.windows.1 -=-=-=-=-=-=-=-=-=-=-=- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#115395): https://edk2.groups.io/g/devel/message/115395 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] -=-=-=-=-=-=-=-=-=-=-=-