1 | /** @file
|
---|
2 |
|
---|
3 | Unit tests for the PRM Module Discovery Library.
|
---|
4 |
|
---|
5 | Copyright (c) Microsoft Corporation
|
---|
6 | SPDX-License-Identifier: BSD-2-Clause-Patent
|
---|
7 |
|
---|
8 | **/
|
---|
9 |
|
---|
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>
|
---|
18 | #include <Library/BaseMemoryLib.h>
|
---|
19 | #include <Library/DebugLib.h>
|
---|
20 | #include <Library/MemoryAllocationLib.h>
|
---|
21 | #include <Library/PrmModuleDiscoveryLib.h>
|
---|
22 | #include <Library/UefiBootServicesTableLib.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 |
|
---|
30 | /// === TEST CASES =================================================================================
|
---|
31 |
|
---|
32 | /// ===== CREATE NEW PRM MODULE IMAGE CONTEXT LIST ENTRY TESTS SUITE ==================================================
|
---|
33 |
|
---|
34 | /**
|
---|
35 | Verifies that the buffer returned can be deallocated.
|
---|
36 |
|
---|
37 | @param[in] Context [Optional] An optional context parameter.
|
---|
38 | Not used in this unit test.
|
---|
39 |
|
---|
40 | @retval UNIT_TEST_PASSED Unit test case prerequisites are met.
|
---|
41 | @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be skipped..
|
---|
42 |
|
---|
43 | **/
|
---|
44 | UNIT_TEST_STATUS
|
---|
45 | EFIAPI
|
---|
46 | PrmModuleImageContextListEntryShouldDeallocate (
|
---|
47 | IN UNIT_TEST_CONTEXT Context
|
---|
48 | )
|
---|
49 | {
|
---|
50 | PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY *ListEntry;
|
---|
51 |
|
---|
52 | ListEntry = CreateNewPrmModuleImageContextListEntry ();
|
---|
53 |
|
---|
54 | UT_ASSERT_NOT_NULL (ListEntry);
|
---|
55 | if (ListEntry != NULL) {
|
---|
56 | FreePool (ListEntry);
|
---|
57 | }
|
---|
58 |
|
---|
59 | return UNIT_TEST_PASSED;
|
---|
60 | }
|
---|
61 |
|
---|
62 | /**
|
---|
63 | Verifies that the list entry signature is set to the appropriate value.
|
---|
64 |
|
---|
65 | @param[in] Context [Optional] An optional context parameter.
|
---|
66 | Not used in this unit test.
|
---|
67 |
|
---|
68 | @retval UNIT_TEST_PASSED Unit test case prerequisites are met.
|
---|
69 | @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be skipped..
|
---|
70 |
|
---|
71 | **/
|
---|
72 | UNIT_TEST_STATUS
|
---|
73 | EFIAPI
|
---|
74 | PrmModuleImageContextListEntrySignatureShouldBeValid (
|
---|
75 | IN UNIT_TEST_CONTEXT Context
|
---|
76 | )
|
---|
77 | {
|
---|
78 | PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY *ListEntry;
|
---|
79 |
|
---|
80 | ListEntry = CreateNewPrmModuleImageContextListEntry ();
|
---|
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 |
|
---|
91 | /**
|
---|
92 | Verifies that the Context buffer in the list entry is initialized to zero.
|
---|
93 |
|
---|
94 | @param[in] Context [Optional] An optional context parameter.
|
---|
95 | Not used in this unit test.
|
---|
96 |
|
---|
97 | @retval UNIT_TEST_PASSED Unit test case prerequisites are met.
|
---|
98 | @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be skipped..
|
---|
99 |
|
---|
100 | **/
|
---|
101 | UNIT_TEST_STATUS
|
---|
102 | EFIAPI
|
---|
103 | PrmModuleImageContextListEntryImageContextShouldBeZeroed (
|
---|
104 | IN UNIT_TEST_CONTEXT Context
|
---|
105 | )
|
---|
106 | {
|
---|
107 | PRM_MODULE_IMAGE_CONTEXT_LIST_ENTRY *ListEntry;
|
---|
108 | PRM_MODULE_IMAGE_CONTEXT ImageContext;
|
---|
109 |
|
---|
110 | ListEntry = CreateNewPrmModuleImageContextListEntry ();
|
---|
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 |
|
---|
122 | /// === TEST ENGINE ================================================================================
|
---|
123 |
|
---|
124 | /**
|
---|
125 | Entry point for the PRM Context Buffer Library unit tests.
|
---|
126 |
|
---|
127 | @param[in] ImageHandle The firmware allocated handle for the EFI image.
|
---|
128 | @param[in] SystemTable A pointer to the EFI System Table.
|
---|
129 |
|
---|
130 | @retval EFI_SUCCESS The entry point executed successfully.
|
---|
131 | @retval other Some error occurred when executing this entry point.
|
---|
132 |
|
---|
133 | **/
|
---|
134 | int
|
---|
135 | main (
|
---|
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 |
|
---|
169 | AddTestCase (
|
---|
170 | CreateNewPrmModuleImageContextListEntryTests,
|
---|
171 | "",
|
---|
172 | "PrmModuleDiscoveryLib.CreateNewPrmModuleImageContextListEntry.ListEntryShouldDeallocate",
|
---|
173 | PrmModuleImageContextListEntryShouldDeallocate,
|
---|
174 | NULL,
|
---|
175 | NULL,
|
---|
176 | NULL
|
---|
177 | );
|
---|
178 |
|
---|
179 | AddTestCase (
|
---|
180 | CreateNewPrmModuleImageContextListEntryTests,
|
---|
181 | "",
|
---|
182 | "PrmModuleDiscoveryLib.CreateNewPrmModuleImageContextListEntry.ListEntrySignatureShouldBeValid",
|
---|
183 | PrmModuleImageContextListEntrySignatureShouldBeValid,
|
---|
184 | NULL,
|
---|
185 | NULL,
|
---|
186 | NULL
|
---|
187 | );
|
---|
188 |
|
---|
189 | AddTestCase (
|
---|
190 | CreateNewPrmModuleImageContextListEntryTests,
|
---|
191 | "",
|
---|
192 | "PrmModuleDiscoveryLib.CreateNewPrmModuleImageContextListEntry.ListEntryImageContextShouldBeZeroed",
|
---|
193 | PrmModuleImageContextListEntryImageContextShouldBeZeroed,
|
---|
194 | NULL,
|
---|
195 | NULL,
|
---|
196 | NULL
|
---|
197 | );
|
---|
198 |
|
---|
199 | //
|
---|
200 | // Execute the tests.
|
---|
201 | //
|
---|
202 | Status = RunAllTestSuites (Framework);
|
---|
203 |
|
---|
204 | EXIT:
|
---|
205 | if (Framework) {
|
---|
206 | FreeUnitTestFramework (Framework);
|
---|
207 | }
|
---|
208 |
|
---|
209 | return Status;
|
---|
210 | }
|
---|