-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CHERRY-PICK] Unit Test Unexpected Exception (#756)
## Description Cherry pick from: tianocore/edk2#5345 - [ ] Impacts functionality? - **Functionality** - Does the change ultimately impact how firmware functions? - Examples: Add a new library, publish a new PPI, update an algorithm, ... - [ ] Impacts security? - **Security** - Does the change have a direct security impact on an application, flow, or firmware? - Examples: Crypto algorithm change, buffer overflow fix, parameter validation improvement, ... - [ ] Breaking change? - **Breaking change** - Will anyone consuming this change experience a break in build or boot behavior? - Examples: Add a new library class, move a module to a different repo, call a function in a new library class in a pre-existing module, ... - [ ] Includes tests? - **Tests** - Does the change include any explicit test code? - Examples: Unit tests, integration tests, robot tests, ... - [ ] Includes documentation? - **Documentation** - Does the change contain explicit documentation additions outside direct code modifications (and comments)? - Examples: Update readme file, add feature readme file, link to documentation on an a separate Web page, ... ## How This Was Tested Local builds and CI tests ran. ## Integration Instructions N/A --------- Signed-off-by: Michael D Kinney <[email protected]> Co-authored-by: Michael D Kinney <[email protected]>
- Loading branch information
Showing
36 changed files
with
2,224 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
/** @file | ||
Unit Test Debug Assert Library for host-based environments | ||
Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <stdexcept> | ||
|
||
#ifdef NULL | ||
#undef NULL | ||
#endif | ||
|
||
extern "C" { | ||
#include <Uefi.h> | ||
#include <UnitTestFrameworkTypes.h> | ||
#include <Library/BaseLib.h> | ||
#include <Library/UnitTestLib.h> | ||
|
||
/// | ||
/// Point to jump buffer used with SetJump()/LongJump() to test if a function | ||
/// under test generates an expected ASSERT() condition. | ||
/// | ||
BASE_LIBRARY_JUMP_BUFFER *gUnitTestExpectAssertFailureJumpBuffer = NULL; | ||
|
||
/** | ||
Unit test library replacement for DebugAssert() in DebugLib. | ||
If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed. | ||
If Description is NULL, then a <Description> string of "(NULL) Description" is printed. | ||
@param FileName The pointer to the name of the source file that generated the assert condition. | ||
@param LineNumber The line number in the source file that generated the assert condition | ||
@param Description The pointer to the description of the assert condition. | ||
**/ | ||
VOID | ||
EFIAPI | ||
UnitTestDebugAssert ( | ||
IN CONST CHAR8 *FileName, | ||
IN UINTN LineNumber, | ||
IN CONST CHAR8 *Description | ||
) | ||
{ | ||
CHAR8 Message[256]; | ||
|
||
if (gUnitTestExpectAssertFailureJumpBuffer != NULL) { | ||
UT_LOG_INFO ("Detected expected ASSERT: %a(%d): %a\n", FileName, LineNumber, Description); | ||
LongJump (gUnitTestExpectAssertFailureJumpBuffer, 1); | ||
} else { | ||
if (GetActiveFrameworkHandle () != NULL) { | ||
AsciiStrCpyS (Message, sizeof (Message), "Detected unexpected ASSERT("); | ||
AsciiStrCatS (Message, sizeof (Message), Description); | ||
AsciiStrCatS (Message, sizeof (Message), ")"); | ||
UnitTestAssertTrue (FALSE, "", LineNumber, FileName, Message); | ||
} else { | ||
snprintf (Message, sizeof (Message), "Detected unexpected ASSERT: %s(%d): %s\n", FileName, (INT32)(UINT32)LineNumber, Description); | ||
throw std::runtime_error (Message); | ||
} | ||
} | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
## @file | ||
# Unit Test Debug Assert Library for host-based environments | ||
# | ||
# Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> | ||
# SPDX-License-Identifier: BSD-2-Clause-Patent | ||
# | ||
## | ||
|
||
[Defines] | ||
INF_VERSION = 0x00010005 | ||
BASE_NAME = UnitTestDebugAssertLibHost | ||
MODULE_UNI_FILE = UnitTestDebugAssertLibHost.uni | ||
FILE_GUID = F097D67C-0340-49C8-AB30-ABC1B7D1C8D2 | ||
MODULE_TYPE = HOST_APPLICATION | ||
VERSION_STRING = 1.0 | ||
LIBRARY_CLASS = NULL | ||
|
||
# | ||
# VALID_ARCHITECTURES = IA32 X64 ARM AARCH64 | ||
# | ||
|
||
[Sources] | ||
UnitTestDebugAssertLibHost.cpp | ||
|
||
[Packages] | ||
MdePkg/MdePkg.dec | ||
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec | ||
|
||
[LibraryClasses] | ||
BaseLib | ||
UnitTestLib | ||
|
||
[BuildOptions] | ||
MSFT:*_*_*_CC_FLAGS == /c /EHs /Zi /Od /MT | ||
GCC:*_*_IA32_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m32 -malign-double -fno-pie | ||
GCC:*_*_X64_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m64 -fno-pie "-DEFIAPI=__attribute__((ms_abi))" |
11 changes: 11 additions & 0 deletions
11
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.uni
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// /** @file | ||
// Unit Test Debug Assert Library for host-based environments | ||
// | ||
// Copyright (c) 2020, Intel Corporation. All rights reserved.<BR> | ||
// SPDX-License-Identifier: BSD-2-Clause-Patent | ||
// | ||
// **/ | ||
|
||
#string STR_MODULE_ABSTRACT #language en-US "Unit Test Debug Assert Library for host-based environments" | ||
|
||
#string STR_MODULE_DESCRIPTION #language en-US "Unit Test Debug Assert Library for host-based environments" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,6 @@ GetActiveFrameworkHandle ( | |
VOID | ||
) | ||
{ | ||
ASSERT (mFrameworkHandle != NULL); | ||
return mFrameworkHandle; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,7 +27,6 @@ GetActiveFrameworkHandle ( | |
VOID | ||
) | ||
{ | ||
ASSERT (mFrameworkHandle != NULL); | ||
return mFrameworkHandle; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.