From nobody Fri Mar 29 07:19:26 2024 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+96346+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+96346+1787277+3901457@groups.io ARC-Seal: i=1; a=rsa-sha256; t=1668427690; cv=none; d=zohomail.com; s=zohoarc; b=Njp7QHu0/w9whQtScAftFwXOIgoZ5UQvN8JC8XfiIYerNUiU8T79WUiq5hmkEqd75PKht1TiAkC0ZlkKKuxvbGdKqsywySJ4wkKHbNUZ9/xYAys2vhJzOd3fl4zXwzFtVzZMcpLcsSFuU3B+TSAa2s7wn1UAXyY+9ENwX0EDCpE= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1668427690; h=Content-Type: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=ZpUlzNNnLv0K5zdoROu7WxrOAyod0Lj6dMxqo0NS5W0=; b=UapWdsCgPK01uKlLKMIti5BvXfIJkWNa+2FjciDOICdYbX0P+JHzYFERHjN/zyEqWPVv/o6JS+rqKb0e1nHjZC4MOwKSBEXUnTLLGTYI6uYgq8M5CyhzwyFvWwl0aoC6dTmFq3y0yPHPan6srwGNIwO5VBxZEVSpDumxWl7GMC8= 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+96346+1787277+3901457@groups.io Received: from mail02.groups.io (mail02.groups.io [66.175.222.108]) by mx.zohomail.com with SMTPS id 1668427690811170.8214412802763; Mon, 14 Nov 2022 04:08:10 -0800 (PST) Return-Path: X-Received: by 127.0.0.2 with SMTP id cbfrYY1788612x5pPGziAvv3; Mon, 14 Nov 2022 04:08:09 -0800 X-Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by mx.groups.io with SMTP id smtpd.web09.4757.1668427688339765151 for ; Mon, 14 Nov 2022 04:08:09 -0800 X-Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4N9p3N4mTcz15MdX; Mon, 14 Nov 2022 20:07:44 +0800 (CST) X-Received: from kwepemm600004.china.huawei.com (7.193.23.242) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.31; Mon, 14 Nov 2022 20:08:03 +0800 X-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.2375.31; Mon, 14 Nov 2022 20:08:02 +0800 From: "wenyi,xie via groups.io" To: , , , , CC: , Subject: [edk2-devel] [PATCH EDK2 v1 1/1] MdeModulePkg/BaseBmpSupportLib:Add unit test Date: Mon, 14 Nov 2022 20:07:43 +0800 Message-ID: <20221114120743.3615088-2-xiewenyi2@huawei.com> In-Reply-To: <20221114120743.3615088-1-xiewenyi2@huawei.com> References: <20221114120743.3615088-1-xiewenyi2@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.247.83.252] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemm600004.china.huawei.com (7.193.23.242) X-CFilter-Loop: Reflected 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,xiewenyi2@huawei.com X-Gm-Message-State: 2hBvpED64TwqxdIc5rKgZk0Ax1787277AA= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=groups.io; q=dns/txt; s=20140610; t=1668427689; bh=2IS+/jCoc+i+TJVmJ1LvMAe7lJGWCgL/N+V2k5xC1/8=; h=CC:Content-Type:Date:From:Reply-To:Subject:To; b=N3M+EM50IgiOwzFr0WB5NfiILZhf86J2wbgtqydmfW4cUfb7MA0e14JVHDQnKljnJdk l7z+wFJOJP1gNXdpABBQ8EfwhfEnvL43CxD/7zFwwqpqB7P1tE+kbBekulw0O6oXVQc8h 99tkBnTdwu2LcWWJUBxcyvN91XZ88HS2tcM= X-ZohoMail-DKIM: pass (identity @groups.io) X-ZM-MESSAGEID: 1668427691191100005 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add unit test for function TranslateBmpToGopBlt in BaseBmpSupportLib. As the translation will fail when color map size is zero and this problem is not solved yet, temporarily mask the fail case check. 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/BaseBmpSupportLib/UnitTest/BaseBmpSupportLibUnitTest.= inf | 33 ++ MdeModulePkg/Library/BaseBmpSupportLib/UnitTest/BaseBmpSupportLibUnitTest.= c | 345 ++++++++++++++++++++ MdeModulePkg/MdeModulePkg.ci.yaml = | 1 + 4 files changed, 384 insertions(+) diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test= /MdeModulePkgHostTest.dsc index c9ec835df65d..4ca54dcca5c7 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/BaseBmpSupportLib/UnitTest/BaseBmpSupportLibUnitTes= t.inf { + + BaseBmpSupportLib|MdeModulePkg/Library/BaseBmpSupportLib/BaseBmpSupp= ortLib.inf + } diff --git a/MdeModulePkg/Library/BaseBmpSupportLib/UnitTest/BaseBmpSupport= LibUnitTest.inf b/MdeModulePkg/Library/BaseBmpSupportLib/UnitTest/BaseBmpSu= pportLibUnitTest.inf new file mode 100644 index 000000000000..d4eb6732d2fb --- /dev/null +++ b/MdeModulePkg/Library/BaseBmpSupportLib/UnitTest/BaseBmpSupportLibUnit= Test.inf @@ -0,0 +1,33 @@ +## @file +# This is a unit test for the BaseBmpSupportLib. +# +# Copyright (C) Huawei Technologies Co., Ltd. All rights reserved +# SPDX-License-Identifier: BSD-2-Clause-Patent +## + +[Defines] + INF_VERSION =3D 0x00010017 + BASE_NAME =3D BaseBmpSupportLibUnitTest + FILE_GUID =3D EA3E37BF-CA48-6816-406C-B10CFB1DDAD4 + 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] + BaseBmpSupportLibUnitTest.c + +[Packages] + MdePkg/MdePkg.dec + MdeModulePkg/MdeModulePkg.dec + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec + +[LibraryClasses] + UnitTestLib + DebugLib + BaseMemoryLib + BaseBmpSupportLib diff --git a/MdeModulePkg/Library/BaseBmpSupportLib/UnitTest/BaseBmpSupport= LibUnitTest.c b/MdeModulePkg/Library/BaseBmpSupportLib/UnitTest/BaseBmpSupp= ortLibUnitTest.c new file mode 100644 index 000000000000..dd3520cb97a9 --- /dev/null +++ b/MdeModulePkg/Library/BaseBmpSupportLib/UnitTest/BaseBmpSupportLibUnit= Test.c @@ -0,0 +1,345 @@ +/** @file + Unit tests of the BaseBmpSupportLib + + 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 +#include + +#include +#include + +#define UNIT_TEST_APP_NAME "BaseBmpSupportLib Unit Tests" +#define UNIT_TEST_APP_VERSION "1.0" + +// Bmp file header template +static BMP_IMAGE_HEADER mBmpHeader =3D { + 'B', //= CharB + 'M', //= CharM + 0, //= Image Size + { 0, 0 }, //= Reserved + sizeof (BMP_IMAGE_HEADER), //= ImageOffset + sizeof (BMP_IMAGE_HEADER) - OFFSET_OF (BMP_IMAGE_HEADER, HeaderSize), //= HeaderSize + 4, //= PixelWidth + 4, //= PixelHeight + 1, //= Planes + 8, //= BitPerPixel + 0, //= CompressionType + 0, //= DataSize + 0, //= XPixelsPerMeter + 0, //= YPixelsPerMeter + 0, //= NumberOfColors + 0 //= ImportantColors +}; + +/** + Create the bmp file. + + @param BmpImage Bmp file image. + @param PixelHeight Bmp file Height. + @param PixelWidth Bmp file Width. + @param BitPerPixel Bit per pixel. + @param ColorMap Color map. + @param ColorMapSize Color map size. + @param Data Bmp file data. + @param DataSize Bmp file data size. + + @retval UNIT_TEST_PASSED Test passed. + @retval others Test failed. +**/ +RETURN_STATUS +CreateBmpFile ( + IN OUT VOID **BmpImage, + IN UINT32 PixelHeight, + IN UINT32 PixelWidth, + IN UINT16 BitPerPixel, + IN UINT8 *ColorMap, + IN UINT32 ColorMapSize, + IN UINT8 *Data, + IN UINT32 DataSize + ) +{ + UINT32 length; + BMP_IMAGE_HEADER Header; + + length =3D 0; + CopyMem (&Header, &mBmpHeader, sizeof (BMP_IMAGE_HEADER)); + Header.Size =3D sizeof (BMP_IMAGE_HEADER) + ColorMapSize + DataSi= ze; + Header.PixelWidth =3D PixelHeight; + Header.PixelHeight =3D PixelWidth; + Header.BitPerPixel =3D BitPerPixel; + Header.ImageOffset =3D Header.Size - sizeof (BMP_IMAGE_HEADER) - ColorMa= pSize; + Header.ImageSize =3D DataSize; + + *BmpImage =3D AllocateZeroPool (Header.Size); + if (*BmpImage =3D=3D NULL) { + return EFI_OUT_OF_RESOURCES; + } + + CopyMem ((UINT8 *)*BmpImage, &Header, sizeof (BMP_IMAGE_HEADER)); + + length =3D sizeof (BMP_IMAGE_HEADER); + if ((ColorMap !=3D NULL) && (ColorMapSize !=3D 0)) { + CopyMem ((UINT8 *)*BmpImage + length, ColorMap, ColorMapSize); + } + + length +=3D ColorMapSize; + if ((Data !=3D NULL) && (DataSize !=3D 0)) { + CopyMem ((UINT8 *)*BmpImage + length, Data, DataSize); + } + + return EFI_SUCCESS; +} + +/** + Unit test for TranslateBmpToGopBlt () API of the BaseBmpSupportLib. + + @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 th= at may + consume it. + + @retval UNIT_TEST_PASSED The Unit test has completed and th= e test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TranslateBmpShouldSuccess ( + IN UNIT_TEST_CONTEXT Context + ) +{ + VOID *BmpImage; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *GopBlt; + UINTN GopBltSize; + UINTN PixelHeight; + UINTN PixelWidth; + UINT32 ImageHeight; + UINT32 ImageWidth; + UINT16 BitPerPixel; + UINT8 *ColorMap; + UINT32 ColorMapSize; + UINT8 *Data; + UINT32 DataSize; + UINT32 Size; + RETURN_STATUS Status; + + ColorMap =3D NULL; + Data =3D NULL; + ImageHeight =3D 4; + ImageWidth =3D 4; + BitPerPixel =3D 8; + ColorMapSize =3D 256 * 4; + DataSize =3D 0x10; + Size =3D sizeof (BMP_IMAGE_HEADER) + ColorMapSize + DataSize; + + // + // Set color map to NULL so that Translate will fail. + // + ColorMap =3D AllocateZeroPool (ColorMapSize); + if (ColorMap =3D=3D NULL) { + return UNIT_TEST_ERROR_TEST_FAILED; + } + + // + // Initial the data section in image file. + // + Data =3D AllocateZeroPool (DataSize); + if (Data =3D=3D NULL) { + return UNIT_TEST_ERROR_TEST_FAILED; + } + + Status =3D CreateBmpFile (&BmpImage, ImageHeight, ImageWidth, BitPerPixe= l, ColorMap, ColorMapSize, Data, DataSize); + + Status =3D TranslateBmpToGopBlt (BmpImage, Size, &GopBlt, &GopBltSize, &= PixelHeight, &PixelWidth); + UT_ASSERT_TRUE (EFI_ERROR (Status)); + + if (BmpImage !=3D NULL) { + FreePool (BmpImage); + } + + if (ColorMap !=3D NULL) { + FreePool (ColorMap); + } + + if (Data !=3D NULL) { + FreePool (Data); + } + + return UNIT_TEST_PASSED; +} + +/** + Unit test for TranslateBmpToGopBlt () API of the BaseBmpSupportLib. + + @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 th= at may + consume it. + + @retval UNIT_TEST_PASSED The Unit test has completed and th= e test + case was successful. + @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed. +**/ +UNIT_TEST_STATUS +EFIAPI +TranslateBmpShouldFailed ( + IN UNIT_TEST_CONTEXT Context + ) +{ + VOID *BmpImage; + EFI_GRAPHICS_OUTPUT_BLT_PIXEL *GopBlt; + UINTN GopBltSize; + UINTN PixelHeight; + UINTN PixelWidth; + UINT32 ImageHeight; + UINT32 ImageWidth; + UINT16 BitPerPixel; + UINT8 *ColorMap; + UINT32 ColorMapSize; + UINT8 *Data; + UINT32 DataSize; + UINT32 Size; + + ImageHeight =3D 4; + ImageWidth =3D 4; + BitPerPixel =3D 8; + DataSize =3D 0x10; + // + // Set color map to NULL so that Translate will fail. + // + ColorMap =3D NULL; + ColorMapSize =3D 0; + Size =3D sizeof (BMP_IMAGE_HEADER) + ColorMapSize + DataSize; + + // + // Initial the data section in image file. + // + Data =3D AllocateZeroPool (DataSize); + if (Data =3D=3D NULL) { + return UNIT_TEST_ERROR_TEST_FAILED; + } + + CreateBmpFile (&BmpImage, ImageHeight, ImageWidth, BitPerPixel, ColorMap= , ColorMapSize, Data, DataSize); + + TranslateBmpToGopBlt (BmpImage, Size, &GopBlt, &GopBltSize, &PixelHeight= , &PixelWidth); + + if (BmpImage !=3D NULL) { + FreePool (BmpImage); + } + + if (ColorMap !=3D NULL) { + FreePool (ColorMap); + } + + if (Data !=3D NULL) { + FreePool (Data); + } + + return UNIT_TEST_PASSED; +} + +/** + Initialze the unit test framework, suite, and unit tests for the + BaseBmpSupportLib and run the BaseBmpSupportLib 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 =3D NULL; + + DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSIO= N)); + + // + // Start setting up the test framework for running the tests. + // + Status =3D InitUnitTestFramework (&Framework, UNIT_TEST_APP_NAME, gEfiCa= llerBaseName, UNIT_TEST_APP_VERSION); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status =3D %r\n= ", Status)); + goto EXIT; + } + + // + // Populate the BaseBmpSupportLib Unit Test Suite. + // + Status =3D CreateUnitTestSuite (&SortTests, Framework, "BaseBmpSupportLi= b Translate Tests", "BaseBmpSupportLib", NULL, NULL); + if (EFI_ERROR (Status)) { + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for BaseBmpSupport= Lib API Tests\n")); + Status =3D EFI_OUT_OF_RESOURCES; + goto EXIT; + } + + // + // --------------Suite--------Description------------Name--------------F= unction-------------Pre---Post---Context--- + // + AddTestCase (SortTests, "Translate Bmp1 To GopBlt", "Translate1", Transl= ateBmpShouldSuccess, NULL, NULL, NULL); + AddTestCase (SortTests, "Translate Bmp2 To GopBlt", "Translate2", Transl= ateBmpShouldFailed, NULL, NULL, NULL); + + // + // Execute the tests. + // + Status =3D RunAllTestSuites (Framework); + +EXIT: + if (Framework) { + FreeUnitTestFramework (Framework); + } + + return Status; +} + +/// +/// Avoid ECC error for function name that starts with lower case letter +/// +#define BaseBmpSupportLibUnitTestMain 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 +BaseBmpSupportLibUnitTestMain ( + IN INT32 Argc, + IN CHAR8 *Argv[] + ) +{ + UnitTestingEntry (); + return 0; +} diff --git a/MdeModulePkg/MdeModulePkg.ci.yaml b/MdeModulePkg/MdeModulePkg.= ci.yaml index f69989087b4c..5d64a7e47116 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", "BaseBmpSupportLibUnitTestMain", ], ## Both file path and directory path are accepted. "IgnoreFiles": [ --=20 2.20.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 (#96346): https://edk2.groups.io/g/devel/message/96346 Mute This Topic: https://groups.io/mt/95017176/1787277 Group Owner: devel+owner@edk2.groups.io Unsubscribe: https://edk2.groups.io/g/devel/unsub [importer@patchew.org] -=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-=3D-