From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by mx.groups.io with SMTP id smtpd.web10.109877.1680632553375816475 for ; Tue, 04 Apr 2023 11:22:34 -0700 Authentication-Results: mx.groups.io; dkim=fail reason="unable to parse pub key" header.i=@intel.com header.s=intel header.b=R7ohXJ06; spf=pass (domain: intel.com, ip: 134.134.136.24, mailfrom: michael.d.kinney@intel.com) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1680632553; x=1712168553; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=OydEjpsM5PBPaYKY5SeZxAV9LFOOlWvQTv3+4j40y6E=; b=R7ohXJ06jVEF6uPgOmXH730pREsGAFTJewZL95OPVMV6dQJl83XFVDbd RMjyCJrSzZsj7NouFHeEudaH0eggVBtRpOhrWPJm7unW3fAmidauGQwbe EOO4mumpKbcHobH+Cu/C9BwiEWxR1SkJvM+GQzVPxhdShLG3JtxpHAdZJ e2+f0zhJ0K4GrwUMCcucsZ57Q5JhQXNWylXIm/IM65ZtruvOcONU/HPhP 6s6/AtJWNysJ8wBjzqI5djUpRoaIb8G57TGq81dP9jaipwurxx8SIK7rO CJ3ebVT73oeV6D1FiU6poUg3tLPh4v7/WF2f2xZw2Kxod2krnTOgjK0JJ A==; X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="343978599" X-IronPort-AV: E=Sophos;i="5.98,318,1673942400"; d="scan'208";a="343978599" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2023 11:22:33 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6600,9927,10670"; a="860686658" X-IronPort-AV: E=Sophos;i="5.98,318,1673942400"; d="scan'208";a="860686658" Received: from unknown (HELO mdkinney-MOBL2.amr.corp.intel.com) ([10.241.111.152]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 04 Apr 2023 11:22:32 -0700 From: "Michael D Kinney" To: devel@edk2.groups.io Cc: Chris Johnson , Jian J Wang , Liming Gao Subject: [Patch v2 06/12] MdeModulePkg/Library/UefiSortLib: Add GoogleTestLib example Date: Tue, 4 Apr 2023 11:22:14 -0700 Message-Id: <20230404182220.688-7-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.39.1.windows.1 In-Reply-To: <20230404182220.688-1-michael.d.kinney@intel.com> References: <20230404182220.688-1-michael.d.kinney@intel.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Chris Johnson REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4389 Cc: Jian J Wang Cc: Liming Gao Signed-off-by: Chris Johnson --- .../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/UefiSortLibGoogleTest.cpp create mode 100644 MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.inf diff --git a/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf b/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf index e716b855a31a..15eb646d7c38 100644 --- a/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf +++ b/MdeModulePkg/Library/DxeResetSystemLib/UnitTest/MockUefiRuntimeServicesTableLib.inf @@ -10,9 +10,9 @@ [Defines] INF_VERSION = 0x00010005 BASE_NAME = MockUefiRuntimeServicesTableLib FILE_GUID = 4EA215EE-85C1-4A0A-847F-D2A8DE20805F - MODULE_TYPE = UEFI_DRIVER + MODULE_TYPE = HOST_APPLICATION VERSION_STRING = 1.0 - LIBRARY_CLASS = UefiRuntimeServicesTableLib|HOST_APPLICATION + LIBRARY_CLASS = UefiRuntimeServicesTableLib # # VALID_ARCHITECTURES = IA32 X64 EBC diff --git a/MdeModulePkg/Library/UefiSortLib/GoogleTest/UefiSortLibGoogleTest.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 = 9; + UINT32 BuffActual[ArraySize]; + UINT32 BuffExpected[ArraySize]; + + for (UINT32 Index = 0; Index < ArraySize; Index++) { + BuffActual[Index] = Index + 1; + BuffExpected[Index] = ArraySize - Index; + } + + PerformQuickSort (BuffActual, (UINTN)ArraySize, sizeof(UINT32), (SORT_COMPARE)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 = (CHAR16*)L"abcdefg"; + + RetVal = 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/UefiSortLibGoogleTest.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 = 0x00010017 + BASE_NAME = UefiSortLibGoogleTest + FILE_GUID = 78FB0BEE-D0EA-4E1A-BD38-67458C8ECDEF + VERSION_STRING = 1.0 + MODULE_TYPE = HOST_APPLICATION + +# +# The following information is for reference only and not required by the build tools. +# +# VALID_ARCHITECTURES = 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 + } -- 2.39.1.windows.1