Re: [edk2-devel] [PATCH EDK2 v3 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test

2021-08-12 Thread Wu, Hao A
> -Original Message-
> From: devel@edk2.groups.io  On Behalf Of Wu, Hao
> A
> Sent: Wednesday, August 11, 2021 4:33 PM
> To: Liming Gao ; Wenyi Xie
> ; devel@edk2.groups.io
> Cc: songdongku...@huawei.com; Wang, Jian J 
> Subject: Re: [edk2-devel] [PATCH EDK2 v3 1/1]
> MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
> 
> > -Original Message-
> > From: Wenyi Xie 
> > Sent: Wednesday, August 11, 2021 2:36 PM
> > To: devel@edk2.groups.io; Wang, Jian J ; Wu, Hao
> A
> > 
> > Cc: songdongku...@huawei.com; xiewen...@huawei.com
> > Subject: [PATCH EDK2 v3 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib
> > unit test
> >
> > Adding two unit test case for UefiSortLib. One is a test on sorting an array
> of
> > UINT32 by using PerformQuickSort, another is a test on comparing the
> same
> > buffer by using StringCompare.
> > Add 'main' function name to ECC exception list to avoid ECC error.
> 
> 
> Reviewed-by: Hao A Wu 
> 
> Hello Liming,
> 
> Since the patch looks more like a feature than a bugfix to me, I would like to
> confirm that can I merge this change now?
> I already gave my 'R-b' tag for the V2 patch on 29th July, but met some ECC
> check issues during previous merging attempt.
> I verified that the latest patch can pass the merging test
> (https://github.com/tianocore/edk2/pull/1892).


Since no objection received, pushed via:
PR - https://github.com/tianocore/edk2/pull/1892
Commit - 
https://github.com/tianocore/edk2/commit/ac826886c98524e918753419c039d8b44198943f

If this commit breaks the Soft Feature Freeze rule, please help to raise. I 
will revert it.

Best Regards,
Hao Wu


> 
> Best Regards,
> Hao Wu
> 
> 
> >
> > Cc: Jian J Wang 
> > Cc: Hao A Wu 
> > Signed-off-by: Wenyi Xie 
> > ---
> >  MdeModulePkg/Test/MdeModulePkgHostTest.dsc|   6 +
> >  MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf |  32
> > +++
> >  MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c   | 207
> > 
> >  MdeModulePkg/MdeModulePkg.ci.yaml |   1 +
> >  4 files changed, 246 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]
> >  
> >
> >
> gEfiMdeModulePkgTokenSpaceGuid.PcdAllowVariablePolicyEnforcementDis
> > able|TRUE
> >}
> > +
> > +  MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf {
> > +
> > +  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 ..85d8dcd69619
> > --- /dev/null
> > +++
> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
> > @@ -0,0 +1,32 @@
> > +## @file
> > +# This is a unit test for the UefiSortLib.
> > +#
> > +# Copyright (C) Huawei Technologies Co., Ltd. All rights reserved #
> > +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 ..4f44a02c5b5d
> > --- /dev/null
> > +++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
&g

Re: [edk2-devel] [PATCH EDK2 v3 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test

2021-08-11 Thread Wu, Hao A
> -Original Message-
> From: Wenyi Xie 
> Sent: Wednesday, August 11, 2021 2:36 PM
> To: devel@edk2.groups.io; Wang, Jian J ; Wu, Hao A
> 
> Cc: songdongku...@huawei.com; xiewen...@huawei.com
> Subject: [PATCH EDK2 v3 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib
> unit test
> 
> Adding two unit test case for UefiSortLib. One is a test on sorting an array 
> of
> UINT32 by using PerformQuickSort, another is a test on comparing the same
> buffer by using StringCompare.
> Add 'main' function name to ECC exception list to avoid ECC error.


Reviewed-by: Hao A Wu 

Hello Liming,

Since the patch looks more like a feature than a bugfix to me, I would like to 
confirm that can I merge this change now?
I already gave my 'R-b' tag for the V2 patch on 29th July, but met some ECC 
check issues during previous merging attempt.
I verified that the latest patch can pass the merging test 
(https://github.com/tianocore/edk2/pull/1892).

Best Regards,
Hao Wu


> 
> Cc: Jian J Wang 
> Cc: Hao A Wu 
> Signed-off-by: Wenyi Xie 
> ---
>  MdeModulePkg/Test/MdeModulePkgHostTest.dsc|   6 +
>  MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf |  32
> +++
>  MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c   | 207
> 
>  MdeModulePkg/MdeModulePkg.ci.yaml |   1 +
>  4 files changed, 246 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]
>  
> 
> gEfiMdeModulePkgTokenSpaceGuid.PcdAllowVariablePolicyEnforcementDis
> able|TRUE
>}
> +
> +  MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf {
> +
> +  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 ..85d8dcd69619
> --- /dev/null
> +++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
> @@ -0,0 +1,32 @@
> +## @file
> +# This is a unit test for the UefiSortLib.
> +#
> +# Copyright (C) Huawei Technologies Co., Ltd. All rights reserved #
> +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 ..4f44a02c5b5d
> --- /dev/null
> +++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
> @@ -0,0 +1,207 @@
> +/** @file
> +  Unit tests of the UefiSortLib
> +
> +  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 
> +
> +#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] LeftThe 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-ent

[edk2-devel] [PATCH EDK2 v3 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test

2021-08-10 Thread wenyi,xie via groups.io
Adding two unit test case for UefiSortLib. One is a test on
sorting an array of UINT32 by using PerformQuickSort, another
is a test on comparing the same buffer by using StringCompare.
Add 'main' function name to ECC exception list to avoid ECC
error.

Cc: Jian J Wang 
Cc: Hao A Wu 
Signed-off-by: Wenyi Xie 
---
 MdeModulePkg/Test/MdeModulePkgHostTest.dsc|   6 +
 MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf |  32 +++
 MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c   | 207 

 MdeModulePkg/MdeModulePkg.ci.yaml |   1 +
 4 files changed, 246 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]
 
   
gEfiMdeModulePkgTokenSpaceGuid.PcdAllowVariablePolicyEnforcementDisable|TRUE
   }
+
+  MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf {
+
+  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 ..85d8dcd69619
--- /dev/null
+++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
@@ -0,0 +1,32 @@
+## @file
+# This is a unit test for the UefiSortLib.
+#
+# Copyright (C) Huawei Technologies Co., Ltd. All rights reserved
+# 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 ..4f44a02c5b5d
--- /dev/null
+++ b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
@@ -0,0 +1,207 @@
+/** @file
+  Unit tests of the UefiSortLib
+
+  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 
+
+#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] LeftThe 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;
+  UINT32 Index;
+  UINT32 TestBuffer[TEST_ARRAY_SIZE_9];
+  UINT32 TestResult[TEST_ARRAY_SIZE_9];
+
+  TestCount = TEST_ARRAY_SIZE_9;
+  for (Index = 0; Index < TEST_ARRAY_SIZE_9; Index++) {
+TestBuffer[Index] = Index + 1;
+TestResult[Index] = TEST_ARRAY_SIZE_9 - Index;
+  }
+
+  PerformQuickSort (TestBuffer, TestCo