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 32DCC7803CF for ; Tue, 13 Feb 2024 17:26:23 +0000 (UTC) DKIM-Signature: a=rsa-sha256; bh=mHF0z6ofGxTz1HCrhfUTge0udWzvzG2DEPcwy9ass3c=; 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=1707845181; v=1; b=YADBJ1owKH0XYDtzwaOBZv1Op4RxRgoU1W0Nm1Ug+3lqQbhV16iHLS4zNEEjb4qE6Tm4/qFk m781MbAHxj59q0UTyTOYd5bEK0brV1SsGEmHZv3M/7eydXXCEH2zcQEOGwRfvY8U0WuUOPjbmdP LmvHk0CKFl/L1qPYquJv8MMc= X-Received: by 127.0.0.2 with SMTP id 2RwEYY7687511xur0kcTzcxY; Tue, 13 Feb 2024 09:26:21 -0800 X-Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.18]) by mx.groups.io with SMTP id smtpd.web11.17844.1707845177295409701 for ; Tue, 13 Feb 2024 09:26:17 -0800 X-IronPort-AV: E=McAfee;i="6600,9927,10982"; a="1733188" X-IronPort-AV: E=Sophos;i="6.06,157,1705392000"; d="scan'208";a="1733188" X-Received: from orviesa004.jf.intel.com ([10.64.159.144]) by fmvoesa112.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2024 09:26:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.06,157,1705392000"; d="scan'208";a="7698060" X-Received: from mdkinney-mobl.amr.corp.intel.com ([10.209.108.163]) by orviesa004-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2024 09:26:17 -0800 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Michael Kubacki , Sean Brogan , Michael Kubacki Subject: [edk2-devel] [edk2-stable202402][Patch v4 4/7] UnitTestFrameworkPkg/UnitTestLib: GetActiveFrameworkHandle() no ASSERT() Date: Tue, 13 Feb 2024 09:26:09 -0800 Message-Id: <20240213172612.636-5-michael.d.kinney@intel.com> In-Reply-To: <20240213172612.636-1-michael.d.kinney@intel.com> References: <20240213172612.636-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: ZxnJbQ40GDg9nh0QYz7WhCW4x7686176AA= 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=YADBJ1ow; 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 Reviewed-by: Michael Kubacki --- 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 (#115396): https://edk2.groups.io/g/devel/message/115396 Mute This Topic: https://groups.io/mt/104336761/7686176 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [rebecca@openfw.io] -=-=-=-=-=-=-=-=-=-=-=-