From nobody Mon Feb 9 03:12:40 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+61258+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+61258+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=cl+X8JvwSM6OLzzr+nzV+9zZ6hj9dvFxlCuMSFhXDq6In7Nj7QJuwQf8kGVgx854DCBtQkGbEOqq3p7msDWxy9V8DBqpexz+OHfEWLm6TtTaM49Py4qEBe6/S7SP+qgNbSSZdMa9CP6KoKuZg/hyrFHJmMoQp8+YhOWCDruCXLM= 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=+Xp/qZ4n2wCHVl3vDTaRPVEWk7QBi0eS3xz85pSsxfY=; b=UQK1Bik4IlhHkflVMAaNUAKkr392OqvM6DGMMiS1aZJnOn8HaE/HpTX5jdNkChbgw2/AuX+T68fYN2quLk5ptPJq85RAKqsWmHXWdWCcIroZ2W4kXIPE2VlWiIK42L0Cp+6TGRNkOB7VAAPJxIdC5I/LEtWPMOv/qpRc3Y5y1Ds= 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+61258+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 1592180379410957.0794299311156; Sun, 14 Jun 2020 17:19:39 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id kuCWYY1788612xrAuwdKLYHJ; Sun, 14 Jun 2020 17:19:39 -0700 X-Received: from mga07.intel.com (mga07.intel.com []) by mx.groups.io with SMTP id smtpd.web12.7397.1592180374394024448 for ; Sun, 14 Jun 2020 17:19:37 -0700 IronPort-SDR: /VpmsB1omU+VvN3D7RTiZ6p7bNvlfnMChL7dJVY8yUcqQOci+CWxHWVv+W7dox4n+15MJvkZ8g /WB1wvrmk4CQ== 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:27 -0700 IronPort-SDR: k0uERmmaRcHbWXbshCVAsswOpLdpTOoEOziPE8cWiBmK8Mc/NdZo4+ATQEz5HTzahqchj6Rcjv 3A2vq5MMiFgw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.73,513,1583222400"; d="scan'208";a="276370312" 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:27 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Sean Brogan , Bret Barkelew , Jiewen Yao Subject: [edk2-devel] [Patch 15/15] UnitTestFramewokPkg/SampleUnitTest: Use UT_EXPECT_ASSERT_FAILURE() Date: Sun, 14 Jun 2020 17:19:18 -0700 Message-Id: <20200615001918.22164-16-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: oPbt6awGNJDg6mlyloxWRHzSx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1592180379; bh=XzZs91G7AMm1KYBnvaTjcwgOB7amlu38TC1Hu+XLLSw=; h=Cc:Date:From:Reply-To:Subject:To; b=bCITIN8WnfiqCbFQMQbpsVLeH7OBfiW/f9lO/bdu2Bw6wqAE+SSSZvKQ6GosDG0cKfW kYFu98NZ0tu/vbiCvvBtSgcUXJFaCPn5lJasCF0Pkb1aseZIMwqSMz94/Nn76Prowy5Sj A8gvkGrj9/DkJfsaz2CfCeUxCj7dDTAFMkg= X-ZohoMail-DKIM: pass (identity @groups.io) Content-Type: text/plain; charset="utf-8" https://bugzilla.tianocore.org/show_bug.cgi?id=3D2801 Add samples using UT_EXPECT_ASSERT_FAILURE() for both positive test cases where the ASSERT() is triggered and detected correctly and negative test cases where an ASSERT() is never triggered. These new test cases also generate passing test results when ASSERT()s are disabled. Cc: Sean Brogan Cc: Bret Barkelew Cc: Jiewen Yao Signed-off-by: Michael D Kinney --- .../Sample/SampleUnitTest/SampleUnitTest.c | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) diff --git a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/Sampl= eUnitTest.c b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/Samp= leUnitTest.c index 37d5747bca..424b7abf88 100644 --- a/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTe= st.c +++ b/UnitTestFrameworkPkg/Test/UnitTest/Sample/SampleUnitTest/SampleUnitTe= st.c @@ -181,6 +181,102 @@ GlobalPointerShouldBeChangeable ( return UNIT_TEST_PASSED; } =20 +UNIT_TEST_STATUS +EFIAPI +DetectExpectedAssert ( + IN UNIT_TEST_CONTEXT Context + ) +{ + // + // This test passes because it directly triggers an ASSERT(). + // + UT_EXPECT_ASSERT_FAILURE (ASSERT (FALSE), NULL); + + // + // This test passes because DecimalToBcd() generates an ASSERT() if the + // value passed in is >=3D 100. The expected ASSERT() is caught by the = unit + // test framework and UT_EXPECT_ASSERT_FAILURE() returns without an erro= r. + // + UT_EXPECT_ASSERT_FAILURE (DecimalToBcd8 (101), NULL); + + return UNIT_TEST_PASSED; +} + +UNIT_TEST_STATUS +EFIAPI +DetectNoAssertsWorker1 ( + IN UNIT_TEST_CONTEXT Context + ) +{ + UNIT_TEST_STATUS Status; + + // + // If ASSERT()s are enabled, then the following test case will not trigg= ered + // an ASSERT() and UT_EXPECT_ASSERT_FAILURE() exits the function from the + // macro with status UNIT_TEST_ERROR_TEST_FAILED. + // + // If ASSERT()s are disabled, then UNIT_TEST_ERROR_TEST_FAILED() is igno= red + // and Status is set to UNIT_TEST_SKIPPED. + // + // If ASSERT()s are enabled and this ASSERT() is incorrectly triggered, = then + // UT_EXPECT_ASSERT_FAILURE() returns with Status set to UNIT_TEST_PASSE= D. + // + UT_EXPECT_ASSERT_FAILURE (ASSERT (TRUE), &Status); + + return Status; +} + +UNIT_TEST_STATUS +EFIAPI +DetectNoAssertsWorker2 ( + IN UNIT_TEST_CONTEXT Context + ) +{ + UNIT_TEST_STATUS Status; + + // + // If ASSERT()s are enabled, then the following test case will not trigg= ered + // an ASSERT() and UT_EXPECT_ASSERT_FAILURE() exits the function from the + // macro with status UNIT_TEST_ERROR_TEST_FAILED. + // + // If ASSERT()s are disabled, then UNIT_TEST_ERROR_TEST_FAILED() is igno= red + // and Status is set to UNIT_TEST_SKIPPED. + // + // If ASSERT()s are enabled and this ASSERT() is incorrectly triggered, = then + // UT_EXPECT_ASSERT_FAILURE() returns with Status set to UNIT_TEST_PASSE= D. + // + // DecimalToBcd() only generates an ASSERT() if the value passed in is >= =3D 100. + // + UT_EXPECT_ASSERT_FAILURE (DecimalToBcd8 (99), &Status); + + return Status; +} + +UNIT_TEST_STATUS +EFIAPI +DetectNoAsserts ( + IN UNIT_TEST_CONTEXT Context + ) +{ + UNIT_TEST_STATUS Status; + + // + // This call is expected to return UNIT_TEST_ERROR_TEST_FAILED or + // UNIT_TEST_SKIPPED. + // + Status =3D DetectNoAssertsWorker1 (Context); + UT_ASSERT_FALSE (Status =3D=3D UNIT_TEST_PASSED); + + // + // This call is expected to return UNIT_TEST_ERROR_TEST_FAILED or + // UNIT_TEST_SKIPPED. + // + Status =3D DetectNoAssertsWorker2 (Context); + UT_ASSERT_FALSE (Status =3D=3D UNIT_TEST_PASSED); + + return UNIT_TEST_PASSED; +} + /** Initialize the unit test framework, suite, and unit tests for the sample unit tests and run the unit tests. @@ -199,6 +295,7 @@ UefiTestMain ( UNIT_TEST_FRAMEWORK_HANDLE Framework; UNIT_TEST_SUITE_HANDLE SimpleMathTests; UNIT_TEST_SUITE_HANDLE GlobalVarTests; + UNIT_TEST_SUITE_HANDLE DebugAssertTests; =20 Framework =3D NULL; =20 @@ -236,6 +333,18 @@ UefiTestMain ( AddTestCase (GlobalVarTests, "You should be able to change a global BOOL= EAN", "Boolean", GlobalBooleanShouldBeChangeable, NULL, NULL, NULL); AddTestCase (GlobalVarTests, "You should be able to change a global poin= ter", "Pointer", GlobalPointerShouldBeChangeable, MakeSureThatPointerIsNull= , ClearThePointer, NULL); =20 + // + // Populate the DebugLib ASSERT() Unit Test Suite. + // + Status =3D CreateUnitTestSuite (&DebugAssertTests, Framework, "DebugLib = ASSERT() Tests", "Sample.DebugLibAssert", NULL, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for DebugAssertTes= ts\n")); + Status =3D EFI_OUT_OF_RESOURCES; + goto EXIT; + } + AddTestCase (DebugAssertTests, "Detect Expected ASSERT()", "DetectExpect= edAssert", DetectExpectedAssert, NULL, NULL, NULL); + AddTestCase (DebugAssertTests, "Detect no ASSERT() triggered", "DetectNo= Asserts", DetectNoAsserts, NULL, NULL, NULL); + // // Execute the tests. // --=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 (#61258): https://edk2.groups.io/g/devel/message/61258 Mute This Topic: https://groups.io/mt/74885928/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-