30#define UNIT_TEST_NAME "PRM Context Buffer Library Unit Test"
31#define UNIT_TEST_VERSION "0.1"
61#define HANDLER_TEST_GUID_1 {0x52960b90, 0x2f3a, 0x4917, { 0xb9, 0x1a, 0xed, 0x5f, 0x59, 0x9a, 0x88, 0x09 }}
62EFI_GUID mHandlerTestGuid1 = HANDLER_TEST_GUID_1;
65#define HANDLER_TEST_GUID_2 {0x9316a80d, 0x06dc, 0x417b, { 0xb2, 0x1d, 0x6b, 0x3c, 0x2a, 0xe4, 0xed, 0x6f }}
66EFI_GUID mHandlerTestGuid2 = HANDLER_TEST_GUID_2;
69#define HANDLER_TEST_GUID_3 {0xd32ac8ba, 0x6cc6, 0x456f, { 0x9e, 0xd9, 0x92, 0x33, 0xfa, 0x31, 0x04, 0x34 }}
70EFI_GUID mHandlerTestGuid3 = HANDLER_TEST_GUID_3;
73#define MODULE_TEST_GUID_1 {0xfaadaa95, 0x070b, 0x4a34, { 0xa9, 0x19, 0x18, 0x30, 0x5d, 0xc0, 0x73, 0x70 }}
74EFI_GUID mModuleTestGuid1 = MODULE_TEST_GUID_1;
77#define MODULE_TEST_GUID_2 {0x0ea24584, 0x731c, 0x4863, { 0x91, 0x00, 0x75, 0x78, 0x0a, 0xf5, 0x09, 0xa7 }}
78EFI_GUID mModuleTestGuid2 = MODULE_TEST_GUID_2;
81#define MODULE_TEST_GUID_3 {0xf456b7a1, 0x82a6, 0x4427, { 0x84, 0x86, 0x87, 0xe3, 0xa6, 0x02, 0xdf, 0x43 }}
82EFI_GUID mModuleTestGuid3 = MODULE_TEST_GUID_3;
85#define NEGATIVE_TEST_GUID {0x4a941a9c, 0x9dcf, 0x471b, {0x94, 0xb5, 0xd9, 0xe2, 0xd8, 0xc6, 0x4a, 0x1b }}
86EFI_GUID mNegativeTestGuid = NEGATIVE_TEST_GUID;
94 PRM_DATA_BUFFER_HEADER_SIGNATURE,
101 PRM_CONTEXT_BUFFER_SIGNATURE,
102 PRM_CONTEXT_BUFFER_INTERFACE_VERSION,
105 &mTestStaticDataBuffer1
111 PRM_CONTEXT_BUFFER_SIGNATURE,
112 PRM_CONTEXT_BUFFER_INTERFACE_VERSION,
119 PRM_CONTEXT_BUFFER_SIGNATURE,
120 PRM_CONTEXT_BUFFER_INTERFACE_VERSION,
123 &mTestStaticDataBuffer1
130 &mTestPrmContextBuffer1,
137 &mTestPrmContextBuffer1,
144 &mTestPrmContextBuffer2[0],
253 return UNIT_TEST_PASSED;
287 ModuleContextBuffers = TestContext->InstallationStructure;
290 if (PrmConfigProtocol ==
NULL) {
291 return UNIT_TEST_ERROR_PREREQUISITE_NOT_MET;
296 PrmConfigProtocol->ModuleContextBuffers.
Buffer = ModuleContextBuffers->
Buffer;
298 Status =
gBS->InstallProtocolInterface (
299 &TestContext->Handle,
300 &gPrmConfigProtocolGuid,
302 (VOID *)PrmConfigProtocol
306 return UNIT_TEST_PASSED;
337 Status =
gBS->HandleProtocol (
339 &gPrmConfigProtocolGuid,
340 (VOID **)&PrmConfigProtocol
343 if (!EFI_ERROR (Status)) {
344 Status =
gBS->UninstallProtocolInterface (
346 &gPrmConfigProtocolGuid,
349 if (!EFI_ERROR (Status)) {
377 ContextBuffers =
NULL;
383 if (!EFI_ERROR (TestContext->ExpectedStatus)) {
386 "%a: Searching by %a GUID ({%g}) returned ContextBuffers at 0x%x\n",
388 ((TestContext->GuidSearchType ==
ByModuleGuid) ?
"module" :
"handler"),
390 (
UINTN)ContextBuffers
394 return UNIT_TEST_PASSED;
419 FoundContextBuffer =
NULL;
425 if (!EFI_ERROR (TestContext->ExpectedStatus)) {
427 UT_ASSERT_TRUE (FoundContextBuffer == TestContext->ExpectedContextBuffer);
430 return UNIT_TEST_PASSED;
463 FoundContextBuffer =
NULL;
470 if (!EFI_ERROR (TestContext->ExpectedStatus)) {
472 UT_ASSERT_TRUE (FoundContextBuffer == TestContext->ExpectedContextBuffer);
475 return UNIT_TEST_PASSED;
496 UNIT_TEST_FRAMEWORK_HANDLE Framework;
497 UNIT_TEST_SUITE_HANDLE BasicTests;
498 UNIT_TEST_SUITE_HANDLE FunctionalCorrectnessTests;
499 CHAR8 TestCaseClassNameString[256];
500 CHAR8 TestCaseDescriptionString[256];
504 DEBUG ((DEBUG_INFO,
"%a v%a\n", UNIT_TEST_NAME, UNIT_TEST_VERSION));
510 if (EFI_ERROR (Status)) {
511 DEBUG ((DEBUG_ERROR,
"Failed in InitUnitTestFramework. Status = %r\n", Status));
519 if (EFI_ERROR (Status)) {
520 DEBUG ((DEBUG_ERROR,
"Failed in CreateUnitTestSuite for PrmContextBufferLib.Basic\n"));
521 Status = EFI_OUT_OF_RESOURCES;
528 "PrmContextBufferLib.Basic.NullPointerGracefulFailure",
535 Status =
CreateUnitTestSuite (&FunctionalCorrectnessTests, Framework,
"Functional Correctness Tests",
"PrmContextBufferLib.Functional",
NULL,
NULL);
536 if (EFI_ERROR (Status)) {
537 DEBUG ((DEBUG_ERROR,
"Failed in CreateUnitTestSuite for PrmContextBufferLib.Functional\n"));
538 Status = EFI_OUT_OF_RESOURCES;
545 for (Index = 0; Index <
ARRAY_SIZE (mContextBuffersArray); Index++) {
550 &TestCaseClassNameString[0],
552 "PrmContextBufferLib.Functional.VerifyGetModuleContextBuffers%d",
556 &TestCaseDescriptionString[0],
558 "Verify Get PRM Module Context Buffers Structure by %a GUID %d\n",
559 ((mContextBuffersArray[Index]->GuidSearchType ==
ByModuleGuid) ?
"module" :
"handler"),
564 FunctionalCorrectnessTests,
565 &TestCaseDescriptionString[0],
566 &TestCaseClassNameString[0],
570 mContextBuffersArray[Index]
574 for (Index = 0; Index <
ARRAY_SIZE (mContextBufferArray); Index++) {
579 &TestCaseClassNameString[0],
581 "PrmContextBufferLib.Functional.VerifyFindContextBufferInModuleBuffers%d",
585 &TestCaseDescriptionString[0],
587 "Verify Find PRM Context Buffer by Handler GUID %d\n",
592 FunctionalCorrectnessTests,
593 &TestCaseDescriptionString[0],
594 &TestCaseClassNameString[0],
598 mContextBufferArray[Index]
602 for (Index = 0; Index <
ARRAY_SIZE (mContextBufferArray); Index++) {
607 &TestCaseClassNameString[0],
609 "PrmContextBufferLib.Functional.VerifyGetContextBuffer%d",
613 &TestCaseDescriptionString[0],
615 "Verify Get PRM Context Buffer by Handler GUID %d\n",
620 FunctionalCorrectnessTests,
621 &TestCaseDescriptionString[0],
622 &TestCaseClassNameString[0],
626 mContextBufferArray[Index]
BOOLEAN EFIAPI CompareGuid(IN CONST GUID *Guid1, IN CONST GUID *Guid2)
GUID *EFIAPI CopyGuid(OUT GUID *DestinationGuid, IN CONST GUID *SourceGuid)
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_HANDLE mTestProtocolHandle
=== TEST DATA ==================================================================================
UNIT_TEST_STATUS EFIAPI VerifyFindContextBufferInModuleBuffers(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI NullPointerArgumentsShouldFailGracefully(IN UNIT_TEST_CONTEXT Context)
=== HELPER FUNCTIONS ===========================================================================
STATIC UNIT_TEST_STATUS EFIAPI InitializeFunctionalCorrectness(IN UNIT_TEST_CONTEXT Context)
===== FUNCTIONAL CORRECTNESS SUITE ==================================================
STATIC VOID EFIAPI DeInitializeFunctionalCorrectness(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI VerifyGetContextBuffer(IN UNIT_TEST_CONTEXT Context)
int main()
=== TEST ENGINE ================================================================================
UNIT_TEST_STATUS EFIAPI VerifyGetModuleContextBuffers(IN UNIT_TEST_CONTEXT Context)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
VOID EFIAPI FreePool(IN VOID *Buffer)
UINTN EFIAPI AsciiSPrint(OUT CHAR8 *StartOfBuffer, IN UINTN BufferSize, IN CONST CHAR8 *FormatString,...)
#define ARRAY_SIZE(Array)
#define DEBUG(Expression)
EFI_STATUS FindContextBufferInModuleBuffers(IN CONST EFI_GUID *HandlerGuid, IN CONST PRM_MODULE_CONTEXT_BUFFERS *ModuleContextBuffers, OUT CONST PRM_CONTEXT_BUFFER **ContextBuffer)
EFI_STATUS GetContextBuffer(IN CONST EFI_GUID *PrmHandlerGuid, IN CONST PRM_MODULE_CONTEXT_BUFFERS *PrmModuleContextBuffers OPTIONAL, OUT CONST PRM_CONTEXT_BUFFER **PrmContextBuffer)
EFI_STATUS GetModuleContextBuffers(IN PRM_GUID_SEARCH_TYPE GuidSearchType, IN CONST EFI_GUID *Guid, OUT CONST PRM_MODULE_CONTEXT_BUFFERS **PrmModuleContextBuffers)
EFI_STATUS EFIAPI RunAllTestSuites(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
#define UT_ASSERT_NOT_NULL(Pointer)
#define UT_ASSERT_TRUE(Expression)
#define UT_ASSERT_EQUAL(ValueA, ValueB)
#define UT_ASSERT_STATUS_EQUAL(Status, Expected)
#define UT_LOG_INFO(Format,...)
EFI_STATUS EFIAPI CreateUnitTestSuite(OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle, IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *Name, IN UNIT_TEST_SUITE_SETUP Setup OPTIONAL, IN UNIT_TEST_SUITE_TEARDOWN Teardown OPTIONAL)
EFI_STATUS EFIAPI FreeUnitTestFramework(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
EFI_STATUS EFIAPI AddTestCase(IN UNIT_TEST_SUITE_HANDLE SuiteHandle, IN CHAR8 *Description, IN CHAR8 *Name, IN UNIT_TEST_FUNCTION Function, IN UNIT_TEST_PREREQUISITE Prerequisite OPTIONAL, IN UNIT_TEST_CLEANUP CleanUp OPTIONAL, IN UNIT_TEST_CONTEXT Context OPTIONAL)
EFI_STATUS EFIAPI InitUnitTestFramework(OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *ShortTitle, IN CHAR8 *VersionString)
#define UT_ASSERT_NOT_EFI_ERROR(Status)
PRM_CONTEXT_BUFFER * Buffer