]> git.proxmox.com Git - mirror_edk2.git/blame - MdePkg/Include/Library/UnitTestLib.h
MdePkg: introduce MM communicate 2 protocol
[mirror_edk2.git] / MdePkg / Include / Library / UnitTestLib.h
CommitLineData
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
16typedef 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
36struct UNIT_TEST_FRAMEWORK_OBJECT;\r
37typedef struct UNIT_TEST_FRAMEWORK_OBJECT *UNIT_TEST_FRAMEWORK_HANDLE;\r
38\r
39///\r
40/// Unit Test Suite Handle\r
41///\r
42struct UNIT_TEST_SUITE_OBJECT;\r
43typedef struct UNIT_TEST_SUITE_OBJECT *UNIT_TEST_SUITE_HANDLE;\r
44\r
45///\r
46/// Unit Test Handle\r
47///\r
48struct UNIT_TEST_OBJECT;\r
49typedef struct UNIT_TEST_OBJECT *UNIT_TEST_HANDLE;\r
50\r
51///\r
52/// Unit Test Context\r
53///\r
54typedef 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
75typedef\r
76UNIT_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
101typedef\r
102UNIT_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
128typedef\r
129VOID\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
142typedef\r
143VOID\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
156typedef\r
157VOID\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
186EFI_STATUS\r
187EFIAPI\r
188InitUnitTestFramework (\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
221EFI_STATUS\r
222EFIAPI\r
223CreateUnitTestSuite (\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
256EFI_STATUS\r
257EFIAPI\r
258AddTestCase (\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
282EFI_STATUS\r
283EFIAPI\r
284RunAllTestSuites (\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
302EFI_STATUS\r
303EFIAPI\r
304FreeUnitTestFramework (\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
316 Generally called from within a test case prior to quitting or rebooting.\r
317\r
318 @param[in] FrameworkHandle A handle to the current running framework that\r
319 dispatched the test. Necessary for recording\r
320 certain test events with the framework.\r
321 @param[in] ContextToSave A buffer of test case-specific data to be saved\r
322 along with framework state. Will be passed as\r
323 "Context" to the test case upon resume. This\r
324 is an optional parameter that may be NULL.\r
325 @param[in] ContextToSaveSize Size of the ContextToSave buffer.\r
326\r
327 @retval EFI_SUCCESS The framework state and context were saved.\r
328 @retval EFI_INVALID_PARAMETER FrameworkHandle is NULL.\r
329 @retval EFI_INVALID_PARAMETER ContextToSave is not NULL and\r
330 ContextToSaveSize is 0.\r
331 @retval EFI_INVALID_PARAMETER ContextToSave is >= 4GB.\r
332 @retval EFI_OUT_OF_RESOURCES There are not enough resources available to\r
333 save the framework and context state.\r
334 @retval EFI_DEVICE_ERROR The framework and context state could not be\r
335 saved to a persistent storage device due to a\r
336 device error.\r
337**/\r
338EFI_STATUS\r
339EFIAPI\r
340SaveFrameworkState (\r
341 IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle,\r
342 IN UNIT_TEST_CONTEXT ContextToSave OPTIONAL,\r
343 IN UINTN ContextToSaveSize\r
344 );\r
345\r
346/**\r
347 This macro uses the framework assertion logic to check an expression for\r
348 "TRUE". If the expression evaluates to TRUE, execution continues.\r
349 Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r
350\r
351 @param[in] Expression Expression to be evaluated for TRUE.\r
352**/\r
353#define UT_ASSERT_TRUE(Expression) \\r
354 if(!UnitTestAssertTrue ((Expression), __FUNCTION__, __LINE__, __FILE__, #Expression)) { \\r
355 return UNIT_TEST_ERROR_TEST_FAILED; \\r
356 }\r
357\r
358/**\r
359 This macro uses the framework assertion logic to check an expression for\r
360 "FALSE". If the expression evaluates to FALSE, execution continues.\r
361 Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r
362\r
363 @param[in] Expression Expression to be evaluated for FALSE.\r
364**/\r
365#define UT_ASSERT_FALSE(Expression) \\r
366 if(!UnitTestAssertFalse ((Expression), __FUNCTION__, __LINE__, __FILE__, #Expression)) { \\r
367 return UNIT_TEST_ERROR_TEST_FAILED; \\r
368 }\r
369\r
370/**\r
371 This macro uses the framework assertion logic to check whether two simple\r
372 values are equal. If the values are equal, execution continues.\r
373 Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r
374\r
375 @param[in] ValueA Value to be compared for equality (64-bit comparison).\r
376 @param[in] ValueB Value to be compared for equality (64-bit comparison).\r
377**/\r
378#define UT_ASSERT_EQUAL(ValueA, ValueB) \\r
379 if(!UnitTestAssertEqual ((UINT64)(ValueA), (UINT64)(ValueB), __FUNCTION__, __LINE__, __FILE__, #ValueA, #ValueB)) { \\r
380 return UNIT_TEST_ERROR_TEST_FAILED; \\r
381 }\r
382\r
383/**\r
384 This macro uses the framework assertion logic to check whether two memory\r
385 buffers are equal. If the buffers are equal, execution continues.\r
386 Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r
387\r
388 @param[in] BufferA Pointer to a buffer for comparison.\r
389 @param[in] BufferB Pointer to a buffer for comparison.\r
390 @param[in] Length Number of bytes to compare in BufferA and BufferB.\r
391**/\r
392#define UT_ASSERT_MEM_EQUAL(BufferA, BufferB, Length) \\r
393 if(!UnitTestAssertMemEqual ((VOID *)(UINTN)(BufferA), (VOID *)(UINTN)(BufferB), (UINTN)Length, __FUNCTION__, __LINE__, __FILE__, #BufferA, #BufferB)) { \\r
394 return UNIT_TEST_ERROR_TEST_FAILED; \\r
395 }\r
396\r
397/**\r
398 This macro uses the framework assertion logic to check whether two simple\r
399 values are non-equal. If the values are non-equal, execution continues.\r
400 Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r
401\r
402 @param[in] ValueA Value to be compared for inequality (64-bit comparison).\r
403 @param[in] ValueB Value to be compared for inequality (64-bit comparison).\r
404**/\r
405#define UT_ASSERT_NOT_EQUAL(ValueA, ValueB) \\r
406 if(!UnitTestAssertNotEqual ((UINT64)(ValueA), (UINT64)(ValueB), __FUNCTION__, __LINE__, __FILE__, #ValueA, #ValueB)) { \\r
407 return UNIT_TEST_ERROR_TEST_FAILED; \\r
408 }\r
409\r
410/**\r
411 This macro uses the framework assertion logic to check whether an EFI_STATUS\r
412 value is !EFI_ERROR(). If the status is !EFI_ERROR(), execution continues.\r
413 Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r
414\r
415 @param[in] Status EFI_STATUS value to check.\r
416**/\r
417#define UT_ASSERT_NOT_EFI_ERROR(Status) \\r
418 if(!UnitTestAssertNotEfiError ((Status), __FUNCTION__, __LINE__, __FILE__, #Status)) { \\r
419 return UNIT_TEST_ERROR_TEST_FAILED; \\r
420 }\r
421\r
422/**\r
423 This macro uses the framework assertion logic to check whether two EFI_STATUS\r
424 values are equal. If the values are equal, execution continues.\r
425 Otherwise, the test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r
426\r
427 @param[in] Status EFI_STATUS values to compare for equality.\r
428 @param[in] Expected EFI_STATUS values to compare for equality.\r
429**/\r
430#define UT_ASSERT_STATUS_EQUAL(Status, Expected) \\r
431 if(!UnitTestAssertStatusEqual ((Status), (Expected), __FUNCTION__, __LINE__, __FILE__, #Status)) { \\r
432 return UNIT_TEST_ERROR_TEST_FAILED; \\r
433 }\r
434\r
435/**\r
436 This macro uses the framework assertion logic to check whether a pointer is\r
437 not NULL. If the pointer is not NULL, execution continues. Otherwise, the\r
438 test case immediately returns UNIT_TEST_ERROR_TEST_FAILED.\r
439\r
440 @param[in] Pointer Pointer to be checked against NULL.\r
441**/\r
442#define UT_ASSERT_NOT_NULL(Pointer) \\r
443 if(!UnitTestAssertNotNull ((Pointer), __FUNCTION__, __LINE__, __FILE__, #Pointer)) { \\r
444 return UNIT_TEST_ERROR_TEST_FAILED; \\r
445 }\r
446\r
447/**\r
448 If Expression is TRUE, then TRUE is returned.\r
449 If Expression is FALSE, then an assert is triggered and the location of the\r
450 assert provided by FunctionName, LineNumber, FileName, and Description are\r
451 recorded and FALSE is returned.\r
452\r
453 @param[in] Expression The BOOLEAN result of the expression evaluation.\r
454 @param[in] FunctionName Null-terminated ASCII string of the function\r
455 executing the assert macro.\r
456 @param[in] LineNumber The source file line number of the assert macro.\r
457 @param[in] FileName Null-terminated ASCII string of the filename\r
458 executing the assert macro.\r
459 @param[in] Description Null-terminated ASCII string of the expression being\r
460 evaluated.\r
461\r
462 @retval TRUE Expression is TRUE.\r
463 @retval FALSE Expression is FALSE.\r
464**/\r
465BOOLEAN\r
466EFIAPI\r
467UnitTestAssertTrue (\r
468 IN BOOLEAN Expression,\r
469 IN CONST CHAR8 *FunctionName,\r
470 IN UINTN LineNumber,\r
471 IN CONST CHAR8 *FileName,\r
472 IN CONST CHAR8 *Description\r
473 );\r
474\r
475/**\r
476 If Expression is FALSE, then TRUE is returned.\r
477 If Expression is TRUE, then an assert is triggered and the location of the\r
478 assert provided by FunctionName, LineNumber, FileName, and Description are\r
479 recorded and FALSE is returned.\r
480\r
481 @param[in] Expression The BOOLEAN result of the expression evaluation.\r
482 @param[in] FunctionName Null-terminated ASCII string of the function\r
483 executing the assert macro.\r
484 @param[in] LineNumber The source file line number of the assert macro.\r
485 @param[in] FileName Null-terminated ASCII string of the filename\r
486 executing the assert macro.\r
487 @param[in] Description Null-terminated ASCII string of the expression being\r
488 evaluated.\r
489\r
490 @retval TRUE Expression is FALSE.\r
491 @retval FALSE Expression is TRUE.\r
492**/\r
493BOOLEAN\r
494EFIAPI\r
495UnitTestAssertFalse (\r
496 IN BOOLEAN Expression,\r
497 IN CONST CHAR8 *FunctionName,\r
498 IN UINTN LineNumber,\r
499 IN CONST CHAR8 *FileName,\r
500 IN CONST CHAR8 *Description\r
501 );\r
502\r
503/**\r
504 If Status is not an EFI_ERROR(), then TRUE is returned.\r
505 If Status is an EFI_ERROR(), then an assert is triggered and the location of\r
506 the assert provided by FunctionName, LineNumber, FileName, and Description are\r
507 recorded and FALSE is returned.\r
508\r
509 @param[in] Status The EFI_STATUS value to evaluate.\r
510 @param[in] FunctionName Null-terminated ASCII string of the function\r
511 executing the assert macro.\r
512 @param[in] LineNumber The source file line number of the assert macro.\r
513 @param[in] FileName Null-terminated ASCII string of the filename\r
514 executing the assert macro.\r
515 @param[in] Description Null-terminated ASCII string of the status\r
516 expression being evaluated.\r
517\r
518 @retval TRUE Status is not an EFI_ERROR().\r
519 @retval FALSE Status is an EFI_ERROR().\r
520**/\r
521BOOLEAN\r
522EFIAPI\r
523UnitTestAssertNotEfiError (\r
524 IN EFI_STATUS Status,\r
525 IN CONST CHAR8 *FunctionName,\r
526 IN UINTN LineNumber,\r
527 IN CONST CHAR8 *FileName,\r
528 IN CONST CHAR8 *Description\r
529 );\r
530\r
531/**\r
532 If ValueA is equal ValueB, then TRUE is returned.\r
533 If ValueA is not equal to ValueB, then an assert is triggered and the location\r
534 of the assert provided by FunctionName, LineNumber, FileName, DescriptionA,\r
535 and DescriptionB are recorded and FALSE is returned.\r
536\r
537 @param[in] ValueA 64-bit value.\r
538 @param[in] ValueB 64-bit value.\r
539 @param[in] FunctionName Null-terminated ASCII string of the function\r
540 executing the assert macro.\r
541 @param[in] LineNumber The source file line number of the assert macro.\r
542 @param[in] FileName Null-terminated ASCII string of the filename\r
543 executing the assert macro.\r
544 @param[in] DescriptionA Null-terminated ASCII string that is a description\r
545 of ValueA.\r
546 @param[in] DescriptionB Null-terminated ASCII string that is a description\r
547 of ValueB.\r
548\r
549 @retval TRUE ValueA is equal to ValueB.\r
550 @retval FALSE ValueA is not equal to ValueB.\r
551**/\r
552BOOLEAN\r
553EFIAPI\r
554UnitTestAssertEqual (\r
555 IN UINT64 ValueA,\r
556 IN UINT64 ValueB,\r
557 IN CONST CHAR8 *FunctionName,\r
558 IN UINTN LineNumber,\r
559 IN CONST CHAR8 *FileName,\r
560 IN CONST CHAR8 *DescriptionA,\r
561 IN CONST CHAR8 *DescriptionB\r
562 );\r
563\r
564/**\r
565 If the contents of BufferA are identical to the contents of BufferB, then TRUE\r
566 is returned. If the contents of BufferA are not identical to the contents of\r
567 BufferB, then an assert is triggered and the location of the assert provided\r
568 by FunctionName, LineNumber, FileName, DescriptionA, and DescriptionB are\r
569 recorded and FALSE is returned.\r
570\r
571 @param[in] BufferA Pointer to a buffer for comparison.\r
572 @param[in] BufferB Pointer to a buffer for comparison.\r
573 @param[in] Length Number of bytes to compare in BufferA and BufferB.\r
574 @param[in] FunctionName Null-terminated ASCII string of the function\r
575 executing the assert macro.\r
576 @param[in] LineNumber The source file line number of the assert macro.\r
577 @param[in] FileName Null-terminated ASCII string of the filename\r
578 executing the assert macro.\r
579 @param[in] DescriptionA Null-terminated ASCII string that is a description\r
580 of BufferA.\r
581 @param[in] DescriptionB Null-terminated ASCII string that is a description\r
582 of BufferB.\r
583\r
584 @retval TRUE The contents of BufferA are identical to the contents of\r
585 BufferB.\r
586 @retval FALSE The contents of BufferA are not identical to the contents of\r
587 BufferB.\r
588**/\r
589BOOLEAN\r
590EFIAPI\r
591UnitTestAssertMemEqual (\r
592 IN VOID *BufferA,\r
593 IN VOID *BufferB,\r
594 IN UINTN Length,\r
595 IN CONST CHAR8 *FunctionName,\r
596 IN UINTN LineNumber,\r
597 IN CONST CHAR8 *FileName,\r
598 IN CONST CHAR8 *DescriptionA,\r
599 IN CONST CHAR8 *DescriptionB\r
600 );\r
601\r
602/**\r
603 If ValueA is not equal ValueB, then TRUE is returned.\r
604 If ValueA is equal to ValueB, then an assert is triggered and the location\r
605 of the assert provided by FunctionName, LineNumber, FileName, DescriptionA\r
606 and DescriptionB are recorded and FALSE is returned.\r
607\r
608 @param[in] ValueA 64-bit value.\r
609 @param[in] ValueB 64-bit value.\r
610 @param[in] FunctionName Null-terminated ASCII string of the function\r
611 executing the assert macro.\r
612 @param[in] LineNumber The source file line number of the assert macro.\r
613 @param[in] FileName Null-terminated ASCII string of the filename\r
614 executing the assert macro.\r
615 @param[in] DescriptionA Null-terminated ASCII string that is a description\r
616 of ValueA.\r
617 @param[in] DescriptionB Null-terminated ASCII string that is a description\r
618 of ValueB.\r
619\r
620 @retval TRUE ValueA is not equal to ValueB.\r
621 @retval FALSE ValueA is equal to ValueB.\r
622**/\r
623BOOLEAN\r
624EFIAPI\r
625UnitTestAssertNotEqual (\r
626 IN UINT64 ValueA,\r
627 IN UINT64 ValueB,\r
628 IN CONST CHAR8 *FunctionName,\r
629 IN UINTN LineNumber,\r
630 IN CONST CHAR8 *FileName,\r
631 IN CONST CHAR8 *DescriptionA,\r
632 IN CONST CHAR8 *DescriptionB\r
633 );\r
634\r
635/**\r
636 If Status is equal to Expected, then TRUE is returned.\r
637 If Status is not equal to Expected, then an assert is triggered and the\r
638 location of the assert provided by FunctionName, LineNumber, FileName, and\r
639 Description are recorded and FALSE is returned.\r
640\r
641 @param[in] Status EFI_STATUS value returned from an API under test.\r
642 @param[in] Expected The expected EFI_STATUS return value from an API\r
643 under test.\r
644 @param[in] FunctionName Null-terminated ASCII string of the function\r
645 executing the assert macro.\r
646 @param[in] LineNumber The source file line number of the assert macro.\r
647 @param[in] FileName Null-terminated ASCII string of the filename\r
648 executing the assert macro.\r
649 @param[in] Description Null-terminated ASCII string that is a description\r
650 of Status.\r
651\r
652 @retval TRUE Status is equal to Expected.\r
653 @retval FALSE Status is not equal to Expected.\r
654**/\r
655BOOLEAN\r
656EFIAPI\r
657UnitTestAssertStatusEqual (\r
658 IN EFI_STATUS Status,\r
659 IN EFI_STATUS Expected,\r
660 IN CONST CHAR8 *FunctionName,\r
661 IN UINTN LineNumber,\r
662 IN CONST CHAR8 *FileName,\r
663 IN CONST CHAR8 *Description\r
664 );\r
665\r
666/**\r
667 If Pointer is not equal to NULL, then TRUE is returned.\r
668 If Pointer is equal to NULL, then an assert is triggered and the location of\r
669 the assert provided by FunctionName, LineNumber, FileName, and PointerName\r
670 are recorded and FALSE is returned.\r
671\r
672 @param[in] Pointer Pointer value to be checked against NULL.\r
673 @param[in] Expected The expected EFI_STATUS return value from a function\r
674 under test.\r
675 @param[in] FunctionName Null-terminated ASCII string of the function\r
676 executing the assert macro.\r
677 @param[in] LineNumber The source file line number of the assert macro.\r
678 @param[in] FileName Null-terminated ASCII string of the filename\r
679 executing the assert macro.\r
680 @param[in] PointerName Null-terminated ASCII string that is a description\r
681 of Pointer.\r
682\r
683 @retval TRUE Pointer is not equal to NULL.\r
684 @retval FALSE Pointer is equal to NULL.\r
685**/\r
686BOOLEAN\r
687EFIAPI\r
688UnitTestAssertNotNull (\r
689 IN VOID *Pointer,\r
690 IN CONST CHAR8 *FunctionName,\r
691 IN UINTN LineNumber,\r
692 IN CONST CHAR8 *FileName,\r
693 IN CONST CHAR8 *PointerName\r
694 );\r
695\r
696/**\r
697 Test logging macro that records an ERROR message in the test framework log.\r
698 Record is associated with the currently executing test case.\r
699\r
700 @param[in] Format Formatting string following the format defined in\r
701 MdePkg/Include/Library/PrintLib.h.\r
702 @param[in] ... Print args.\r
703**/\r
704#define UT_LOG_ERROR(Format, ...) \\r
705 UnitTestLog (UNIT_TEST_LOG_LEVEL_ERROR, Format, ##__VA_ARGS__)\r
706\r
707/**\r
708 Test logging macro that records a WARNING message in the test framework log.\r
709 Record is associated with the currently executing test case.\r
710\r
711 @param[in] Format Formatting string following the format defined in\r
712 MdePkg/Include/Library/PrintLib.h.\r
713 @param[in] ... Print args.\r
714**/\r
715#define UT_LOG_WARNING(Format, ...) \\r
716 UnitTestLog (UNIT_TEST_LOG_LEVEL_WARN, Format, ##__VA_ARGS__)\r
717\r
718/**\r
719 Test logging macro that records an INFO message in the test framework log.\r
720 Record is associated with the currently executing test case.\r
721\r
722 @param[in] Format Formatting string following the format defined in\r
723 MdePkg/Include/Library/PrintLib.h.\r
724 @param[in] ... Print args.\r
725**/\r
726#define UT_LOG_INFO(Format, ...) \\r
727 UnitTestLog (UNIT_TEST_LOG_LEVEL_INFO, Format, ##__VA_ARGS__)\r
728\r
729/**\r
730 Test logging macro that records a VERBOSE message in the test framework log.\r
731 Record is associated with the currently executing test case.\r
732\r
733 @param[in] Format Formatting string following the format defined in\r
734 MdePkg/Include/Library/PrintLib.h.\r
735 @param[in] ... Print args.\r
736**/\r
737#define UT_LOG_VERBOSE(Format, ...) \\r
738 UnitTestLog (UNIT_TEST_LOG_LEVEL_VERBOSE, Format, ##__VA_ARGS__)\r
739\r
740/**\r
741 Test logging function that records a messages in the test framework log.\r
742 Record is associated with the currently executing test case.\r
743\r
744 @param[in] ErrorLevel The error level of the unit test log message.\r
745 @param[in] Format Formatting string following the format defined in the\r
746 MdePkg/Include/Library/PrintLib.h.\r
747 @param[in] ... Print args.\r
748**/\r
749VOID\r
750EFIAPI\r
751UnitTestLog (\r
752 IN UINTN ErrorLevel,\r
753 IN CONST CHAR8 *Format,\r
754 ...\r
755 );\r
756\r
757#endif\r