From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by spool.mail.gandi.net (Postfix) with ESMTPS id 121D37803CF for ; Wed, 7 Feb 2024 03:41:24 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=YincOgCEzGHnYR33M+hPZCoE5VaFeCYxCzSifJq5aFo=; c=relaxed/simple; d=groups.io; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References:MIME-Version:Precedence:List-Subscribe:List-Help:Sender:List-Id:Mailing-List:Delivered-To:Reply-To:List-Unsubscribe-Post:List-Unsubscribe:Content-Transfer-Encoding; s=20140610; t=1707277283; v=1; b=h+MoMDuo5eHSRyryffvPvA45dNsmY0g+/myFS0768QN/WH+QznGW5iCFbATQJ3m3ry8sHi8o p6w/AplJFqkaRKhF7snV/1k3lu3hiRVy78vLs7DPwFYHbdX7vz6iQlEgTc/T+SnvIRKb9vBbEgu FES6RkcYpbZDk0kst5dpI4u8= X-Received: by 127.0.0.2 with SMTP id UdT7YY7687511xwfoaaXDsU1; Tue, 06 Feb 2024 19:41:23 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [198.175.65.12]) by mx.groups.io with SMTP id smtpd.web10.13161.1707277279536915825 for ; Tue, 06 Feb 2024 19:41:19 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10976"; a="12258667" X-IronPort-AV: E=Sophos;i="6.05,250,1701158400"; d="scan'208";a="12258667" X-Received: from orviesa008.jf.intel.com ([10.64.159.148]) by orvoesa104.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2024 19:41:19 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,250,1701158400"; d="scan'208";a="1568987" X-Received: from mdkinney-mobl.amr.corp.intel.com ([10.209.93.91]) by orviesa008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 06 Feb 2024 19:41:19 -0800 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Michael Kubacki , Sean Brogan Subject: [edk2-devel] [edk2-stable202402][Patch 4/7] UnitTestFrameworkPkg/UnitTestLib: GetActiveFrameworkHandle() no ASSERT() Date: Tue, 6 Feb 2024 19:41:03 -0800 Message-Id: <20240207034106.1860-5-michael.d.kinney@intel.com> In-Reply-To: <20240207034106.1860-1-michael.d.kinney@intel.com> References: <20240207034106.1860-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Subscribe: List-Help: Sender: devel@edk2.groups.io List-Id: Mailing-List: list devel@edk2.groups.io; contact devel+owner@edk2.groups.io Reply-To: devel@edk2.groups.io,michael.d.kinney@intel.com List-Unsubscribe-Post: List-Unsubscribe=One-Click List-Unsubscribe: X-Gm-Message-State: zFODdVa2YU1H0VdaiHrB2DThx7686176AA= Content-Transfer-Encoding: 8bit X-GND-Status: LEGIT Authentication-Results: spool.mail.gandi.net; dkim=pass header.d=groups.io header.s=20140610 header.b=h+MoMDuo; dmarc=fail reason="SPF not aligned (relaxed), DKIM not aligned (relaxed)" header.from=intel.com (policy=none); spf=pass (spool.mail.gandi.net: domain of bounce@groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce@groups.io Update GetActiveFrameworkHandle() to remove ASSERT() and require caller to check for NULL. This allows this API 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 Cc: Sean Brogan Signed-off-by: Michael D Kinney --- 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 (#115228): https://edk2.groups.io/g/devel/message/115228 Mute This Topic: https://groups.io/mt/104212831/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-