public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
From: "Michael D Kinney" <michael.d.kinney@intel.com>
To: devel@edk2.groups.io
Cc: Michael Kubacki <mikuback@linux.microsoft.com>,
	Sean Brogan <sean.brogan@microsoft.com>
Subject: [edk2-devel] [edk2-stable202402][Patch V2 4/7] UnitTestFrameworkPkg/UnitTestLib: GetActiveFrameworkHandle() no ASSERT()
Date: Fri,  9 Feb 2024 10:33:33 -0800	[thread overview]
Message-ID: <20240209183336.1777-5-michael.d.kinney@intel.com> (raw)
In-Reply-To: <20240209183336.1777-1-michael.d.kinney@intel.com>

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>
---
 UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c         | 4 ++++
 UnitTestFrameworkPkg/Library/UnitTestLib/Log.c            | 4 ++++
 UnitTestFrameworkPkg/Library/UnitTestLib/RunTests.c       | 1 -
 UnitTestFrameworkPkg/Library/UnitTestLib/RunTestsCmocka.c | 1 -
 UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLib.c    | 4 ++++
 5 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c b/UnitTestFrameworkPkg/Library/UnitTestLib/Assert.c
index 35636565b783..53cb71f61065 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 19eb8ee0db6e..f61b9d57b10a 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 9bc743ca8ec0..dc1b6147d2f4 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 ca4dae120690..f24b65174c5c 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 322ea15b1575..3e3a850af125 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.
-- 
2.40.1.windows.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#115319): https://edk2.groups.io/g/devel/message/115319
Mute This Topic: https://groups.io/mt/104264747/7686176
Group Owner: devel+owner@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io]
-=-=-=-=-=-=-=-=-=-=-=-



  parent reply	other threads:[~2024-02-09 18:33 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-02-09 18:33 [edk2-devel] [edk2-stable202402][Patch V2 0/7] EDK II CI misses UnitTestFrameworkPkg failures Michael D Kinney
2024-02-09 18:33 ` [edk2-devel] [edk2-stable202402][Patch V2 1/7] MdePkg/Include: Rename _DEBUG() to address name collision Michael D Kinney
2024-02-09 18:33 ` [edk2-devel] [edk2-stable202402][Patch V2 2/7] UnitTestFrameworkPkg: MSFT CC_FLAGS add /MT to for host builds Michael D Kinney
2024-02-09 18:33 ` [edk2-devel] [edk2-stable202402][Patch V2 3/7] UnitTestFrameworkPkg: Expand host-based exception handling and gcov Michael D Kinney
2024-02-09 18:33 ` Michael D Kinney [this message]
2024-02-09 18:33 ` [edk2-devel] [edk2-stable202402][Patch V2 5/7] UnitTestFrameworkPkg/UnitTestDebugAssertLib: Add GoogleTest support Michael D Kinney
2024-02-09 18:33 ` [edk2-devel] [edk2-stable202402][Patch V2 6/7] UnitTestFrameworkPkg/SampleGoogleTest: Use EXPECT_ANY_THROW() Michael D Kinney
2024-02-09 18:33 ` [edk2-devel] [edk2-stable202402][Patch V2 7/7] UnitTestFrameworkPkg: Add DSC and host tests that always fail Michael D Kinney

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240209183336.1777-5-michael.d.kinney@intel.com \
    --to=devel@edk2.groups.io \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox