From nobody Fri Nov 1 10:33:30 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 1517441791621244.81071418158467; Wed, 31 Jan 2018 15:36:31 -0800 (PST) Received: from [127.0.0.1] (localhost [IPv6:::1]) by ml01.01.org (Postfix) with ESMTP id 6A0DA21E256BD; Wed, 31 Jan 2018 15:30:53 -0800 (PST) Received: from mga17.intel.com (mga17.intel.com [192.55.52.151]) (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 67D0522393656 for ; Wed, 31 Jan 2018 15:30:51 -0800 (PST) Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 31 Jan 2018 15:36:25 -0800 Received: from mdkinney-mobl2.amr.corp.intel.com ([10.252.134.85]) by FMSMGA003.fm.intel.com with ESMTP; 31 Jan 2018 15:36:24 -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=192.55.52.151; helo=mga17.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,442,1511856000"; d="scan'208";a="23982700" From: "Kinney, Michael D" To: edk2-devel@lists.01.org Date: Wed, 31 Jan 2018 15:36:21 -0800 Message-Id: <20180131233621.15896-1-michael.d.kinney@intel.com> X-Mailer: git-send-email 2.14.2.windows.3 Subject: [edk2] [staging/edk2-test Patch] 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 --- MdePkgUnitTest/MdePkgUnitTest.dsc | 8 +- MdePkgUnitTest/UefiLib/UefiLibUnitTests.c | 266 ++++++++++++++++++++++++= ++++ MdePkgUnitTest/UefiLib/UefiLibUnitTests.inf | 46 +++++ 3 files changed, 319 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..3f021639b2 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,13 @@ 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 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