From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web12.14757.1594709797800452900 for ; Mon, 13 Jul 2020 23:56:37 -0700 Authentication-Results: mx.groups.io; dkim=pass header.i=@intel.onmicrosoft.com header.s=selector2-intel-onmicrosoft-com header.b=cs2LYki/; spf=pass (domain: intel.com, ip: 192.55.52.115, mailfrom: liming.gao@intel.com) IronPort-SDR: +HMKVxQCtkAP4KvLnHZ6xpNu/E4FVvNqdtGB+bTV0F94sx8UmM/2Z9DUNzUU35/kQnVefnzi6B L7KHPUlBE9cg== X-IronPort-AV: E=McAfee;i="6000,8403,9681"; a="147961291" X-IronPort-AV: E=Sophos;i="5.75,350,1589266800"; d="scan'208";a="147961291" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Jul 2020 23:56:35 -0700 IronPort-SDR: pqCNoiKBSoy5HriMGou4B52QpPdS1C3kWvmA0wwY7LVnkj87SZYA8qh/pZ93C9vaeamJAVT/Rz SBRIrWCsHjpw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.75,350,1589266800"; d="scan'208";a="485772184" Received: from fmsmsx107.amr.corp.intel.com ([10.18.124.205]) by fmsmga005.fm.intel.com with ESMTP; 13 Jul 2020 23:56:34 -0700 Received: from fmsmsx161.amr.corp.intel.com (10.18.125.9) by fmsmsx107.amr.corp.intel.com (10.18.124.205) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 13 Jul 2020 23:56:33 -0700 Received: from FMSEDG002.ED.cps.intel.com (10.1.192.134) by FMSMSX161.amr.corp.intel.com (10.18.125.9) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 13 Jul 2020 23:56:33 -0700 Received: from NAM10-MW2-obe.outbound.protection.outlook.com (104.47.55.104) by edgegateway.intel.com (192.55.55.69) with Microsoft SMTP Server (TLS) id 14.3.439.0; Mon, 13 Jul 2020 23:56:33 -0700 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=LkXTVaMnyb5n1v+ACnc0IknQqBNSoa08LnxALHR3VgZ+vxzzaKuEqjUt0PnlFIJM032uQx2Ve+dNb4JESDdPQhtRU9ok85+W6sc6jrYXDPYwDcAqgZz4gh4puT+Y5cpiT/Z/uZi3s9uGLJTvuBQcqjy+ARqMdWcAVGVNnnT0zmDGw9Za/C/qDC0PBLe/1qxPi0nYYyfMdc/ZFT5EV9qMraNN/mxqZ9E9TExI9Y5IN+UQk7hFZM9RS7vmsHT/jBC04iQ3x65INFvTpMSLb0O67dQMkaCsNIqvKWdkmiqTZ3fN5vM/pkK2WgG/ke3900KGl3Z4rlCQYnGV0bVk0M4O/g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LL41FA3NDGsbrD3L6zcwBLLBdeCPUKcU/wfO0Q/bz68=; b=jBbvOeKczgwM2XwW9VyJZUAr3CG+yrbVC9cXcuRVaiQU9SmdrZvJ2IH+02E8PXyvria3gqc6gtAReI72I3evm6q8lozGCep5YEzg9h7ac6aWytB3dw63dwJouIs7QE0qLuP5ZNLU+05jpWgIS67YSzgn9BKrdkaxl++qlq2dOv3nd8jZNf8WXbHl78ojW3+U5wNeulF0h52VF27vmwMq1t7MBntQHvX7OGjsBRGzg7wZvvY6haOCkKSfImWbYd+BvcXoDwxsyWcdt0t8mr9e9lCuYa9L01dq958QHnDHpQWxXU0F/fpGk1xuNp9pORHwtFi5NPkUmomHIwbz2bv/ow== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=intel.com; dmarc=pass action=none header.from=intel.com; dkim=pass header.d=intel.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=intel.onmicrosoft.com; s=selector2-intel-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=LL41FA3NDGsbrD3L6zcwBLLBdeCPUKcU/wfO0Q/bz68=; b=cs2LYki/d2+9AODvX2EWtpyff8HjJhmDMSzB9Ed4B7tZNE40mMQRQxvQEkBlgXRAp3sOi8uEXAd3GJIZZbjlf3YEIVKl37qm5GwJB6S1Kry5xGJSIfTvMCjtrRJjevaRjeoTcKXkLTdbyuJDe+ALL0ebYYZimCKfly+5qFKx9io= Received: from MWHPR11MB1630.namprd11.prod.outlook.com (2603:10b6:301:e::7) by MWHPR1101MB2142.namprd11.prod.outlook.com (2603:10b6:301:56::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3195.17; Tue, 14 Jul 2020 06:56:31 +0000 Received: from MWHPR11MB1630.namprd11.prod.outlook.com ([fe80::7847:b564:1b55:b67e]) by MWHPR11MB1630.namprd11.prod.outlook.com ([fe80::7847:b564:1b55:b67e%6]) with mapi id 15.20.3174.025; Tue, 14 Jul 2020 06:56:31 +0000 From: "Liming Gao" To: "devel@edk2.groups.io" , "Kinney, Michael D" CC: Sean Brogan , Bret Barkelew , "Yao, Jiewen" Subject: Re: [edk2-devel] [Patch v3 12/16] UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT() Thread-Topic: [edk2-devel] [Patch v3 12/16] UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT() Thread-Index: AQHWVyhrAy9Y5A3PdkajfrTtJF4qO6kGqVDw Date: Tue, 14 Jul 2020 06:56:31 +0000 Message-ID: References: <20200711020904.24116-1-michael.d.kinney@intel.com> <20200711020904.24116-13-michael.d.kinney@intel.com> In-Reply-To: <20200711020904.24116-13-michael.d.kinney@intel.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: dlp-version: 11.2.0.6 dlp-product: dlpe-windows dlp-reaction: no-action authentication-results: edk2.groups.io; dkim=none (message not signed) header.d=none;edk2.groups.io; dmarc=none action=none header.from=intel.com; x-originating-ip: [192.198.147.217] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: fb492e03-e980-4345-0ee7-08d827c30a34 x-ms-traffictypediagnostic: MWHPR1101MB2142: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:10000; x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: /bm21jxfv3akaICZULUmDScm3whT0GrMgUk3R6KpP9TUXMG/xjosxv90f1rU+oGRUO4Wo55rvlrDJ64zZbkFKaZgNp0UaOhq48Rlo5fTzvztthnehw91fCiLtK9Y14jUMcBNvFOoUXlzgSnNzWG704O6NB0RomhmwbaBT0PiikSWsiBDA3y2HoC4L1bAXJeQ3M6wSkMLB3p7Eyi6qzPDVIQeJN4uBWjrB2jb37BASypPtJnvbX6CLQVPc0pRMzZkk4NXpKC9BX2VRzHlArNUm6Q2BCy0qG+S2PasiNEhyXN0FqAywRCi8BraVWDjhe40/V+ju7w9xmQ2h/8nLBHK6tWgkxlmM6OH0ry8tpHMX5/Mn59D5W6EnTBM9sWefJH41skXv1z5/Av+Rd8LsJEuzg== x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:MWHPR11MB1630.namprd11.prod.outlook.com;PTR:;CAT:NONE;SFTY:;SFS:(4636009)(366004)(39860400002)(376002)(396003)(136003)(346002)(76116006)(186003)(966005)(54906003)(26005)(66946007)(110136005)(86362001)(8676002)(64756008)(6636002)(5660300002)(66556008)(66476007)(66446008)(6506007)(107886003)(30864003)(8936002)(478600001)(2906002)(71200400001)(83380400001)(9686003)(7696005)(4326008)(316002)(33656002)(53546011)(55016002)(52536014)(579004)(559001);DIR:OUT;SFP:1102; x-ms-exchange-antispam-messagedata: Ia5HvlbtNv1bS2CV+9MxxHQRo+NeQ0FhV0JaAJpCBzihsVvgZ1PDKX0oXwhtqpIpN4t5GPHyYsIWaavV8aMmasjfiX/0W00xU7Rn3EpcRBllfVOJPeJS9l836EuRu5Q/SiUKCWVBOPurh1LZjO2LJBGw7FgFsC9LES7Ife+uMwvhsYxQCMSYdAm4kL5HcehnhZ32hXn419w6z7vJ6rLzQPATPtS3h0ntc+N31BgIXu/V4/3AvhEQVbC1eVpZVRl15n/gaUVS99p8zJm6A4cUNHDNPqV7Gf1ES0erFeqJu6oYhwhrFEotPq1Q0204lxg4/aAqLlMxKvrsIMoKJ8YrDSg1qQEBj0uxwTbewBPVHMoSPf/oRMXhjMjYmIQ7JgLlvItioWyMujgzAkiDtWzZ9FXAnkFgECSMi6E9KO74jAU54yXBT4XNTBMwg/8dfsgk1I82HDDYFeAD0tgTyyQq2p8Km0tRkFwKsXp6utJj02sjiYsUspM978RO9Q1+Mw0W MIME-Version: 1.0 X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: MWHPR11MB1630.namprd11.prod.outlook.com X-MS-Exchange-CrossTenant-Network-Message-Id: fb492e03-e980-4345-0ee7-08d827c30a34 X-MS-Exchange-CrossTenant-originalarrivaltime: 14 Jul 2020 06:56:31.4105 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 46c98d88-e344-4ed4-8496-4ed7712e255d X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: h6VCl6tPd/vwD6F4k+s/yYXvps4/5pIbrDXt3sxagkEjE5GR/CkvbR/46h80ZZDpgxBpE1tKQtQ/e7gaUESYSQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR1101MB2142 Return-Path: liming.gao@intel.com X-OriginatorOrg: intel.com Content-Language: en-US Content-Type: text/plain; charset="iso-2022-jp" Content-Transfer-Encoding: quoted-printable Mike: -----Original Message----- From: devel@edk2.groups.io On Behalf Of Michael D K= inney Sent: 2020=1B$BG/=1B(B7=1B$B7n=1B(B11=1B$BF|=1B(B 10:09 To: devel@edk2.groups.io Cc: Sean Brogan ; Bret Barkelew ; Yao, Jiewen Subject: [edk2-devel] [Patch v3 12/16] UnitTestFrameworkPkg/UnitTestLib: A= dd checks for ASSERT() REF: REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D2801 Add UnitTestDebugAssertLib that provides the UnitTestDebugAssert() service= and the gUnitTestExpectAssertFailureJumpBuffer global variable. This NULL= library is linked against all host and target unit test builds. This guar= antees that the UnitTestDebugAssert() service is available to link against = all libraries and modules that use the DebugLib class. EDKII_UNIT_TEST_FRAMEWORK_ENABLED must always be defined when building uni= t tests so the behavior of the DebugLib ASSERT() macros can be adjusted to = allow the unit test framework to catch an ASSERT() if it is triggered by a = function under test. Cc: Sean Brogan Cc: Bret Barkelew Cc: Jiewen Yao Signed-off-by: Michael D Kinney --- .../UnitTestDebugAssertLib.c | 49 +++++ .../UnitTestDebugAssertLib.inf | 31 +++ .../UnitTestDebugAssertLib.uni | 11 + .../Library/UnitTestLib/Assert.c | 203 ++++++++++++------ .../Library/UnitTestLib/AssertCmocka.c | 68 ++++++ .../Library/UnitTestLib/RunTests.c | 23 +- .../UnitTestResultReportLib.c | 3 +- .../PrivateInclude/UnitTestFrameworkTypes.h | 1 + .../Test/UnitTestFrameworkPkgHostTest.dsc | 2 +- UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc | 1 + .../UnitTestFrameworkPkgTarget.dsc.inc | 6 +- 11 files changed, 328 insertions(+), 70 deletions(-) create mode 100644 = UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.= c create mode 100644 UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un= itTestDebugAssertLib.inf create mode 100644 UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un= itTestDebugAssertLib.uni diff --git a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestD= ebugAssertLib.c b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitT= estDebugAssertLib.c new file mode 100644 index 0000000000..0a4001e182 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugA +++ ssertLib.c @@ -0,0 +1,49 @@ +/** @file + Unit Test Debug Assert Library + + Copyright (c) 2020, Intel Corporation. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include + +/// +/// Point to jump buffer used with SetJump()/LongJump() to test if a=20 +function /// under test generates an expected ASSERT() condition. +/// +BASE_LIBRARY_JUMP_BUFFER *gUnitTestExpectAssertFailureJumpBuffer =3D=20 +NULL; + +/** + Unit test library replacement for DebugAssert() in DebugLib. + + If FileName is NULL, then a string of "(NULL) Filename" is p= rinted. + If Description is NULL, then a string of "(NULL) Descript= ion" is printed. + + @param FileName The pointer to the name of the source file that ge= nerated the assert condition. + @param LineNumber The line number in the source file that generated = the assert condition + @param Description The pointer to the description of the assert condi= tion. + +**/ +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, Line= Number, Description); + LongJump (gUnitTestExpectAssertFailureJumpBuffer, 1); + } else { + AsciiStrCpyS (Message, sizeof(Message), "Detected unexpected ASSERT("= ); + AsciiStrCatS (Message, sizeof(Message), Description); + AsciiStrCatS (Message, sizeof(Message), ")"); + UnitTestAssertTrue (FALSE, "", LineNumber, FileName, Message); + } +} diff --git a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestD= ebugAssertLib.inf b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Uni= tTestDebugAssertLib.inf new file mode 100644 index 0000000000..e6ccab0dd9 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugA +++ ssertLib.inf @@ -0,0 +1,31 @@ +## @file +# Unit Test Debug Assert Library +# +# Copyright (c) 2020, Intel Corporation. All rights reserved.
# +SPDX-License-Identifier: BSD-2-Clause-Patent # ## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D UnitTestDebugAssertLib + MODULE_UNI_FILE =3D UnitTestDebugAssertLib.uni + FILE_GUID =3D 9D53AD0D-5416-451F-A5BF-E5420051A99B + MODULE_TYPE =3D BASE + VERSION_STRING =3D 1.0 + LIBRARY_CLASS =3D NULL + +# +# VALID_ARCHITECTURES =3D ARM AARCH64 +# Seemly, this comment is incorrect. Valid arch should include IA32 and X64.= Right? Thanks Liming + +[Sources] + UnitTestDebugAssertLib.c + +[Packages] + MdePkg/MdePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + BaseLib + UnitTestLib diff --git a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestD= ebugAssertLib.uni b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Uni= tTestDebugAssertLib.uni new file mode 100644 index 0000000000..9b794aa205 --- /dev/null +++ b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugA +++ ssertLib.uni @@ -0,0 +1,11 @@ +// /** @file +// Unit Test Debug Assert Library +// +// Copyright (c) 2020, Intel Corporation. All rights reserved.
//=20 +SPDX-License-Identifier: BSD-2-Clause-Patent // // **/ + +#string STR_MODULE_ABSTRACT #language en-US "Unit Test Debug = Assert Library" + +#string STR_MODULE_DESCRIPTION #language en-US "Unit Test Debug = Assert Library" diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c b/UnitTestF= rameworkPkg/Library/UnitTestLib/Assert.c index 8a131fab2b..3669d63701 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c +++ b/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c @@ -13,6 +13,8 @@ #include #include =20 +extern BASE_LIBRARY_JUMP_BUFFER gUnitTestJumpBuffer; + STATIC EFI_STATUS AddUnitTestFailure ( @@ -71,7 +73,7 @@ UnitTestLogFailure ( FailureType ); =20 - return; + LongJump (&gUnitTestJumpBuffer, 1); } =20 /** @@ -103,6 +105,12 @@ UnitTestAssertTrue ( ) { if (!Expression) { + UT_LOG_ERROR ( + "[ASSERT FAIL] %a:%d: Expression (%a) is not TRUE!\n", + FileName, + LineNumber, + Description + ); UnitTestLogFailure ( FAILURETYPE_ASSERTTRUE, "%a:%d: Expression (%a) is not TRUE!\n", @@ -110,12 +118,6 @@ UnitT= estAssertTrue ( LineNumber, Description ); - UT_LOG_ERROR ( - "[ASSERT FAIL] %a:%d: Expression (%a) is not TRUE!\n", - FileName, - LineNumber, - Description - ); } return Expression; } @@ -149,6 +151,12 @@ UnitTestAssertFalse ( ) { if (Expression) { + UT_LOG_ERROR ( + "[ASSERT FAIL] %a:%d: Expression (%a) is not FALSE!\n", + FileName, + LineNumber, + Description + ); UnitTestLogFailure ( FAILURETYPE_ASSERTFALSE, "%a:%d: Expression(%a) is not FALSE!\n", @@ -156,12 +164,6 @@ UnitT= estAssertFalse ( LineNumber, Description ); - UT_LOG_ERROR ( - "[ASSERT FAIL] %a:%d: Expression (%a) is not FALSE!\n", - FileName, - LineNumber, - Description - ); } return !Expression; } @@ -195,6 +197,13 @@ UnitTestAssertNotEfiError ( ) { if (EFI_ERROR (Status)) { + UT_LOG_ERROR ( + "[ASSERT FAIL] %a:%d: Status '%a' is EFI_ERROR (%r)!\n", + FileName, + LineNumber, + Description, + Status + ); UnitTestLogFailure ( FAILURETYPE_ASSERTNOTEFIERROR, "%a:%d: Status '%a' is EFI_ERROR (%r)!\n", @@ -203,13 +212,6 @@ Uni= tTestAssertNotEfiError ( Description, Status ); - UT_LOG_ERROR ( - "[ASSERT FAIL] %a:%d: Status '%a' is EFI_ERROR (%r)!\n", - FileName, - LineNumber, - Description, - Status - ); } return !EFI_ERROR( Status ); } @@ -248,16 +250,6 @@ UnitTestAssertEqual ( ) { if (ValueA !=3D ValueB) { - UnitTestLogFailure ( - FAILURETYPE_ASSERTEQUAL, - "%a:%d: Value %a !=3D %a (%d !=3D %d)!\n", - FileName, - LineNumber, - DescriptionA, - DescriptionB, - ValueA, - ValueB - ); UT_LOG_ERROR ( "[ASSERT FAIL] %a:%d: Value %a !=3D %a (%d !=3D %d)!\n", FileName, @@ -267,6 +259,16 @@ UnitTestAssertEqual ( ValueA, ValueB ); + UnitTestLogFailure ( + FAILURETYPE_ASSERTEQUAL, + "%a:%d: Value %a !=3D %a (%d !=3D %d)!\n", + FileName, + LineNumber, + DescriptionA, + DescriptionB, + ValueA, + ValueB + ); } return (ValueA =3D=3D ValueB); } @@ -310,15 +312,6 @@ UnitTestAssertMemEqual ( ) { if (CompareMem(BufferA, BufferB, Length) !=3D 0) { - UnitTestLogFailure ( - FAILURETYPE_ASSERTEQUAL, - "%a:%d: Memory at %a !=3D %a for length %d bytes!\n", - FileName, - LineNumber, - DescriptionA, - DescriptionB, - Length - ); UT_LOG_ERROR ( "[ASSERT FAIL] %a:%d: Value %a !=3D %a for length %d bytes!\n", FileName, @@ -327,6 +320,15 @@ UnitTestAssertMemEqual ( DescriptionB, Length ); + UnitTestLogFailure ( + FAILURETYPE_ASSERTEQUAL, + "%a:%d: Memory at %a !=3D %a for length %d bytes!\n", + FileName, + LineNumber, + DescriptionA, + DescriptionB, + Length + ); return FALSE; } return TRUE; @@ -366,6 +368,15 @@ UnitTestAssertNotEqual ( ) { if (ValueA =3D=3D ValueB) { + UT_LOG_ERROR ( + "[ASSERT FAIL] %a:%d: Value %a =3D=3D %a (%d =3D=3D %d)!\n", + FileName, + LineNumber, + DescriptionA, + DescriptionB, + ValueA, + ValueB + ); UnitTestLogFailure ( FAILURETYPE_ASSERTNOTEQUAL, "%a:%d: Value %a =3D=3D %a (%d =3D=3D %d)!\n", @@ -376,15 +387,6 @@= UnitTestAssertNotEqual ( ValueA, ValueB ); - UT_LOG_ERROR ( - "[ASSERT FAIL] %a:%d: Value %a =3D=3D %a (%d =3D=3D %d)!\n", - FileName, - LineNumber, - DescriptionA, - DescriptionB, - ValueA, - ValueB - ); } return (ValueA !=3D ValueB); } @@ -421,6 +423,14 @@ UnitTestAssertStatusEqual ( ) { if (Status !=3D Expected) { + UT_LOG_ERROR ( + "[ASSERT FAIL] %a:%d: Status '%a' is %r, should be %r!\n", + FileName, + LineNumber, + Description, + Status, + Expected + ); UnitTestLogFailure ( FAILURETYPE_ASSERTSTATUSEQUAL, "%a:%d: Status '%a' is %r, should be %r!\n", @@ -430,14 +440,6 @@ U= nitTestAssertStatusEqual ( Status, Expected ); - UT_LOG_ERROR ( - "[ASSERT FAIL] %a:%d: Status '%a' is %r, should be %r!\n", - FileName, - LineNumber, - Description, - Status, - Expected - ); } return (Status =3D=3D Expected); } @@ -473,6 +475,12 @@ UnitTestAssertNotNull ( ) { if (Pointer =3D=3D NULL) { + UT_LOG_ERROR ( + "[ASSERT FAIL] %a:%d: Pointer (%a) is NULL!\n", + FileName, + LineNumber, + PointerName + ); UnitTestLogFailure ( FAILURETYPE_ASSERTNOTNULL, "%a:%d: Pointer (%a) is NULL!\n", @@ -480,12 +488,83 @@ UnitTestAss= ertNotNull ( LineNumber, PointerName ); - UT_LOG_ERROR ( - "[ASSERT FAIL] %a:%d: Pointer (%a) is NULL!\n", - FileName, - LineNumber, - PointerName - ); } return (Pointer !=3D NULL); } + +/** + If UnitTestStatus is UNIT_TEST_PASSED, then log an info message and=20 +return + TRUE because an ASSERT() was expected when FunctionCall was executed=20 +and an + ASSERT() was triggered. If UnitTestStatus is UNIT_TEST_SKIPPED, then=20 +log a + warning message and return TRUE because ASSERT() macros are disabled. +If + UnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED, then log an error=20 +message and + return FALSE because an ASSERT() was expected when FunctionCall was=20 +executed, + but no ASSERT() conditions were triggered. The log messages contain + FunctionName, LineNumber, and FileName strings to provide the=20 +location of the + UT_EXPECT_ASSERT_FAILURE() macro. + + @param[in] UnitTestStatus The status from UT_EXPECT_ASSERT_FAILURE() = that + is either pass, skipped, or failed. + @param[in] FunctionName Null-terminated ASCII string of the functio= n + executing the UT_EXPECT_ASSERT_FAILURE() ma= cro. + @param[in] LineNumber The source file line number of the the func= tion + executing the UT_EXPECT_ASSERT_FAILURE() ma= cro. + @param[in] FileName Null-terminated ASCII string of the filenam= e + executing the UT_EXPECT_ASSERT_FAILURE() ma= cro. + @param[in] FunctionCall Null-terminated ASCII string of the functio= n call + executed by the UT_EXPECT_ASSERT_FAILURE() = macro. + @param[out] ResultStatus Used to return the UnitTestStatus value to = the + caller of UT_EXPECT_ASSERT_FAILURE(). This= is + optional parameter that may be NULL. + + @retval TRUE UnitTestStatus is UNIT_TEST_PASSED. + @retval TRUE UnitTestStatus is UNIT_TEST_SKIPPED. + @retval FALSE UnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED. +**/ +BOOLEAN +EFIAPI +UnitTestExpectAssertFailure ( + IN UNIT_TEST_STATUS UnitTestStatus, + IN CONST CHAR8 *FunctionName, + IN UINTN LineNumber, + IN CONST CHAR8 *FileName, + IN CONST CHAR8 *FunctionCall, + OUT UNIT_TEST_STATUS *ResultStatus OPTIONAL + ) +{ + if (ResultStatus !=3D NULL) { + *ResultStatus =3D UnitTestStatus; + } + if (UnitTestStatus =3D=3D UNIT_TEST_PASSED) { + UT_LOG_INFO ( + "[ASSERT PASS] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) detected expecte= d assert\n", + FileName, + LineNumber, + FunctionCall + ); + } + if (UnitTestStatus =3D=3D UNIT_TEST_SKIPPED) { + UT_LOG_WARNING ( + "[ASSERT WARN] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) disabled\n", + FileName, + LineNumber, + FunctionCall + ); + } + if (UnitTestStatus =3D=3D UNIT_TEST_ERROR_TEST_FAILED) { + UT_LOG_ERROR ( + "[ASSERT FAIL] %a:%d: Function call (%a) did not ASSERT()!\n", + FileName, + LineNumber, + FunctionCall + ); + UnitTestLogFailure ( + FAILURETYPE_EXPECTASSERT, + "%a:%d: Function call (%a) did not ASSERT()!\n", + FileName, + LineNumber, + FunctionCall + ); + } + return (UnitTestStatus !=3D UNIT_TEST_ERROR_TEST_FAILED); } diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/AssertCmocka.c b/Uni= tTestFrameworkPkg/Library/UnitTestLib/AssertCmocka.c index e48d614976..687c6243ab 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestLib/AssertCmocka.c +++ b/UnitTestFrameworkPkg/Library/UnitTestLib/AssertCmocka.c @@ -333,3 +333,71 @@ UnitTestAssertNotNull ( =20 return (Pointer !=3D NULL); } + +/** + If UnitTestStatus is UNIT_TEST_PASSED, then log an info message and=20 +return + TRUE because an ASSERT() was expected when FunctionCall was executed=20 +and an + ASSERT() was triggered. If UnitTestStatus is UNIT_TEST_SKIPPED, then=20 +log a + warning message and return TRUE because ASSERT() macros are disabled. +If + UnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED, then log an error=20 +message and + return FALSE because an ASSERT() was expected when FunctionCall was=20 +executed, + but no ASSERT() conditions were triggered. The log messages contain + FunctionName, LineNumber, and FileName strings to provide the=20 +location of the + UT_EXPECT_ASSERT_FAILURE() macro. + + @param[in] UnitTestStatus The status from UT_EXPECT_ASSERT_FAILURE() = that + is either pass, skipped, or failed. + @param[in] FunctionName Null-terminated ASCII string of the functio= n + executing the UT_EXPECT_ASSERT_FAILURE() ma= cro. + @param[in] LineNumber The source file line number of the the func= tion + executing the UT_EXPECT_ASSERT_FAILURE() ma= cro. + @param[in] FileName Null-terminated ASCII string of the filenam= e + executing the UT_EXPECT_ASSERT_FAILURE() ma= cro. + @param[in] FunctionCall Null-terminated ASCII string of the functio= n call + executed by the UT_EXPECT_ASSERT_FAILURE() = macro. + @param[out] ResultStatus Used to return the UnitTestStatus value to = the + caller of UT_EXPECT_ASSERT_FAILURE(). This= is + optional parameter that may be NULL. + + @retval TRUE UnitTestStatus is UNIT_TEST_PASSED. + @retval TRUE UnitTestStatus is UNIT_TEST_SKIPPED. + @retval FALSE UnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED. +**/ +BOOLEAN +EFIAPI +UnitTestExpectAssertFailure ( + IN UNIT_TEST_STATUS UnitTestStatus, + IN CONST CHAR8 *FunctionName, + IN UINTN LineNumber, + IN CONST CHAR8 *FileName, + IN CONST CHAR8 *FunctionCall, + OUT UNIT_TEST_STATUS *ResultStatus OPTIONAL + ) +{ + CHAR8 TempStr[MAX_STRING_SIZE]; + + if (ResultStatus !=3D NULL) { + *ResultStatus =3D UnitTestStatus; + } + if (UnitTestStatus =3D=3D UNIT_TEST_PASSED) { + UT_LOG_INFO ( + "[ASSERT PASS] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) detected expecte= d assert\n", + FileName, + LineNumber, + FunctionCall + ); + } + if (UnitTestStatus =3D=3D UNIT_TEST_SKIPPED) { + UT_LOG_WARNING ( + "[ASSERT WARN] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) disabled\n", + FileName, + LineNumber, + FunctionCall + ); + } + if (UnitTestStatus =3D=3D UNIT_TEST_ERROR_TEST_FAILED) { + snprintf (TempStr, sizeof(TempStr), "UT_EXPECT_ASSERT_FAILURE(%s) did= not trigger ASSERT()", FunctionCall); + _assert_true (FALSE, TempStr, FileName, (INT32)LineNumber); + } + return (UnitTestStatus !=3D UNIT_TEST_ERROR_TEST_FAILED); } diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c b/UnitTes= tFrameworkPkg/Library/UnitTestLib/RunTests.c index 793335fd0f..2dc1d159d5 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c +++ b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c @@ -14,6 +14,8 @@ =20 STATIC UNIT_TEST_FRAMEWORK_HANDLE mFrameworkHandle =3D NULL; =20 +BASE_LIBRARY_JUMP_BUFFER gUnitTestJumpBuffer; + UNIT_TEST_FRAMEWORK_HANDLE GetActiveFrameworkHandle ( VOID @@ -75,7 +77,14 @@ RunTestSuite ( // Next, if we're still running, make sure that our test prerequisite= s are in place. if (Test->Result =3D=3D UNIT_TEST_PENDING && Test->Prerequisite !=3D = NULL) { DEBUG ((DEBUG_VERBOSE, "PREREQ\n")); - if (Test->Prerequisite (Test->Context) !=3D UNIT_TEST_PASSED) { + if (SetJump (&gUnitTestJumpBuffer) =3D=3D 0) { + if (Test->Prerequisite (Test->Context) !=3D UNIT_TEST_PASSED) { + DEBUG ((DEBUG_ERROR, "Prerequisite Not Met\n")); + Test->Result =3D UNIT_TEST_ERROR_PREREQUISITE_NOT_MET; + ParentFramework->CurrentTest =3D NULL; + continue; + } + } else { DEBUG ((DEBUG_ERROR, "Prerequisite Not Met\n")); Test->Result =3D UNIT_TEST_ERROR_PREREQUISITE_NOT_MET; ParentFramework->CurrentTest =3D NULL; @@ -88,14 +97,20 @@ RunTe= stSuite ( // We set the status to UNIT_TEST_RUNNING in case the test needs to r= eboot // or quit. The UNIT_TEST_RUNNING state will allow the test to resume // but will prevent the Prerequisite from being dispatched a second t= ime. - Test->Result =3D UNIT_TEST_RUNNING; - Test->Result =3D Test->RunTest (Test->Context); + if (SetJump (&gUnitTestJumpBuffer) =3D=3D 0) { + Test->Result =3D UNIT_TEST_RUNNING; + Test->Result =3D Test->RunTest (Test->Context); + } else { + Test->Result =3D UNIT_TEST_ERROR_TEST_FAILED; + } =20 // // Finally, clean everything up, if need be. if (Test->CleanUp !=3D NULL) { DEBUG ((DEBUG_VERBOSE, "CLEANUP\n")); - Test->CleanUp (Test->Context); + if (SetJump (&gUnitTestJumpBuffer) =3D=3D 0) { + Test->CleanUp (Test->Context); + } } =20 // diff --git a/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTest= ResultReportLib.c b/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/Un= itTestResultReportLib.c index eba68e330c..66c9db457d 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultR= eportLib.c +++ b/UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResul +++ tReportLib.c @@ -49,7 +49,8 @@ struct _UNIT_TEST_FAILURE_TYPE_STRING mFailureTypeString= s[] =3D { { FAILURETYPE_ASSERTNOTEQUAL, "ASSERT_NOTEQUAL FAILURE"}, { FAILURETYPE_ASSERTNOTEFIERROR, "ASSERT_NOTEFIERROR FAILURE"}, { FAILURETYPE_ASSERTSTATUSEQUAL, "ASSERT_STATUSEQUAL FAILURE"}, - { FAILURETYPE_ASSERTNOTNULL , "ASSERT_NOTNULL FAILURE"}, + { FAILURETYPE_ASSERTNOTNULL, "ASSERT_NOTNULL FAILURE"}, + { FAILURETYPE_EXPECTASSERT, "EXPECT_ASSERT FAILURE"}, { 0, "*UNKNOWN* Failure"} }; =20 diff --git a/UnitTestFrameworkPkg/PrivateInclude/UnitTestFrameworkTypes.h = b/UnitTestFrameworkPkg/PrivateInclude/UnitTestFrameworkTypes.h index e58b30093e..b0e2f61bbf 100644 --- a/UnitTestFrameworkPkg/PrivateInclude/UnitTestFrameworkTypes.h +++ b/UnitTestFrameworkPkg/PrivateInclude/UnitTestFrameworkTypes.h @@ -44,6 +44,7 @@ typedef UINT32 FAILURE_TYPE; #define FAILURETYPE_ASSERTNOTEFIERROR (6) #define FAILURETYPE_ASSERTSTATUSEQUAL (7) #define FAILURETYPE_ASSERTNOTNULL (8) +#define FAILURETYPE_EXPECTASSERT (9) =20 /// /// Unit Test context structure tracked by the unit test framework. diff --git a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc b/= UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc index 701e7299d7..70affddead 100644 --- a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc +++ b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc @@ -25,7 +25,7 @@ [Components] UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTest= Host.inf =20 # - # Build Libraries + # Build HOST_APPLICATION Libraries # UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc b/UnitTestFrame= workPkg/UnitTestFrameworkPkg.dsc index 2d84691bf1..0dfd98f2a8 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc @@ -28,6 +28,7 @@ [Components] UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultRepo= rtLibConOut.inf UnitTestFrameworkPkg/Library/UnitTestBootLibUsbClass/UnitTestBootLibUsb= Class.inf UnitTestFrameworkPkg/Library/UnitTestPersistenceLibSimpleFileSystem/Uni= tTestPersistenceLibSimpleFileSystem.inf + + UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAsser + tLib.inf =20 UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTest= Dxe.inf UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTest= Pei.inf diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc b/Uni= tTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc index 0881278ab0..8adf690098 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgTarget.dsc.inc @@ -29,6 +29,7 @@ [LibraryClasses] UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.inf UnitTestPersistenceLib|UnitTestFrameworkPkg/Library/UnitTestPersistence= LibNull/UnitTestPersistenceLibNull.inf UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultRepo= rtLib/UnitTestResultReportLibDebugLib.inf + + NULL|UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebug + AssertLib.inf =20 [LibraryClasses.ARM, LibraryClasses.AARCH64] # @@ -56,5 +57,6 @@ [PcdsFixedAtBuild] gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x17 =20 [BuildOptions] - MSFT:*_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES - GCC:*_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES + MSFT:*_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES -D EDKII_= UNIT_TEST_FRAMEWORK_ENABLED + GCC:*_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES -D EDKII_= UNIT_TEST_FRAMEWORK_ENABLED + XCODE:*_*_*_CC_FLAGS =3D -D DISABLE_NEW_DEPRECATED_INTERFACES -D=20 + EDKII_UNIT_TEST_FRAMEWORK_ENABLED -- 2.21.0.windows.1