]> git.proxmox.com Git - mirror_edk2.git/blob - UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c
0a4001e182ce03068e210b519b158e544266ac8e
[mirror_edk2.git] / UnitTestFrameworkPkg / Library / UnitTestDebugAssertLib / UnitTestDebugAssertLib.c
1 /** @file
2 Unit Test Debug Assert Library
3
4 Copyright (c) 2020, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
6
7 **/
8
9 #include <Uefi.h>
10 #include <Library/BaseLib.h>
11 #include <Library/UnitTestLib.h>
12
13 ///
14 /// Point to jump buffer used with SetJump()/LongJump() to test if a function
15 /// under test generates an expected ASSERT() condition.
16 ///
17 BASE_LIBRARY_JUMP_BUFFER *gUnitTestExpectAssertFailureJumpBuffer = NULL;
18
19 /**
20 Unit test library replacement for DebugAssert() in DebugLib.
21
22 If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.
23 If Description is NULL, then a <Description> string of "(NULL) Description" is printed.
24
25 @param FileName The pointer to the name of the source file that generated the assert condition.
26 @param LineNumber The line number in the source file that generated the assert condition
27 @param Description The pointer to the description of the assert condition.
28
29 **/
30 VOID
31 EFIAPI
32 UnitTestDebugAssert (
33 IN CONST CHAR8 *FileName,
34 IN UINTN LineNumber,
35 IN CONST CHAR8 *Description
36 )
37 {
38 CHAR8 Message[256];
39
40 if (gUnitTestExpectAssertFailureJumpBuffer != NULL) {
41 UT_LOG_INFO ("Detected expected ASSERT: %a(%d): %a\n", FileName, LineNumber, Description);
42 LongJump (gUnitTestExpectAssertFailureJumpBuffer, 1);
43 } else {
44 AsciiStrCpyS (Message, sizeof(Message), "Detected unexpected ASSERT(");
45 AsciiStrCatS (Message, sizeof(Message), Description);
46 AsciiStrCatS (Message, sizeof(Message), ")");
47 UnitTestAssertTrue (FALSE, "", LineNumber, FileName, Message);
48 }
49 }