From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by mx.groups.io with SMTP id smtpd.web11.12338.1647966165214074320 for ; Tue, 22 Mar 2022 09:22:45 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="body hash did not verify" header.i=@linux.microsoft.com header.s=default header.b=Vd5loWsF; spf=pass (domain: linux.microsoft.com, ip: 13.77.154.182, mailfrom: mikuback@linux.microsoft.com) Received: from localhost.localdomain (unknown [47.202.59.224]) by linux.microsoft.com (Postfix) with ESMTPSA id B987020B4783; Tue, 22 Mar 2022 09:22:43 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com B987020B4783 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1647966164; bh=d3/A5plzjchzKttag+0mykxYqfkU5j46ToNNPDaa4AE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Vd5loWsFHaZPEOQ+X5QFhxpcDZyXPzvMSe0j+tWkrcnLlN0bPM6r6crR6zWb0Frlt +IwBmCxIN8GcbB/D7G3eiNOYRqbyrrjsWTr6taUdb/0bhzIY3oqn/hnEjCmJR1xBZy HSrsnvMRNe53s2FATkbX5kychT3xX4y2CznPsXkU= From: "Michael Kubacki" To: devel@edk2.groups.io Cc: Andrew Fish , Kang Gao , Michael D Kinney , Michael Kubacki , Leif Lindholm , Benjamin You , Liu Yun , Ankit Sinha , Nate DeSimone Subject: [PATCH v1 31/41] PrmPkg/DxePrmModuleDiscoveryLib: Add initial host-based unit tests Date: Tue, 22 Mar 2022 12:19:37 -0400 Message-Id: <20220322161947.9319-32-mikuback@linux.microsoft.com> X-Mailer: git-send-email 2.28.0.windows.1 In-Reply-To: <20220322161947.9319-1-mikuback@linux.microsoft.com> References: <20220322161947.9319-1-mikuback@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable From: Michael Kubacki Adds host-based unit tests for DxePrmModuleDiscoveryLib. This is an initial set of support, more tests should be added in the future. Cc: Andrew Fish Cc: Kang Gao Cc: Michael D Kinney Cc: Michael Kubacki Cc: Leif Lindholm Cc: Benjamin You Cc: Liu Yun Cc: Ankit Sinha Cc: Nate DeSimone Signed-off-by: Michael Kubacki --- PrmPkg/Library/DxePrmModuleDiscoveryLib/DxePrmModuleDiscoveryLib.c = | 1 - PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxePrmModuleDiscoveryLi= bUnitTest.c | 209 ++++++++++++++++++++ PrmPkg/Library/DxePrmModuleDiscoveryLib/PrmModuleDiscovery.h = | 12 ++ PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxePrmModuleDiscoveryLi= bUnitTestHost.inf | 39 ++++ PrmPkg/Test/PrmPkgHostTest.dsc = | 5 + 5 files changed, 265 insertions(+), 1 deletion(-) diff --git a/PrmPkg/Library/DxePrmModuleDiscoveryLib/DxePrmModuleDiscover= yLib.c b/PrmPkg/Library/DxePrmModuleDiscoveryLib/DxePrmModuleDiscoveryLib= .c index 6977799aa8f3..0dd6a76be4d7 100644 --- a/PrmPkg/Library/DxePrmModuleDiscoveryLib/DxePrmModuleDiscoveryLib.c +++ b/PrmPkg/Library/DxePrmModuleDiscoveryLib/DxePrmModuleDiscoveryLib.c @@ -87,7 +87,6 @@ GetNextPrmModuleEntry ( otherwise, NULL is returned. =20 **/ -STATIC PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY * CreateNewPrmModuleImageContextListEntry ( VOID diff --git a/PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxePrmModul= eDiscoveryLibUnitTest.c b/PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTes= t/DxePrmModuleDiscoveryLibUnitTest.c new file mode 100644 index 000000000000..ef8abe397cd4 --- /dev/null +++ b/PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxePrmModuleDiscov= eryLibUnitTest.c @@ -0,0 +1,209 @@ +/** @file + + Unit tests for the PRM Module Discovery Library. + + Copyright (c) Microsoft Corporation + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "../PrmModuleDiscovery.h" + +#define UNIT_TEST_NAME "PRM Module Discovery Library Unit Test" +#define UNIT_TEST_VERSION "0.1" + +///=3D=3D=3D TEST CASES =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +///=3D=3D=3D=3D=3D CREATE NEW PRM MODULE IMAGE CONTEXT LIST ENTRY TESTS = SUITE =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D + +/** + Verifies that the buffer returned can be deallocated. + + @param[in] Context [Optional] An optional context paramet= er. + Not used in this unit test. + + @retval UNIT_TEST_PASSED Unit test case prerequi= sites are met. + @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be ski= pped.. + +**/ +UNIT_TEST_STATUS +EFIAPI +PrmModuleImageContextListEntryShouldDeallocate ( + IN UNIT_TEST_CONTEXT Context + ) +{ + PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY *ListEntry; + + ListEntry =3D CreateNewPrmModuleImageContextListEntry (); + + UT_ASSERT_NOT_NULL (ListEntry); + if (ListEntry !=3D NULL) { + FreePool (ListEntry); + } + + return UNIT_TEST_PASSED; +} + +/** + Verifies that the list entry signature is set to the appropriate value= . + + @param[in] Context [Optional] An optional context paramet= er. + Not used in this unit test. + + @retval UNIT_TEST_PASSED Unit test case prerequi= sites are met. + @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be ski= pped.. + +**/ +UNIT_TEST_STATUS +EFIAPI +PrmModuleImageContextListEntrySignatureShouldBeValid ( + IN UNIT_TEST_CONTEXT Context + ) +{ + PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY *ListEntry; + + ListEntry =3D CreateNewPrmModuleImageContextListEntry (); + + UT_ASSERT_TRUE (ListEntry->Signature =3D=3D PRM_MODULE_IMAGE_CONTEXT_L= IST_ENTRY_SIGNATURE); + + if (ListEntry !=3D NULL) { + FreePool (ListEntry); + } + + return UNIT_TEST_PASSED; +} + +/** + Verifies that the Context buffer in the list entry is initialized to z= ero. + + @param[in] Context [Optional] An optional context paramet= er. + Not used in this unit test. + + @retval UNIT_TEST_PASSED Unit test case prerequi= sites are met. + @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be ski= pped.. + +**/ +UNIT_TEST_STATUS +EFIAPI +PrmModuleImageContextListEntryImageContextShouldBeZeroed ( + IN UNIT_TEST_CONTEXT Context + ) +{ + PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY *ListEntry; + PRM_MODULE_IMAGE_CONTEXT ImageContext; + + ListEntry =3D CreateNewPrmModuleImageContextListEntry (); + + ZeroMem (&ImageContext, sizeof (ImageContext)); + UT_ASSERT_MEM_EQUAL (&ListEntry->Context, &ImageContext, sizeof (Image= Context)); + + if (ListEntry !=3D NULL) { + FreePool (ListEntry); + } + + return UNIT_TEST_PASSED; +} + +///=3D=3D=3D TEST ENGINE =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D + +/** + Entry point for the PRM Context Buffer Library unit tests. + + @param[in] ImageHandle The firmware allocated handle for the EFI imag= e. + @param[in] SystemTable A pointer to the EFI System Table. + + @retval EFI_SUCCESS The entry point executed successfully. + @retval other Some error occurred when executing this entry = point. + +**/ +int main () +{ + EFI_STATUS Status; + UNIT_TEST_FRAMEWORK_HANDLE Framework; + UNIT_TEST_SUITE_HANDLE CreateNewPrmModuleImageContextListEntryTes= ts; + + Framework =3D NULL; + + DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_NAME, UNIT_TEST_VERSION)); + + // + // Start setting up the test framework for running the tests. + // + Status =3D InitUnitTestFramework (&Framework, UNIT_TEST_NAME, gEfiCall= erBaseName, UNIT_TEST_VERSION); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status =3D %r= \n", Status)); + goto EXIT; + } + + Status =3D CreateUnitTestSuite ( + &CreateNewPrmModuleImageContextListEntryTests, + Framework, + "Create New PRM Module Image Context List Entry Tests", + "PrmModuleDiscoveryLib.CreateNewPrmModuleImageContextListE= ntry", + NULL, + NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for PrmModuleDis= coveryLib.CreateNewPrmModuleImageContextListEntry\n")); + Status =3D EFI_OUT_OF_RESOURCES; + goto EXIT; + } + + AddTestCase ( + CreateNewPrmModuleImageContextListEntryTests, + "", + "PrmModuleDiscoveryLib.CreateNewPrmModuleImageContextListEntry.ListE= ntryShouldDeallocate", + PrmModuleImageContextListEntryShouldDeallocate, + NULL, + NULL, + NULL + ); + + AddTestCase ( + CreateNewPrmModuleImageContextListEntryTests, + "", + "PrmModuleDiscoveryLib.CreateNewPrmModuleImageContextListEntry.ListE= ntrySignatureShouldBeValid", + PrmModuleImageContextListEntrySignatureShouldBeValid, + NULL, + NULL, + NULL + ); + + AddTestCase ( + CreateNewPrmModuleImageContextListEntryTests, + "", + "PrmModuleDiscoveryLib.CreateNewPrmModuleImageContextListEntry.ListE= ntryImageContextShouldBeZeroed", + PrmModuleImageContextListEntryImageContextShouldBeZeroed, + NULL, + NULL, + NULL + ); + + // + // Execute the tests. + // + Status =3D RunAllTestSuites (Framework); + +EXIT: + if (Framework) + { + FreeUnitTestFramework (Framework); + } + + return Status; +} diff --git a/PrmPkg/Library/DxePrmModuleDiscoveryLib/PrmModuleDiscovery.h= b/PrmPkg/Library/DxePrmModuleDiscoveryLib/PrmModuleDiscovery.h index 79058d15317e..ea42cf272550 100644 --- a/PrmPkg/Library/DxePrmModuleDiscoveryLib/PrmModuleDiscovery.h +++ b/PrmPkg/Library/DxePrmModuleDiscoveryLib/PrmModuleDiscovery.h @@ -24,4 +24,16 @@ typedef struct { =20 #pragma pack(pop) =20 +/** + Creates a new PRM Module Image Context linked list entry. + + @retval PrmModuleImageContextListEntry If successful, a pointer a PRM= Module Image Context linked list entry + otherwise, NULL is returned. + +**/ +PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY * +CreateNewPrmModuleImageContextListEntry ( + VOID + ); + #endif diff --git a/PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxePrmModul= eDiscoveryLibUnitTestHost.inf b/PrmPkg/Library/DxePrmModuleDiscoveryLib/U= nitTest/DxePrmModuleDiscoveryLibUnitTestHost.inf new file mode 100644 index 000000000000..8aae1f7cd78a --- /dev/null +++ b/PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxePrmModuleDiscov= eryLibUnitTestHost.inf @@ -0,0 +1,39 @@ +## @file +# PRM Module Discovery Library Host-Based Unit Tests +# +# Copyright (c) Microsoft Corporation +# +# SPDX-License-Identifier: BSD-2-Clause-Patent +# +## + +[Defines] + INF_VERSION =3D 0x00010006 + BASE_NAME =3D PrmModuleDiscoveryLibUnitTestHost + FILE_GUID =3D 864886C5-5458-4FF5-A160-4D5B2EAEC55= 8 + MODULE_TYPE =3D HOST_APPLICATION + VERSION_STRING =3D 1.0 + +# +# The following information is for reference only and not required by th= e build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 ARM AARCH64 +# + +[Sources] + DxePrmModuleDiscoveryLibUnitTest.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + PrmPkg/PrmPkg.dec + +[LibraryClasses] + BaseLib + BaseMemoryLib + DebugLib + MemoryAllocationLib + PrmModuleDiscoveryLib + UefiBootServicesTableLib + UnitTestLib diff --git a/PrmPkg/Test/PrmPkgHostTest.dsc b/PrmPkg/Test/PrmPkgHostTest.= dsc index 1f44037d0102..67fb4f5bd0d2 100644 --- a/PrmPkg/Test/PrmPkgHostTest.dsc +++ b/PrmPkg/Test/PrmPkgHostTest.dsc @@ -19,7 +19,11 @@ [Defines] !include UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc =20 [LibraryClasses] + PeCoffExtraActionLib|MdePkg/Library/BasePeCoffExtraActionLibNull/BaseP= eCoffExtraActionLibNull.inf + PeCoffLib|MdePkg/Library/BasePeCoffLib/BasePeCoffLib.inf PrmContextBufferLib|PrmPkg/Library/DxePrmContextBufferLib/DxePrmContex= tBufferLib.inf + PrmModuleDiscoveryLib|PrmPkg/Library/DxePrmModuleDiscoveryLib/DxePrmMo= duleDiscoveryLib.inf + PrmPeCoffLib|PrmPkg/Library/DxePrmPeCoffLib/DxePrmPeCoffLib.inf UefiBootServicesTableLib|PrmPkg/Test/UnitTest/Library/UefiBootServices= TableLibUnitTest/UefiBootServicesTableLibUnitTest.inf =20 [Components] @@ -32,3 +36,4 @@ [Components] # Unit test host applications # PrmPkg/Library/DxePrmContextBufferLib/UnitTest/DxePrmContextBufferLibU= nitTestHost.inf + PrmPkg/Library/DxePrmModuleDiscoveryLib/UnitTest/DxePrmModuleDiscovery= LibUnitTestHost.inf --=20 2.28.0.windows.1