From nobody Fri May 3 09:28:35 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; spf=none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) smtp.mailfrom=edk2-devel-bounces@lists.01.org Return-Path: Received: from ml01.01.org (ml01.01.org [198.145.21.10]) by mx.zohomail.com with SMTPS id 1517620185716602.8324937635746; Fri, 2 Feb 2018 17:09:45 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 3EC1E2237A4FA; Fri, 2 Feb 2018 17:04:05 -0800 (PST) Received: from mga06.intel.com (mga06.intel.com [134.134.136.31]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 6DE9C2237A4CD for ; Fri, 2 Feb 2018 17:04:03 -0800 (PST) Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by orsmga104.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Feb 2018 17:09:42 -0800 Received: from mdkinney-mobl2.amr.corp.intel.com ([10.254.102.40]) by fmsmga006.fm.intel.com with ESMTP; 02 Feb 2018 17:09:41 -0800 X-Original-To: edk2-devel@lists.01.org Received-SPF: none (zoho.com: 198.145.21.10 is neither permitted nor denied by domain of lists.01.org) client-ip=198.145.21.10; envelope-from=edk2-devel-bounces@lists.01.org; helo=ml01.01.org; Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=134.134.136.31; helo=mga06.intel.com; envelope-from=michael.d.kinney@intel.com; receiver=edk2-devel@lists.01.org X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,452,1511856000"; d="scan'208";a="200986677" From: "Kinney, Michael D" To: edk2-devel@lists.01.org Date: Fri, 2 Feb 2018 17:09:39 -0800 Message-Id: <20180203010939.8288-1-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.14.2.windows.3 Subject: [edk2] [staging/edk2-test Patch V2] MdePkgUnitTest: Add UefiLib unit tests X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael D Kinney , Liming Gao MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Errors-To: edk2-devel-bounces@lists.01.org Sender: "edk2-devel" X-ZohoMail: RSF_4 Z_629925259 SPT_0 Content-Type: text/plain; charset="utf-8" Add UefiLib unit tests for the new API EfiLocateProtocolBuffer(). Cc: Sean Brogan Cc: Liming Gao Contributed-under: TianoCore Contribution Agreement 1.1 Signed-off-by: Michael D Kinney Reviewed-By: Bret Barkelew Bret.Barkelew@microsoft.com --- MdePkgUnitTest/MdePkgUnitTest.dsc | 17 +- MdePkgUnitTest/UefiLib/UefiLibUnitTests.c | 266 ++++++++++++++++++++++++= ++++ MdePkgUnitTest/UefiLib/UefiLibUnitTests.inf | 46 +++++ 3 files changed, 328 insertions(+), 1 deletion(-) create mode 100644 MdePkgUnitTest/UefiLib/UefiLibUnitTests.c create mode 100644 MdePkgUnitTest/UefiLib/UefiLibUnitTests.inf diff --git a/MdePkgUnitTest/MdePkgUnitTest.dsc b/MdePkgUnitTest/MdePkgUnitT= est.dsc index d98483020b..522464b545 100644 --- a/MdePkgUnitTest/MdePkgUnitTest.dsc +++ b/MdePkgUnitTest/MdePkgUnitTest.dsc @@ -1,7 +1,7 @@ ## @file # This Package provides unit tests for the MdePkg # -# Copyright (c) 2017, Intel Corporation. All rights reserved.
+# Copyright (c) 2017 - 2018, Intel Corporation. All rights reserved.
# # This program and the accompanying materials are licensed and made availa= ble under # the terms and conditions of the BSD License which accompanies this distr= ibution. @@ -33,6 +33,7 @@ BaseLib|MdePkg/Library/BaseLib/BaseLib.inf BaseMemoryLib|MdePkg/Library/BaseMemoryLib/BaseMemoryLib.inf PrintLib|MdePkg/Library/BasePrintLib/BasePrintLib.inf + DebugLib|MdePkg/Library/UefiDebugLibStdErr/UefiDebugLibStdErr.inf DebugPrintErrorLevelLib|MdePkg/Library/BaseDebugPrintErrorLevelLib/BaseD= ebugPrintErrorLevelLib.inf PcdLib|MdePkg/Library/BasePcdLibNull/BasePcdLibNull.inf @@ -50,8 +51,22 @@ UefiHiiServicesLib|MdeModulePkg/Library/UefiHiiServicesLib/UefiHiiServic= esLib.inf SortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf =20 +[PcdsFixedAtBuild] + gEfiMdePkgTokenSpaceGuid.PcdDebugPrintErrorLevel|0x80000047 + gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask|0x1f + [Components] MdePkgUnitTest/SafeIntLib/SafeIntLibUnitTests.inf { SafeIntLib|MdePkg/Library/BaseSafeIntLib/BaseSafeIntLib.inf } + MdePkgUnitTest/UefiLib/UefiLibUnitTests.inf { + + UefiLib|MdePkg/Library/UefiLib/UefiLib.inf + } + MdePkgUnitTest/UefiLib/UefiLibUnitTests.inf { + + FILE_GUID =3D 98286492-B21F-42CD-87BF-4DA8BF617CEB + + UefiLib|IntelFrameworkPkg/Library/FrameworkUefiLib/FrameworkUefiLib.= inf + } diff --git a/MdePkgUnitTest/UefiLib/UefiLibUnitTests.c b/MdePkgUnitTest/Uef= iLib/UefiLibUnitTests.c new file mode 100644 index 0000000000..244715c2ca --- /dev/null +++ b/MdePkgUnitTest/UefiLib/UefiLibUnitTests.c @@ -0,0 +1,266 @@ +/** @file + Uefi Shell based Application that Unit Tests the UefiLib + + Copyright (c) 2018, Intel Corporation. All rights reserved.
+ This program and the accompanying materials + are licensed and made available under the terms and conditions of the BS= D License + which accompanies this distribution. The full text of the license may b= e found at + http://opensource.org/licenses/bsd-license.php + + THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, + WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMP= LIED. + +**/ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + + +#define UNIT_TEST_APP_NAME L"Uefi Lib Unit Test Application" +#define UNIT_TEST_APP_VERSION L"0.1" + +EFI_GUID mUnitTestProtocolGuid =3D { 0xe5f282af, 0x895c, 0x4ece, { 0xae, = 0xf0, 0x19, 0xbf, 0x6f, 0xdd, 0x41, 0x2 } }; + +// +// Conversion function tests: +// +UNIT_TEST_STATUS +EFIAPI +TestEfiLocateProtocolBuffer ( + IN UNIT_TEST_FRAMEWORK_HANDLE Framework, + IN UNIT_TEST_CONTEXT Context + ) +{ + EFI_STATUS Status; + UINTN NoProtocols; + VOID **Buffer; + EFI_HANDLE Handle1; + EFI_HANDLE Handle2; + EFI_HANDLE Handle3; + UINT32 Instance2; + UINT32 Instance3; + + // + // NULL Protocol should result in EFI_INVALID_PARAMETER + // + Status =3D EfiLocateProtocolBuffer (NULL, &NoProtocols, &Buffer); + UT_ASSERT_EQUAL (EFI_INVALID_PARAMETER, Status); + + // + // NULL NoProtocols should result in EFI_INVALID_PARAMETER + // + Status =3D EfiLocateProtocolBuffer (&gEfiCallerIdGuid, NULL, &Buffer); + UT_ASSERT_EQUAL (EFI_INVALID_PARAMETER, Status); + + // + // NULL Buffer should result in EFI_INVALID_PARAMETER + // + Status =3D EfiLocateProtocolBuffer (&gEfiCallerIdGuid, &NoProtocols, NUL= L); + UT_ASSERT_EQUAL (EFI_INVALID_PARAMETER, Status); + + // + // All NULL should result in EFI_INVALID_PARAMETER + // + Status =3D EfiLocateProtocolBuffer (NULL, NULL, NULL); + UT_ASSERT_EQUAL (EFI_INVALID_PARAMETER, Status); + + // + // Request for unknown protocol should result in EFI_NOT_FOUND + // + NoProtocols =3D 0; + Buffer =3D NULL; + Status =3D EfiLocateProtocolBuffer (&mUnitTestProtocolGuid, &NoProtocols= , &Buffer); + UT_ASSERT_EQUAL (EFI_NOT_FOUND, Status); + + // + // Request for Loaded Image Protocol should result in EFI_SUCCESS + // + NoProtocols =3D 0; + Buffer =3D NULL; + Status =3D EfiLocateProtocolBuffer (&gEfiLoadedImageProtocolGuid, &NoPro= tocols, &Buffer); + UT_ASSERT_EQUAL (EFI_SUCCESS, Status); + UT_ASSERT_TRUE (NoProtocols > 0); + UT_ASSERT_NOT_NULL (Buffer); + + if (Buffer !=3D NULL) { + FreePool (Buffer); + } + + // + // Install 1 instance of a protocol + // + Handle1 =3D NULL; + Status =3D gBS->InstallProtocolInterface ( + &Handle1, + &mUnitTestProtocolGuid, + EFI_NATIVE_INTERFACE, + NULL + ); + + // + // Verify 1 instance found + // + NoProtocols =3D 0; + Buffer =3D NULL; + Status =3D EfiLocateProtocolBuffer (&mUnitTestProtocolGuid, &NoProtocols= , &Buffer); + UT_ASSERT_EQUAL (EFI_SUCCESS, Status); + UT_ASSERT_EQUAL (NoProtocols, 1); + UT_ASSERT_EQUAL ((UINTN)Buffer[0], (UINTN)NULL); + + if (Buffer !=3D NULL) { + FreePool (Buffer); + } + + // + // Install a 2nd instance of a protocol + // + Handle2 =3D NULL; + Status =3D gBS->InstallProtocolInterface ( + &Handle2, + &mUnitTestProtocolGuid, + EFI_NATIVE_INTERFACE, + &Instance2 + ); + + // + // Verify 2 instances found + // + NoProtocols =3D 0; + Buffer =3D NULL; + Status =3D EfiLocateProtocolBuffer (&mUnitTestProtocolGuid, &NoProtocols= , &Buffer); + UT_ASSERT_EQUAL (EFI_SUCCESS, Status); + UT_ASSERT_EQUAL (NoProtocols, 2); + UT_ASSERT_EQUAL ((UINTN)Buffer[0], (UINTN)NULL); + UT_ASSERT_EQUAL ((UINTN)Buffer[1], (UINTN)&Instance2); + + if (Buffer !=3D NULL) { + FreePool (Buffer); + } + + // + // Install a 3rd instance of a protocol + // + Handle3 =3D NULL; + Status =3D gBS->InstallProtocolInterface ( + &Handle3, + &mUnitTestProtocolGuid, + EFI_NATIVE_INTERFACE, + &Instance3 + ); + + // + // Verify 3 instances found + // + NoProtocols =3D 0; + Buffer =3D NULL; + Status =3D EfiLocateProtocolBuffer (&mUnitTestProtocolGuid, &NoProtocols= , &Buffer); + UT_ASSERT_EQUAL (EFI_SUCCESS, Status); + UT_ASSERT_EQUAL (NoProtocols, 3); + UT_ASSERT_EQUAL ((UINTN)Buffer[0], (UINTN)NULL); + UT_ASSERT_EQUAL ((UINTN)Buffer[1], (UINTN)&Instance2); + UT_ASSERT_EQUAL ((UINTN)Buffer[2], (UINTN)&Instance3); + + if (Buffer !=3D NULL) { + FreePool (Buffer); + } + + // + // Uninstall test protocols + // + Status =3D gBS->UninstallProtocolInterface ( + Handle3, + &mUnitTestProtocolGuid, + &Instance3 + ); + + Status =3D gBS->UninstallProtocolInterface ( + Handle2, + &mUnitTestProtocolGuid, + &Instance2 + ); + + Status =3D gBS->UninstallProtocolInterface ( + Handle1, + &mUnitTestProtocolGuid, + NULL + ); + + return UNIT_TEST_PASSED; +} + +/** + + Main fuction sets up the unit test environment + +**/ +EFI_STATUS +EFIAPI +UefiMain ( + IN EFI_HANDLE ImageHandle, + IN EFI_SYSTEM_TABLE *SystemTable + ) +{ + EFI_STATUS Status; + UNIT_TEST_FRAMEWORK *Fw; + UNIT_TEST_SUITE *ProtocolTestSuite; + CHAR16 ShortName[100]; + + + DEBUG ((DEBUG_INFO, "%s v%s\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSIO= N)); + + ShortName[0] =3D L'\0'; + UnicodeSPrint (&ShortName[0], sizeof (ShortName), L"%a", gEfiCallerBaseN= ame); + + // + // Start setting up the test framework for running the tests. + // + Fw =3D NULL; + Status =3D InitUnitTestFramework (&Fw, UNIT_TEST_APP_NAME, ShortName, UN= IT_TEST_APP_VERSION); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status =3D %r\n= ", Status)); + goto EXIT; + } + + // + // Test the protocol functions + // + Status =3D CreateUnitTestSuite ( + &ProtocolTestSuite, + Fw, + L"Uefi Lib Test Suite", + L"Common.UefiLib.Protocol", + NULL, NULL + ); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for Protocol Test = Suite\n")); + Status =3D EFI_OUT_OF_RESOURCES; + goto EXIT; + } + + // + // Add test protocol test cases + // + AddTestCase (ProtocolTestSuite, L"Test EfiLocateProtocolBuffer", L"Co= mmon.UefiLib.Protocol.EfiLocateProtocolBuffer", TestEfiLocateProtocolBuf= fer, NULL, NULL, NULL); + + // + // Execute the tests. + // + Status =3D RunAllTestSuites (Fw); + +EXIT: + if (Fw) { + FreeUnitTestFramework (Fw); + } + + return Status; +} diff --git a/MdePkgUnitTest/UefiLib/UefiLibUnitTests.inf b/MdePkgUnitTest/U= efiLib/UefiLibUnitTests.inf new file mode 100644 index 0000000000..b7913c9105 --- /dev/null +++ b/MdePkgUnitTest/UefiLib/UefiLibUnitTests.inf @@ -0,0 +1,46 @@ +## @file +# Uefi Shell based Application that Unit Tests the UefiLib +# +# Copyright (c) 2018, Intel Corporation. All rights reserved.
+# This program and the accompanying materials +# are licensed and made available under the terms and conditions of the B= SD License +# which accompanies this distribution. The full text of the license may = be found at +# http://opensource.org/licenses/bsd-license.php +# +# THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS, +# WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IM= PLIED. +# +## + +[Defines] + INF_VERSION =3D 0x00010005 + BASE_NAME =3D UefiLibUnitTestApp + FILE_GUID =3D BD9FC1C5-A381-4201-BD8A-4EC78A6F3A17 + MODULE_TYPE =3D UEFI_APPLICATION + VERSION_STRING =3D 1.0 + ENTRY_POINT =3D UefiMain + +# +# The following information is for reference only and not required by the = build tools. +# +# VALID_ARCHITECTURES =3D IA32 X64 +# + +[Sources] + UefiLibUnitTests.c + +[Packages] + MdePkg/MdePkg.dec + MsUnitTestPkg/MsUnitTestPkg.dec + MdeModulePkg/MdeModulePkg.dec + +[LibraryClasses] + UefiApplicationEntryPoint + BaseLib + UefiLib + UnitTestLib + UnitTestAssertLib + PrintLib + +[Protocols] + gEfiLoadedImageProtocolGuid --=20 2.14.2.windows.3 _______________________________________________ edk2-devel mailing list edk2-devel@lists.01.org https://lists.01.org/mailman/listinfo/edk2-devel