diff options
author | Michael D Kinney <michael.d.kinney@intel.com> | 2024-02-06 14:43:16 -0800 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2024-02-14 02:37:16 +0000 |
commit | 312ccaf81b6343c9bcee1f8992086075353abeca (patch) | |
tree | e1913dbc5e5a0a8a92ce466f691632b49f5297e9 | |
parent | 81b69f306fe801546786186e1e5ae5f79a2fde97 (diff) | |
download | edk2-312ccaf81b6343c9bcee1f8992086075353abeca.zip edk2-312ccaf81b6343c9bcee1f8992086075353abeca.tar.gz edk2-312ccaf81b6343c9bcee1f8992086075353abeca.tar.bz2 |
UnitTestFrameworkPkg/UnitTestLib: GetActiveFrameworkHandle() no ASSERT()
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4683
Update GetActiveFrameworkHandle() to remove ASSERT() and require
caller to check for NULL.
This allows GetActiveFrameworkHandle() to be used to determine if the
current host-based test environment is framework/cmocka or gtest. In
the framework/cmocka host-based environment GetActiveFrameworkHandle()
returns non-NULL. In the gtest host-based environment
GetActiveFrameworkHandle() returns NULL.
Cc: Michael Kubacki <mikuback@linux.microsoft.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com>
5 files changed, 12 insertions, 2 deletions
diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c b/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c index 3563656..53cb71f 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c +++ b/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c @@ -57,6 +57,10 @@ UnitTestLogFailure ( // Get active Framework handle
//
FrameworkHandle = GetActiveFrameworkHandle ();
+ if (FrameworkHandle == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a - FrameworkHandle not initialized\n", __func__));
+ return;
+ }
//
// Convert the message to an ASCII String
diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/Log.c b/UnitTestFrameworkPkg/Library/UnitTestLib/Log.c index 19eb8ee..f61b9d5 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestLib/Log.c +++ b/UnitTestFrameworkPkg/Library/UnitTestLib/Log.c @@ -166,6 +166,10 @@ UnitTestLog ( VA_LIST Marker;
FrameworkHandle = GetActiveFrameworkHandle ();
+ if (FrameworkHandle == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a - FrameworkHandle not initialized\n", __func__));
+ return;
+ }
LogTypePrefix = NULL;
diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c index 9bc743c..dc1b614 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c +++ b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c @@ -21,7 +21,6 @@ GetActiveFrameworkHandle ( VOID
)
{
- ASSERT (mFrameworkHandle != NULL);
return mFrameworkHandle;
}
diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c index ca4dae1..f24b651 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c +++ b/UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c @@ -27,7 +27,6 @@ GetActiveFrameworkHandle ( VOID
)
{
- ASSERT (mFrameworkHandle != NULL);
return mFrameworkHandle;
}
diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c index 322ea15..3e3a850 100644 --- a/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c +++ b/UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c @@ -826,6 +826,10 @@ SaveFrameworkState ( Header = NULL;
FrameworkHandle = GetActiveFrameworkHandle ();
+ if (FrameworkHandle == NULL) {
+ DEBUG ((DEBUG_ERROR, "%a - Could not save state! FrameworkHandle not initialized\n", __func__));
+ return EFI_DEVICE_ERROR;
+ }
//
// Return a unique error code if the framework is not set.
|