]>
Commit | Line | Data |
---|---|---|
0eb52298 MK |
1 | /**\r |
2 | Implement UnitTestLib assert services\r | |
3 | \r | |
4 | Copyright (c) Microsoft Corporation.<BR>\r | |
5 | SPDX-License-Identifier: BSD-2-Clause-Patent\r | |
6 | **/\r | |
7 | \r | |
8 | #include <Uefi.h>\r | |
9 | #include <UnitTestFrameworkTypes.h>\r | |
10 | #include <Library/UnitTestLib.h>\r | |
11 | #include <Library/BaseLib.h>\r | |
12 | #include <Library/BaseMemoryLib.h>\r | |
13 | #include <Library/DebugLib.h>\r | |
14 | #include <Library/PrintLib.h>\r | |
15 | \r | |
26824851 MK |
16 | extern BASE_LIBRARY_JUMP_BUFFER gUnitTestJumpBuffer;\r |
17 | \r | |
0eb52298 MK |
18 | STATIC\r |
19 | EFI_STATUS\r | |
20 | AddUnitTestFailure (\r | |
21 | IN OUT UNIT_TEST *UnitTest,\r | |
22 | IN CONST CHAR8 *FailureMessage,\r | |
23 | IN FAILURE_TYPE FailureType\r | |
24 | )\r | |
25 | {\r | |
26 | //\r | |
27 | // Make sure that you're cooking with gas.\r | |
28 | //\r | |
7c0ad2c3 | 29 | if ((UnitTest == NULL) || (FailureMessage == NULL)) {\r |
0eb52298 MK |
30 | return EFI_INVALID_PARAMETER;\r |
31 | }\r | |
32 | \r | |
33 | UnitTest->FailureType = FailureType;\r | |
34 | AsciiStrCpyS (\r | |
35 | &UnitTest->FailureMessage[0],\r | |
36 | UNIT_TEST_TESTFAILUREMSG_LENGTH,\r | |
37 | FailureMessage\r | |
38 | );\r | |
39 | \r | |
40 | return EFI_SUCCESS;\r | |
41 | }\r | |
42 | \r | |
43 | STATIC\r | |
44 | VOID\r | |
f297b7f2 | 45 | EFIAPI\r |
0eb52298 MK |
46 | UnitTestLogFailure (\r |
47 | IN FAILURE_TYPE FailureType,\r | |
48 | IN CONST CHAR8 *Format,\r | |
49 | ...\r | |
50 | )\r | |
51 | {\r | |
52 | UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle;\r | |
53 | CHAR8 LogString[UNIT_TEST_TESTFAILUREMSG_LENGTH];\r | |
54 | VA_LIST Marker;\r | |
55 | \r | |
56 | //\r | |
57 | // Get active Framework handle\r | |
58 | //\r | |
59 | FrameworkHandle = GetActiveFrameworkHandle ();\r | |
60 | \r | |
61 | //\r | |
62 | // Convert the message to an ASCII String\r | |
63 | //\r | |
64 | VA_START (Marker, Format);\r | |
65 | AsciiVSPrint (LogString, sizeof (LogString), Format, Marker);\r | |
66 | VA_END (Marker);\r | |
67 | \r | |
68 | //\r | |
69 | // Finally, add the string to the log.\r | |
70 | //\r | |
71 | AddUnitTestFailure (\r | |
72 | ((UNIT_TEST_FRAMEWORK *)FrameworkHandle)->CurrentTest,\r | |
73 | LogString,\r | |
74 | FailureType\r | |
75 | );\r | |
76 | \r | |
26824851 | 77 | LongJump (&gUnitTestJumpBuffer, 1);\r |
0eb52298 MK |
78 | }\r |
79 | \r | |
80 | /**\r | |
81 | If Expression is TRUE, then TRUE is returned.\r | |
82 | If Expression is FALSE, then an assert is triggered and the location of the\r | |
83 | assert provided by FunctionName, LineNumber, FileName, and Description are\r | |
84 | recorded and FALSE is returned.\r | |
85 | \r | |
86 | @param[in] Expression The BOOLEAN result of the expression evaluation.\r | |
87 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
88 | executing the assert macro.\r | |
89 | @param[in] LineNumber The source file line number of the assert macro.\r | |
90 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
91 | executing the assert macro.\r | |
92 | @param[in] Description Null-terminated ASCII string of the expression being\r | |
93 | evaluated.\r | |
94 | \r | |
95 | @retval TRUE Expression is TRUE.\r | |
96 | @retval FALSE Expression is FALSE.\r | |
97 | **/\r | |
98 | BOOLEAN\r | |
99 | EFIAPI\r | |
100 | UnitTestAssertTrue (\r | |
101 | IN BOOLEAN Expression,\r | |
102 | IN CONST CHAR8 *FunctionName,\r | |
103 | IN UINTN LineNumber,\r | |
104 | IN CONST CHAR8 *FileName,\r | |
105 | IN CONST CHAR8 *Description\r | |
106 | )\r | |
107 | {\r | |
108 | if (!Expression) {\r | |
26824851 MK |
109 | UT_LOG_ERROR (\r |
110 | "[ASSERT FAIL] %a:%d: Expression (%a) is not TRUE!\n",\r | |
425df692 | 111 | FileName,\r |
0eb52298 MK |
112 | LineNumber,\r |
113 | Description\r | |
114 | );\r | |
26824851 MK |
115 | UnitTestLogFailure (\r |
116 | FAILURETYPE_ASSERTTRUE,\r | |
117 | "%a:%d: Expression (%a) is not TRUE!\n",\r | |
425df692 | 118 | FileName,\r |
0eb52298 MK |
119 | LineNumber,\r |
120 | Description\r | |
121 | );\r | |
122 | }\r | |
7c0ad2c3 | 123 | \r |
0eb52298 MK |
124 | return Expression;\r |
125 | }\r | |
126 | \r | |
127 | /**\r | |
128 | If Expression is FALSE, then TRUE is returned.\r | |
129 | If Expression is TRUE, then an assert is triggered and the location of the\r | |
130 | assert provided by FunctionName, LineNumber, FileName, and Description are\r | |
131 | recorded and FALSE is returned.\r | |
132 | \r | |
133 | @param[in] Expression The BOOLEAN result of the expression evaluation.\r | |
134 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
135 | executing the assert macro.\r | |
136 | @param[in] LineNumber The source file line number of the assert macro.\r | |
137 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
138 | executing the assert macro.\r | |
139 | @param[in] Description Null-terminated ASCII string of the expression being\r | |
140 | evaluated.\r | |
141 | \r | |
142 | @retval TRUE Expression is FALSE.\r | |
143 | @retval FALSE Expression is TRUE.\r | |
144 | **/\r | |
145 | BOOLEAN\r | |
146 | EFIAPI\r | |
147 | UnitTestAssertFalse (\r | |
148 | IN BOOLEAN Expression,\r | |
149 | IN CONST CHAR8 *FunctionName,\r | |
150 | IN UINTN LineNumber,\r | |
151 | IN CONST CHAR8 *FileName,\r | |
152 | IN CONST CHAR8 *Description\r | |
153 | )\r | |
154 | {\r | |
155 | if (Expression) {\r | |
26824851 MK |
156 | UT_LOG_ERROR (\r |
157 | "[ASSERT FAIL] %a:%d: Expression (%a) is not FALSE!\n",\r | |
425df692 | 158 | FileName,\r |
0eb52298 MK |
159 | LineNumber,\r |
160 | Description\r | |
161 | );\r | |
26824851 MK |
162 | UnitTestLogFailure (\r |
163 | FAILURETYPE_ASSERTFALSE,\r | |
164 | "%a:%d: Expression(%a) is not FALSE!\n",\r | |
425df692 | 165 | FileName,\r |
0eb52298 MK |
166 | LineNumber,\r |
167 | Description\r | |
168 | );\r | |
169 | }\r | |
7c0ad2c3 | 170 | \r |
0eb52298 MK |
171 | return !Expression;\r |
172 | }\r | |
173 | \r | |
174 | /**\r | |
175 | If Status is not an EFI_ERROR(), then TRUE is returned.\r | |
176 | If Status is an EFI_ERROR(), then an assert is triggered and the location of\r | |
177 | the assert provided by FunctionName, LineNumber, FileName, and Description are\r | |
178 | recorded and FALSE is returned.\r | |
179 | \r | |
180 | @param[in] Status The EFI_STATUS value to evaluate.\r | |
181 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
182 | executing the assert macro.\r | |
183 | @param[in] LineNumber The source file line number of the assert macro.\r | |
184 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
185 | executing the assert macro.\r | |
186 | @param[in] Description Null-terminated ASCII string of the status\r | |
187 | expression being evaluated.\r | |
188 | \r | |
189 | @retval TRUE Status is not an EFI_ERROR().\r | |
190 | @retval FALSE Status is an EFI_ERROR().\r | |
191 | **/\r | |
192 | BOOLEAN\r | |
193 | EFIAPI\r | |
194 | UnitTestAssertNotEfiError (\r | |
195 | IN EFI_STATUS Status,\r | |
196 | IN CONST CHAR8 *FunctionName,\r | |
197 | IN UINTN LineNumber,\r | |
198 | IN CONST CHAR8 *FileName,\r | |
199 | IN CONST CHAR8 *Description\r | |
200 | )\r | |
201 | {\r | |
202 | if (EFI_ERROR (Status)) {\r | |
26824851 MK |
203 | UT_LOG_ERROR (\r |
204 | "[ASSERT FAIL] %a:%d: Status '%a' is EFI_ERROR (%r)!\n",\r | |
425df692 | 205 | FileName,\r |
0eb52298 MK |
206 | LineNumber,\r |
207 | Description,\r | |
208 | Status\r | |
209 | );\r | |
26824851 MK |
210 | UnitTestLogFailure (\r |
211 | FAILURETYPE_ASSERTNOTEFIERROR,\r | |
212 | "%a:%d: Status '%a' is EFI_ERROR (%r)!\n",\r | |
425df692 | 213 | FileName,\r |
0eb52298 MK |
214 | LineNumber,\r |
215 | Description,\r | |
216 | Status\r | |
217 | );\r | |
218 | }\r | |
7c0ad2c3 MK |
219 | \r |
220 | return !EFI_ERROR (Status);\r | |
0eb52298 MK |
221 | }\r |
222 | \r | |
223 | /**\r | |
224 | If ValueA is equal ValueB, then TRUE is returned.\r | |
225 | If ValueA is not equal to ValueB, then an assert is triggered and the location\r | |
226 | of the assert provided by FunctionName, LineNumber, FileName, DescriptionA,\r | |
227 | and DescriptionB are recorded and FALSE is returned.\r | |
228 | \r | |
229 | @param[in] ValueA 64-bit value.\r | |
230 | @param[in] ValueB 64-bit value.\r | |
231 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
232 | executing the assert macro.\r | |
233 | @param[in] LineNumber The source file line number of the assert macro.\r | |
234 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
235 | executing the assert macro.\r | |
236 | @param[in] DescriptionA Null-terminated ASCII string that is a description\r | |
237 | of ValueA.\r | |
238 | @param[in] DescriptionB Null-terminated ASCII string that is a description\r | |
239 | of ValueB.\r | |
240 | \r | |
241 | @retval TRUE ValueA is equal to ValueB.\r | |
242 | @retval FALSE ValueA is not equal to ValueB.\r | |
243 | **/\r | |
244 | BOOLEAN\r | |
245 | EFIAPI\r | |
246 | UnitTestAssertEqual (\r | |
247 | IN UINT64 ValueA,\r | |
248 | IN UINT64 ValueB,\r | |
249 | IN CONST CHAR8 *FunctionName,\r | |
250 | IN UINTN LineNumber,\r | |
251 | IN CONST CHAR8 *FileName,\r | |
252 | IN CONST CHAR8 *DescriptionA,\r | |
253 | IN CONST CHAR8 *DescriptionB\r | |
254 | )\r | |
255 | {\r | |
f76d5016 | 256 | if (ValueA != ValueB) {\r |
26824851 MK |
257 | UT_LOG_ERROR (\r |
258 | "[ASSERT FAIL] %a:%d: Value %a != %a (%d != %d)!\n",\r | |
425df692 | 259 | FileName,\r |
0eb52298 MK |
260 | LineNumber,\r |
261 | DescriptionA,\r | |
262 | DescriptionB,\r | |
263 | ValueA,\r | |
264 | ValueB\r | |
265 | );\r | |
26824851 MK |
266 | UnitTestLogFailure (\r |
267 | FAILURETYPE_ASSERTEQUAL,\r | |
268 | "%a:%d: Value %a != %a (%d != %d)!\n",\r | |
425df692 | 269 | FileName,\r |
0eb52298 MK |
270 | LineNumber,\r |
271 | DescriptionA,\r | |
272 | DescriptionB,\r | |
273 | ValueA,\r | |
274 | ValueB\r | |
275 | );\r | |
276 | }\r | |
7c0ad2c3 | 277 | \r |
0eb52298 MK |
278 | return (ValueA == ValueB);\r |
279 | }\r | |
280 | \r | |
281 | /**\r | |
282 | If the contents of BufferA are identical to the contents of BufferB, then TRUE\r | |
283 | is returned. If the contents of BufferA are not identical to the contents of\r | |
284 | BufferB, then an assert is triggered and the location of the assert provided\r | |
285 | by FunctionName, LineNumber, FileName, DescriptionA, and DescriptionB are\r | |
286 | recorded and FALSE is returned.\r | |
287 | \r | |
288 | @param[in] BufferA Pointer to a buffer for comparison.\r | |
289 | @param[in] BufferB Pointer to a buffer for comparison.\r | |
290 | @param[in] Length Number of bytes to compare in BufferA and BufferB.\r | |
291 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
292 | executing the assert macro.\r | |
293 | @param[in] LineNumber The source file line number of the assert macro.\r | |
294 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
295 | executing the assert macro.\r | |
296 | @param[in] DescriptionA Null-terminated ASCII string that is a description\r | |
297 | of BufferA.\r | |
298 | @param[in] DescriptionB Null-terminated ASCII string that is a description\r | |
299 | of BufferB.\r | |
300 | \r | |
301 | @retval TRUE The contents of BufferA are identical to the contents of\r | |
302 | BufferB.\r | |
303 | @retval FALSE The contents of BufferA are not identical to the contents of\r | |
304 | BufferB.\r | |
305 | **/\r | |
306 | BOOLEAN\r | |
307 | EFIAPI\r | |
308 | UnitTestAssertMemEqual (\r | |
309 | IN VOID *BufferA,\r | |
310 | IN VOID *BufferB,\r | |
311 | IN UINTN Length,\r | |
312 | IN CONST CHAR8 *FunctionName,\r | |
313 | IN UINTN LineNumber,\r | |
314 | IN CONST CHAR8 *FileName,\r | |
315 | IN CONST CHAR8 *DescriptionA,\r | |
316 | IN CONST CHAR8 *DescriptionB\r | |
317 | )\r | |
318 | {\r | |
7c0ad2c3 | 319 | if (CompareMem (BufferA, BufferB, Length) != 0) {\r |
26824851 MK |
320 | UT_LOG_ERROR (\r |
321 | "[ASSERT FAIL] %a:%d: Value %a != %a for length %d bytes!\n",\r | |
425df692 | 322 | FileName,\r |
0eb52298 MK |
323 | LineNumber,\r |
324 | DescriptionA,\r | |
325 | DescriptionB,\r | |
326 | Length\r | |
327 | );\r | |
26824851 MK |
328 | UnitTestLogFailure (\r |
329 | FAILURETYPE_ASSERTEQUAL,\r | |
330 | "%a:%d: Memory at %a != %a for length %d bytes!\n",\r | |
425df692 | 331 | FileName,\r |
0eb52298 MK |
332 | LineNumber,\r |
333 | DescriptionA,\r | |
334 | DescriptionB,\r | |
335 | Length\r | |
336 | );\r | |
337 | return FALSE;\r | |
338 | }\r | |
7c0ad2c3 | 339 | \r |
0eb52298 MK |
340 | return TRUE;\r |
341 | }\r | |
342 | \r | |
343 | /**\r | |
344 | If ValueA is not equal ValueB, then TRUE is returned.\r | |
345 | If ValueA is equal to ValueB, then an assert is triggered and the location\r | |
346 | of the assert provided by FunctionName, LineNumber, FileName, DescriptionA\r | |
347 | and DescriptionB are recorded and FALSE is returned.\r | |
348 | \r | |
349 | @param[in] ValueA 64-bit value.\r | |
350 | @param[in] ValueB 64-bit value.\r | |
351 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
352 | executing the assert macro.\r | |
353 | @param[in] LineNumber The source file line number of the assert macro.\r | |
354 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
355 | executing the assert macro.\r | |
356 | @param[in] DescriptionA Null-terminated ASCII string that is a description\r | |
357 | of ValueA.\r | |
358 | @param[in] DescriptionB Null-terminated ASCII string that is a description\r | |
359 | of ValueB.\r | |
360 | \r | |
361 | @retval TRUE ValueA is not equal to ValueB.\r | |
362 | @retval FALSE ValueA is equal to ValueB.\r | |
363 | **/\r | |
364 | BOOLEAN\r | |
365 | EFIAPI\r | |
366 | UnitTestAssertNotEqual (\r | |
367 | IN UINT64 ValueA,\r | |
368 | IN UINT64 ValueB,\r | |
369 | IN CONST CHAR8 *FunctionName,\r | |
370 | IN UINTN LineNumber,\r | |
371 | IN CONST CHAR8 *FileName,\r | |
372 | IN CONST CHAR8 *DescriptionA,\r | |
373 | IN CONST CHAR8 *DescriptionB\r | |
374 | )\r | |
375 | {\r | |
f76d5016 | 376 | if (ValueA == ValueB) {\r |
26824851 MK |
377 | UT_LOG_ERROR (\r |
378 | "[ASSERT FAIL] %a:%d: Value %a == %a (%d == %d)!\n",\r | |
425df692 | 379 | FileName,\r |
0eb52298 MK |
380 | LineNumber,\r |
381 | DescriptionA,\r | |
382 | DescriptionB,\r | |
383 | ValueA,\r | |
384 | ValueB\r | |
385 | );\r | |
26824851 MK |
386 | UnitTestLogFailure (\r |
387 | FAILURETYPE_ASSERTNOTEQUAL,\r | |
388 | "%a:%d: Value %a == %a (%d == %d)!\n",\r | |
425df692 | 389 | FileName,\r |
0eb52298 MK |
390 | LineNumber,\r |
391 | DescriptionA,\r | |
392 | DescriptionB,\r | |
393 | ValueA,\r | |
394 | ValueB\r | |
395 | );\r | |
396 | }\r | |
7c0ad2c3 | 397 | \r |
0eb52298 MK |
398 | return (ValueA != ValueB);\r |
399 | }\r | |
400 | \r | |
401 | /**\r | |
402 | If Status is equal to Expected, then TRUE is returned.\r | |
403 | If Status is not equal to Expected, then an assert is triggered and the\r | |
404 | location of the assert provided by FunctionName, LineNumber, FileName, and\r | |
405 | Description are recorded and FALSE is returned.\r | |
406 | \r | |
407 | @param[in] Status EFI_STATUS value returned from an API under test.\r | |
408 | @param[in] Expected The expected EFI_STATUS return value from an API\r | |
409 | under test.\r | |
410 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
411 | executing the assert macro.\r | |
412 | @param[in] LineNumber The source file line number of the assert macro.\r | |
413 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
414 | executing the assert macro.\r | |
415 | @param[in] Description Null-terminated ASCII string that is a description\r | |
416 | of Status.\r | |
417 | \r | |
418 | @retval TRUE Status is equal to Expected.\r | |
419 | @retval FALSE Status is not equal to Expected.\r | |
420 | **/\r | |
421 | BOOLEAN\r | |
422 | EFIAPI\r | |
423 | UnitTestAssertStatusEqual (\r | |
424 | IN EFI_STATUS Status,\r | |
425 | IN EFI_STATUS Expected,\r | |
426 | IN CONST CHAR8 *FunctionName,\r | |
427 | IN UINTN LineNumber,\r | |
428 | IN CONST CHAR8 *FileName,\r | |
429 | IN CONST CHAR8 *Description\r | |
430 | )\r | |
431 | {\r | |
f76d5016 | 432 | if (Status != Expected) {\r |
26824851 MK |
433 | UT_LOG_ERROR (\r |
434 | "[ASSERT FAIL] %a:%d: Status '%a' is %r, should be %r!\n",\r | |
425df692 | 435 | FileName,\r |
0eb52298 MK |
436 | LineNumber,\r |
437 | Description,\r | |
438 | Status,\r | |
439 | Expected\r | |
440 | );\r | |
26824851 MK |
441 | UnitTestLogFailure (\r |
442 | FAILURETYPE_ASSERTSTATUSEQUAL,\r | |
443 | "%a:%d: Status '%a' is %r, should be %r!\n",\r | |
425df692 | 444 | FileName,\r |
0eb52298 MK |
445 | LineNumber,\r |
446 | Description,\r | |
447 | Status,\r | |
448 | Expected\r | |
449 | );\r | |
450 | }\r | |
7c0ad2c3 | 451 | \r |
0eb52298 MK |
452 | return (Status == Expected);\r |
453 | }\r | |
454 | \r | |
455 | /**\r | |
456 | If Pointer is not equal to NULL, then TRUE is returned.\r | |
457 | If Pointer is equal to NULL, then an assert is triggered and the location of\r | |
458 | the assert provided by FunctionName, LineNumber, FileName, and PointerName\r | |
459 | are recorded and FALSE is returned.\r | |
460 | \r | |
461 | @param[in] Pointer Pointer value to be checked against NULL.\r | |
462 | @param[in] Expected The expected EFI_STATUS return value from a function\r | |
463 | under test.\r | |
464 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
465 | executing the assert macro.\r | |
466 | @param[in] LineNumber The source file line number of the assert macro.\r | |
467 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
468 | executing the assert macro.\r | |
469 | @param[in] PointerName Null-terminated ASCII string that is a description\r | |
470 | of Pointer.\r | |
471 | \r | |
472 | @retval TRUE Pointer is not equal to NULL.\r | |
473 | @retval FALSE Pointer is equal to NULL.\r | |
474 | **/\r | |
475 | BOOLEAN\r | |
476 | EFIAPI\r | |
477 | UnitTestAssertNotNull (\r | |
478 | IN VOID *Pointer,\r | |
479 | IN CONST CHAR8 *FunctionName,\r | |
480 | IN UINTN LineNumber,\r | |
481 | IN CONST CHAR8 *FileName,\r | |
482 | IN CONST CHAR8 *PointerName\r | |
483 | )\r | |
484 | {\r | |
485 | if (Pointer == NULL) {\r | |
26824851 MK |
486 | UT_LOG_ERROR (\r |
487 | "[ASSERT FAIL] %a:%d: Pointer (%a) is NULL!\n",\r | |
488 | FileName,\r | |
489 | LineNumber,\r | |
490 | PointerName\r | |
491 | );\r | |
0eb52298 MK |
492 | UnitTestLogFailure (\r |
493 | FAILURETYPE_ASSERTNOTNULL,\r | |
425df692 MK |
494 | "%a:%d: Pointer (%a) is NULL!\n",\r |
495 | FileName,\r | |
0eb52298 MK |
496 | LineNumber,\r |
497 | PointerName\r | |
498 | );\r | |
26824851 | 499 | }\r |
7c0ad2c3 | 500 | \r |
26824851 MK |
501 | return (Pointer != NULL);\r |
502 | }\r | |
503 | \r | |
504 | /**\r | |
505 | If UnitTestStatus is UNIT_TEST_PASSED, then log an info message and return\r | |
506 | TRUE because an ASSERT() was expected when FunctionCall was executed and an\r | |
507 | ASSERT() was triggered. If UnitTestStatus is UNIT_TEST_SKIPPED, then log a\r | |
508 | warning message and return TRUE because ASSERT() macros are disabled. If\r | |
509 | UnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED, then log an error message and\r | |
510 | return FALSE because an ASSERT() was expected when FunctionCall was executed,\r | |
511 | but no ASSERT() conditions were triggered. The log messages contain\r | |
512 | FunctionName, LineNumber, and FileName strings to provide the location of the\r | |
513 | UT_EXPECT_ASSERT_FAILURE() macro.\r | |
514 | \r | |
515 | @param[in] UnitTestStatus The status from UT_EXPECT_ASSERT_FAILURE() that\r | |
516 | is either pass, skipped, or failed.\r | |
517 | @param[in] FunctionName Null-terminated ASCII string of the function\r | |
518 | executing the UT_EXPECT_ASSERT_FAILURE() macro.\r | |
519 | @param[in] LineNumber The source file line number of the the function\r | |
520 | executing the UT_EXPECT_ASSERT_FAILURE() macro.\r | |
521 | @param[in] FileName Null-terminated ASCII string of the filename\r | |
522 | executing the UT_EXPECT_ASSERT_FAILURE() macro.\r | |
523 | @param[in] FunctionCall Null-terminated ASCII string of the function call\r | |
524 | executed by the UT_EXPECT_ASSERT_FAILURE() macro.\r | |
525 | @param[out] ResultStatus Used to return the UnitTestStatus value to the\r | |
526 | caller of UT_EXPECT_ASSERT_FAILURE(). This is\r | |
527 | optional parameter that may be NULL.\r | |
528 | \r | |
529 | @retval TRUE UnitTestStatus is UNIT_TEST_PASSED.\r | |
530 | @retval TRUE UnitTestStatus is UNIT_TEST_SKIPPED.\r | |
531 | @retval FALSE UnitTestStatus is UNIT_TEST_ERROR_TEST_FAILED.\r | |
532 | **/\r | |
533 | BOOLEAN\r | |
534 | EFIAPI\r | |
535 | UnitTestExpectAssertFailure (\r | |
536 | IN UNIT_TEST_STATUS UnitTestStatus,\r | |
537 | IN CONST CHAR8 *FunctionName,\r | |
538 | IN UINTN LineNumber,\r | |
539 | IN CONST CHAR8 *FileName,\r | |
540 | IN CONST CHAR8 *FunctionCall,\r | |
541 | OUT UNIT_TEST_STATUS *ResultStatus OPTIONAL\r | |
542 | )\r | |
543 | {\r | |
544 | if (ResultStatus != NULL) {\r | |
545 | *ResultStatus = UnitTestStatus;\r | |
546 | }\r | |
7c0ad2c3 | 547 | \r |
26824851 MK |
548 | if (UnitTestStatus == UNIT_TEST_PASSED) {\r |
549 | UT_LOG_INFO (\r | |
550 | "[ASSERT PASS] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) detected expected assert\n",\r | |
551 | FileName,\r | |
552 | LineNumber,\r | |
553 | FunctionCall\r | |
554 | );\r | |
555 | }\r | |
7c0ad2c3 | 556 | \r |
26824851 MK |
557 | if (UnitTestStatus == UNIT_TEST_SKIPPED) {\r |
558 | UT_LOG_WARNING (\r | |
559 | "[ASSERT WARN] %a:%d: UT_EXPECT_ASSERT_FAILURE(%a) disabled\n",\r | |
560 | FileName,\r | |
561 | LineNumber,\r | |
562 | FunctionCall\r | |
563 | );\r | |
564 | }\r | |
7c0ad2c3 | 565 | \r |
26824851 | 566 | if (UnitTestStatus == UNIT_TEST_ERROR_TEST_FAILED) {\r |
0eb52298 | 567 | UT_LOG_ERROR (\r |
26824851 | 568 | "[ASSERT FAIL] %a:%d: Function call (%a) did not ASSERT()!\n",\r |
425df692 | 569 | FileName,\r |
0eb52298 | 570 | LineNumber,\r |
26824851 MK |
571 | FunctionCall\r |
572 | );\r | |
573 | UnitTestLogFailure (\r | |
574 | FAILURETYPE_EXPECTASSERT,\r | |
575 | "%a:%d: Function call (%a) did not ASSERT()!\n",\r | |
576 | FileName,\r | |
577 | LineNumber,\r | |
578 | FunctionCall\r | |
0eb52298 MK |
579 | );\r |
580 | }\r | |
7c0ad2c3 | 581 | \r |
26824851 | 582 | return (UnitTestStatus != UNIT_TEST_ERROR_TEST_FAILED);\r |
0eb52298 | 583 | }\r |