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 CBD5D74003D for ; Fri, 9 Feb 2024 18:33:54 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=ohiJj60UhmlMValCKQTtOWESt9Fg2RyxTguSFXy33SM=; 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=1707503633; v=1; b=bJY4FrBCWdpn2MvC+BYERUiR0aJ0j4OjJdpomwVkoigWl2SXWYHisv+k6bJBVMwTPLZHRnnd AoDNUamr2P7tCoK+szoe2JU87BmRjxqMakHLoRz0S1IwFZ4H6VJpTjHdi72T00e+xp0cgLexmBm C70CfwkCuPCw/QASsBXHWYZc= X-Received: by 127.0.0.2 with SMTP id FAGcYY7687511xd2vyWNYDaq; Fri, 09 Feb 2024 10:33:53 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.13]) by mx.groups.io with SMTP id smtpd.web10.20021.1707503628985058043 for ; Fri, 09 Feb 2024 10:33:50 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10979"; a="4458810" X-IronPort-AV: E=Sophos;i="6.05,257,1701158400"; d="scan'208";a="4458810" X-Received: from fmviesa008.fm.intel.com ([10.60.135.148]) by fmvoesa107.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2024 10:33:50 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.05,257,1701158400"; d="scan'208";a="2212139" X-Received: from mdkinney-mobl.amr.corp.intel.com ([10.209.59.192]) by fmviesa008-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Feb 2024 10:33:50 -0800 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Michael Kubacki , Sean Brogan Subject: [edk2-devel] [edk2-stable202402][Patch V2 4/7] UnitTestFrameworkPkg/UnitTestLib: GetActiveFrameworkHandle() no ASSERT() Date: Fri, 9 Feb 2024 10:33:33 -0800 Message-Id: <20240209183336.1777-5-michael.d.kinney@intel.com> In-Reply-To: <20240209183336.1777-1-michael.d.kinney@intel.com> References: <20240209183336.1777-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: DWKvYE78RTsHsYk91jVN1LaWx7686176AA= 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=bJY4FrBC; 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 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 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 (#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] -=-=-=-=-=-=-=-=-=-=-=-