* [PATCH EDK2 v1 0/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
@ 2021-07-28 5:58 wenyi,xie
2021-07-28 5:58 ` [PATCH EDK2 v1 1/1] " wenyi,xie
0 siblings, 1 reply; 4+ messages in thread
From: wenyi,xie @ 2021-07-28 5:58 UTC (permalink / raw)
To: devel, jian.j.wang, hao.a.wu; +Cc: songdongkuang, xiewenyi2
Main Changes :
Adding unit test for UefiSortLib.
Wenyi Xie (1):
MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 6 +
MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf | 32 ++++
MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c | 188 ++++++++++++++++++++
3 files changed, 226 insertions(+)
create mode 100644 MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
create mode 100644 MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
--
2.20.1.windows.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH EDK2 v1 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
2021-07-28 5:58 [PATCH EDK2 v1 0/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test wenyi,xie
@ 2021-07-28 5:58 ` wenyi,xie
2021-07-29 5:42 ` Wu, Hao A
0 siblings, 1 reply; 4+ messages in thread
From: wenyi,xie @ 2021-07-28 5:58 UTC (permalink / raw)
To: devel, jian.j.wang, hao.a.wu; +Cc: songdongkuang, xiewenyi2
Adding unit test for UefiSortLib.
Cc: Jian J Wang <jian.j.wang@intel.com>
Cc: Hao A Wu <hao.a.wu@intel.com>
Signed-off-by: Wenyi Xie <xiewenyi2@huawei.com>
---
MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 6 +
MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf | 32 ++++
MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c | 188 ++++++++++++++++++++
3 files changed, 226 insertions(+)
diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
index 4da4692c8451..c9ec835df65d 100644
--- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
+++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
@@ -41,3 +41,9 @@ [Components]
<PcdsFixedAtBuild>
gEfiMdeModulePkgTokenSpaceGuid.PcdAllowVariablePolicyEnforcementDisable|TRUE
}
+
+ MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf {
+ <LibraryClasses>
+ UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
+ DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
+ }
diff --git a/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
new file mode 100644
index 000000000000..d9dac307934e
--- /dev/null
+++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
@@ -0,0 +1,32 @@
+## @file
+# This is a unit test for the UefiSortLib.
+#
+# Copyright (c) Microsoft Corporation.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010017
+ BASE_NAME = UefiSortLibUnitTest
+ FILE_GUID = 271337A3-0D79-BA3E-BC03-714E518E3B1B
+ 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]
+ UefiSortLibUnitTest.c
+
+[Packages]
+ MdePkg/MdePkg.dec
+ MdeModulePkg/MdeModulePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+ UnitTestLib
+ DebugLib
+ UefiSortLib
diff --git a/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
new file mode 100644
index 000000000000..f2f89daef7ba
--- /dev/null
+++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
@@ -0,0 +1,188 @@
+/** @file
+ Unit tests of the UefiSortLib
+
+ Copyright (C) Huawei Technologies Co., Ltd. All rights reserved
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include <stdio.h>
+#include <string.h>
+#include <stdarg.h>
+#include <stddef.h>
+#include <setjmp.h>
+#include <cmocka.h>
+
+#include <Uefi.h>
+#include <Library/BaseLib.h>
+#include <Library/DebugLib.h>
+#include <Library/MemoryAllocationLib.h>
+
+#include <Library/UnitTestLib.h>
+#include <Library/SortLib.h>
+
+#define UNIT_TEST_APP_NAME "UefiSortLib Unit Tests"
+#define UNIT_TEST_APP_VERSION "1.0"
+
+#define TEST_ARRAY_SIZE_9 9
+
+/**
+ The function is called by PerformQuickSort to compare int values.
+
+ @param[in] Left The pointer to first buffer.
+ @param[in] Right The pointer to second buffer.
+
+ @retval 0 Buffer1 equal to Buffer2.
+ @return <0 Buffer1 is less than Buffer2.
+ @return >0 Buffer1 is greater than Buffer2.
+
+**/
+INTN
+EFIAPI
+TestCompareFunction (
+ 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;
+}
+
+/**
+ Unit test for PerformQuickSort () API of the UefiSortLib.
+
+ @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
+SortUINT32ArrayShouldSucceed (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ UINTN TestCount = TEST_ARRAY_SIZE_9;
+ UINT32 TestBuffer[TEST_ARRAY_SIZE_9] = {1, 2, 3, 4, 5, 6, 7 ,8, 9};
+ UINT32 TestResult[TEST_ARRAY_SIZE_9] = {9, 8, 7, 6, 5, 4, 3, 2, 1};
+
+ PerformQuickSort (TestBuffer, TestCount, sizeof (UINT32), (SORT_COMPARE)TestCompareFunction);
+ UT_ASSERT_MEM_EQUAL (TestBuffer, TestResult, sizeof (UINT32) * TEST_ARRAY_SIZE_9);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Unit test for StringCompare () API of the UefiSortLib.
+
+ @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
+CompareSameBufferShouldSucceed (
+ IN UNIT_TEST_CONTEXT Context
+ )
+{
+ INTN retval;
+ CONST CHAR16* TestBuffer[] = { L"abcdefg" };
+
+ retval = StringCompare (TestBuffer, TestBuffer);
+ UT_ASSERT_TRUE (retval == 0);
+
+ return UNIT_TEST_PASSED;
+}
+
+/**
+ Initialze the unit test framework, suite, and unit tests for the
+ UefiSortLib and run the UefiSortLib 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 UefiSortLib Unit Test Suite.
+ //
+ Status = CreateUnitTestSuite (&SortTests, Framework, "UefiSortLib Sort Tests", "UefiSortLib.SortLib", NULL, NULL);
+ if (EFI_ERROR (Status)) {
+ DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for UefiSortLib API Tests\n"));
+ Status = EFI_OUT_OF_RESOURCES;
+ goto EXIT;
+ }
+
+ //
+ // --------------Suite--------Description------------Name--------------Function----------------Pre---Post---Context-----------
+ //
+ AddTestCase (SortTests, "Sort the Array", "Sort", SortUINT32ArrayShouldSucceed, NULL, NULL, NULL);
+ AddTestCase (SortTests, "Compare the Buffer", "Compare", CompareSameBufferShouldSucceed, NULL, NULL, NULL);
+
+ //
+ // Execute the tests.
+ //
+ Status = RunAllTestSuites (Framework);
+
+EXIT:
+ if (Framework) {
+ FreeUnitTestFramework (Framework);
+ }
+
+ return Status;
+}
+
+/**
+ Standard POSIX C entry point for host based unit test execution.
+**/
+int
+main (
+ int argc,
+ char *argv[]
+ )
+{
+ return UnitTestingEntry ();
+}
--
2.20.1.windows.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH EDK2 v1 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
2021-07-28 5:58 ` [PATCH EDK2 v1 1/1] " wenyi,xie
@ 2021-07-29 5:42 ` Wu, Hao A
2021-07-29 8:07 ` wenyi,xie
0 siblings, 1 reply; 4+ messages in thread
From: Wu, Hao A @ 2021-07-29 5:42 UTC (permalink / raw)
To: Wenyi Xie, devel@edk2.groups.io, Wang, Jian J; +Cc: songdongkuang@huawei.com
Thanks for the patch.
Some inline comments below:
> -----Original Message-----
> From: Wenyi Xie <xiewenyi2@huawei.com>
> Sent: Wednesday, July 28, 2021 1:58 PM
> To: devel@edk2.groups.io; Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A
> <hao.a.wu@intel.com>
> Cc: songdongkuang@huawei.com; xiewenyi2@huawei.com
> Subject: [PATCH EDK2 v1 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit
> test
>
> Adding unit test for UefiSortLib.
Could you help to give a brief summary on what tests are added?
>
> Cc: Jian J Wang <jian.j.wang@intel.com>
> Cc: Hao A Wu <hao.a.wu@intel.com>
> Signed-off-by: Wenyi Xie <xiewenyi2@huawei.com>
> ---
> MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 6 +
> MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf | 32 ++++
> MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c | 188
> ++++++++++++++++++++
> 3 files changed, 226 insertions(+)
>
> diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
> b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
> index 4da4692c8451..c9ec835df65d 100644
> --- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
> +++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
> @@ -41,3 +41,9 @@ [Components]
> <PcdsFixedAtBuild>
>
> gEfiMdeModulePkgTokenSpaceGuid.PcdAllowVariablePolicyEnforcementDisable
> |TRUE
> }
> +
> + MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf {
> + <LibraryClasses>
> + UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
> +
> + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
> + }
> diff --git a/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
> new file mode 100644
> index 000000000000..d9dac307934e
> --- /dev/null
> +++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
> @@ -0,0 +1,32 @@
> +## @file
> +# This is a unit test for the UefiSortLib.
> +#
> +# Copyright (c) Microsoft Corporation.
Please help to use the 'copyright' information of Huawei like in file UefiSortLibUnitTest.c.
> +# SPDX-License-Identifier: BSD-2-Clause-Patent ##
> +
> +[Defines]
> + INF_VERSION = 0x00010017
> + BASE_NAME = UefiSortLibUnitTest
> + FILE_GUID = 271337A3-0D79-BA3E-BC03-714E518E3B1B
> + 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]
> + UefiSortLibUnitTest.c
> +
> +[Packages]
> + MdePkg/MdePkg.dec
> + MdeModulePkg/MdeModulePkg.dec
> + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
> +
> +[LibraryClasses]
> + UnitTestLib
> + DebugLib
> + UefiSortLib
> diff --git a/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
> new file mode 100644
> index 000000000000..f2f89daef7ba
> --- /dev/null
> +++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
> @@ -0,0 +1,188 @@
> +/** @file
> + Unit tests of the UefiSortLib
> +
> + Copyright (C) Huawei Technologies Co., Ltd. All rights reserved
> + SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include <stdio.h>
> +#include <string.h>
> +#include <stdarg.h>
> +#include <stddef.h>
> +#include <setjmp.h>
> +#include <cmocka.h>
> +
> +#include <Uefi.h>
> +#include <Library/BaseLib.h>
> +#include <Library/DebugLib.h>
> +#include <Library/MemoryAllocationLib.h>
> +
> +#include <Library/UnitTestLib.h>
> +#include <Library/SortLib.h>
> +
> +#define UNIT_TEST_APP_NAME "UefiSortLib Unit Tests"
> +#define UNIT_TEST_APP_VERSION "1.0"
> +
> +#define TEST_ARRAY_SIZE_9 9
> +
> +/**
> + The function is called by PerformQuickSort to compare int values.
> +
> + @param[in] Left The pointer to first buffer.
> + @param[in] Right The pointer to second buffer.
> +
> + @retval 0 Buffer1 equal to Buffer2.
> + @return <0 Buffer1 is less than Buffer2.
> + @return >0 Buffer1 is greater than Buffer2.
> +
> +**/
> +INTN
> +EFIAPI
> +TestCompareFunction (
> + 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;
> +}
> +
> +/**
> + Unit test for PerformQuickSort () API of the UefiSortLib.
> +
> + @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
> +SortUINT32ArrayShouldSucceed (
> + IN UNIT_TEST_CONTEXT Context
> + )
> +{
> + UINTN TestCount = TEST_ARRAY_SIZE_9;
> + UINT32 TestBuffer[TEST_ARRAY_SIZE_9] = {1, 2, 3, 4, 5, 6, 7 ,8, 9};
> + UINT32 TestResult[TEST_ARRAY_SIZE_9] = {9, 8, 7, 6, 5, 4, 3, 2, 1};
> +
> + PerformQuickSort (TestBuffer, TestCount, sizeof (UINT32),
> + (SORT_COMPARE)TestCompareFunction);
> + UT_ASSERT_MEM_EQUAL (TestBuffer, TestResult, sizeof (UINT32) *
> + TEST_ARRAY_SIZE_9);
> +
> + return UNIT_TEST_PASSED;
> +}
> +
> +/**
> + Unit test for StringCompare () API of the UefiSortLib.
> +
> + @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
> +CompareSameBufferShouldSucceed (
> + IN UNIT_TEST_CONTEXT Context
> + )
> +{
> + INTN retval;
> + CONST CHAR16* TestBuffer[] = { L"abcdefg" };
> +
> + retval = StringCompare (TestBuffer, TestBuffer); UT_ASSERT_TRUE
> + (retval == 0);
> +
> + return UNIT_TEST_PASSED;
> +}
> +
> +/**
> + Initialze the unit test framework, suite, and unit tests for the
> + UefiSortLib and run the UefiSortLib 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;
Please help to refine the indent of the codes in the above 'if' statement to 2 spaces.
Best Regards,
Hao Wu
> + }
> +
> + //
> + // Populate the UefiSortLib Unit Test Suite.
> + //
> + Status = CreateUnitTestSuite (&SortTests, Framework, "UefiSortLib
> + Sort Tests", "UefiSortLib.SortLib", NULL, NULL); if (EFI_ERROR (Status)) {
> + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for UefiSortLib API
> Tests\n"));
> + Status = EFI_OUT_OF_RESOURCES;
> + goto EXIT;
> + }
> +
> + //
> + //
> + --------------Suite--------Description------------Name--------------Fu
> + nction----------------Pre---Post---Context-----------
> + //
> + AddTestCase (SortTests, "Sort the Array", "Sort",
> SortUINT32ArrayShouldSucceed, NULL, NULL, NULL);
> + AddTestCase (SortTests, "Compare the Buffer", "Compare",
> CompareSameBufferShouldSucceed, NULL, NULL, NULL);
> +
> + //
> + // Execute the tests.
> + //
> + Status = RunAllTestSuites (Framework);
> +
> +EXIT:
> + if (Framework) {
> + FreeUnitTestFramework (Framework);
> + }
> +
> + return Status;
> +}
> +
> +/**
> + Standard POSIX C entry point for host based unit test execution.
> +**/
> +int
> +main (
> + int argc,
> + char *argv[]
> + )
> +{
> + return UnitTestingEntry ();
> +}
> --
> 2.20.1.windows.1
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH EDK2 v1 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
2021-07-29 5:42 ` Wu, Hao A
@ 2021-07-29 8:07 ` wenyi,xie
0 siblings, 0 replies; 4+ messages in thread
From: wenyi,xie @ 2021-07-29 8:07 UTC (permalink / raw)
To: Wu, Hao A, devel@edk2.groups.io, Wang, Jian J; +Cc: songdongkuang@huawei.com
Hi, Wu Hao
Thank you for your reviewing.
I have create the v2 patch according to your comments.
Thanks
Wenyi
On 2021/7/29 13:42, Wu, Hao A wrote:
> Thanks for the patch.
> Some inline comments below:
>
>
>> -----Original Message-----
>> From: Wenyi Xie <xiewenyi2@huawei.com>
>> Sent: Wednesday, July 28, 2021 1:58 PM
>> To: devel@edk2.groups.io; Wang, Jian J <jian.j.wang@intel.com>; Wu, Hao A
>> <hao.a.wu@intel.com>
>> Cc: songdongkuang@huawei.com; xiewenyi2@huawei.com
>> Subject: [PATCH EDK2 v1 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit
>> test
>>
>> Adding unit test for UefiSortLib.
>
>
> Could you help to give a brief summary on what tests are added?
>
>
>>
>> Cc: Jian J Wang <jian.j.wang@intel.com>
>> Cc: Hao A Wu <hao.a.wu@intel.com>
>> Signed-off-by: Wenyi Xie <xiewenyi2@huawei.com>
>> ---
>> MdeModulePkg/Test/MdeModulePkgHostTest.dsc | 6 +
>> MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf | 32 ++++
>> MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c | 188
>> ++++++++++++++++++++
>> 3 files changed, 226 insertions(+)
>>
>> diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
>> b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
>> index 4da4692c8451..c9ec835df65d 100644
>> --- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
>> +++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
>> @@ -41,3 +41,9 @@ [Components]
>> <PcdsFixedAtBuild>
>>
>> gEfiMdeModulePkgTokenSpaceGuid.PcdAllowVariablePolicyEnforcementDisable
>> |TRUE
>> }
>> +
>> + MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf {
>> + <LibraryClasses>
>> + UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
>> +
>> + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.inf
>> + }
>> diff --git a/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
>> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
>> new file mode 100644
>> index 000000000000..d9dac307934e
>> --- /dev/null
>> +++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
>> @@ -0,0 +1,32 @@
>> +## @file
>> +# This is a unit test for the UefiSortLib.
>> +#
>> +# Copyright (c) Microsoft Corporation.
>
>
> Please help to use the 'copyright' information of Huawei like in file UefiSortLibUnitTest.c.
>
>
>> +# SPDX-License-Identifier: BSD-2-Clause-Patent ##
>> +
>> +[Defines]
>> + INF_VERSION = 0x00010017
>> + BASE_NAME = UefiSortLibUnitTest
>> + FILE_GUID = 271337A3-0D79-BA3E-BC03-714E518E3B1B
>> + 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]
>> + UefiSortLibUnitTest.c
>> +
>> +[Packages]
>> + MdePkg/MdePkg.dec
>> + MdeModulePkg/MdeModulePkg.dec
>> + UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
>> +
>> +[LibraryClasses]
>> + UnitTestLib
>> + DebugLib
>> + UefiSortLib
>> diff --git a/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
>> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
>> new file mode 100644
>> index 000000000000..f2f89daef7ba
>> --- /dev/null
>> +++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
>> @@ -0,0 +1,188 @@
>> +/** @file
>> + Unit tests of the UefiSortLib
>> +
>> + Copyright (C) Huawei Technologies Co., Ltd. All rights reserved
>> + SPDX-License-Identifier: BSD-2-Clause-Patent
>> +
>> +**/
>> +
>> +#include <stdio.h>
>> +#include <string.h>
>> +#include <stdarg.h>
>> +#include <stddef.h>
>> +#include <setjmp.h>
>> +#include <cmocka.h>
>> +
>> +#include <Uefi.h>
>> +#include <Library/BaseLib.h>
>> +#include <Library/DebugLib.h>
>> +#include <Library/MemoryAllocationLib.h>
>> +
>> +#include <Library/UnitTestLib.h>
>> +#include <Library/SortLib.h>
>> +
>> +#define UNIT_TEST_APP_NAME "UefiSortLib Unit Tests"
>> +#define UNIT_TEST_APP_VERSION "1.0"
>> +
>> +#define TEST_ARRAY_SIZE_9 9
>> +
>> +/**
>> + The function is called by PerformQuickSort to compare int values.
>> +
>> + @param[in] Left The pointer to first buffer.
>> + @param[in] Right The pointer to second buffer.
>> +
>> + @retval 0 Buffer1 equal to Buffer2.
>> + @return <0 Buffer1 is less than Buffer2.
>> + @return >0 Buffer1 is greater than Buffer2.
>> +
>> +**/
>> +INTN
>> +EFIAPI
>> +TestCompareFunction (
>> + 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;
>> +}
>> +
>> +/**
>> + Unit test for PerformQuickSort () API of the UefiSortLib.
>> +
>> + @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
>> +SortUINT32ArrayShouldSucceed (
>> + IN UNIT_TEST_CONTEXT Context
>> + )
>> +{
>> + UINTN TestCount = TEST_ARRAY_SIZE_9;
>> + UINT32 TestBuffer[TEST_ARRAY_SIZE_9] = {1, 2, 3, 4, 5, 6, 7 ,8, 9};
>> + UINT32 TestResult[TEST_ARRAY_SIZE_9] = {9, 8, 7, 6, 5, 4, 3, 2, 1};
>> +
>> + PerformQuickSort (TestBuffer, TestCount, sizeof (UINT32),
>> + (SORT_COMPARE)TestCompareFunction);
>> + UT_ASSERT_MEM_EQUAL (TestBuffer, TestResult, sizeof (UINT32) *
>> + TEST_ARRAY_SIZE_9);
>> +
>> + return UNIT_TEST_PASSED;
>> +}
>> +
>> +/**
>> + Unit test for StringCompare () API of the UefiSortLib.
>> +
>> + @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
>> +CompareSameBufferShouldSucceed (
>> + IN UNIT_TEST_CONTEXT Context
>> + )
>> +{
>> + INTN retval;
>> + CONST CHAR16* TestBuffer[] = { L"abcdefg" };
>> +
>> + retval = StringCompare (TestBuffer, TestBuffer); UT_ASSERT_TRUE
>> + (retval == 0);
>> +
>> + return UNIT_TEST_PASSED;
>> +}
>> +
>> +/**
>> + Initialze the unit test framework, suite, and unit tests for the
>> + UefiSortLib and run the UefiSortLib 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;
>
>
> Please help to refine the indent of the codes in the above 'if' statement to 2 spaces.
>
> Best Regards,
> Hao Wu
>
>
>> + }
>> +
>> + //
>> + // Populate the UefiSortLib Unit Test Suite.
>> + //
>> + Status = CreateUnitTestSuite (&SortTests, Framework, "UefiSortLib
>> + Sort Tests", "UefiSortLib.SortLib", NULL, NULL); if (EFI_ERROR (Status)) {
>> + DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for UefiSortLib API
>> Tests\n"));
>> + Status = EFI_OUT_OF_RESOURCES;
>> + goto EXIT;
>> + }
>> +
>> + //
>> + //
>> + --------------Suite--------Description------------Name--------------Fu
>> + nction----------------Pre---Post---Context-----------
>> + //
>> + AddTestCase (SortTests, "Sort the Array", "Sort",
>> SortUINT32ArrayShouldSucceed, NULL, NULL, NULL);
>> + AddTestCase (SortTests, "Compare the Buffer", "Compare",
>> CompareSameBufferShouldSucceed, NULL, NULL, NULL);
>> +
>> + //
>> + // Execute the tests.
>> + //
>> + Status = RunAllTestSuites (Framework);
>> +
>> +EXIT:
>> + if (Framework) {
>> + FreeUnitTestFramework (Framework);
>> + }
>> +
>> + return Status;
>> +}
>> +
>> +/**
>> + Standard POSIX C entry point for host based unit test execution.
>> +**/
>> +int
>> +main (
>> + int argc,
>> + char *argv[]
>> + )
>> +{
>> + return UnitTestingEntry ();
>> +}
>> --
>> 2.20.1.windows.1
>
> .
>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2021-07-29 8:08 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-28 5:58 [PATCH EDK2 v1 0/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test wenyi,xie
2021-07-28 5:58 ` [PATCH EDK2 v1 1/1] " wenyi,xie
2021-07-29 5:42 ` Wu, Hao A
2021-07-29 8:07 ` wenyi,xie
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox