From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by mx.groups.io with SMTP id smtpd.web09.90093.1638351845420465253 for ; Wed, 01 Dec 2021 01:44:06 -0800 Authentication-Results: mx.groups.io; dkim=missing; spf=pass (domain: huawei.com, ip: 45.249.212.188, mailfrom: xiewenyi2@huawei.com) Received: from dggemv704-chm.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4J3vL35fYBzbj7g; Wed, 1 Dec 2021 17:43:55 +0800 (CST) Received: from kwepemm600004.china.huawei.com (7.193.23.242) by dggemv704-chm.china.huawei.com (10.3.19.47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 1 Dec 2021 17:44:03 +0800 Received: from kwephisprg16640.huawei.com (10.247.83.252) by kwepemm600004.china.huawei.com (7.193.23.242) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Wed, 1 Dec 2021 17:44:02 +0800 From: "wenyi,xie" To: , , , , CC: , Subject: [PATCH EDK2 v1 1/1] MdeModulePkg/FrameBufferBltLib:Add unit test Date: Wed, 1 Dec 2021 17:43:57 +0800 Message-ID: <20211201094357.2804827-2-xiewenyi2@huawei.com> X-Mailer: git-send-email 2.18.0.huawei.25 In-Reply-To: <20211201094357.2804827-1-xiewenyi2@huawei.com> References: <20211201094357.2804827-1-xiewenyi2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.247.83.252] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected Content-Type: text/plain Add unit test for FrameBufferBltLib. Cc: Jian J Wang Cc: Liming Gao Cc: Zhichao Gao Cc: Ray Ni Signed-off-by: Wenyi Xie --- MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 5 + MdeModulePkg/Library/FrameBufferBltLib/UnitTest/FrameBufferBltLibUnitTest.inf | 32 ++++ MdeModulePkg/Library/FrameBufferBltLib/UnitTest/FrameBufferBltLibUnitTest.c | 174 ++++++++++++++++++++ MdeModulePkg/MdeModulePkg.ci.yaml | 1 + 4 files changed, 212 insertions(+) diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc index c9ec835df65d..e08bf7d95fe7 100644 --- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc +++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc @@ -47,3 +47,8 @@ [Components] UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf } + + MdeModulePkg/Library/FrameBufferBltLib/UnitTest/FrameBufferBltLibUnitTest.inf { + + FrameBufferBltLib|MdeModulePkg/Library/FrameBufferBltLib/FrameBufferBltLib.inf + } diff --git a/MdeModulePkg/Library/FrameBufferBltLib/UnitTest/FrameBufferBltLibUnitTest.inf b/MdeModulePkg/Library/FrameBufferBltLib/UnitTest/FrameBufferBltLibUnitTest.inf new file mode 100644 index 000000000000..de32f2d93ba6 --- /dev/null +++ b/MdeModulePkg/Library/FrameBufferBltLib/UnitTest/FrameBufferBltLibUnitTest.inf @@ -0,0 +1,32 @@ +## @file +# This is a unit test for the FrameBufferBltLib. +# +# Copyright (C) Huawei Technologies Co., Ltd. All rights reserved +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION = 0x00010017 + BASE_NAME = FrameBufferBltLibUnitTest + FILE_GUID = E9E25A30-D34A-8E09-F9D1-40249AB39778 + 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] + FrameBufferBltLibUnitTest.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + UnitTestLib + DebugLib + FrameBufferBltLib diff --git a/MdeModulePkg/Library/FrameBufferBltLib/UnitTest/FrameBufferBltLibUnitTest.c b/MdeModulePkg/Library/FrameBufferBltLib/UnitTest/FrameBufferBltLibUnitTest.c new file mode 100644 index 000000000000..0d157f55cb69 --- /dev/null +++ b/MdeModulePkg/Library/FrameBufferBltLib/UnitTest/FrameBufferBltLibUnitTest.c @@ -0,0 +1,174 @@ +/** @file + Unit tests of the FrameBufferBltLib + + Copyright (C) Huawei Technologies Co., Ltd. All rights reserved + SPDX-License-Identifier: BSD-2-Clause-Patent + +**/ + +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include +#include + +#define UNIT_TEST_APP_NAME "FrameBufferBltLib Unit Tests" +#define UNIT_TEST_APP_VERSION "1.0" + +struct FRAME_BUFFER_CONFIGURE { + UINT32 PixelsPerScanLine; + UINT32 BytesPerPixel; + UINT32 Width; + UINT32 Height; + UINT8 *FrameBuffer; + EFI_GRAPHICS_PIXEL_FORMAT PixelFormat; + EFI_PIXEL_BITMASK PixelMasks; + INT8 PixelShl[4]; // R-G-B-Rsvd + INT8 PixelShr[4]; // R-G-B-Rsvd + UINT8 LineBuffer[0]; +}; + +typedef struct { + EFI_GRAPHICS_OUTPUT_MODE_INFORMATION Information; + RETURN_STATUS ExpectedResult; +} BASIC_TEST_CONTEXT; + +static BASIC_TEST_CONTEXT mBasicTestTrue1 = { + {0, 1920, 1080, PixelRedGreenBlueReserved8BitPerColor, {0, 0, 0, 0}, 1920}, + RETURN_SUCCESS +}; + +static BASIC_TEST_CONTEXT mBasicTestFalse1 = { + {0, 1920, 1080, PixelRedGreenBlueReserved8BitPerColor, {0, 0, 0, 0}, 1080}, + RETURN_UNSUPPORTED +}; + +/** + Unit test for FrameBufferBltConfigure () API of the FrameBufferBltLib. + + @param[in] Context [Optional] An optional parameter that enables: + 1) test-case reuse with varied parameters and + 2) test-case re-entry for Target tests that need a + reboot. This parameter is a VOID* and it is the + responsibility of the test author to ensure that the + contents are well understood by all test cases that may + consume it. + + @retval UNIT_TEST_PASSED The Unit test has completed and the test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +FrameBufferBltConfigureTest ( + IN UNIT_TEST_CONTEXT Context + ) +{ + RETURN_STATUS Result; + VOID *FrameBuffer; + BASIC_TEST_CONTEXT *BasicContext; + FRAME_BUFFER_CONFIGURE Configure; + UINTN ConfigureSize; + + FrameBuffer = NULL; + + //FrameBufferInfoInitial (&FrameBufferInfo); + BasicContext = (BASIC_TEST_CONTEXT*)Context; + Result = FrameBufferBltConfigure (FrameBuffer, &(BasicContext->Information), &Configure, &ConfigureSize); + UT_ASSERT_TRUE (Result == BasicContext->ExpectedResult); + + return UNIT_TEST_PASSED; +} + +/** + Initialze the unit test framework, suite, and unit tests for the + FrameBufferBltLib and run the FrameBufferBltLib unit test. + + @retval EFI_SUCCESS All test cases were dispatched. + @retval EFI_OUT_OF_RESOURCES There are not enough resources available to + initialize the unit tests. +**/ +STATIC +EFI_STATUS +EFIAPI +UnitTestingEntry ( + VOID + ) +{ + EFI_STATUS Status; + UNIT_TEST_FRAMEWORK_HANDLE Framework; + UNIT_TEST_SUITE_HANDLE SortTests; + + Framework = NULL; + + DEBUG(( DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION )); + + // + // Start setting up the test framework for running the tests. + // + Status = InitUnitTestFramework (&Framework, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status)); + goto EXIT; + } + + // + // Populate the FrameBufferBltLib Unit Test Suite. + // + Status = CreateUnitTestSuite (&SortTests, Framework, "FrameBufferBltLib Tests", "FrameBufferBltLib.Configure", NULL, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for FrameBufferBltLib API Tests\n")); + Status = EFI_OUT_OF_RESOURCES; + goto EXIT; + } + + // + // -------------Suite-----------Description----------Name-------------Function-------------Pre---Post---Context----------- + // + AddTestCase (SortTests, "Create the configuration", "Sort", FrameBufferBltConfigureTest, NULL, NULL, &mBasicTestTrue1); + AddTestCase (SortTests, "Create the configuration", "Sort", FrameBufferBltConfigureTest, NULL, NULL, &mBasicTestFalse1); + + // + // Execute the tests. + // + Status = RunAllTestSuites (Framework); + +EXIT: + if (Framework) { + FreeUnitTestFramework (Framework); + } + + return Status; +} + +/// +/// Avoid ECC error for function name that starts with lower case letter +/// +#define FrameBufferBltLibUnitTestMain main + +/** + Standard POSIX C entry point for host based unit test execution. + + @param[in] Argc Number of arguments + @param[in] Argv Array of pointers to arguments + + @retval 0 Success + @retval other Error +**/ +INT32 +FrameBufferBltLibUnitTestMain ( + IN INT32 Argc, + IN CHAR8 *Argv[] + ) +{ + UnitTestingEntry (); + return 0; +} diff --git a/MdeModulePkg/MdeModulePkg.ci.yaml b/MdeModulePkg/MdeModulePkg.ci.yaml index f69989087b4c..58dfc3659718 100644 --- a/MdeModulePkg/MdeModulePkg.ci.yaml +++ b/MdeModulePkg/MdeModulePkg.ci.yaml @@ -20,6 +20,7 @@ "8005", "UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGE.UID", "8005", "UNIVERSAL_PAYLOAD_PCI_ROOT_BRIDGE.HID", "8001", "UefiSortLibUnitTestMain", + "8001", "FrameBufferBltLibUnitTestMain", ], ## Both file path and directory path are accepted. "IgnoreFiles": [ -- 2.20.1.windows.1