From nobody Mon Feb 9 05:19:03 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) client-ip=66.175.222.12; envelope-from=bounce+27952+61257+1787277+3901457@groups.io; helo=web01.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61257+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1592180379; cv=none; d=zohomail.com; s=zohoarc; b=MDXAHGaZ7tfmnCONKLrJMUZHJ2az/ZaB1q4TAFz2JGImccAaSMkn6wbWAxXzcBkm0O6ZtSopoabNCCah+41s1cnz3jFe97NPb4P6dZGuKoqGgWCRxu5QP4p3Mn55t2h6yjzVPtV5Tb4VITHsc11xpputMMPoDOZpg0f8YbHFHQA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1592180379; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Id:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=MRfeJajP+H76xo1tC3/bt9lR/6qMHtB1eRCV80M/9FQ=; b=KXdGaaoURyMDFufv9bDqsk13CBtFPkIOAVRRR2pZVZKUfXIhILIHJzglqHu4Zg6lpv/72DB7n5jWe+UlpGDCN+/AmacQpitjOV4LqSolDb4EVAIuP4zU3z3XioavCIZEg9xuquBjEx1rBf0juouYNbVP+VMhSjfYe/FoT3GwzeQ= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.12 as permitted sender) smtp.mailfrom=bounce+27952+61257+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) header.from= Received: from web01.groups.io (web01.groups.io [66.175.222.12]) by mx.zohomail.com with SMTPS id 15921803790151003.1227978439746; Sun, 14 Jun 2020 17:19:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id uRHoYY1788612xSBZMGDDjNG; Sun, 14 Jun 2020 17:19:38 -0700 X-Received: from mga07.intel.com (mga07.intel.com []) by mx.groups.io with SMTP id smtpd.web10.7296.1592180375915973024 for ; Sun, 14 Jun 2020 17:19:36 -0700 IronPort-SDR: ga48k0a95zGiFYjYKd8DBLftd6tutlY/SCIruG/ZtUA1jSag5qPlzoIojdmNT7/CN+4FI89cpL RmOcl2ECcikw== X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 14 Jun 2020 17:19:26 -0700 IronPort-SDR: jmZ9ISEQUeYHbDnzagU+hbH3aDput4ARPNujgyxgwJKFHqagrbhzXu8ZbFm9N5eNqAgRobNoTu Rm9/AzYFzOzA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,513,1583222400"; d="scan'208";a="276370304" X-Received: from mdkinney-mobl2.amr.corp.intel.com ([10.252.142.246]) by orsmga006.jf.intel.com with ESMTP; 14 Jun 2020 17:19:26 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Liming Gao , Sean Brogan , Bret Barkelew , Jiewen Yao Subject: [edk2-devel] [Patch 14/15] MdePkg/Include: Add UT_EXPECT_ASSERT_FAILURE() to UnitTestLib Date: Sun, 14 Jun 2020 17:19:17 -0700 Message-Id: <20200615001918.22164-15-michael.d.kinney@intel.com> In-Reply-To: <20200615001918.22164-1-michael.d.kinney@intel.com> References: <20200615001918.22164-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: RDTIsBP8Wk7k05acnHCAV58Jx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1592180378; bh=OFNq+L/9+ldf6Xp1M05TiIVBl44MjIxYif4qGR8FY6E=; h=Cc:Date:From:Reply-To:Subject:To; b=kNRuAxkCblFn3C9qc3BflL3zw6AXyVAKwq7lWNxBo43BFmACFLsPEGNjL681jN+/72Y tCBKVZ3ayIfb9ersPk+P9I1XRO/8XqPSIfvQOgu1+SN/DUzdWuCOlKQ9UGIc9zEe+BgoX JGt2dDCiwKbdP1+K8u9To6uniQOowjcHEak= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" https://bugzilla.tianocore.org/show_bug.cgi?id=3D2801 Add the UT_EXPECT_ASSERT_FAILURE(FunctionCall, Status) macro to the UnitTestLib that can be used to check if a function under test triggers an ASSERT() condition. If an ASSERT() condition is triggered, then the macro returns. If the ASSERT() condition is not triggered, then the current unit test fails with a status of UNIT_TEST_ERROR_TEST_FAILED. If ASSERT()s are disabled, then this check for ASSERT() behavior is not possible, and the check is skipped. Add the UnitTestDebugAssert() to the UnitTestLib class. The UnitTestDebugAssert() service is the same as the DebugLib DebugAssert() service and is invoked from the DebugLib _ASSERT() macro if unit testing is enabled. This allows the Unit Test Framework to know when code under test triggers an ASSERT() condition. The global variable gUnitTestExpectAssertFailureJumpBuffer is added to the UnitTestLib to save/restore context when the UT_EXPECT_ASSERT_FAILURE(FunctionCall, Status) macro is used. The UT_EXPECT_ASSERT_FAILURE() macro uses the SetJump() service with this global variable. The UnitTestLib service UnitTestDebugAssert() uses the LongJump() service with this global to restore context if an ASSERT() is triggered by the code under test. Cc: Liming Gao Cc: Sean Brogan Cc: Bret Barkelew Cc: Jiewen Yao Signed-off-by: Michael D Kinney --- MdePkg/Include/Library/UnitTestLib.h | 70 ++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/MdePkg/Include/Library/UnitTestLib.h b/MdePkg/Include/Library/= UnitTestLib.h index a4374580a8..1935a14ad1 100644 --- a/MdePkg/Include/Library/UnitTestLib.h +++ b/MdePkg/Include/Library/UnitTestLib.h @@ -10,6 +10,14 @@ #ifndef __UNIT_TEST_LIB_H__ #define __UNIT_TEST_LIB_H__ =20 +#include + +/// +/// Pointer to jump buffer used with SetJump()/LongJump() to test if a fun= ction +/// under test generates an expected ASSERT() condition. +/// +extern BASE_LIBRARY_JUMP_BUFFER *gUnitTestExpectAssertFailureJumpBuffer; + /// /// Unit Test Status /// @@ -441,6 +449,68 @@ SaveFrameworkState ( return UNIT_TEST_ERROR_TEST_FAILED; = \ } =20 +/** + This macro uses the framework assertion logic to check whether a functio= n call + triggers an ASSERT() condition. The BaseLib SetJump()/LongJump() servic= es + are used to establish a safe return point when an ASSERT() is triggered. + If an ASSERT() is triggered, unit test execution continues and Status is= set + to UNIT_TEST_PASSED. Otherwise, a unit test case failure is raised and + Status is set to UNIT_TEST_ERROR_TEST_FAILED. + + If ASSERT() macros are disabled, then the test case is skipped and a war= ning + message is added to the unit test log. Status is set to UNIT_TEST_SKIPP= ED. + + @param[in] FunctionCall Function call that is expected to trigger ASSE= RT(). + @param[out] Status Pointer to a UNIT_TEST_STATUS return value. T= his + is an optional parameter that may be NULL. +**/ +#if defined (EDKII_UNIT_TEST_FRAMEWORK_ENABLED) + #define UT_EXPECT_ASSERT_FAILURE(FunctionCall, Status) = \ + if (DebugAssertEnabled ()) { = \ + BASE_LIBRARY_JUMP_BUFFER UnitTestJumpBuffer; = \ + gUnitTestExpectAssertFailureJumpBuffer =3D &UnitTestJumpBuffer; = \ + if (SetJump (gUnitTestExpectAssertFailureJumpBuffer) =3D=3D 0) { = \ + FunctionCall; = \ + gUnitTestExpectAssertFailureJumpBuffer =3D NULL; = \ + UT_LOG_ERROR ("UT_EXPECT_ASSERT_FAILURE("#FunctionCall") did not A= SSERT()\n"); \ + if (Status !=3D NULL) { = \ + *((UNIT_TEST_STATUS *)Status) =3D UNIT_TEST_ERROR_TEST_FAILED; = \ + } = \ + return UNIT_TEST_ERROR_TEST_FAILED; = \ + } = \ + gUnitTestExpectAssertFailureJumpBuffer =3D NULL; = \ + if (Status !=3D NULL) { = \ + *((UNIT_TEST_STATUS *)Status) =3D UNIT_TEST_PASSED; = \ + } = \ + } else { = \ + UT_LOG_WARNING ("UT_EXPECT_ASSERT_FAILURE("#FunctionCall") disabled\= n"); \ + if (Status !=3D NULL) { = \ + *((UNIT_TEST_STATUS *)Status) =3D UNIT_TEST_SKIPPED; = \ + } = \ + } +#else + #define UT_EXPECT_ASSERT_FAILURE(FunctionCall, Status) FunctionCall; +#endif + +/** + Unit test library replacement for DebugAssert() in DebugLib. + + If FileName is NULL, then a string of "(NULL) Filename" is pr= inted. + If Description is NULL, then a string of "(NULL) Descripti= on" is printed. + + @param FileName The pointer to the name of the source file that gen= erated the assert condition. + @param LineNumber The line number in the source file that generated t= he assert condition + @param Description The pointer to the description of the assert condit= ion. + +**/ +VOID +EFIAPI +UnitTestDebugAssert ( + IN CONST CHAR8 *FileName, + IN UINTN LineNumber, + IN CONST CHAR8 *Description + ); + /** If Expression is TRUE, then TRUE is returned. If Expression is FALSE, then an assert is triggered and the location of = the --=20 2.21.0.windows.1 -=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 (#61257): https://edk2.groups.io/g/devel/message/61257 Mute This Topic: https://groups.io/mt/74885927/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-