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 86792AC14EF for ; Mon, 12 Feb 2024 16:25:39 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=SYwNvYCyncgjjwxx6Kf9fz2taXxFqmOCJfozp7PAph0=; 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=1707755138; v=1; b=Mq/0eGXCjdwPApoZirYDShM1/YMiGkGfq8Bco8jIlQIUunwk2SfU24izEmSet/9GbXqcHTtd Vvz7Pcy9PIvPKOAcJRF2oGk4A/EUTYGXrWIZs2+CG4IBENrm7VC/tRKSOtOlIaNs5xsUmVWC3a6 NPKClmLz+dcxG6IjqbqkXVic= X-Received: by 127.0.0.2 with SMTP id QiI9YY7687511xmsMXNsOuaB; Mon, 12 Feb 2024 08:25:38 -0800 X-Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.10675.1707755137280625666 for ; Mon, 12 Feb 2024 08:25:37 -0800 X-Received: from [10.0.0.154] (unknown [20.39.63.12]) by linux.microsoft.com (Postfix) with ESMTPSA id AB91520B2001; Mon, 12 Feb 2024 08:25:36 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com AB91520B2001 Message-ID: <0a4bf108-dfd6-4236-b43f-dc97eceb9ded@linux.microsoft.com> Date: Mon, 12 Feb 2024 11:25:36 -0500 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [edk2-devel] [edk2-stable202402][Patch V3 5/7] UnitTestFrameworkPkg/UnitTestDebugAssertLib: Add GoogleTest support To: Michael D Kinney , devel@edk2.groups.io Cc: Sean Brogan References: <20240209203253.488-1-michael.d.kinney@intel.com> <20240209203253.488-6-michael.d.kinney@intel.com> From: "Michael Kubacki" In-Reply-To: <20240209203253.488-6-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: vcA4Pd0gpUqqDI9nQj5pyiuOx7686176AA= 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="Mq/0eGXC"; 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 Reviewed-by: Michael Kubacki On 2/9/2024 3:32 PM, Michael D Kinney wrote: > Add an C++ implementation of UnitTestDebugAssert() API for > host-based environments. GoogleTest based environments throw > a C++ exception of type std::runtime_error when an ASSERT() is > triggered with a description that contains the filename, line > number, and the expression that triggered the ASSERT(). >=20 > Cc: Michael Kubacki > Cc: Sean Brogan > Signed-off-by: Michael D Kinney > --- > .../UnitTestDebugAssertLibHost.cpp | 63 +++++++++++++++++++ > .../UnitTestDebugAssertLibHost.inf | 36 +++++++++++ > .../UnitTestDebugAssertLibHost.uni | 11 ++++ > .../Test/UnitTestFrameworkPkgHostTest.dsc | 1 + > .../UnitTestFrameworkPkgHost.dsc.inc | 1 + > .../UnitTestFrameworkPkgTarget.dsc.inc | 14 +++++ > 6 files changed, 126 insertions(+) > create mode 100644 UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/= UnitTestDebugAssertLibHost.cpp > create mode 100644 UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/= UnitTestDebugAssertLibHost.inf > create mode 100644 UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/= UnitTestDebugAssertLibHost.uni >=20 > diff --git a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTest= DebugAssertLibHost.cpp b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLi= b/UnitTestDebugAssertLibHost.cpp > new file mode 100644 > index 000000000000..a4405cc205ba > --- /dev/null > +++ b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAs= sertLibHost.cpp > @@ -0,0 +1,63 @@ > +/** @file > + Unit Test Debug Assert Library for host-based environments > + > + Copyright (c) 2020, Intel Corporation. All rights reserved.
> + SPDX-License-Identifier: BSD-2-Clause-Patent > + > +**/ > + > +#include > + > +#ifdef NULL > + #undef NULL > +#endif > + > +extern "C" { > + #include > + #include > + #include > + #include > + > + /// > + /// Point to jump buffer used with SetJump()/LongJump() to test if a f= unction > + /// under test generates an expected ASSERT() condition. > + /// > + BASE_LIBRARY_JUMP_BUFFER *gUnitTestExpectAssertFailureJumpBuffer =3D = NULL; > + > + /** > + Unit test library replacement for DebugAssert() in DebugLib. > + > + If FileName is NULL, then a string of "(NULL) Filename" i= s printed. > + If Description is NULL, then a string of "(NULL) Descr= iption" is printed. > + > + @param FileName The pointer to the name of the source file that= generated the assert condition. > + @param LineNumber The line number in the source file that generat= ed the assert condition > + @param Description The pointer to the description of the assert co= ndition. > + > + **/ > + VOID > + EFIAPI > + UnitTestDebugAssert ( > + IN CONST CHAR8 *FileName, > + IN UINTN LineNumber, > + IN CONST CHAR8 *Description > + ) > + { > + CHAR8 Message[256]; > + > + if (gUnitTestExpectAssertFailureJumpBuffer !=3D NULL) { > + UT_LOG_INFO ("Detected expected ASSERT: %a(%d): %a\n", FileName, L= ineNumber, Description); > + LongJump (gUnitTestExpectAssertFailureJumpBuffer, 1); > + } else { > + if (GetActiveFrameworkHandle () !=3D NULL) { > + AsciiStrCpyS (Message, sizeof (Message), "Detected unexpected AS= SERT("); > + AsciiStrCatS (Message, sizeof (Message), Description); > + AsciiStrCatS (Message, sizeof (Message), ")"); > + UnitTestAssertTrue (FALSE, "", LineNumber, FileName, Message); > + } else { > + snprintf (Message, sizeof (Message), "Detected unexpected ASSERT= : %s(%d): %s\n", FileName, (INT32)(UINT32)LineNumber, Description); > + throw std::runtime_error (Message); > + } > + } > + } > +} > diff --git a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTest= DebugAssertLibHost.inf b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLi= b/UnitTestDebugAssertLibHost.inf > new file mode 100644 > index 000000000000..9a7673f179cf > --- /dev/null > +++ b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAs= sertLibHost.inf > @@ -0,0 +1,36 @@ > +## @file > +# Unit Test Debug Assert Library for host-based environments > +# > +# Copyright (c) 2020, Intel Corporation. All rights reserved.
> +# SPDX-License-Identifier: BSD-2-Clause-Patent > +# > +## > + > +[Defines] > + INF_VERSION =3D 0x00010005 > + BASE_NAME =3D UnitTestDebugAssertLibHost > + MODULE_UNI_FILE =3D UnitTestDebugAssertLibHost.uni > + FILE_GUID =3D F097D67C-0340-49C8-AB30-ABC1B7D1C8D= 2 > + MODULE_TYPE =3D HOST_APPLICATION > + VERSION_STRING =3D 1.0 > + LIBRARY_CLASS =3D NULL > + > +# > +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 > +# > + > +[Sources] > + UnitTestDebugAssertLibHost.cpp > + > +[Packages] > + MdePkg/MdePkg.dec > + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec > + > +[LibraryClasses] > + BaseLib > + UnitTestLib > + > +[BuildOptions] > + 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/Library/UnitTestDebugAssertLib/UnitTest= DebugAssertLibHost.uni b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLi= b/UnitTestDebugAssertLibHost.uni > new file mode 100644 > index 000000000000..63d1753a856f > --- /dev/null > +++ b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAs= sertLibHost.uni > @@ -0,0 +1,11 @@ > +// /** @file > +// Unit Test Debug Assert Library for host-based environments > +// > +// Copyright (c) 2020, Intel Corporation. All rights reserved.
> +// SPDX-License-Identifier: BSD-2-Clause-Patent > +// > +// **/ > + > +#string STR_MODULE_ABSTRACT #language en-US "Unit Test Debug= Assert Library for host-based environments" > + > +#string STR_MODULE_DESCRIPTION #language en-US "Unit Test Debug= Assert Library for host-based environments" > diff --git a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc b= /UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc > index dbb429faaeca..b1b8eb0fe58b 100644 > --- a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc > +++ b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc > @@ -38,3 +38,4 @@ [Components] > UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAll= ocationLibPosix.inf > UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf > UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf > + UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAsser= tLibHost.inf > diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/Unit= TestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc > index 24a50a22106f..83d3205b636c 100644 > --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc > +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc > @@ -22,6 +22,7 @@ [LibraryClasses.common.HOST_APPLICATION] > MemoryAllocationLib|UnitTestFrameworkPkg/Library/Posix/MemoryAllocati= onLibPosix/MemoryAllocationLibPosix.inf > UefiBootServicesTableLib|UnitTestFrameworkPkg/Library/UnitTestUefiBoo= tServicesTableLib/UnitTestUefiBootServicesTableLib.inf > PeiServicesTablePointerLib|UnitTestFrameworkPkg/Library/UnitTestPeiSe= rvicesTablePointerLib/UnitTestPeiServicesTablePointerLib.inf > + NULL|UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebug= AssertLibHost.inf > =20 > [BuildOptions] > MSFT:*_*_*_CC_FLAGS =3D /MT > diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc b/Un= itTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc > index 8adf690098ae..1a059ed4aad2 100644 > --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc > +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc > @@ -29,6 +29,20 @@ [LibraryClasses] > UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.inf > UnitTestPersistenceLib|UnitTestFrameworkPkg/Library/UnitTestPersisten= ceLibNull/UnitTestPersistenceLibNull.inf > UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultRe= portLib/UnitTestResultReportLibDebugLib.inf > + > +[LibraryClasses.common.SEC, LibraryClasses.common.PEI_CORE, LibraryClass= es.common.PEIM] > + NULL|UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebug= AssertLib.inf > + > +[LibraryClasses.common.DXE_CORE, LibraryClasses.common.DXE_DRIVER, Libra= ryClasses.common.DXE_RUNTIME_DRIVER] > + NULL|UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebug= AssertLib.inf > + > +[LibraryClasses.common.SMM_CORE, LibraryClasses.common.DXE_SMM_DRIVER] > + NULL|UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebug= AssertLib.inf > + > +[LibraryClasses.common.MM_STANDALONE] > + NULL|UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebug= AssertLib.inf > + > +[LibraryClasses.common.UEFI_DRIVER, LibraryClasses.common.UEFI_APPLICATI= ON] > NULL|UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebu= gAssertLib.inf > =20 > [LibraryClasses.ARM, LibraryClasses.AARCH64] -=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 (#115357): https://edk2.groups.io/g/devel/message/115357 Mute This Topic: https://groups.io/mt/104267260/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-