2 Unit tests of the DxeResetSystemLib instance of the ResetSystemLib class
4 Copyright (C) Microsoft Corporation.
5 SPDX-License-Identifier: BSD-2-Clause-Patent
17 #include <Library/BaseLib.h>
18 #include <Library/BaseMemoryLib.h>
19 #include <Library/DebugLib.h>
20 #include <Library/MemoryAllocationLib.h>
22 #include <Library/UnitTestLib.h>
23 #include <Library/ResetSystemLib.h>
25 #define UNIT_TEST_APP_NAME "DxeResetSystemLib Unit Tests"
26 #define UNIT_TEST_APP_VERSION "1.0"
29 Resets the entire platform.
31 @param[in] ResetType The type of reset to perform.
32 @param[in] ResetStatus The status code for the reset.
33 @param[in] DataSize The size, in bytes, of ResetData.
34 @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or
35 EfiResetShutdown the data buffer starts with a Null-terminated
36 string, optionally followed by additional binary data.
37 The string is a description that the caller may use to further
38 indicate the reason for the system reset.
39 For a ResetType of EfiResetPlatformSpecific the data buffer
40 also starts with a Null-terminated string that is followed
41 by an EFI_GUID that describes the specific type of reset to perform.
47 IN EFI_RESET_TYPE ResetType
,
48 IN EFI_STATUS ResetStatus
,
50 IN VOID
*ResetData OPTIONAL
53 check_expected_ptr (ResetType
);
54 check_expected_ptr (ResetStatus
);
57 // NOTE: Mocked functions can also return values, but that
58 // is for another demo.
62 /// Mock version of the UEFI Runtime Services Table
64 EFI_RUNTIME_SERVICES MockRuntime
= {
66 EFI_RUNTIME_SERVICES_SIGNATURE
, // Signature
67 EFI_RUNTIME_SERVICES_REVISION
, // Revision
68 sizeof (EFI_RUNTIME_SERVICES
), // HeaderSize
74 NULL
, // GetWakeupTime
75 NULL
, // SetWakeupTime
76 NULL
, // SetVirtualAddressMap
77 NULL
, // ConvertPointer
79 NULL
, // GetNextVariableName
81 NULL
, // GetNextHighMonotonicCount
82 MockResetSystem
, // ResetSystem
83 NULL
, // UpdateCapsule
84 NULL
, // QueryCapsuleCapabilities
85 NULL
// QueryVariableInfo
89 Unit test for ColdReset () API of the ResetSystemLib.
91 @param[in] Context [Optional] An optional parameter that enables:
92 1) test-case reuse with varied parameters and
93 2) test-case re-entry for Target tests that need a
94 reboot. This parameter is a VOID* and it is the
95 responsibility of the test author to ensure that the
96 contents are well understood by all test cases that may
99 @retval UNIT_TEST_PASSED The Unit test has completed and the test
101 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
105 ResetColdShouldIssueAColdReset (
106 IN UNIT_TEST_CONTEXT Context
109 expect_value (MockResetSystem
, ResetType
, EfiResetCold
);
110 expect_value (MockResetSystem
, ResetStatus
, EFI_SUCCESS
);
114 return UNIT_TEST_PASSED
;
118 Unit test for WarmReset () API of the ResetSystemLib.
120 @param[in] Context [Optional] An optional parameter that enables:
121 1) test-case reuse with varied parameters and
122 2) test-case re-entry for Target tests that need a
123 reboot. This parameter is a VOID* and it is the
124 responsibility of the test author to ensure that the
125 contents are well understood by all test cases that may
128 @retval UNIT_TEST_PASSED The Unit test has completed and the test
130 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
134 ResetWarmShouldIssueAWarmReset (
135 IN UNIT_TEST_CONTEXT Context
138 expect_value (MockResetSystem
, ResetType
, EfiResetWarm
);
139 expect_value (MockResetSystem
, ResetStatus
, EFI_SUCCESS
);
143 return UNIT_TEST_PASSED
;
147 Unit test for ResetShutdown () API of the ResetSystemLib.
149 @param[in] Context [Optional] An optional parameter that enables:
150 1) test-case reuse with varied parameters and
151 2) test-case re-entry for Target tests that need a
152 reboot. This parameter is a VOID* and it is the
153 responsibility of the test author to ensure that the
154 contents are well understood by all test cases that may
157 @retval UNIT_TEST_PASSED The Unit test has completed and the test
159 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
163 ResetShutdownShouldIssueAShutdown (
164 IN UNIT_TEST_CONTEXT Context
167 expect_value (MockResetSystem
, ResetType
, EfiResetShutdown
);
168 expect_value (MockResetSystem
, ResetStatus
, EFI_SUCCESS
);
172 return UNIT_TEST_PASSED
;
176 Unit test for ResetPlatformSpecific () API of the ResetSystemLib.
178 @param[in] Context [Optional] An optional parameter that enables:
179 1) test-case reuse with varied parameters and
180 2) test-case re-entry for Target tests that need a
181 reboot. This parameter is a VOID* and it is the
182 responsibility of the test author to ensure that the
183 contents are well understood by all test cases that may
186 @retval UNIT_TEST_PASSED The Unit test has completed and the test
188 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
192 ResetPlatformSpecificShouldIssueAPlatformSpecificReset (
193 IN UNIT_TEST_CONTEXT Context
196 expect_value (MockResetSystem
, ResetType
, EfiResetPlatformSpecific
);
197 expect_value (MockResetSystem
, ResetStatus
, EFI_SUCCESS
);
199 ResetPlatformSpecific (0, NULL
);
201 return UNIT_TEST_PASSED
;
205 Unit test for ResetSystem () API of the ResetSystemLib.
207 @param[in] Context [Optional] An optional parameter that enables:
208 1) test-case reuse with varied parameters and
209 2) test-case re-entry for Target tests that need a
210 reboot. This parameter is a VOID* and it is the
211 responsibility of the test author to ensure that the
212 contents are well understood by all test cases that may
215 @retval UNIT_TEST_PASSED The Unit test has completed and the test
217 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
221 ResetSystemShouldPassTheParametersThrough (
222 IN UNIT_TEST_CONTEXT Context
225 expect_value (MockResetSystem
, ResetType
, EfiResetCold
);
226 expect_value (MockResetSystem
, ResetStatus
, EFI_SUCCESS
);
228 ResetSystem (EfiResetCold
, EFI_SUCCESS
, 0, NULL
);
230 expect_value (MockResetSystem
, ResetType
, EfiResetShutdown
);
231 expect_value (MockResetSystem
, ResetStatus
, EFI_SUCCESS
);
233 ResetSystem (EfiResetShutdown
, EFI_SUCCESS
, 0, NULL
);
235 return UNIT_TEST_PASSED
;
239 Initialze the unit test framework, suite, and unit tests for the
240 ResetSystemLib and run the ResetSystemLib unit test.
242 @retval EFI_SUCCESS All test cases were dispatched.
243 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to
244 initialize the unit tests.
254 UNIT_TEST_FRAMEWORK_HANDLE Framework
;
255 UNIT_TEST_SUITE_HANDLE ResetTests
;
259 DEBUG ((DEBUG_INFO
, "%a v%a\n", UNIT_TEST_APP_NAME
, UNIT_TEST_APP_VERSION
));
262 // Start setting up the test framework for running the tests.
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
));
271 // Populate the ResetSytemLib Unit Test Suite.
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
;
281 // --------------Suite-----------Description--------------Name----------Function--------Pre---Post-------------------Context-----------
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
);
290 // Execute the tests.
292 Status
= RunAllTestSuites (Framework
);
296 FreeUnitTestFramework (Framework
);
303 Standard POSIX C entry point for host based unit test execution.
311 return UnitTestingEntry ();