]>
Commit | Line | Data |
---|---|---|
b238ce28 BB |
1 | /** @file\r |
2 | Provides a unit test framework. This allows tests to focus on testing logic\r | |
3 | and the framework to focus on runnings, reporting, statistics, etc.\r | |
4 | \r | |
5 | Copyright (c) Microsoft Corporation.<BR>\r | |
6 | Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>\r | |
7 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
8 | **/\r | |
9 | \r | |
10 | #ifndef __UNIT_TEST_LIB_H__\r | |
11 | #define __UNIT_TEST_LIB_H__\r | |
12 | \r | |
13 | ///\r | |
14 | /// Unit Test Status\r | |
15 | ///\r | |
16 | typedef UINT32 UNIT_TEST_STATUS;\r | |
17 | #define UNIT_TEST_PASSED (0)\r | |
18 | #define UNIT_TEST_ERROR_PREREQUISITE_NOT_MET (1)\r | |
19 | #define UNIT_TEST_ERROR_TEST_FAILED (2)\r | |
20 | #define UNIT_TEST_ERROR_CLEANUP_FAILED (3)\r | |
21 | #define UNIT_TEST_SKIPPED (0xFFFFFFFD)\r | |
22 | #define UNIT_TEST_RUNNING (0xFFFFFFFE)\r | |
23 | #define UNIT_TEST_PENDING (0xFFFFFFFF)\r | |
24 | \r | |
25 | ///\r | |
26 | /// Declare PcdUnitTestLogLevel bits and UnitTestLog() ErrorLevel parameter.\r | |
27 | ///\r | |
28 | #define UNIT_TEST_LOG_LEVEL_ERROR BIT0\r | |
29 | #define UNIT_TEST_LOG_LEVEL_WARN BIT1\r | |
30 | #define UNIT_TEST_LOG_LEVEL_INFO BIT2\r | |
31 | #define UNIT_TEST_LOG_LEVEL_VERBOSE BIT3\r | |
32 | \r | |
33 | ///\r | |
34 | /// Unit Test Framework Handle\r | |
35 | ///\r | |
36 | struct UNIT_TEST_FRAMEWORK_OBJECT;\r | |
37 | typedef struct UNIT_TEST_FRAMEWORK_OBJECT *UNIT_TEST_FRAMEWORK_HANDLE;\r | |
38 | \r | |
39 | ///\r | |
40 | /// Unit Test Suite Handle\r | |
41 | ///\r | |
42 | struct UNIT_TEST_SUITE_OBJECT;\r | |
43 | typedef struct UNIT_TEST_SUITE_OBJECT *UNIT_TEST_SUITE_HANDLE;\r | |
44 | \r | |
45 | ///\r | |
46 | /// Unit Test Handle\r | |
47 | ///\r | |
48 | struct UNIT_TEST_OBJECT;\r | |
49 | typedef struct UNIT_TEST_OBJECT *UNIT_TEST_HANDLE;\r | |
50 | \r | |
51 | ///\r | |
52 | /// Unit Test Context\r | |
53 | ///\r | |
54 | typedef VOID* UNIT_TEST_CONTEXT;\r | |
55 | \r | |
56 | /**\r | |
57 | The prototype for a single UnitTest case function.\r | |
58 | \r | |
59 | Functions with this prototype are registered to be dispatched by the\r | |
60 | UnitTest framework, and results are recorded as test Pass or Fail.\r | |
61 | \r | |
62 | @param[in] Context [Optional] An optional parameter that enables:\r | |
63 | 1) test-case reuse with varied parameters and\r | |
64 | 2) test-case re-entry for Target tests that need a\r | |
65 | reboot. This parameter is a VOID* and it is the\r | |
66 | responsibility of the test author to ensure that the\r | |
67 | contents are well understood by all test cases that may\r | |
68 | consume it.\r | |
69 | \r | |
70 | @retval UNIT_TEST_PASSED The Unit test has completed and the test\r | |
71 | case was successful.\r | |
72 | @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.\r | |
73 | \r | |
74 | **/\r | |
75 | typedef\r | |
76 | UNIT_TEST_STATUS\r | |
77 | (EFIAPI *UNIT_TEST_FUNCTION)(\r | |
78 | IN UNIT_TEST_CONTEXT Context\r | |
79 | );\r | |
80 | \r | |
81 | /**\r | |
82 | Unit-Test Prerequisite Function pointer type.\r | |
83 | \r | |
84 | Functions with this prototype are registered to be dispatched by the unit test\r | |
85 | framework prior to a given test case. If this prereq function returns\r | |
86 | UNIT_TEST_ERROR_PREREQUISITE_NOT_MET, the test case will be skipped.\r | |
87 | \r | |
88 | @param[in] Context [Optional] An optional parameter that enables:\r | |
89 | 1) test-case reuse with varied parameters and\r | |
90 | 2) test-case re-entry for Target tests that need a\r | |
91 | reboot. This parameter is a VOID* and it is the\r | |
92 | responsibility of the test author to ensure that the\r | |
93 | contents are well understood by all test cases that may\r | |
94 | consume it.\r | |
95 | \r | |
96 | @retval UNIT_TEST_PASSED Unit test case prerequisites\r | |
97 | are met.\r | |
98 | @retval UNIT_TEST_ERROR_PREREQUISITE_NOT_MET Test case should be skipped.\r | |
99 | \r | |
100 | **/\r | |
101 | typedef\r | |
102 | UNIT_TEST_STATUS\r | |
103 | (EFIAPI *UNIT_TEST_PREREQUISITE)(\r | |
104 | IN UNIT_TEST_CONTEXT Context\r | |
105 | );\r | |
106 | \r | |
107 | /**\r | |
108 | Unit-Test Cleanup (after) function pointer type.\r | |
109 | \r | |
110 | Functions with this prototype are registered to be dispatched by the\r | |
111 | unit test framework after a given test case. This will be called even if the\r | |
112 | test case returns an error, but not if the prerequisite fails and the test is\r | |
113 | skipped. The purpose of this function is to clean up any global state or\r | |
114 | test data.\r | |
115 | \r | |
116 | @param[in] Context [Optional] An optional parameter that enables:\r | |
117 | 1) test-case reuse with varied parameters and\r | |
118 | 2) test-case re-entry for Target tests that need a\r | |
119 | reboot. This parameter is a VOID* and it is the\r | |
120 | responsibility of the test author to ensure that the\r | |
121 | contents are well understood by all test cases that may\r | |
122 | consume it.\r | |
123 | \r | |
124 | @retval UNIT_TEST_PASSED Test case cleanup succeeded.\r | |
125 | @retval UNIT_TEST_ERROR_CLEANUP_FAILED Test case cleanup failed.\r | |
126 | \r | |
127 | **/\r | |
128 | typedef\r | |
129 | VOID\r | |
130 | (EFIAPI *UNIT_TEST_CLEANUP)(\r | |
131 | IN UNIT_TEST_CONTEXT Context\r | |
132 | );\r | |
133 | \r | |
134 | /**\r | |
135 | Unit-Test Test Suite Setup (before) function pointer type. Functions with this\r | |
136 | prototype are registered to be dispatched by the UnitTest framework prior to\r | |
137 | running any of the test cases in a test suite. It will only be run once at\r | |
138 | the beginning of the suite (not prior to each case).\r | |
139 | \r | |
140 | The purpose of this function is to set up any global state or test data.\r | |
141 | **/\r | |
142 | typedef\r | |
143 | VOID\r | |
144 | (EFIAPI *UNIT_TEST_SUITE_SETUP)(\r | |
145 | VOID\r | |
146 | );\r | |
147 | \r | |
148 | /**\r | |
149 | Unit-Test Test Suite Teardown (after) function pointer type. Functions with\r | |
150 | this prototype are registered to be dispatched by the UnitTest framework after\r | |
151 | running all of the test cases in a test suite. It will only be run once at\r | |
152 | the end of the suite.\r | |
153 | \r | |
154 | The purpose of this function is to clean up any global state or test data.\r | |
155 | **/\r | |
156 | typedef\r | |
157 | VOID\r | |
158 | (EFIAPI *UNIT_TEST_SUITE_TEARDOWN)(\r | |
159 | VOID\r | |
160 | );\r | |
161 | \r | |
162 | /**\r | |
163 | Method to Initialize the Unit Test framework. This function registers the\r | |
164 | test name and also initializes the internal state of the test framework to\r | |
165 | receive any new suites and tests.\r | |
166 | \r | |
167 | @param[out] FrameworkHandle Unit test framework to be created.\r | |
168 | @param[in] Title Null-terminated ASCII string that is the user\r | |
169 | friendly name of the framework. String is\r | |
170 | copied.\r | |
171 | @param[in] ShortTitle Null-terminated ASCII short string that is the\r | |
172 | short name of the framework with no spaces.\r | |
173 | String is copied.\r | |
174 | @param[in] VersionString Null-terminated ASCII version string for the\r | |
175 | framework. String is copied.\r | |
176 | \r | |
177 | @retval EFI_SUCCESS The unit test framework was initialized.\r | |
178 | @retval EFI_INVALID_PARAMETER FrameworkHandle is NULL.\r | |
179 | @retval EFI_INVALID_PARAMETER Title is NULL.\r | |
180 | @retval EFI_INVALID_PARAMETER ShortTitle is NULL.\r | |
181 | @retval EFI_INVALID_PARAMETER VersionString is NULL.\r | |
182 | @retval EFI_INVALID_PARAMETER ShortTitle is invalid.\r | |
183 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to\r | |
184 | initialize the unit test framework.\r | |
185 | **/\r | |
186 | EFI_STATUS\r | |
187 | EFIAPI\r | |
188 | InitUnitTestFramework (\r | |
189 | OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle,\r | |
190 | IN CHAR8 *Title,\r | |
191 | IN CHAR8 *ShortTitle,\r | |
192 | IN CHAR8 *VersionString\r | |
193 | );\r | |
194 | \r | |
195 | /**\r | |
196 | Registers a Unit Test Suite in the Unit Test Framework.\r | |
197 | At least one test suite must be registered, because all test cases must be\r | |
198 | within a unit test suite.\r | |
199 | \r | |
200 | @param[out] SuiteHandle Unit test suite to create\r | |
201 | @param[in] FrameworkHandle Unit test framework to add unit test suite to\r | |
202 | @param[in] Title Null-terminated ASCII string that is the user\r | |
203 | friendly name of the test suite. String is\r | |
204 | copied.\r | |
205 | @param[in] Name Null-terminated ASCII string that is the short\r | |
206 | name of the test suite with no spaces. String\r | |
207 | is copied.\r | |
208 | @param[in] Setup Setup function, runs before suite. This is an\r | |
209 | optional parameter that may be NULL.\r | |
210 | @param[in] Teardown Teardown function, runs after suite. This is an\r | |
211 | optional parameter that may be NULL.\r | |
212 | \r | |
213 | @retval EFI_SUCCESS The unit test suite was created.\r | |
214 | @retval EFI_INVALID_PARAMETER SuiteHandle is NULL.\r | |
215 | @retval EFI_INVALID_PARAMETER FrameworkHandle is NULL.\r | |
216 | @retval EFI_INVALID_PARAMETER Title is NULL.\r | |
217 | @retval EFI_INVALID_PARAMETER Name is NULL.\r | |
218 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to\r | |
219 | initialize the unit test suite.\r | |
220 | **/\r | |
221 | EFI_STATUS\r | |
222 | EFIAPI\r | |
223 | CreateUnitTestSuite (\r | |
224 | OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle,\r | |
225 | IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,\r | |
226 | IN CHAR8 *Title,\r | |
227 | IN CHAR8 *Name,\r | |
228 | IN UNIT_TEST_SUITE_SETUP Setup OPTIONAL,\r | |
229 | IN UNIT_TEST_SUITE_TEARDOWN Teardown OPTIONAL\r | |
230 | );\r | |
231 | \r | |
232 | /**\r | |
233 | Adds test case to Suite\r | |
234 | \r | |
235 | @param[in] SuiteHandle Unit test suite to add test to.\r | |
236 | @param[in] Description Null-terminated ASCII string that is the user\r | |
237 | friendly description of a test. String is copied.\r | |
238 | @param[in] Name Null-terminated ASCII string that is the short name\r | |
239 | of the test with no spaces. String is copied.\r | |
240 | @param[in] Function Unit test function.\r | |
241 | @param[in] Prerequisite Prerequisite function, runs before test. This is\r | |
242 | an optional parameter that may be NULL.\r | |
243 | @param[in] CleanUp Clean up function, runs after test. This is an\r | |
244 | optional parameter that may be NULL.\r | |
245 | @param[in] Context Pointer to context. This is an optional parameter\r | |
246 | that may be NULL.\r | |
247 | \r | |
248 | @retval EFI_SUCCESS The unit test case was added to Suite.\r | |
249 | @retval EFI_INVALID_PARAMETER SuiteHandle is NULL.\r | |
250 | @retval EFI_INVALID_PARAMETER Description is NULL.\r | |
251 | @retval EFI_INVALID_PARAMETER Name is NULL.\r | |
252 | @retval EFI_INVALID_PARAMETER Function is NULL.\r | |
253 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to\r | |
254 | add the unit test case to Suite.\r | |
255 | **/\r | |
256 | EFI_STATUS\r | |
257 | EFIAPI\r | |
258 | AddTestCase (\r | |
259 | IN UNIT_TEST_SUITE_HANDLE SuiteHandle,\r | |
260 | IN CHAR8 *Description,\r | |
261 | IN CHAR8 *Name,\r | |
262 | IN UNIT_TEST_FUNCTION Function,\r | |
263 | IN UNIT_TEST_PREREQUISITE Prerequisite OPTIONAL,\r | |
264 | IN UNIT_TEST_CLEANUP CleanUp OPTIONAL,\r | |
265 | IN UNIT_TEST_CONTEXT Context OPTIONAL\r | |
266 | );\r | |
267 | \r | |
268 | /**\r | |
269 | Execute all unit test cases in all unit test suites added to a Framework.\r | |
270 | \r | |
271 | Once a unit test framework is initialized and all unit test suites and unit\r | |
272 | test cases are registered, this function will cause the unit test framework to\r | |
273 | dispatch all unit test cases in sequence and record the results for reporting.\r | |
274 | \r | |
275 | @param[in] FrameworkHandle A handle to the current running framework that\r | |
276 | dispatched the test. Necessary for recording\r | |
277 | certain test events with the framework.\r | |
278 | \r | |
279 | @retval EFI_SUCCESS All test cases were dispatched.\r | |
280 | @retval EFI_INVALID_PARAMETER FrameworkHandle is NULL.\r | |
281 | **/\r | |
282 | EFI_STATUS\r | |
283 | EFIAPI\r | |
284 | RunAllTestSuites (\r | |
285 | IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle\r | |
286 | );\r | |
287 | \r | |
288 | /**\r | |
289 | Cleanup a test framework.\r | |
290 | \r | |
291 | After tests are run, this will teardown the entire framework and free all\r | |
292 | allocated data within.\r | |
293 | \r | |
294 | @param[in] FrameworkHandle A handle to the current running framework that\r | |
295 | dispatched the test. Necessary for recording\r | |
296 | certain test events with the framework.\r | |
297 | \r | |
298 | @retval EFI_SUCCESS All resources associated with framework were\r | |
299 | freed.\r | |
300 | @retval EFI_INVALID_PARAMETER FrameworkHandle is NULL.\r | |
301 | **/\r | |
302 | EFI_STATUS\r | |
303 | EFIAPI\r | |
304 | FreeUnitTestFramework (\r | |
305 | IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle\r | |
306 | );\r | |
307 | \r | |
308 | /**\r | |
309 | Leverages a framework-specific mechanism (see UnitTestPersistenceLib if you're\r | |
310 | a framework author) to save the state of the executing framework along with\r | |
311 | any allocated data so that the test may be resumed upon reentry. A test case\r | |
312 | should pass any needed context (which, to prevent an infinite loop, should be\r | |
313 | at least the current execution count) which will be saved by the framework and\r | |
314 | passed to the test case upon resume.\r | |
315 | \r | |
4260c478 MK |
316 | This should be called while the current test framework is valid and active. It is\r |
317 | generally called from within a test case prior to quitting or rebooting.\r | |
b238ce28 | 318 | \r |
b238ce28 BB |
319 | @param[in] ContextToSave A buffer of test case-specific data to be saved\r |
320 | along with framework state. Will be passed as\r | |
321 | "Context" to the test case upon resume. This\r | |
322 | is an optional parameter that may be NULL.\r | |
323 | @param[in] ContextToSaveSize Size of the ContextToSave buffer.\r | |
324 | \r | |
325 | @retval EFI_SUCCESS The framework state and context were saved.\r | |
4260c478 | 326 | @retval EFI_NOT_FOUND An active framework handle was not found.\r |
b238ce28 BB |
327 | @retval EFI_INVALID_PARAMETER ContextToSave is not NULL and\r |
328 | ContextToSaveSize is 0.\r | |
329 | @retval EFI_INVALID_PARAMETER ContextToSave is >= 4GB.\r | |
330 | @retval EFI_OUT_OF_RESOURCES There are not enough resources available to\r | |
331 | save the framework and context state.\r | |
332 | @retval EFI_DEVICE_ERROR The framework and context state could not be\r | |
333 | saved to a persistent storage device due to a\r | |
334 | device error.\r | |
335 | **/\r | |
336 | EFI_STATUS\r | |
337 | EFIAPI\r | |
338 | SaveFrameworkState (\r | |
b238ce28 BB |
339 | IN UNIT_TEST_CONTEXT ContextToSave OPTIONAL,\r |
340 | IN UINTN ContextToSaveSize\r | |
341 | );\r | |
342 | \r | |
343 | /**\r | |
344 | This macro uses the framework assertion logic to check an expression for\r | |
345 | "TRUE". If the expression evaluates to TRUE, execution continues.\r | |
346 | Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r | |
347 | \r | |
348 | @param[in] Expression Expression to be evaluated for TRUE.\r | |
349 | **/\r | |
350 | #define UT_ASSERT_TRUE(Expression) \\r | |
351 | if(!UnitTestAssertTrue ((Expression), __FUNCTION__, __LINE__, __FILE__, #Expression)) { \\r | |
352 | return UNIT_TEST_ERROR_TEST_FAILED; \\r | |
353 | }\r | |
354 | \r | |
355 | /**\r | |
356 | This macro uses the framework assertion logic to check an expression for\r | |
357 | "FALSE". If the expression evaluates to FALSE, execution continues.\r | |
358 | Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r | |
359 | \r | |
360 | @param[in] Expression Expression to be evaluated for FALSE.\r | |
361 | **/\r | |
362 | #define UT_ASSERT_FALSE(Expression) \\r | |
363 | if(!UnitTestAssertFalse ((Expression), __FUNCTION__, __LINE__, __FILE__, #Expression)) { \\r | |
364 | return UNIT_TEST_ERROR_TEST_FAILED; \\r | |
365 | }\r | |
366 | \r | |
367 | /**\r | |
368 | This macro uses the framework assertion logic to check whether two simple\r | |
369 | values are equal. If the values are equal, execution continues.\r | |
370 | Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r | |
371 | \r | |
372 | @param[in] ValueA Value to be compared for equality (64-bit comparison).\r | |
373 | @param[in] ValueB Value to be compared for equality (64-bit comparison).\r | |
374 | **/\r | |
375 | #define UT_ASSERT_EQUAL(ValueA, ValueB) \\r | |
376 | if(!UnitTestAssertEqual ((UINT64)(ValueA), (UINT64)(ValueB), __FUNCTION__, __LINE__, __FILE__, #ValueA, #ValueB)) { \\r | |
377 | return UNIT_TEST_ERROR_TEST_FAILED; \\r | |
378 | }\r | |
379 | \r | |
380 | /**\r | |
381 | This macro uses the framework assertion logic to check whether two memory\r | |
382 | buffers are equal. If the buffers are equal, execution continues.\r | |
383 | Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r | |
384 | \r | |
385 | @param[in] BufferA Pointer to a buffer for comparison.\r | |
386 | @param[in] BufferB Pointer to a buffer for comparison.\r | |
387 | @param[in] Length Number of bytes to compare in BufferA and BufferB.\r | |
388 | **/\r | |
389 | #define UT_ASSERT_MEM_EQUAL(BufferA, BufferB, Length) \\r | |
390 | if(!UnitTestAssertMemEqual ((VOID *)(UINTN)(BufferA), (VOID *)(UINTN)(BufferB), (UINTN)Length, __FUNCTION__, __LINE__, __FILE__, #BufferA, #BufferB)) { \\r | |
391 | return UNIT_TEST_ERROR_TEST_FAILED; \\r | |
392 | }\r | |
393 | \r | |
394 | /**\r | |
395 | This macro uses the framework assertion logic to check whether two simple\r | |
396 | values are non-equal. If the values are non-equal, execution continues.\r | |
397 | Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r | |
398 | \r | |
399 | @param[in] ValueA Value to be compared for inequality (64-bit comparison).\r | |
400 | @param[in] ValueB Value to be compared for inequality (64-bit comparison).\r | |
401 | **/\r | |
402 | #define UT_ASSERT_NOT_EQUAL(ValueA, ValueB) \\r | |
403 | if(!UnitTestAssertNotEqual ((UINT64)(ValueA), (UINT64)(ValueB), __FUNCTION__, __LINE__, __FILE__, #ValueA, #ValueB)) { \\r | |
404 | return UNIT_TEST_ERROR_TEST_FAILED; \\r | |
405 | }\r | |
406 | \r | |
407 | /**\r | |
408 | This macro uses the framework assertion logic to check whether an EFI_STATUS\r | |
409 | value is !EFI_ERROR(). If the status is !EFI_ERROR(), execution continues.\r | |
410 | Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r | |
411 | \r | |
412 | @param[in] Status EFI_STATUS value to check.\r | |
413 | **/\r | |
414 | #define UT_ASSERT_NOT_EFI_ERROR(Status) \\r | |
415 | if(!UnitTestAssertNotEfiError ((Status), __FUNCTION__, __LINE__, __FILE__, #Status)) { \\r | |
416 | return UNIT_TEST_ERROR_TEST_FAILED; \\r | |
417 | }\r | |
418 | \r | |
419 | /**\r | |
420 | This macro uses the framework assertion logic to check whether two EFI_STATUS\r | |
421 | values are equal. If the values are equal, execution continues.\r | |
422 | Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r | |
423 | \r | |
424 | @param[in] Status EFI_STATUS values to compare for equality.\r | |
425 | @param[in] Expected EFI_STATUS values to compare for equality.\r | |
426 | **/\r | |
427 | #define UT_ASSERT_STATUS_EQUAL(Status, Expected) \\r | |
428 | if(!UnitTestAssertStatusEqual ((Status), (Expected), __FUNCTION__, __LINE__, __FILE__, #Status)) { \\r | |
429 | return UNIT_TEST_ERROR_TEST_FAILED; \\r | |
430 | }\r | |
431 | \r | |
432 | /**\r | |
433 | This macro uses the framework assertion logic to check whether a pointer is\r | |
434 | not NULL. If the pointer is not NULL, execution continues. Otherwise, the\r | |
435 | test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r | |
436 | \r | |
437 | @param[in] Pointer Pointer to be checked against NULL.\r | |
438 | **/\r | |
439 | #define UT_ASSERT_NOT_NULL(Pointer) \\r | |
440 | if(!UnitTestAssertNotNull ((Pointer), __FUNCTION__, __LINE__, __FILE__, #Pointer)) { \\r | |
441 | return UNIT_TEST_ERROR_TEST_FAILED; \\r | |
442 | }\r | |
443 | \r | |
444 | /**\r | |
445 | If Expression is TRUE, then TRUE is returned.\r | |
446 | If Expression is FALSE, then an assert is triggered and the location of the\r | |
447 | assert provided by FunctionName, LineNumber, FileName, and Description are\r | |
448 | recorded and FALSE is returned.\r | |
449 | \r | |
450 | @param[in] Expression The BOOLEAN result of the expression evaluation.\r | |
451 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
452 | executing the assert macro.\r | |
453 | @param[in] LineNumber The source file line number of the assert macro.\r | |
454 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
455 | executing the assert macro.\r | |
456 | @param[in] Description Null-terminated ASCII string of the expression being\r | |
457 | evaluated.\r | |
458 | \r | |
459 | @retval TRUE Expression is TRUE.\r | |
460 | @retval FALSE Expression is FALSE.\r | |
461 | **/\r | |
462 | BOOLEAN\r | |
463 | EFIAPI\r | |
464 | UnitTestAssertTrue (\r | |
465 | IN BOOLEAN Expression,\r | |
466 | IN CONST CHAR8 *FunctionName,\r | |
467 | IN UINTN LineNumber,\r | |
468 | IN CONST CHAR8 *FileName,\r | |
469 | IN CONST CHAR8 *Description\r | |
470 | );\r | |
471 | \r | |
472 | /**\r | |
473 | If Expression is FALSE, then TRUE is returned.\r | |
474 | If Expression is TRUE, then an assert is triggered and the location of the\r | |
475 | assert provided by FunctionName, LineNumber, FileName, and Description are\r | |
476 | recorded and FALSE is returned.\r | |
477 | \r | |
478 | @param[in] Expression The BOOLEAN result of the expression evaluation.\r | |
479 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
480 | executing the assert macro.\r | |
481 | @param[in] LineNumber The source file line number of the assert macro.\r | |
482 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
483 | executing the assert macro.\r | |
484 | @param[in] Description Null-terminated ASCII string of the expression being\r | |
485 | evaluated.\r | |
486 | \r | |
487 | @retval TRUE Expression is FALSE.\r | |
488 | @retval FALSE Expression is TRUE.\r | |
489 | **/\r | |
490 | BOOLEAN\r | |
491 | EFIAPI\r | |
492 | UnitTestAssertFalse (\r | |
493 | IN BOOLEAN Expression,\r | |
494 | IN CONST CHAR8 *FunctionName,\r | |
495 | IN UINTN LineNumber,\r | |
496 | IN CONST CHAR8 *FileName,\r | |
497 | IN CONST CHAR8 *Description\r | |
498 | );\r | |
499 | \r | |
500 | /**\r | |
501 | If Status is not an EFI_ERROR(), then TRUE is returned.\r | |
502 | If Status is an EFI_ERROR(), then an assert is triggered and the location of\r | |
503 | the assert provided by FunctionName, LineNumber, FileName, and Description are\r | |
504 | recorded and FALSE is returned.\r | |
505 | \r | |
506 | @param[in] Status The EFI_STATUS value to evaluate.\r | |
507 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
508 | executing the assert macro.\r | |
509 | @param[in] LineNumber The source file line number of the assert macro.\r | |
510 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
511 | executing the assert macro.\r | |
512 | @param[in] Description Null-terminated ASCII string of the status\r | |
513 | expression being evaluated.\r | |
514 | \r | |
515 | @retval TRUE Status is not an EFI_ERROR().\r | |
516 | @retval FALSE Status is an EFI_ERROR().\r | |
517 | **/\r | |
518 | BOOLEAN\r | |
519 | EFIAPI\r | |
520 | UnitTestAssertNotEfiError (\r | |
521 | IN EFI_STATUS Status,\r | |
522 | IN CONST CHAR8 *FunctionName,\r | |
523 | IN UINTN LineNumber,\r | |
524 | IN CONST CHAR8 *FileName,\r | |
525 | IN CONST CHAR8 *Description\r | |
526 | );\r | |
527 | \r | |
528 | /**\r | |
529 | If ValueA is equal ValueB, then TRUE is returned.\r | |
530 | If ValueA is not equal to ValueB, then an assert is triggered and the location\r | |
531 | of the assert provided by FunctionName, LineNumber, FileName, DescriptionA,\r | |
532 | and DescriptionB are recorded and FALSE is returned.\r | |
533 | \r | |
534 | @param[in] ValueA 64-bit value.\r | |
535 | @param[in] ValueB 64-bit value.\r | |
536 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
537 | executing the assert macro.\r | |
538 | @param[in] LineNumber The source file line number of the assert macro.\r | |
539 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
540 | executing the assert macro.\r | |
541 | @param[in] DescriptionA Null-terminated ASCII string that is a description\r | |
542 | of ValueA.\r | |
543 | @param[in] DescriptionB Null-terminated ASCII string that is a description\r | |
544 | of ValueB.\r | |
545 | \r | |
546 | @retval TRUE ValueA is equal to ValueB.\r | |
547 | @retval FALSE ValueA is not equal to ValueB.\r | |
548 | **/\r | |
549 | BOOLEAN\r | |
550 | EFIAPI\r | |
551 | UnitTestAssertEqual (\r | |
552 | IN UINT64 ValueA,\r | |
553 | IN UINT64 ValueB,\r | |
554 | IN CONST CHAR8 *FunctionName,\r | |
555 | IN UINTN LineNumber,\r | |
556 | IN CONST CHAR8 *FileName,\r | |
557 | IN CONST CHAR8 *DescriptionA,\r | |
558 | IN CONST CHAR8 *DescriptionB\r | |
559 | );\r | |
560 | \r | |
561 | /**\r | |
562 | If the contents of BufferA are identical to the contents of BufferB, then TRUE\r | |
563 | is returned. If the contents of BufferA are not identical to the contents of\r | |
564 | BufferB, then an assert is triggered and the location of the assert provided\r | |
565 | by FunctionName, LineNumber, FileName, DescriptionA, and DescriptionB are\r | |
566 | recorded and FALSE is returned.\r | |
567 | \r | |
568 | @param[in] BufferA Pointer to a buffer for comparison.\r | |
569 | @param[in] BufferB Pointer to a buffer for comparison.\r | |
570 | @param[in] Length Number of bytes to compare in BufferA and BufferB.\r | |
571 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
572 | executing the assert macro.\r | |
573 | @param[in] LineNumber The source file line number of the assert macro.\r | |
574 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
575 | executing the assert macro.\r | |
576 | @param[in] DescriptionA Null-terminated ASCII string that is a description\r | |
577 | of BufferA.\r | |
578 | @param[in] DescriptionB Null-terminated ASCII string that is a description\r | |
579 | of BufferB.\r | |
580 | \r | |
581 | @retval TRUE The contents of BufferA are identical to the contents of\r | |
582 | BufferB.\r | |
583 | @retval FALSE The contents of BufferA are not identical to the contents of\r | |
584 | BufferB.\r | |
585 | **/\r | |
586 | BOOLEAN\r | |
587 | EFIAPI\r | |
588 | UnitTestAssertMemEqual (\r | |
589 | IN VOID *BufferA,\r | |
590 | IN VOID *BufferB,\r | |
591 | IN UINTN Length,\r | |
592 | IN CONST CHAR8 *FunctionName,\r | |
593 | IN UINTN LineNumber,\r | |
594 | IN CONST CHAR8 *FileName,\r | |
595 | IN CONST CHAR8 *DescriptionA,\r | |
596 | IN CONST CHAR8 *DescriptionB\r | |
597 | );\r | |
598 | \r | |
599 | /**\r | |
600 | If ValueA is not equal ValueB, then TRUE is returned.\r | |
601 | If ValueA is equal to ValueB, then an assert is triggered and the location\r | |
602 | of the assert provided by FunctionName, LineNumber, FileName, DescriptionA\r | |
603 | and DescriptionB are recorded and FALSE is returned.\r | |
604 | \r | |
605 | @param[in] ValueA 64-bit value.\r | |
606 | @param[in] ValueB 64-bit value.\r | |
607 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
608 | executing the assert macro.\r | |
609 | @param[in] LineNumber The source file line number of the assert macro.\r | |
610 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
611 | executing the assert macro.\r | |
612 | @param[in] DescriptionA Null-terminated ASCII string that is a description\r | |
613 | of ValueA.\r | |
614 | @param[in] DescriptionB Null-terminated ASCII string that is a description\r | |
615 | of ValueB.\r | |
616 | \r | |
617 | @retval TRUE ValueA is not equal to ValueB.\r | |
618 | @retval FALSE ValueA is equal to ValueB.\r | |
619 | **/\r | |
620 | BOOLEAN\r | |
621 | EFIAPI\r | |
622 | UnitTestAssertNotEqual (\r | |
623 | IN UINT64 ValueA,\r | |
624 | IN UINT64 ValueB,\r | |
625 | IN CONST CHAR8 *FunctionName,\r | |
626 | IN UINTN LineNumber,\r | |
627 | IN CONST CHAR8 *FileName,\r | |
628 | IN CONST CHAR8 *DescriptionA,\r | |
629 | IN CONST CHAR8 *DescriptionB\r | |
630 | );\r | |
631 | \r | |
632 | /**\r | |
633 | If Status is equal to Expected, then TRUE is returned.\r | |
634 | If Status is not equal to Expected, then an assert is triggered and the\r | |
635 | location of the assert provided by FunctionName, LineNumber, FileName, and\r | |
636 | Description are recorded and FALSE is returned.\r | |
637 | \r | |
638 | @param[in] Status EFI_STATUS value returned from an API under test.\r | |
639 | @param[in] Expected The expected EFI_STATUS return value from an API\r | |
640 | under test.\r | |
641 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
642 | executing the assert macro.\r | |
643 | @param[in] LineNumber The source file line number of the assert macro.\r | |
644 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
645 | executing the assert macro.\r | |
646 | @param[in] Description Null-terminated ASCII string that is a description\r | |
647 | of Status.\r | |
648 | \r | |
649 | @retval TRUE Status is equal to Expected.\r | |
650 | @retval FALSE Status is not equal to Expected.\r | |
651 | **/\r | |
652 | BOOLEAN\r | |
653 | EFIAPI\r | |
654 | UnitTestAssertStatusEqual (\r | |
655 | IN EFI_STATUS Status,\r | |
656 | IN EFI_STATUS Expected,\r | |
657 | IN CONST CHAR8 *FunctionName,\r | |
658 | IN UINTN LineNumber,\r | |
659 | IN CONST CHAR8 *FileName,\r | |
660 | IN CONST CHAR8 *Description\r | |
661 | );\r | |
662 | \r | |
663 | /**\r | |
664 | If Pointer is not equal to NULL, then TRUE is returned.\r | |
665 | If Pointer is equal to NULL, then an assert is triggered and the location of\r | |
666 | the assert provided by FunctionName, LineNumber, FileName, and PointerName\r | |
667 | are recorded and FALSE is returned.\r | |
668 | \r | |
669 | @param[in] Pointer Pointer value to be checked against NULL.\r | |
670 | @param[in] Expected The expected EFI_STATUS return value from a function\r | |
671 | under test.\r | |
672 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
673 | executing the assert macro.\r | |
674 | @param[in] LineNumber The source file line number of the assert macro.\r | |
675 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
676 | executing the assert macro.\r | |
677 | @param[in] PointerName Null-terminated ASCII string that is a description\r | |
678 | of Pointer.\r | |
679 | \r | |
680 | @retval TRUE Pointer is not equal to NULL.\r | |
681 | @retval FALSE Pointer is equal to NULL.\r | |
682 | **/\r | |
683 | BOOLEAN\r | |
684 | EFIAPI\r | |
685 | UnitTestAssertNotNull (\r | |
686 | IN VOID *Pointer,\r | |
687 | IN CONST CHAR8 *FunctionName,\r | |
688 | IN UINTN LineNumber,\r | |
689 | IN CONST CHAR8 *FileName,\r | |
690 | IN CONST CHAR8 *PointerName\r | |
691 | );\r | |
692 | \r | |
693 | /**\r | |
694 | Test logging macro that records an ERROR message in the test framework log.\r | |
695 | Record is associated with the currently executing test case.\r | |
696 | \r | |
697 | @param[in] Format Formatting string following the format defined in\r | |
698 | MdePkg/Include/Library/PrintLib.h.\r | |
699 | @param[in] ... Print args.\r | |
700 | **/\r | |
701 | #define UT_LOG_ERROR(Format, ...) \\r | |
702 | UnitTestLog (UNIT_TEST_LOG_LEVEL_ERROR, Format, ##__VA_ARGS__)\r | |
703 | \r | |
704 | /**\r | |
705 | Test logging macro that records a WARNING message in the test framework log.\r | |
706 | Record is associated with the currently executing test case.\r | |
707 | \r | |
708 | @param[in] Format Formatting string following the format defined in\r | |
709 | MdePkg/Include/Library/PrintLib.h.\r | |
710 | @param[in] ... Print args.\r | |
711 | **/\r | |
712 | #define UT_LOG_WARNING(Format, ...) \\r | |
713 | UnitTestLog (UNIT_TEST_LOG_LEVEL_WARN, Format, ##__VA_ARGS__)\r | |
714 | \r | |
715 | /**\r | |
716 | Test logging macro that records an INFO message in the test framework log.\r | |
717 | Record is associated with the currently executing test case.\r | |
718 | \r | |
719 | @param[in] Format Formatting string following the format defined in\r | |
720 | MdePkg/Include/Library/PrintLib.h.\r | |
721 | @param[in] ... Print args.\r | |
722 | **/\r | |
723 | #define UT_LOG_INFO(Format, ...) \\r | |
724 | UnitTestLog (UNIT_TEST_LOG_LEVEL_INFO, Format, ##__VA_ARGS__)\r | |
725 | \r | |
726 | /**\r | |
727 | Test logging macro that records a VERBOSE message in the test framework log.\r | |
728 | Record is associated with the currently executing test case.\r | |
729 | \r | |
730 | @param[in] Format Formatting string following the format defined in\r | |
731 | MdePkg/Include/Library/PrintLib.h.\r | |
732 | @param[in] ... Print args.\r | |
733 | **/\r | |
734 | #define UT_LOG_VERBOSE(Format, ...) \\r | |
735 | UnitTestLog (UNIT_TEST_LOG_LEVEL_VERBOSE, Format, ##__VA_ARGS__)\r | |
736 | \r | |
737 | /**\r | |
738 | Test logging function that records a messages in the test framework log.\r | |
739 | Record is associated with the currently executing test case.\r | |
740 | \r | |
741 | @param[in] ErrorLevel The error level of the unit test log message.\r | |
742 | @param[in] Format Formatting string following the format defined in the\r | |
743 | MdePkg/Include/Library/PrintLib.h.\r | |
744 | @param[in] ... Print args.\r | |
745 | **/\r | |
746 | VOID\r | |
747 | EFIAPI\r | |
748 | UnitTestLog (\r | |
749 | IN UINTN ErrorLevel,\r | |
750 | IN CONST CHAR8 *Format,\r | |
751 | ...\r | |
752 | );\r | |
753 | \r | |
754 | #endif\r |