TianoCore EDK2 master
Loading...
Searching...
No Matches
DxePrmModuleDiscoveryLibUnitTest.c
Go to the documentation of this file.
1
10#include <stdio.h>
11#include <string.h>
12#include <stdarg.h>
13#include <stddef.h>
14#include <setjmp.h>
15#include <cmocka.h>
16
17#include <Library/BaseLib.h>
19#include <Library/DebugLib.h>
23#include <Library/UnitTestLib.h>
24
25#include "../PrmModuleDiscovery.h"
26
27#define UNIT_TEST_NAME "PRM Module Discovery Library Unit Test"
28#define UNIT_TEST_VERSION "0.1"
29
31
33
45EFIAPI
47 IN UNIT_TEST_CONTEXT Context
48 )
49{
51
53
54 UT_ASSERT_NOT_NULL (ListEntry);
55 if (ListEntry != NULL) {
56 FreePool (ListEntry);
57 }
58
59 return UNIT_TEST_PASSED;
60}
61
73EFIAPI
75 IN UNIT_TEST_CONTEXT Context
76 )
77{
79
81
82 UT_ASSERT_TRUE (ListEntry->Signature == PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY_SIGNATURE);
83
84 if (ListEntry != NULL) {
85 FreePool (ListEntry);
86 }
87
88 return UNIT_TEST_PASSED;
89}
90
102EFIAPI
104 IN UNIT_TEST_CONTEXT Context
105 )
106{
108 PRM_MODULE_IMAGE_CONTEXT ImageContext;
109
111
112 ZeroMem (&ImageContext, sizeof (ImageContext));
113 UT_ASSERT_MEM_EQUAL (&ListEntry->Context, &ImageContext, sizeof (ImageContext));
114
115 if (ListEntry != NULL) {
116 FreePool (ListEntry);
117 }
118
119 return UNIT_TEST_PASSED;
120}
121
123
134int
136 )
137{
138 EFI_STATUS Status;
139 UNIT_TEST_FRAMEWORK_HANDLE Framework;
140 UNIT_TEST_SUITE_HANDLE CreateNewPrmModuleImageContextListEntryTests;
141
142 Framework = NULL;
143
144 DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_NAME, UNIT_TEST_VERSION));
145
146 //
147 // Start setting up the test framework for running the tests.
148 //
149 Status = InitUnitTestFramework (&Framework, UNIT_TEST_NAME, gEfiCallerBaseName, UNIT_TEST_VERSION);
150 if (EFI_ERROR (Status)) {
151 DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status));
152 goto EXIT;
153 }
154
155 Status = CreateUnitTestSuite (
156 &CreateNewPrmModuleImageContextListEntryTests,
157 Framework,
158 "Create New PRM Module Image Context List Entry Tests",
159 "PrmModuleDiscoveryLib.CreateNewPrmModuleImageContextListEntry",
160 NULL,
161 NULL
162 );
163 if (EFI_ERROR (Status)) {
164 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for PrmModuleDiscoveryLib.CreateNewPrmModuleImageContextListEntry\n"));
165 Status = EFI_OUT_OF_RESOURCES;
166 goto EXIT;
167 }
168
170 CreateNewPrmModuleImageContextListEntryTests,
171 "",
172 "PrmModuleDiscoveryLib.CreateNewPrmModuleImageContextListEntry.ListEntryShouldDeallocate",
174 NULL,
175 NULL,
176 NULL
177 );
178
180 CreateNewPrmModuleImageContextListEntryTests,
181 "",
182 "PrmModuleDiscoveryLib.CreateNewPrmModuleImageContextListEntry.ListEntrySignatureShouldBeValid",
184 NULL,
185 NULL,
186 NULL
187 );
188
190 CreateNewPrmModuleImageContextListEntryTests,
191 "",
192 "PrmModuleDiscoveryLib.CreateNewPrmModuleImageContextListEntry.ListEntryImageContextShouldBeZeroed",
194 NULL,
195 NULL,
196 NULL
197 );
198
199 //
200 // Execute the tests.
201 //
202 Status = RunAllTestSuites (Framework);
203
204EXIT:
205 if (Framework) {
206 FreeUnitTestFramework (Framework);
207 }
208
209 return Status;
210}
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY * CreateNewPrmModuleImageContextListEntry(VOID)
UNIT_TEST_STATUS EFIAPI PrmModuleImageContextListEntryShouldDeallocate(IN UNIT_TEST_CONTEXT Context)
=== TEST CASES =================================================================================
UNIT_TEST_STATUS EFIAPI PrmModuleImageContextListEntryImageContextShouldBeZeroed(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI PrmModuleImageContextListEntrySignatureShouldBeValid(IN UNIT_TEST_CONTEXT Context)
int main()
=== TEST ENGINE ================================================================================
VOID EFIAPI FreePool(IN VOID *Buffer)
#define NULL
Definition: Base.h:319
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
EFI_STATUS EFIAPI RunAllTestSuites(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
Definition: RunTests.c:145
#define UT_ASSERT_NOT_NULL(Pointer)
Definition: UnitTestLib.h:439
VOID * UNIT_TEST_CONTEXT
Definition: UnitTestLib.h:54
#define UT_ASSERT_MEM_EQUAL(BufferA, BufferB, Length)
Definition: UnitTestLib.h:389
#define UT_ASSERT_TRUE(Expression)
Definition: UnitTestLib.h:350
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)
Definition: UnitTestLib.c:326
EFI_STATUS EFIAPI FreeUnitTestFramework(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
Definition: UnitTestLib.c:150
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)
Definition: UnitTestLib.c:426
EFI_STATUS EFIAPI InitUnitTestFramework(OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *ShortTitle, IN CHAR8 *VersionString)
Definition: UnitTestLib.c:204
UINT32 UNIT_TEST_STATUS
Definition: UnitTestLib.h:16