From nobody Mon Feb 9 03:13:06 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) client-ip=66.175.222.108; envelope-from=bounce+27952+102730+1787277+3901457@groups.io; helo=mail02.groups.io; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+102730+1787277+3901457@groups.io; dmarc=fail(p=none dis=none) header.from=intel.com ARC-Seal: i=1; a=rsa-sha256; t=1680906063; cv=none; d=zohomail.com; s=zohoarc; b=Thwq27vUTs4IWmhiGEepEJB9/oQY86KUAhz5+641l7qRnpXJwpHNeem29nTS6FESOTLkfkHvBQyD39rBnqWChr09EgawMu142XXD24BRG9WnbMjozNGwa/asL2jSxPVKcVyx82xaoiTC+0fVRsJ3sxeY7zhkzn+zHtcNU3dQe5k= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1680906063; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Reply-To:References:Sender:Subject:To; bh=uElAGYf0S1OHXfNpIxisnPaGq1rP7tOheBEndUk0+OE=; b=hsSGU6fTGp9ZK9Y2qUhFp3+eKFOEReqSRHGuaY3dHbknivLkhUC05eXmq63n5hl8pqDePhB131TwapOO1NkXG0G0kIu1N9WyLHt6FB3lf1dMHkkSuuA4faeUzCf0/zvsMv+HOWllqYJ+ZusxqV+IHS7wsWOeDSlQPNkt0GsUXa0= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of groups.io designates 66.175.222.108 as permitted sender) smtp.mailfrom=bounce+27952+102730+1787277+3901457@groups.io; dmarc=fail header.from= (p=none dis=none) Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1680906063624302.51848678422175; Fri, 7 Apr 2023 15:21:03 -0700 (PDT) Return-Path: X-Received: by 127.0.0.2 with SMTP id wkTFYY1788612xFOkI04Sw8p; Fri, 07 Apr 2023 15:21:03 -0700 X-Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by mx.groups.io with SMTP id smtpd.web10.2854.1680906059556530823 for ; Fri, 07 Apr 2023 15:21:02 -0700 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="343085659" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="343085659" X-Received: from fmsmga007.fm.intel.com ([10.253.24.52]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2023 15:21:02 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10673"; a="690177474" X-IronPort-AV: E=Sophos;i="5.98,328,1673942400"; d="scan'208";a="690177474" X-Received: from mdkinney-mobl2.amr.corp.intel.com ([10.209.18.108]) by fmsmga007-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Apr 2023 15:21:01 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Chris Johnson , Jian J Wang , Liming Gao , Oliver Smith-Denny Subject: [edk2-devel] [Patch v3 06/12] MdeModulePkg/Library/UefiSortLib: Add GoogleTestLib example Date: Fri, 7 Apr 2023 15:20:44 -0700 Message-Id: <20230407222051.1095-7-michael.d.kinney@intel.com> In-Reply-To: <20230407222051.1095-1-michael.d.kinney@intel.com> References: <20230407222051.1095-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Precedence: Bulk List-Unsubscribe: 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 X-Gm-Message-State: HjZTww9p4lnfeQaxDxoJYJgDx1787277AA= Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1680906063; bh=FytwDwX0U8Xu4tAykThWpaeO4kMPNUeKrnZwZ5ffxQA=; h=Cc:Date:From:Reply-To:Subject:To; b=IwiwC2O/M6q0waSuRaeR7hpyukaOC9fKzpiiRs9GZM0qtfi0qyZ6FttfeN/RGt6dSTp ql4Z36NTa4dym949FTs3Jw9HFOlkWEN04x7pyZgiXa0O62tXoRA+IYnECM3lfg/DSeu48 BCI/iBHiQv7hBsuWKzP4ttsNcl/alTZ8dk4= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1680906064666100019 Content-Type: text/plain; charset="utf-8" From: Chris Johnson REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3D4389 Cc: Jian J Wang Cc: Liming Gao Signed-off-by: Chris Johnson Reviewed-by: Oliver Smith-Denny Reviewed-by: Michael D Kinney --- .../MockUefiRuntimeServicesTableLib.inf | 4 +- .../GoogleTest/UefiSortLibGoogleTest.cpp | 61 +++++++++++++++++++ .../GoogleTest/UefiSortLibGoogleTest.inf | 31 ++++++++++ MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 6 ++ 4 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLib= GoogleTest.cpp create mode 100644 MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLib= GoogleTest.inf diff --git a/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntim= eServicesTableLib.inf b/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/Moc= kUefiRuntimeServicesTableLib.inf index e716b855a31a..15eb646d7c38 100644 --- a/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServic= esTableLib.inf +++ b/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServic= esTableLib.inf @@ -10,9 +10,9 @@ [Defines] INF_VERSION =3D 0x00010005 BASE_NAME =3D MockUefiRuntimeServicesTableLib FILE_GUID =3D 4EA215EE-85C1-4A0A-847F-D2A8DE20805F - MODULE_TYPE =3D UEFI_DRIVER + MODULE_TYPE =3D HOST_APPLICATION VERSION_STRING =3D 1.0 - LIBRARY_CLASS =3D UefiRuntimeServicesTableLib|HOST_APPL= ICATION + LIBRARY_CLASS =3D UefiRuntimeServicesTableLib =20 # # VALID_ARCHITECTURES =3D IA32 X64 EBC diff --git a/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleT= est.cpp b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest= .cpp new file mode 100644 index 000000000000..23f6e9cc0611 --- /dev/null +++ b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.cpp @@ -0,0 +1,61 @@ +/** @file + Unit tests for the implementation of UefiSortLib. + + Copyright (c) 2022, Intel Corporation. All rights reserved. + SPDX-License-Identifier: BSD-2-Clause-Patent +**/ +#include + +extern "C" { + #include + #include +} + +using namespace testing; + +INTN +EFIAPI +CompareUint32 ( + IN CONST VOID *Left, + IN CONST VOID *Right + ) +{ + if (*(UINT32*)Right > *(UINT32*)Left) { + return 1; + } else if (*(UINT32*)Right < *(UINT32*)Left) { + return -1; + } + + return 0; +} + +// Test PerformQuickSort() API from UefiSortLib to verify a UINT32 array +// with 9 elements in ascending order is sorted into descending order. +TEST(PerformQuickSortTest, SortUint32AscendingArray_Size9) { + CONST UINT32 ArraySize =3D 9; + UINT32 BuffActual[ArraySize]; + UINT32 BuffExpected[ArraySize]; + + for (UINT32 Index =3D 0; Index < ArraySize; Index++) { + BuffActual[Index] =3D Index + 1; + BuffExpected[Index] =3D ArraySize - Index; + } + + PerformQuickSort (BuffActual, (UINTN)ArraySize, sizeof(UINT32), (SORT_CO= MPARE)CompareUint32); + EXPECT_THAT(BuffActual, ElementsAreArray(BuffExpected, ArraySize)); +} + +// Test StringCompare() API from UefiSortLib to verify the comparison +// succeeds when the same buffer is compared with itself. +TEST(StringCompareTest, CompareSameBuffer) { + INTN RetVal; + CONST CHAR16 *Buffer =3D (CHAR16*)L"abcdefg"; + + RetVal =3D StringCompare (&Buffer, &Buffer); + EXPECT_EQ(RetVal, 0); +} + +int main(int argc, char* argv[]) { + testing::InitGoogleTest(&argc, argv); + return RUN_ALL_TESTS(); +} diff --git a/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleT= est.inf b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest= .inf new file mode 100644 index 000000000000..ac5ffb3bc29d --- /dev/null +++ b/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.inf @@ -0,0 +1,31 @@ +## @file +# Unit test suite for the UefiSortLib using Google Test +# +# Copyright (c) 2022, Intel Corporation. All rights reserved. +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010017 + BASE_NAME =3D UefiSortLibGoogleTest + FILE_GUID =3D 78FB0BEE-D0EA-4E1A-BD38-67458C8ECDEF + VERSION_STRING =3D 1.0 + MODULE_TYPE =3D HOST_APPLICATION + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + UefiSortLibGoogleTest.cpp + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + GoogleTestLib + UefiSortLib diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test= /MdeModulePkgHostTest.dsc index c9ec835df65d..a2bbbe8adf44 100644 --- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc +++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc @@ -47,3 +47,9 @@ [Components] UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf } + + MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.inf { + + UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf + } --=20 2.39.1.windows.1 -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D- Groups.io Links: You receive all messages sent to this group. View/Reply Online (#102730): https://edk2.groups.io/g/devel/message/102730 Mute This Topic: https://groups.io/mt/98134498/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/leave/3901457/1787277/102458076= /xyzzy [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-