TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeResetSystemLibUnitTest.c
Go to the documentation of this file.
1
9#include <stdio.h>
10#include <string.h>
11#include <stdarg.h>
12#include <stddef.h>
13#include <setjmp.h>
14#include <cmocka.h>
15
16#include <Uefi.h>
17#include <Library/BaseLib.h>
19#include <Library/DebugLib.h>
21
22#include <Library/UnitTestLib.h>
24
25#define UNIT_TEST_APP_NAME "DxeResetSystemLib Unit Tests"
26#define UNIT_TEST_APP_VERSION "1.0"
27
44VOID
45EFIAPI
47 IN EFI_RESET_TYPE ResetType,
48 IN EFI_STATUS ResetStatus,
49 IN UINTN DataSize,
50 IN VOID *ResetData OPTIONAL
51 )
52{
53 check_expected_ptr (ResetType);
54 check_expected_ptr (ResetStatus);
55
56 //
57 // NOTE: Mocked functions can also return values, but that
58 // is for another demo.
59}
60
65 {
66 EFI_RUNTIME_SERVICES_SIGNATURE, // Signature
67 EFI_RUNTIME_SERVICES_REVISION, // Revision
68 sizeof (EFI_RUNTIME_SERVICES), // HeaderSize
69 0, // CRC32
70 0 // Reserved
71 },
72 NULL, // GetTime
73 NULL, // SetTime
74 NULL, // GetWakeupTime
75 NULL, // SetWakeupTime
76 NULL, // SetVirtualAddressMap
77 NULL, // ConvertPointer
78 NULL, // GetVariable
79 NULL, // GetNextVariableName
80 NULL, // SetVariable
81 NULL, // GetNextHighMonotonicCount
82 MockResetSystem, // ResetSystem
83 NULL, // UpdateCapsule
84 NULL, // QueryCapsuleCapabilities
85 NULL // QueryVariableInfo
86};
87
104EFIAPI
106 IN UNIT_TEST_CONTEXT Context
107 )
108{
109 expect_value (MockResetSystem, ResetType, EfiResetCold);
110 expect_value (MockResetSystem, ResetStatus, EFI_SUCCESS);
111
112 ResetCold ();
113
114 return UNIT_TEST_PASSED;
115}
116
133EFIAPI
135 IN UNIT_TEST_CONTEXT Context
136 )
137{
138 expect_value (MockResetSystem, ResetType, EfiResetWarm);
139 expect_value (MockResetSystem, ResetStatus, EFI_SUCCESS);
140
141 ResetWarm ();
142
143 return UNIT_TEST_PASSED;
144}
145
162EFIAPI
164 IN UNIT_TEST_CONTEXT Context
165 )
166{
167 expect_value (MockResetSystem, ResetType, EfiResetShutdown);
168 expect_value (MockResetSystem, ResetStatus, EFI_SUCCESS);
169
170 ResetShutdown ();
171
172 return UNIT_TEST_PASSED;
173}
174
191EFIAPI
193 IN UNIT_TEST_CONTEXT Context
194 )
195{
196 expect_value (MockResetSystem, ResetType, EfiResetPlatformSpecific);
197 expect_value (MockResetSystem, ResetStatus, EFI_SUCCESS);
198
200
201 return UNIT_TEST_PASSED;
202}
203
220EFIAPI
222 IN UNIT_TEST_CONTEXT Context
223 )
224{
225 expect_value (MockResetSystem, ResetType, EfiResetCold);
226 expect_value (MockResetSystem, ResetStatus, EFI_SUCCESS);
227
229
230 expect_value (MockResetSystem, ResetType, EfiResetShutdown);
231 expect_value (MockResetSystem, ResetStatus, EFI_SUCCESS);
232
234
235 return UNIT_TEST_PASSED;
236}
237
246STATIC
248EFIAPI
250 VOID
251 )
252{
253 EFI_STATUS Status;
254 UNIT_TEST_FRAMEWORK_HANDLE Framework;
255 UNIT_TEST_SUITE_HANDLE ResetTests;
256
257 Framework = NULL;
258
259 DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));
260
261 //
262 // Start setting up the test framework for running the tests.
263 //
264 Status = InitUnitTestFramework (&Framework, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION);
265 if (EFI_ERROR (Status)) {
266 DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status));
267 goto EXIT;
268 }
269
270 //
271 // Populate the ResetSytemLib Unit Test Suite.
272 //
273 Status = CreateUnitTestSuite (&ResetTests, Framework, "DxeResetSystemLib Reset Tests", "ResetSystemLib.Reset", NULL, NULL);
274 if (EFI_ERROR (Status)) {
275 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for ResetTests\n"));
276 Status = EFI_OUT_OF_RESOURCES;
277 goto EXIT;
278 }
279
280 //
281 // --------------Suite-----------Description--------------Name----------Function--------Pre---Post-------------------Context-----------
282 //
283 AddTestCase (ResetTests, "ResetCold should issue a cold reset", "Cold", ResetColdShouldIssueAColdReset, NULL, NULL, NULL);
284 AddTestCase (ResetTests, "ResetWarm should issue a warm reset", "Warm", ResetWarmShouldIssueAWarmReset, NULL, NULL, NULL);
285 AddTestCase (ResetTests, "ResetShutdown should issue a shutdown", "Shutdown", ResetShutdownShouldIssueAShutdown, NULL, NULL, NULL);
286 AddTestCase (ResetTests, "ResetPlatformSpecific should issue a platform-specific reset", "Platform", ResetPlatformSpecificShouldIssueAPlatformSpecificReset, NULL, NULL, NULL);
287 AddTestCase (ResetTests, "ResetSystem should pass all parameters through", "Parameters", ResetSystemShouldPassTheParametersThrough, NULL, NULL, NULL);
288
289 //
290 // Execute the tests.
291 //
292 Status = RunAllTestSuites (Framework);
293
294EXIT:
295 if (Framework) {
296 FreeUnitTestFramework (Framework);
297 }
298
299 return Status;
300}
301
305int
307 int argc,
308 char *argv[]
309 )
310{
311 return UnitTestingEntry ();
312}
UINT64 UINTN
VOID EFIAPI ResetWarm(VOID)
VOID EFIAPI ResetShutdown(VOID)
VOID EFIAPI ResetSystem(IN EFI_RESET_TYPE ResetType, IN EFI_STATUS ResetStatus, IN UINTN DataSize, IN VOID *ResetData OPTIONAL)
VOID EFIAPI ResetPlatformSpecific(IN UINTN DataSize, IN VOID *ResetData)
VOID EFIAPI ResetCold(VOID)
int main()
=== TEST ENGINE ================================================================================
EFI_RUNTIME_SERVICES MockRuntime
STATIC VOID EFIAPI MockResetSystem(IN EFI_RESET_TYPE ResetType, IN EFI_STATUS ResetStatus, IN UINTN DataSize, IN VOID *ResetData OPTIONAL)
UNIT_TEST_STATUS EFIAPI ResetShutdownShouldIssueAShutdown(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI ResetSystemShouldPassTheParametersThrough(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI ResetColdShouldIssueAColdReset(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI ResetWarmShouldIssueAWarmReset(IN UNIT_TEST_CONTEXT Context)
STATIC EFI_STATUS EFIAPI UnitTestingEntry(VOID)
UNIT_TEST_STATUS EFIAPI ResetPlatformSpecificShouldIssueAPlatformSpecificReset(IN UNIT_TEST_CONTEXT Context)
#define NULL
Definition: Base.h:319
#define STATIC
Definition: Base.h:264
#define IN
Definition: Base.h:279
#define DEBUG(Expression)
Definition: DebugLib.h:434
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_RESET_TYPE
@ EfiResetCold
@ EfiResetShutdown
@ EfiResetWarm
@ EfiResetPlatformSpecific
EFI_STATUS EFIAPI RunAllTestSuites(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
Definition: RunTests.c:145
VOID * UNIT_TEST_CONTEXT
Definition: UnitTestLib.h:54
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