public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH EDK2 v2 0/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
@ 2021-07-29  8:01 wenyi,xie
  2021-07-29  8:01 ` [PATCH EDK2 v2 1/1] " wenyi,xie
  0 siblings, 1 reply; 9+ messages in thread
From: wenyi,xie @ 2021-07-29  8:01 UTC (permalink / raw)
  To: devel, jian.j.wang, hao.a.wu; +Cc: songdongkuang, xiewenyi2

Main Changes since v1 :
1.add brief summary in commit message
2.change the copyright in UefiSortLibUnitTest.inf
3.refine the indent in UnitTestingEntry

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] 9+ messages in thread

* [PATCH EDK2 v2 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
  2021-07-29  8:01 [PATCH EDK2 v2 0/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test wenyi,xie
@ 2021-07-29  8:01 ` wenyi,xie
  2021-07-29  8:25   ` Wu, Hao A
  0 siblings, 1 reply; 9+ messages in thread
From: wenyi,xie @ 2021-07-29  8:01 UTC (permalink / raw)
  To: devel, jian.j.wang, hao.a.wu; +Cc: songdongkuang, xiewenyi2

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.

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..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 000000000000..71f30d8b9f7f
--- /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] 9+ messages in thread

* Re: [PATCH EDK2 v2 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
  2021-07-29  8:01 ` [PATCH EDK2 v2 1/1] " wenyi,xie
@ 2021-07-29  8:25   ` Wu, Hao A
  2021-08-02  1:56     ` [edk2-devel] " Wu, Hao A
  0 siblings, 1 reply; 9+ messages in thread
From: Wu, Hao A @ 2021-07-29  8:25 UTC (permalink / raw)
  To: Wenyi Xie, devel@edk2.groups.io, Wang, Jian J; +Cc: songdongkuang@huawei.com

> -----Original Message-----
> From: Wenyi Xie <xiewenyi2@huawei.com>
> Sent: Thursday, July 29, 2021 4:01 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 v2 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.


Thanks.
Reviewed-by: Hao A Wu <hao.a.wu@intel.com>

I will wait a couple days before merging to see if any additional comment from other reviewers.

Best Regards,
Hao Wu


> 
> 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.PcdAllowVariablePolicyEnforcementDis
> able|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..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 000000000000..71f30d8b9f7f
> --- /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--------------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] 9+ messages in thread

* Re: [edk2-devel] [PATCH EDK2 v2 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
  2021-07-29  8:25   ` Wu, Hao A
@ 2021-08-02  1:56     ` Wu, Hao A
  2021-08-04  8:04       ` wenyi,xie
  0 siblings, 1 reply; 9+ messages in thread
From: Wu, Hao A @ 2021-08-02  1:56 UTC (permalink / raw)
  To: devel@edk2.groups.io, Wenyi Xie; +Cc: songdongkuang@huawei.com, Wang, Jian J

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wu, Hao
> A
> Sent: Thursday, July 29, 2021 4:26 PM
> To: Wenyi Xie <xiewenyi2@huawei.com>; devel@edk2.groups.io; Wang, Jian
> J <jian.j.wang@intel.com>
> Cc: songdongkuang@huawei.com
> Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
> MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
> 
> > -----Original Message-----
> > From: Wenyi Xie <xiewenyi2@huawei.com>
> > Sent: Thursday, July 29, 2021 4:01 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 v2 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.
> 
> 
> Thanks.
> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>


Sorry, I found that there are a couple of coding format style check failures when merging the patch.
Could you help to resolve them and then create a test pull request on the GitHub for verification? Thanks in advance.
(I think you can take the case under MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/ for reference.)

Error details:
2021-08-02T01:09:28.5955820Z ##[section]Starting: Build and Test MdeModulePkg IA32,X64,ARM,AARCH64,RISCV64
2021-08-02T01:09:28.5960733Z ==============================================================================
2021-08-02T01:09:28.5961018Z Task         : Command Line
2021-08-02T01:09:28.5961258Z Description  : Run a command line with arguments
2021-08-02T01:09:28.5961502Z Version      : 1.1.3
2021-08-02T01:09:28.5961897Z Author       : Microsoft Corporation
2021-08-02T01:09:28.5962259Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613735)
2021-08-02T01:09:28.5962678Z ==============================================================================
2021-08-02T01:09:29.3504946Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
2021-08-02T01:09:29.3510020Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
2021-08-02T01:09:29.3511551Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
2021-08-02T01:09:29.3513605Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
2021-08-02T01:09:29.3516798Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
2021-08-02T01:09:29.3517536Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
2021-08-02T01:09:29.3518178Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
2021-08-02T01:09:29.3545461Z [command]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build -c .pytool/CISettings.py -p MdeModulePkg -t RELEASE,NO-TARGET -a IA32,X64,ARM,AARCH64,RISCV64 TOOL_CHAIN_TAG=GCC5
2021-08-02T01:09:29.3546707Z SECTION - Init SDE
2021-08-02T01:09:29.3547571Z WARNING - Using Pip Tools based BaseTools
2021-08-02T01:09:29.3548395Z SECTION - Loading Plugins
2021-08-02T01:09:29.3549212Z SECTION - Start Invocable Tool
2021-08-02T01:09:29.3550018Z SECTION - Getting Environment
2021-08-02T01:09:29.3550794Z SECTION - Loading plugins
2021-08-02T01:09:29.3551675Z SECTION - Building MdeModulePkg Package
2021-08-02T01:09:29.3552693Z PROGRESS - --Running MdeModulePkg: EccCheck Test NO-TARGET --
2021-08-02T01:09:33.0697006Z ERROR - 
2021-08-02T01:09:33.0698018Z ERROR - EFI coding style error
2021-08-02T01:09:33.0698748Z ERROR - *Error code: 5007
2021-08-02T01:09:33.0700631Z ERROR - *There should be no initialization of a variable as part of its declaration
2021-08-02T01:09:33.0702675Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
2021-08-02T01:09:33.0703421Z ERROR - *Line number: 77
2021-08-02T01:09:33.0703929Z ERROR - *Variable Name: TestCount
2021-08-02T01:09:33.0715684Z ERROR - 
2021-08-02T01:09:33.0716634Z ERROR - EFI coding style error
2021-08-02T01:09:33.0717372Z ERROR - *Error code: 5007
2021-08-02T01:09:33.0718214Z ERROR - *There should be no initialization of a variable as part of its declaration
2021-08-02T01:09:33.0719195Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
2021-08-02T01:09:33.0720631Z ERROR - *Line number: 78
2021-08-02T01:09:33.0721451Z ERROR - *Variable Name: TestBuffer
2021-08-02T01:09:33.0722114Z ERROR - 
2021-08-02T01:09:33.0724953Z ERROR - EFI coding style error
2021-08-02T01:09:33.0725713Z ERROR - *Error code: 5007
2021-08-02T01:09:33.0726562Z ERROR - *There should be no initialization of a variable as part of its declaration
2021-08-02T01:09:33.0727526Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
2021-08-02T01:09:33.0728345Z ERROR - *Line number: 79
2021-08-02T01:09:33.0729046Z ERROR - *Variable Name: TestResult
2021-08-02T01:09:33.0729694Z ERROR - 
2021-08-02T01:09:33.0732496Z ERROR - EFI coding style error
2021-08-02T01:09:33.0733224Z ERROR - *Error code: 7001
2021-08-02T01:09:33.0734114Z ERROR - *There should be no use of int, unsigned, char, void, long in any .c, .h or .asl files
2021-08-02T01:09:33.0737620Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
2021-08-02T01:09:33.0739185Z ERROR - *Line number: 117
2021-08-02T01:09:33.0741301Z ERROR - *[main] Return type int
2021-08-02T01:09:33.0744099Z ERROR - 
2021-08-02T01:09:33.0744829Z ERROR - EFI coding style error
2021-08-02T01:09:33.0745459Z ERROR - *Error code: 7001
2021-08-02T01:09:33.0746821Z ERROR - *There should be no use of int, unsigned, char, void, long in any .c, .h or .asl files
2021-08-02T01:09:33.0747774Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
2021-08-02T01:09:33.0749076Z ERROR - *Line number: 117
2021-08-02T01:09:33.0749713Z ERROR - *Parameter argc
2021-08-02T01:09:33.0750999Z ERROR - 
2021-08-02T01:09:33.0751607Z ERROR - EFI coding style error
2021-08-02T01:09:33.0754599Z ERROR - *Error code: 7001
2021-08-02T01:09:33.0761175Z ERROR - *There should be no use of int, unsigned, char, void, long in any .c, .h or .asl files
2021-08-02T01:09:33.0762167Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
2021-08-02T01:09:33.0763160Z ERROR - *Line number: 117
2021-08-02T01:09:33.0763741Z ERROR - *Parameter argv
2021-08-02T01:09:33.0764290Z ERROR - 
2021-08-02T01:09:33.0764843Z ERROR - EFI coding style error
2021-08-02T01:09:33.0766810Z ERROR - *Error code: 8006
2021-08-02T01:09:33.0767819Z ERROR - *Function name does not follow the rules: 1. First character should be upper case 2. Must contain lower case characters 3. No white space characters
2021-08-02T01:09:33.0768881Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
2021-08-02T01:09:33.0769619Z ERROR - *Line number: 181
2021-08-02T01:09:33.0773329Z ERROR - *The function name [main] does not follow the rules
2021-08-02T01:09:33.0791935Z ERROR - 
2021-08-02T01:09:33.0793865Z ERROR - EFI coding style error
2021-08-02T01:09:33.0794555Z ERROR - *Error code: 9002
2021-08-02T01:09:33.0795350Z ERROR - *The function headers should follow Doxygen special documentation blocks in section 2.3.5
2021-08-02T01:09:33.0796271Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
2021-08-02T01:09:33.0796985Z ERROR - *Line number: 178
2021-08-02T01:09:33.0797610Z ERROR - *No doxygen tags in comment
2021-08-02T01:09:33.0798208Z ERROR - 
2021-08-02T01:09:33.0798859Z ERROR - --->Test Failed: EccCheck Test NO-TARGET returned 1
2021-08-02T01:09:33.0807351Z PROGRESS - --Running MdeModulePkg: Dsc Complete Check Test NO-TARGET --
2021-08-02T01:09:33.1524790Z PROGRESS - --->Test Success: Dsc Complete Check Test NO-TARGET
2021-08-02T01:09:33.1536004Z PROGRESS - --Running MdeModulePkg: Char Encoding Check Test NO-TARGET --
2021-08-02T01:09:33.6280380Z PROGRESS - --->Test Success: Char Encoding Check Test NO-TARGET
2021-08-02T01:09:33.6289076Z PROGRESS - --Running MdeModulePkg: License Check Test NO-TARGET --
2021-08-02T01:09:33.6495642Z PROGRESS - --->Test Success: License Check Test NO-TARGET
2021-08-02T01:09:33.6508125Z PROGRESS - --Running MdeModulePkg: Compiler Plugin RELEASE --
2021-08-02T01:09:33.6785178Z PROGRESS - Start time: 2021-08-02 01:09:33.677952
2021-08-02T01:09:33.6787716Z PROGRESS - Setting up the Environment
2021-08-02T01:09:33.7725244Z PROGRESS - Running Pre Build
2021-08-02T01:09:33.7740357Z PROGRESS - Running Build RELEASE
2021-08-02T01:17:18.5479885Z PROGRESS - Running Post Build
2021-08-02T01:17:18.5511807Z PROGRESS - End time: 2021-08-02 01:17:18.549974	 Total time Elapsed: 0:07:44
2021-08-02T01:17:18.5512997Z PROGRESS - --->Test Success: Compiler Plugin RELEASE
2021-08-02T01:17:18.5519284Z PROGRESS - --Running MdeModulePkg: Library Class Check Test NO-TARGET --
2021-08-02T01:17:18.5639216Z PROGRESS - --->Test Success: Library Class Check Test NO-TARGET
2021-08-02T01:17:18.5648791Z PROGRESS - --Running MdeModulePkg: Dependency Check Test NO-TARGET --
2021-08-02T01:17:18.7306611Z PROGRESS - --->Test Success: Dependency Check Test NO-TARGET
2021-08-02T01:17:18.7316162Z PROGRESS - --Running MdeModulePkg: Spell Check Test NO-TARGET --
2021-08-02T01:17:23.7922166Z WARNING - --->Test Skipped: in plugin! Spell Check Test NO-TARGET
2021-08-02T01:17:23.7934112Z PROGRESS - --Running MdeModulePkg: Guid Check Test NO-TARGET --
2021-08-02T01:17:27.1928850Z PROGRESS - --->Test Success: Guid Check Test NO-TARGET
2021-08-02T01:17:27.1939129Z PROGRESS - --Running MdeModulePkg: Host Unit Test Dsc Complete Check Test NO-TARGET --
2021-08-02T01:17:27.3703640Z PROGRESS - --->Test Success: Host Unit Test Dsc Complete Check Test NO-TARGET
2021-08-02T01:17:27.3731676Z ERROR - Overall Build Status: Error
2021-08-02T01:17:27.3733283Z PROGRESS - There were 1 failures out of 10 attempts
2021-08-02T01:17:27.3734501Z SECTION - Summary
2021-08-02T01:17:27.3735613Z ERROR - Error
2021-08-02T01:17:27.4159842Z ##[error]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build failed with return code: 1
2021-08-02T01:17:27.4173134Z ##[error]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build failed with error: /opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build failed with return code: 1
2021-08-02T01:17:27.4178252Z ##[section]Finishing: Build and Test MdeModulePkg IA32,X64,ARM,AARCH64,RISCV64

Best Regards,
Hao Wu


> 
> I will wait a couple days before merging to see if any additional comment
> from other reviewers.
> 
> Best Regards,
> Hao Wu
> 
> 
> >
> > 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.PcdAllowVariablePolicyEnforcementDis
> > able|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..85d8dcd69619
> > --- /dev/null
> > +++
> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.in
> > +++ f
> > @@ -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 000000000000..71f30d8b9f7f
> > --- /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--------------
> > + 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] 9+ messages in thread

* Re: [edk2-devel] [PATCH EDK2 v2 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
  2021-08-02  1:56     ` [edk2-devel] " Wu, Hao A
@ 2021-08-04  8:04       ` wenyi,xie
  2021-08-04  8:24         ` Wu, Hao A
  0 siblings, 1 reply; 9+ messages in thread
From: wenyi,xie @ 2021-08-04  8:04 UTC (permalink / raw)
  To: Wu, Hao A, devel@edk2.groups.io; +Cc: songdongkuang@huawei.com, Wang, Jian J



On 2021/8/2 9:56, Wu, Hao A wrote:
>> -----Original Message-----
>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wu, Hao
>> A
>> Sent: Thursday, July 29, 2021 4:26 PM
>> To: Wenyi Xie <xiewenyi2@huawei.com>; devel@edk2.groups.io; Wang, Jian
>> J <jian.j.wang@intel.com>
>> Cc: songdongkuang@huawei.com
>> Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
>> MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
>>
>>> -----Original Message-----
>>> From: Wenyi Xie <xiewenyi2@huawei.com>
>>> Sent: Thursday, July 29, 2021 4:01 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 v2 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.
>>
>>
>> Thanks.
>> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
> 
> 
> Sorry, I found that there are a couple of coding format style check failures when merging the patch.
> Could you help to resolve them and then create a test pull request on the GitHub for verification? Thanks in advance.
> (I think you can take the case under MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/ for reference.)
> 

Hi, Wu Hao

I try to deal with the coding format style check failures, and meet a failure which I am not sure how to solve.
I take the case you told for reference, but still there's a failure said the define should be capital letters.
but if change it to capital letters, there will be another error
Function name does not follow the rules: 1. First character should be upper case 2. Must contain lower case characters 3. No white space characters

#define Main main

INT32
Main (
  IN INT32  Argc,
  IN CHAR8  *Argv[]
  )
{
  UnitTestingEntry ();
  return 0;
}

Thanks
Wenyi

> Error details:
> 2021-08-02T01:09:28.5955820Z ##[section]Starting: Build and Test MdeModulePkg IA32,X64,ARM,AARCH64,RISCV64
> 2021-08-02T01:09:28.5960733Z ==============================================================================
> 2021-08-02T01:09:28.5961018Z Task         : Command Line
> 2021-08-02T01:09:28.5961258Z Description  : Run a command line with arguments
> 2021-08-02T01:09:28.5961502Z Version      : 1.1.3
> 2021-08-02T01:09:28.5961897Z Author       : Microsoft Corporation
> 2021-08-02T01:09:28.5962259Z Help         : [More Information](https://go.microsoft.com/fwlink/?LinkID=613735)
> 2021-08-02T01:09:28.5962678Z ==============================================================================
> 2021-08-02T01:09:29.3504946Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
> 2021-08-02T01:09:29.3510020Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
> 2021-08-02T01:09:29.3511551Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
> 2021-08-02T01:09:29.3513605Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
> 2021-08-02T01:09:29.3516798Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
> 2021-08-02T01:09:29.3517536Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
> 2021-08-02T01:09:29.3518178Z (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
> 2021-08-02T01:09:29.3545461Z [command]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build -c .pytool/CISettings.py -p MdeModulePkg -t RELEASE,NO-TARGET -a IA32,X64,ARM,AARCH64,RISCV64 TOOL_CHAIN_TAG=GCC5
> 2021-08-02T01:09:29.3546707Z SECTION - Init SDE
> 2021-08-02T01:09:29.3547571Z WARNING - Using Pip Tools based BaseTools
> 2021-08-02T01:09:29.3548395Z SECTION - Loading Plugins
> 2021-08-02T01:09:29.3549212Z SECTION - Start Invocable Tool
> 2021-08-02T01:09:29.3550018Z SECTION - Getting Environment
> 2021-08-02T01:09:29.3550794Z SECTION - Loading plugins
> 2021-08-02T01:09:29.3551675Z SECTION - Building MdeModulePkg Package
> 2021-08-02T01:09:29.3552693Z PROGRESS - --Running MdeModulePkg: EccCheck Test NO-TARGET --
> 2021-08-02T01:09:33.0697006Z ERROR - 
> 2021-08-02T01:09:33.0698018Z ERROR - EFI coding style error
> 2021-08-02T01:09:33.0698748Z ERROR - *Error code: 5007
> 2021-08-02T01:09:33.0700631Z ERROR - *There should be no initialization of a variable as part of its declaration
> 2021-08-02T01:09:33.0702675Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
> 2021-08-02T01:09:33.0703421Z ERROR - *Line number: 77
> 2021-08-02T01:09:33.0703929Z ERROR - *Variable Name: TestCount
> 2021-08-02T01:09:33.0715684Z ERROR - 
> 2021-08-02T01:09:33.0716634Z ERROR - EFI coding style error
> 2021-08-02T01:09:33.0717372Z ERROR - *Error code: 5007
> 2021-08-02T01:09:33.0718214Z ERROR - *There should be no initialization of a variable as part of its declaration
> 2021-08-02T01:09:33.0719195Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
> 2021-08-02T01:09:33.0720631Z ERROR - *Line number: 78
> 2021-08-02T01:09:33.0721451Z ERROR - *Variable Name: TestBuffer
> 2021-08-02T01:09:33.0722114Z ERROR - 
> 2021-08-02T01:09:33.0724953Z ERROR - EFI coding style error
> 2021-08-02T01:09:33.0725713Z ERROR - *Error code: 5007
> 2021-08-02T01:09:33.0726562Z ERROR - *There should be no initialization of a variable as part of its declaration
> 2021-08-02T01:09:33.0727526Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
> 2021-08-02T01:09:33.0728345Z ERROR - *Line number: 79
> 2021-08-02T01:09:33.0729046Z ERROR - *Variable Name: TestResult
> 2021-08-02T01:09:33.0729694Z ERROR - 
> 2021-08-02T01:09:33.0732496Z ERROR - EFI coding style error
> 2021-08-02T01:09:33.0733224Z ERROR - *Error code: 7001
> 2021-08-02T01:09:33.0734114Z ERROR - *There should be no use of int, unsigned, char, void, long in any .c, .h or .asl files
> 2021-08-02T01:09:33.0737620Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
> 2021-08-02T01:09:33.0739185Z ERROR - *Line number: 117
> 2021-08-02T01:09:33.0741301Z ERROR - *[main] Return type int
> 2021-08-02T01:09:33.0744099Z ERROR - 
> 2021-08-02T01:09:33.0744829Z ERROR - EFI coding style error
> 2021-08-02T01:09:33.0745459Z ERROR - *Error code: 7001
> 2021-08-02T01:09:33.0746821Z ERROR - *There should be no use of int, unsigned, char, void, long in any .c, .h or .asl files
> 2021-08-02T01:09:33.0747774Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
> 2021-08-02T01:09:33.0749076Z ERROR - *Line number: 117
> 2021-08-02T01:09:33.0749713Z ERROR - *Parameter argc
> 2021-08-02T01:09:33.0750999Z ERROR - 
> 2021-08-02T01:09:33.0751607Z ERROR - EFI coding style error
> 2021-08-02T01:09:33.0754599Z ERROR - *Error code: 7001
> 2021-08-02T01:09:33.0761175Z ERROR - *There should be no use of int, unsigned, char, void, long in any .c, .h or .asl files
> 2021-08-02T01:09:33.0762167Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
> 2021-08-02T01:09:33.0763160Z ERROR - *Line number: 117
> 2021-08-02T01:09:33.0763741Z ERROR - *Parameter argv
> 2021-08-02T01:09:33.0764290Z ERROR - 
> 2021-08-02T01:09:33.0764843Z ERROR - EFI coding style error
> 2021-08-02T01:09:33.0766810Z ERROR - *Error code: 8006
> 2021-08-02T01:09:33.0767819Z ERROR - *Function name does not follow the rules: 1. First character should be upper case 2. Must contain lower case characters 3. No white space characters
> 2021-08-02T01:09:33.0768881Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
> 2021-08-02T01:09:33.0769619Z ERROR - *Line number: 181
> 2021-08-02T01:09:33.0773329Z ERROR - *The function name [main] does not follow the rules
> 2021-08-02T01:09:33.0791935Z ERROR - 
> 2021-08-02T01:09:33.0793865Z ERROR - EFI coding style error
> 2021-08-02T01:09:33.0794555Z ERROR - *Error code: 9002
> 2021-08-02T01:09:33.0795350Z ERROR - *The function headers should follow Doxygen special documentation blocks in section 2.3.5
> 2021-08-02T01:09:33.0796271Z ERROR - *file: //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.c
> 2021-08-02T01:09:33.0796985Z ERROR - *Line number: 178
> 2021-08-02T01:09:33.0797610Z ERROR - *No doxygen tags in comment
> 2021-08-02T01:09:33.0798208Z ERROR - 
> 2021-08-02T01:09:33.0798859Z ERROR - --->Test Failed: EccCheck Test NO-TARGET returned 1
> 2021-08-02T01:09:33.0807351Z PROGRESS - --Running MdeModulePkg: Dsc Complete Check Test NO-TARGET --
> 2021-08-02T01:09:33.1524790Z PROGRESS - --->Test Success: Dsc Complete Check Test NO-TARGET
> 2021-08-02T01:09:33.1536004Z PROGRESS - --Running MdeModulePkg: Char Encoding Check Test NO-TARGET --
> 2021-08-02T01:09:33.6280380Z PROGRESS - --->Test Success: Char Encoding Check Test NO-TARGET
> 2021-08-02T01:09:33.6289076Z PROGRESS - --Running MdeModulePkg: License Check Test NO-TARGET --
> 2021-08-02T01:09:33.6495642Z PROGRESS - --->Test Success: License Check Test NO-TARGET
> 2021-08-02T01:09:33.6508125Z PROGRESS - --Running MdeModulePkg: Compiler Plugin RELEASE --
> 2021-08-02T01:09:33.6785178Z PROGRESS - Start time: 2021-08-02 01:09:33.677952
> 2021-08-02T01:09:33.6787716Z PROGRESS - Setting up the Environment
> 2021-08-02T01:09:33.7725244Z PROGRESS - Running Pre Build
> 2021-08-02T01:09:33.7740357Z PROGRESS - Running Build RELEASE
> 2021-08-02T01:17:18.5479885Z PROGRESS - Running Post Build
> 2021-08-02T01:17:18.5511807Z PROGRESS - End time: 2021-08-02 01:17:18.549974	 Total time Elapsed: 0:07:44
> 2021-08-02T01:17:18.5512997Z PROGRESS - --->Test Success: Compiler Plugin RELEASE
> 2021-08-02T01:17:18.5519284Z PROGRESS - --Running MdeModulePkg: Library Class Check Test NO-TARGET --
> 2021-08-02T01:17:18.5639216Z PROGRESS - --->Test Success: Library Class Check Test NO-TARGET
> 2021-08-02T01:17:18.5648791Z PROGRESS - --Running MdeModulePkg: Dependency Check Test NO-TARGET --
> 2021-08-02T01:17:18.7306611Z PROGRESS - --->Test Success: Dependency Check Test NO-TARGET
> 2021-08-02T01:17:18.7316162Z PROGRESS - --Running MdeModulePkg: Spell Check Test NO-TARGET --
> 2021-08-02T01:17:23.7922166Z WARNING - --->Test Skipped: in plugin! Spell Check Test NO-TARGET
> 2021-08-02T01:17:23.7934112Z PROGRESS - --Running MdeModulePkg: Guid Check Test NO-TARGET --
> 2021-08-02T01:17:27.1928850Z PROGRESS - --->Test Success: Guid Check Test NO-TARGET
> 2021-08-02T01:17:27.1939129Z PROGRESS - --Running MdeModulePkg: Host Unit Test Dsc Complete Check Test NO-TARGET --
> 2021-08-02T01:17:27.3703640Z PROGRESS - --->Test Success: Host Unit Test Dsc Complete Check Test NO-TARGET
> 2021-08-02T01:17:27.3731676Z ERROR - Overall Build Status: Error
> 2021-08-02T01:17:27.3733283Z PROGRESS - There were 1 failures out of 10 attempts
> 2021-08-02T01:17:27.3734501Z SECTION - Summary
> 2021-08-02T01:17:27.3735613Z ERROR - Error
> 2021-08-02T01:17:27.4159842Z ##[error]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build failed with return code: 1
> 2021-08-02T01:17:27.4173134Z ##[error]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build failed with error: /opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build failed with return code: 1
> 2021-08-02T01:17:27.4178252Z ##[section]Finishing: Build and Test MdeModulePkg IA32,X64,ARM,AARCH64,RISCV64
> 
> Best Regards,
> Hao Wu
> 
> 
>>
>> I will wait a couple days before merging to see if any additional comment
>> from other reviewers.
>>
>> Best Regards,
>> Hao Wu
>>
>>
>>>
>>> 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.PcdAllowVariablePolicyEnforcementDis
>>> able|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..85d8dcd69619
>>> --- /dev/null
>>> +++
>> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.in
>>> +++ f
>>> @@ -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 000000000000..71f30d8b9f7f
>>> --- /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--------------
>>> + 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] 9+ messages in thread

* Re: [edk2-devel] [PATCH EDK2 v2 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
  2021-08-04  8:04       ` wenyi,xie
@ 2021-08-04  8:24         ` Wu, Hao A
  2021-08-10  4:11           ` Wu, Hao A
  0 siblings, 1 reply; 9+ messages in thread
From: Wu, Hao A @ 2021-08-04  8:24 UTC (permalink / raw)
  To: xiewenyi (A), Kinney, Michael D, devel@edk2.groups.io
  Cc: songdongkuang@huawei.com, Wang, Jian J

> -----Original Message-----
> From: xiewenyi (A) <xiewenyi2@huawei.com>
> Sent: Wednesday, August 4, 2021 4:05 PM
> To: Wu, Hao A <hao.a.wu@intel.com>; devel@edk2.groups.io
> Cc: songdongkuang@huawei.com; Wang, Jian J <jian.j.wang@intel.com>
> Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1] MdeModulePkg/UefiSortLib:Add
> UefiSortLib unit test
> 
> 
> 
> On 2021/8/2 9:56, Wu, Hao A wrote:
> >> -----Original Message-----
> >> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wu,
> >> Hao A
> >> Sent: Thursday, July 29, 2021 4:26 PM
> >> To: Wenyi Xie <xiewenyi2@huawei.com>; devel@edk2.groups.io; Wang,
> >> Jian J <jian.j.wang@intel.com>
> >> Cc: songdongkuang@huawei.com
> >> Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
> >> MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
> >>
> >>> -----Original Message-----
> >>> From: Wenyi Xie <xiewenyi2@huawei.com>
> >>> Sent: Thursday, July 29, 2021 4:01 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 v2 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.
> >>
> >>
> >> Thanks.
> >> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
> >
> >
> > Sorry, I found that there are a couple of coding format style check failures
> when merging the patch.
> > Could you help to resolve them and then create a test pull request on the
> GitHub for verification? Thanks in advance.
> > (I think you can take the case under
> > MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/ for
> > reference.)
> >
> 
> Hi, Wu Hao
> 
> I try to deal with the coding format style check failures, and meet a failure which
> I am not sure how to solve.
> I take the case you told for reference, but still there's a failure said the define
> should be capital letters.
> but if change it to capital letters, there will be another error Function name does
> not follow the rules: 1. First character should be upper case 2. Must contain
> lower case characters 3. No white space characters
> 
> #define Main main
> 
> INT32
> Main (
>   IN INT32  Argc,
>   IN CHAR8  *Argv[]
>   )
> {
>   UnitTestingEntry ();
>   return 0;
> }


Hello Mike,

I saw the below commit:
  SHA-1: dcaa93936591883aa7826eb45ef00416ad82ef08
  * MdeModulePkg/Variable/RuntimeDxe: Add Variable Lock Protocol Unit Tests
has a similar case that should involve the naming of the 'main' function within the unit test codes.

I am wondering how the open raised by Wenyi was handled back then.
Do you have suggestions for this case? Thanks in advance.

Best Regards,
Hao Wu


> 
> Thanks
> Wenyi
> 
> > Error details:
> > 2021-08-02T01:09:28.5955820Z ##[section]Starting: Build and Test
> > MdeModulePkg IA32,X64,ARM,AARCH64,RISCV64 2021-08-
> 02T01:09:28.5960733Z
> =================================================================
> =============
> > 2021-08-02T01:09:28.5961018Z Task         : Command Line
> > 2021-08-02T01:09:28.5961258Z Description  : Run a command line with
> arguments
> > 2021-08-02T01:09:28.5961502Z Version      : 1.1.3
> > 2021-08-02T01:09:28.5961897Z Author       : Microsoft Corporation
> > 2021-08-02T01:09:28.5962259Z Help         : [More
> Information](https://go.microsoft.com/fwlink/?LinkID=613735)
> > 2021-08-02T01:09:28.5962678Z
> >
> =================================================================
> =====
> > ======== 2021-08-02T01:09:29.3504946Z (node:3659) Warning: Use
> > Cipheriv for counter mode of aes-256-ctr 2021-08-02T01:09:29.3510020Z
> > (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
> > 2021-08-02T01:09:29.3511551Z (node:3659) Warning: Use Cipheriv for
> > counter mode of aes-256-ctr 2021-08-02T01:09:29.3513605Z (node:3659)
> > Warning: Use Cipheriv for counter mode of aes-256-ctr
> > 2021-08-02T01:09:29.3516798Z (node:3659) Warning: Use Cipheriv for
> > counter mode of aes-256-ctr 2021-08-02T01:09:29.3517536Z (node:3659)
> > Warning: Use Cipheriv for counter mode of aes-256-ctr
> > 2021-08-02T01:09:29.3518178Z (node:3659) Warning: Use Cipheriv for
> > counter mode of aes-256-ctr 2021-08-02T01:09:29.3545461Z
> > [command]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build -c
> > .pytool/CISettings.py -p MdeModulePkg -t RELEASE,NO-TARGET -a
> > IA32,X64,ARM,AARCH64,RISCV64 TOOL_CHAIN_TAG=GCC5
> > 2021-08-02T01:09:29.3546707Z SECTION - Init SDE
> > 2021-08-02T01:09:29.3547571Z WARNING - Using Pip Tools based BaseTools
> > 2021-08-02T01:09:29.3548395Z SECTION - Loading Plugins
> > 2021-08-02T01:09:29.3549212Z SECTION - Start Invocable Tool
> > 2021-08-02T01:09:29.3550018Z SECTION - Getting Environment
> > 2021-08-02T01:09:29.3550794Z SECTION - Loading plugins
> > 2021-08-02T01:09:29.3551675Z SECTION - Building MdeModulePkg Package
> > 2021-08-02T01:09:29.3552693Z PROGRESS - --Running MdeModulePkg:
> > EccCheck Test NO-TARGET -- 2021-08-02T01:09:33.0697006Z ERROR -
> > 2021-08-02T01:09:33.0698018Z ERROR - EFI coding style error
> > 2021-08-02T01:09:33.0698748Z ERROR - *Error code: 5007
> > 2021-08-02T01:09:33.0700631Z ERROR - *There should be no
> > initialization of a variable as part of its declaration
> > 2021-08-02T01:09:33.0702675Z ERROR - *file:
> > //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSor
> > tLibUnitTest.c 2021-08-02T01:09:33.0703421Z ERROR - *Line number: 77
> > 2021-08-02T01:09:33.0703929Z ERROR - *Variable Name: TestCount
> > 2021-08-02T01:09:33.0715684Z ERROR - 2021-08-02T01:09:33.0716634Z
> > ERROR - EFI coding style error 2021-08-02T01:09:33.0717372Z ERROR -
> > *Error code: 5007 2021-08-02T01:09:33.0718214Z ERROR - *There should
> > be no initialization of a variable as part of its declaration
> > 2021-08-02T01:09:33.0719195Z ERROR - *file:
> > //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSor
> > tLibUnitTest.c 2021-08-02T01:09:33.0720631Z ERROR - *Line number: 78
> > 2021-08-02T01:09:33.0721451Z ERROR - *Variable Name: TestBuffer
> > 2021-08-02T01:09:33.0722114Z ERROR - 2021-08-02T01:09:33.0724953Z
> > ERROR - EFI coding style error 2021-08-02T01:09:33.0725713Z ERROR -
> > *Error code: 5007 2021-08-02T01:09:33.0726562Z ERROR - *There should
> > be no initialization of a variable as part of its declaration
> > 2021-08-02T01:09:33.0727526Z ERROR - *file:
> > //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSor
> > tLibUnitTest.c 2021-08-02T01:09:33.0728345Z ERROR - *Line number: 79
> > 2021-08-02T01:09:33.0729046Z ERROR - *Variable Name: TestResult
> > 2021-08-02T01:09:33.0729694Z ERROR - 2021-08-02T01:09:33.0732496Z
> > ERROR - EFI coding style error 2021-08-02T01:09:33.0733224Z ERROR -
> > *Error code: 7001 2021-08-02T01:09:33.0734114Z ERROR - *There should
> > be no use of int, unsigned, char, void, long in any .c, .h or .asl
> > files 2021-08-02T01:09:33.0737620Z ERROR - *file:
> > //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSor
> > tLibUnitTest.c 2021-08-02T01:09:33.0739185Z ERROR - *Line number: 117
> > 2021-08-02T01:09:33.0741301Z ERROR - *[main] Return type int
> > 2021-08-02T01:09:33.0744099Z ERROR - 2021-08-02T01:09:33.0744829Z
> > ERROR - EFI coding style error 2021-08-02T01:09:33.0745459Z ERROR -
> > *Error code: 7001 2021-08-02T01:09:33.0746821Z ERROR - *There should
> > be no use of int, unsigned, char, void, long in any .c, .h or .asl
> > files 2021-08-02T01:09:33.0747774Z ERROR - *file:
> > //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSor
> > tLibUnitTest.c 2021-08-02T01:09:33.0749076Z ERROR - *Line number: 117
> > 2021-08-02T01:09:33.0749713Z ERROR - *Parameter argc
> > 2021-08-02T01:09:33.0750999Z ERROR - 2021-08-02T01:09:33.0751607Z
> > ERROR - EFI coding style error 2021-08-02T01:09:33.0754599Z ERROR -
> > *Error code: 7001 2021-08-02T01:09:33.0761175Z ERROR - *There should
> > be no use of int, unsigned, char, void, long in any .c, .h or .asl
> > files 2021-08-02T01:09:33.0762167Z ERROR - *file:
> > //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSor
> > tLibUnitTest.c 2021-08-02T01:09:33.0763160Z ERROR - *Line number: 117
> > 2021-08-02T01:09:33.0763741Z ERROR - *Parameter argv
> > 2021-08-02T01:09:33.0764290Z ERROR - 2021-08-02T01:09:33.0764843Z
> > ERROR - EFI coding style error 2021-08-02T01:09:33.0766810Z ERROR -
> > *Error code: 8006 2021-08-02T01:09:33.0767819Z ERROR - *Function name
> > does not follow the rules: 1. First character should be upper case 2.
> > Must contain lower case characters 3. No white space characters
> > 2021-08-02T01:09:33.0768881Z ERROR - *file:
> > //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSor
> > tLibUnitTest.c 2021-08-02T01:09:33.0769619Z ERROR - *Line number: 181
> > 2021-08-02T01:09:33.0773329Z ERROR - *The function name [main] does
> > not follow the rules 2021-08-02T01:09:33.0791935Z ERROR -
> > 2021-08-02T01:09:33.0793865Z ERROR - EFI coding style error
> > 2021-08-02T01:09:33.0794555Z ERROR - *Error code: 9002
> > 2021-08-02T01:09:33.0795350Z ERROR - *The function headers should
> > follow Doxygen special documentation blocks in section 2.3.5
> > 2021-08-02T01:09:33.0796271Z ERROR - *file:
> > //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSor
> > tLibUnitTest.c 2021-08-02T01:09:33.0796985Z ERROR - *Line number: 178
> > 2021-08-02T01:09:33.0797610Z ERROR - *No doxygen tags in comment
> > 2021-08-02T01:09:33.0798208Z ERROR - 2021-08-02T01:09:33.0798859Z
> > ERROR - --->Test Failed: EccCheck Test NO-TARGET returned 1
> > 2021-08-02T01:09:33.0807351Z PROGRESS - --Running MdeModulePkg: Dsc
> > Complete Check Test NO-TARGET -- 2021-08-02T01:09:33.1524790Z
> PROGRESS
> > - --->Test Success: Dsc Complete Check Test NO-TARGET
> > 2021-08-02T01:09:33.1536004Z PROGRESS - --Running MdeModulePkg: Char
> > Encoding Check Test NO-TARGET -- 2021-08-02T01:09:33.6280380Z
> PROGRESS
> > - --->Test Success: Char Encoding Check Test NO-TARGET
> > 2021-08-02T01:09:33.6289076Z PROGRESS - --Running MdeModulePkg:
> > License Check Test NO-TARGET -- 2021-08-02T01:09:33.6495642Z PROGRESS
> > - --->Test Success: License Check Test NO-TARGET
> > 2021-08-02T01:09:33.6508125Z PROGRESS - --Running MdeModulePkg:
> > Compiler Plugin RELEASE -- 2021-08-02T01:09:33.6785178Z PROGRESS -
> > Start time: 2021-08-02 01:09:33.677952 2021-08-02T01:09:33.6787716Z
> PROGRESS - Setting up the Environment 2021-08-02T01:09:33.7725244Z
> PROGRESS - Running Pre Build 2021-08-02T01:09:33.7740357Z PROGRESS -
> Running Build RELEASE 2021-08-02T01:17:18.5479885Z PROGRESS - Running
> Post Build
> > 2021-08-02T01:17:18.5511807Z PROGRESS - End time: 2021-08-02
> 01:17:18.549974	 Total time Elapsed: 0:07:44
> > 2021-08-02T01:17:18.5512997Z PROGRESS - --->Test Success: Compiler
> > Plugin RELEASE 2021-08-02T01:17:18.5519284Z PROGRESS - --Running
> > MdeModulePkg: Library Class Check Test NO-TARGET --
> > 2021-08-02T01:17:18.5639216Z PROGRESS - --->Test Success: Library
> > Class Check Test NO-TARGET 2021-08-02T01:17:18.5648791Z PROGRESS -
> > --Running MdeModulePkg: Dependency Check Test NO-TARGET --
> > 2021-08-02T01:17:18.7306611Z PROGRESS - --->Test Success: Dependency
> > Check Test NO-TARGET 2021-08-02T01:17:18.7316162Z PROGRESS - --Running
> > MdeModulePkg: Spell Check Test NO-TARGET --
> > 2021-08-02T01:17:23.7922166Z WARNING - --->Test Skipped: in plugin!
> > Spell Check Test NO-TARGET 2021-08-02T01:17:23.7934112Z PROGRESS -
> > --Running MdeModulePkg: Guid Check Test NO-TARGET --
> > 2021-08-02T01:17:27.1928850Z PROGRESS - --->Test Success: Guid Check
> > Test NO-TARGET 2021-08-02T01:17:27.1939129Z PROGRESS - --Running
> > MdeModulePkg: Host Unit Test Dsc Complete Check Test NO-TARGET --
> > 2021-08-02T01:17:27.3703640Z PROGRESS - --->Test Success: Host Unit
> > Test Dsc Complete Check Test NO-TARGET 2021-08-02T01:17:27.3731676Z
> > ERROR - Overall Build Status: Error 2021-08-02T01:17:27.3733283Z
> > PROGRESS - There were 1 failures out of 10 attempts
> > 2021-08-02T01:17:27.3734501Z SECTION - Summary
> > 2021-08-02T01:17:27.3735613Z ERROR - Error
> > 2021-08-02T01:17:27.4159842Z
> > ##[error]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build
> > failed with return code: 1 2021-08-02T01:17:27.4173134Z
> > ##[error]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build
> > failed with error:
> > /opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build failed with
> > return code: 1 2021-08-02T01:17:27.4178252Z ##[section]Finishing:
> > Build and Test MdeModulePkg IA32,X64,ARM,AARCH64,RISCV64
> >
> > Best Regards,
> > Hao Wu
> >
> >
> >>
> >> I will wait a couple days before merging to see if any additional
> >> comment from other reviewers.
> >>
> >> Best Regards,
> >> Hao Wu
> >>
> >>
> >>>
> >>> 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.PcdAllowVariablePolicyEnforcementDis
> >>> able|TRUE
> >>>    }
> >>> +
> >>> +  MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf {
> >>> +    <LibraryClasses>
> >>> +      UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
> >>> +
> >>> + DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib.i
> >>> + DevicePathLib|nf
> >>> +  }
> >>> diff --git
> >>> a/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
> >>> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf
> >>> new file mode 100644
> >>> index 000000000000..85d8dcd69619
> >>> --- /dev/null
> >>> +++
> >> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.in
> >>> +++ f
> >>> @@ -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 000000000000..71f30d8b9f7f
> >>> --- /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------------
> >>> + --
> >>> + 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] 9+ messages in thread

* Re: [edk2-devel] [PATCH EDK2 v2 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
  2021-08-04  8:24         ` Wu, Hao A
@ 2021-08-10  4:11           ` Wu, Hao A
  2021-08-11  1:50             ` Wu, Hao A
  0 siblings, 1 reply; 9+ messages in thread
From: Wu, Hao A @ 2021-08-10  4:11 UTC (permalink / raw)
  To: Kinney, Michael D, devel@edk2.groups.io, xiewenyi (A)
  Cc: songdongkuang@huawei.com, Wang, Jian J

Sorry Mike,

Do you have advice on how to deal with ECC reporting function naming issue on the 'main' function for unit test cases?
So far, I think Wenyi has tried following the same pattern in file MdeModulePkg\Universal\Variable\RuntimeDxe\RuntimeDxeUnitTest\VariableLockRequestToLockUnitTest.c:

///
/// Avoid ECC error for function name that starts with lower case letter
///
#define Main 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
Main (
  IN INT32  Argc,
  IN CHAR8  *Argv[]
  )

But it looks like the ECC checker in the merge test is still complaining.

Best Regards,
Hao Wu

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wu, Hao
> A
> Sent: Wednesday, August 4, 2021 4:24 PM
> To: xiewenyi (A) <xiewenyi2@huawei.com>; Kinney, Michael D
> <michael.d.kinney@intel.com>; devel@edk2.groups.io
> Cc: songdongkuang@huawei.com; Wang, Jian J <jian.j.wang@intel.com>
> Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
> MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
> 
> > -----Original Message-----
> > From: xiewenyi (A) <xiewenyi2@huawei.com>
> > Sent: Wednesday, August 4, 2021 4:05 PM
> > To: Wu, Hao A <hao.a.wu@intel.com>; devel@edk2.groups.io
> > Cc: songdongkuang@huawei.com; Wang, Jian J <jian.j.wang@intel.com>
> > Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
> > MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
> >
> >
> >
> > On 2021/8/2 9:56, Wu, Hao A wrote:
> > >> -----Original Message-----
> > >> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wu,
> > >> Hao A
> > >> Sent: Thursday, July 29, 2021 4:26 PM
> > >> To: Wenyi Xie <xiewenyi2@huawei.com>; devel@edk2.groups.io; Wang,
> > >> Jian J <jian.j.wang@intel.com>
> > >> Cc: songdongkuang@huawei.com
> > >> Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
> > >> MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
> > >>
> > >>> -----Original Message-----
> > >>> From: Wenyi Xie <xiewenyi2@huawei.com>
> > >>> Sent: Thursday, July 29, 2021 4:01 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 v2 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.
> > >>
> > >>
> > >> Thanks.
> > >> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
> > >
> > >
> > > Sorry, I found that there are a couple of coding format style check
> > > failures
> > when merging the patch.
> > > Could you help to resolve them and then create a test pull request
> > > on the
> > GitHub for verification? Thanks in advance.
> > > (I think you can take the case under
> > > MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/
> for
> > > reference.)
> > >
> >
> > Hi, Wu Hao
> >
> > I try to deal with the coding format style check failures, and meet a
> > failure which I am not sure how to solve.
> > I take the case you told for reference, but still there's a failure
> > said the define should be capital letters.
> > but if change it to capital letters, there will be another error
> > Function name does not follow the rules: 1. First character should be
> > upper case 2. Must contain lower case characters 3. No white space
> > characters
> >
> > #define Main main
> >
> > INT32
> > Main (
> >   IN INT32  Argc,
> >   IN CHAR8  *Argv[]
> >   )
> > {
> >   UnitTestingEntry ();
> >   return 0;
> > }
> 
> 
> Hello Mike,
> 
> I saw the below commit:
>   SHA-1: dcaa93936591883aa7826eb45ef00416ad82ef08
>   * MdeModulePkg/Variable/RuntimeDxe: Add Variable Lock Protocol Unit
> Tests has a similar case that should involve the naming of the 'main' function
> within the unit test codes.
> 
> I am wondering how the open raised by Wenyi was handled back then.
> Do you have suggestions for this case? Thanks in advance.
> 
> Best Regards,
> Hao Wu
> 
> 
> >
> > Thanks
> > Wenyi
> >
> > > Error details:
> > > 2021-08-02T01:09:28.5955820Z ##[section]Starting: Build and Test
> > > MdeModulePkg IA32,X64,ARM,AARCH64,RISCV64 2021-08-
> > 02T01:09:28.5960733Z
> >
> ==========================================================
> =======
> > =============
> > > 2021-08-02T01:09:28.5961018Z Task         : Command Line
> > > 2021-08-02T01:09:28.5961258Z Description  : Run a command line with
> > arguments
> > > 2021-08-02T01:09:28.5961502Z Version      : 1.1.3
> > > 2021-08-02T01:09:28.5961897Z Author       : Microsoft Corporation
> > > 2021-08-02T01:09:28.5962259Z Help         : [More
> > Information](https://go.microsoft.com/fwlink/?LinkID=613735)
> > > 2021-08-02T01:09:28.5962678Z
> > >
> >
> ==========================================================
> =======
> > =====
> > > ======== 2021-08-02T01:09:29.3504946Z (node:3659) Warning: Use
> > > Cipheriv for counter mode of aes-256-ctr
> > > 2021-08-02T01:09:29.3510020Z
> > > (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
> > > 2021-08-02T01:09:29.3511551Z (node:3659) Warning: Use Cipheriv for
> > > counter mode of aes-256-ctr 2021-08-02T01:09:29.3513605Z (node:3659)
> > > Warning: Use Cipheriv for counter mode of aes-256-ctr
> > > 2021-08-02T01:09:29.3516798Z (node:3659) Warning: Use Cipheriv for
> > > counter mode of aes-256-ctr 2021-08-02T01:09:29.3517536Z (node:3659)
> > > Warning: Use Cipheriv for counter mode of aes-256-ctr
> > > 2021-08-02T01:09:29.3518178Z (node:3659) Warning: Use Cipheriv for
> > > counter mode of aes-256-ctr 2021-08-02T01:09:29.3545461Z
> > > [command]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build
> > > -c .pytool/CISettings.py -p MdeModulePkg -t RELEASE,NO-TARGET -a
> > > IA32,X64,ARM,AARCH64,RISCV64 TOOL_CHAIN_TAG=GCC5
> > > 2021-08-02T01:09:29.3546707Z SECTION - Init SDE
> > > 2021-08-02T01:09:29.3547571Z WARNING - Using Pip Tools based
> > > BaseTools 2021-08-02T01:09:29.3548395Z SECTION - Loading Plugins
> > > 2021-08-02T01:09:29.3549212Z SECTION - Start Invocable Tool
> > > 2021-08-02T01:09:29.3550018Z SECTION - Getting Environment
> > > 2021-08-02T01:09:29.3550794Z SECTION - Loading plugins
> > > 2021-08-02T01:09:29.3551675Z SECTION - Building MdeModulePkg
> Package
> > > 2021-08-02T01:09:29.3552693Z PROGRESS - --Running MdeModulePkg:
> > > EccCheck Test NO-TARGET -- 2021-08-02T01:09:33.0697006Z ERROR -
> > > 2021-08-02T01:09:33.0698018Z ERROR - EFI coding style error
> > > 2021-08-02T01:09:33.0698748Z ERROR - *Error code: 5007
> > > 2021-08-02T01:09:33.0700631Z ERROR - *There should be no
> > > initialization of a variable as part of its declaration
> > > 2021-08-02T01:09:33.0702675Z ERROR - *file:
> > >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > or tLibUnitTest.c 2021-08-02T01:09:33.0703421Z ERROR - *Line number:
> > > 77 2021-08-02T01:09:33.0703929Z ERROR - *Variable Name: TestCount
> > > 2021-08-02T01:09:33.0715684Z ERROR - 2021-08-02T01:09:33.0716634Z
> > > ERROR - EFI coding style error 2021-08-02T01:09:33.0717372Z ERROR -
> > > *Error code: 5007 2021-08-02T01:09:33.0718214Z ERROR - *There should
> > > be no initialization of a variable as part of its declaration
> > > 2021-08-02T01:09:33.0719195Z ERROR - *file:
> > >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > or tLibUnitTest.c 2021-08-02T01:09:33.0720631Z ERROR - *Line number:
> > > 78 2021-08-02T01:09:33.0721451Z ERROR - *Variable Name: TestBuffer
> > > 2021-08-02T01:09:33.0722114Z ERROR - 2021-08-02T01:09:33.0724953Z
> > > ERROR - EFI coding style error 2021-08-02T01:09:33.0725713Z ERROR -
> > > *Error code: 5007 2021-08-02T01:09:33.0726562Z ERROR - *There should
> > > be no initialization of a variable as part of its declaration
> > > 2021-08-02T01:09:33.0727526Z ERROR - *file:
> > >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > or tLibUnitTest.c 2021-08-02T01:09:33.0728345Z ERROR - *Line number:
> > > 79 2021-08-02T01:09:33.0729046Z ERROR - *Variable Name: TestResult
> > > 2021-08-02T01:09:33.0729694Z ERROR - 2021-08-02T01:09:33.0732496Z
> > > ERROR - EFI coding style error 2021-08-02T01:09:33.0733224Z ERROR -
> > > *Error code: 7001 2021-08-02T01:09:33.0734114Z ERROR - *There should
> > > be no use of int, unsigned, char, void, long in any .c, .h or .asl
> > > files 2021-08-02T01:09:33.0737620Z ERROR - *file:
> > >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > or tLibUnitTest.c 2021-08-02T01:09:33.0739185Z ERROR - *Line number:
> > > 117 2021-08-02T01:09:33.0741301Z ERROR - *[main] Return type int
> > > 2021-08-02T01:09:33.0744099Z ERROR - 2021-08-02T01:09:33.0744829Z
> > > ERROR - EFI coding style error 2021-08-02T01:09:33.0745459Z ERROR -
> > > *Error code: 7001 2021-08-02T01:09:33.0746821Z ERROR - *There should
> > > be no use of int, unsigned, char, void, long in any .c, .h or .asl
> > > files 2021-08-02T01:09:33.0747774Z ERROR - *file:
> > >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > or tLibUnitTest.c 2021-08-02T01:09:33.0749076Z ERROR - *Line number:
> > > 117 2021-08-02T01:09:33.0749713Z ERROR - *Parameter argc
> > > 2021-08-02T01:09:33.0750999Z ERROR - 2021-08-02T01:09:33.0751607Z
> > > ERROR - EFI coding style error 2021-08-02T01:09:33.0754599Z ERROR -
> > > *Error code: 7001 2021-08-02T01:09:33.0761175Z ERROR - *There should
> > > be no use of int, unsigned, char, void, long in any .c, .h or .asl
> > > files 2021-08-02T01:09:33.0762167Z ERROR - *file:
> > >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > or tLibUnitTest.c 2021-08-02T01:09:33.0763160Z ERROR - *Line number:
> > > 117 2021-08-02T01:09:33.0763741Z ERROR - *Parameter argv
> > > 2021-08-02T01:09:33.0764290Z ERROR - 2021-08-02T01:09:33.0764843Z
> > > ERROR - EFI coding style error 2021-08-02T01:09:33.0766810Z ERROR -
> > > *Error code: 8006 2021-08-02T01:09:33.0767819Z ERROR - *Function
> > > name does not follow the rules: 1. First character should be upper case 2.
> > > Must contain lower case characters 3. No white space characters
> > > 2021-08-02T01:09:33.0768881Z ERROR - *file:
> > >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > or tLibUnitTest.c 2021-08-02T01:09:33.0769619Z ERROR - *Line number:
> > > 181 2021-08-02T01:09:33.0773329Z ERROR - *The function name [main]
> > > does not follow the rules 2021-08-02T01:09:33.0791935Z ERROR -
> > > 2021-08-02T01:09:33.0793865Z ERROR - EFI coding style error
> > > 2021-08-02T01:09:33.0794555Z ERROR - *Error code: 9002
> > > 2021-08-02T01:09:33.0795350Z ERROR - *The function headers should
> > > follow Doxygen special documentation blocks in section 2.3.5
> > > 2021-08-02T01:09:33.0796271Z ERROR - *file:
> > >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > or tLibUnitTest.c 2021-08-02T01:09:33.0796985Z ERROR - *Line number:
> > > 178 2021-08-02T01:09:33.0797610Z ERROR - *No doxygen tags in comment
> > > 2021-08-02T01:09:33.0798208Z ERROR - 2021-08-02T01:09:33.0798859Z
> > > ERROR - --->Test Failed: EccCheck Test NO-TARGET returned 1
> > > 2021-08-02T01:09:33.0807351Z PROGRESS - --Running MdeModulePkg:
> Dsc
> > > Complete Check Test NO-TARGET -- 2021-08-02T01:09:33.1524790Z
> > PROGRESS
> > > - --->Test Success: Dsc Complete Check Test NO-TARGET
> > > 2021-08-02T01:09:33.1536004Z PROGRESS - --Running MdeModulePkg:
> Char
> > > Encoding Check Test NO-TARGET -- 2021-08-02T01:09:33.6280380Z
> > PROGRESS
> > > - --->Test Success: Char Encoding Check Test NO-TARGET
> > > 2021-08-02T01:09:33.6289076Z PROGRESS - --Running MdeModulePkg:
> > > License Check Test NO-TARGET -- 2021-08-02T01:09:33.6495642Z
> > > PROGRESS
> > > - --->Test Success: License Check Test NO-TARGET
> > > 2021-08-02T01:09:33.6508125Z PROGRESS - --Running MdeModulePkg:
> > > Compiler Plugin RELEASE -- 2021-08-02T01:09:33.6785178Z PROGRESS -
> > > Start time: 2021-08-02 01:09:33.677952 2021-08-02T01:09:33.6787716Z
> > PROGRESS - Setting up the Environment 2021-08-02T01:09:33.7725244Z
> > PROGRESS - Running Pre Build 2021-08-02T01:09:33.7740357Z PROGRESS -
> > Running Build RELEASE 2021-08-02T01:17:18.5479885Z PROGRESS - Running
> > Post Build
> > > 2021-08-02T01:17:18.5511807Z PROGRESS - End time: 2021-08-02
> > 01:17:18.549974	 Total time Elapsed: 0:07:44
> > > 2021-08-02T01:17:18.5512997Z PROGRESS - --->Test Success: Compiler
> > > Plugin RELEASE 2021-08-02T01:17:18.5519284Z PROGRESS - --Running
> > > MdeModulePkg: Library Class Check Test NO-TARGET --
> > > 2021-08-02T01:17:18.5639216Z PROGRESS - --->Test Success: Library
> > > Class Check Test NO-TARGET 2021-08-02T01:17:18.5648791Z PROGRESS -
> > > --Running MdeModulePkg: Dependency Check Test NO-TARGET --
> > > 2021-08-02T01:17:18.7306611Z PROGRESS - --->Test Success: Dependency
> > > Check Test NO-TARGET 2021-08-02T01:17:18.7316162Z PROGRESS -
> > > --Running
> > > MdeModulePkg: Spell Check Test NO-TARGET --
> > > 2021-08-02T01:17:23.7922166Z WARNING - --->Test Skipped: in plugin!
> > > Spell Check Test NO-TARGET 2021-08-02T01:17:23.7934112Z PROGRESS -
> > > --Running MdeModulePkg: Guid Check Test NO-TARGET --
> > > 2021-08-02T01:17:27.1928850Z PROGRESS - --->Test Success: Guid Check
> > > Test NO-TARGET 2021-08-02T01:17:27.1939129Z PROGRESS - --Running
> > > MdeModulePkg: Host Unit Test Dsc Complete Check Test NO-TARGET --
> > > 2021-08-02T01:17:27.3703640Z PROGRESS - --->Test Success: Host Unit
> > > Test Dsc Complete Check Test NO-TARGET 2021-08-02T01:17:27.3731676Z
> > > ERROR - Overall Build Status: Error 2021-08-02T01:17:27.3733283Z
> > > PROGRESS - There were 1 failures out of 10 attempts
> > > 2021-08-02T01:17:27.3734501Z SECTION - Summary
> > > 2021-08-02T01:17:27.3735613Z ERROR - Error
> > > 2021-08-02T01:17:27.4159842Z
> > > ##[error]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build
> > > failed with return code: 1 2021-08-02T01:17:27.4173134Z
> > > ##[error]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build
> > > failed with error:
> > > /opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build failed
> > > with return code: 1 2021-08-02T01:17:27.4178252Z ##[section]Finishing:
> > > Build and Test MdeModulePkg IA32,X64,ARM,AARCH64,RISCV64
> > >
> > > Best Regards,
> > > Hao Wu
> > >
> > >
> > >>
> > >> I will wait a couple days before merging to see if any additional
> > >> comment from other reviewers.
> > >>
> > >> Best Regards,
> > >> Hao Wu
> > >>
> > >>
> > >>>
> > >>> 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.PcdAllowVariablePolicyEnforcementDis
> > >>> able|TRUE
> > >>>    }
> > >>> +
> > >>> +
> MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf {
> > >>> +    <LibraryClasses>
> > >>> +
> > >>> + UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
> > >>> +
> > >>> +
> DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib
> > >>> + DevicePathLib|.i
> > >>> + DevicePathLib|nf
> > >>> +  }
> > >>> diff --git
> > >>> a/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.in
> > >>> f
> > >>>
> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.in
> > >>> f
> > >>> new file mode 100644
> > >>> index 000000000000..85d8dcd69619
> > >>> --- /dev/null
> > >>> +++
> > >> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.in
> > >>> +++ f
> > >>> @@ -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 000000000000..71f30d8b9f7f
> > >>> --- /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----------
> > >>> + --
> > >>> + --
> > >>> + 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] 9+ messages in thread

* Re: [edk2-devel] [PATCH EDK2 v2 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
  2021-08-10  4:11           ` Wu, Hao A
@ 2021-08-11  1:50             ` Wu, Hao A
  2021-08-11  1:59               ` wenyi,xie
  0 siblings, 1 reply; 9+ messages in thread
From: Wu, Hao A @ 2021-08-11  1:50 UTC (permalink / raw)
  To: xiewenyi (A), devel@edk2.groups.io
  Cc: songdongkuang@huawei.com, Wang, Jian J, Kinney, Michael D

Seems no help is received so far.
The approach I can think of is to add this to the ECC exception list defined in file MdeModulePkg.ci.yaml.

Hello Wenyi,

Could you help to check if the code changes in https://github.com/tianocore/edk2/pull/1883 works for you?
If so, could you update a V3 version of the patch? Thanks in advance.

Best Regards,
Hao Wu

> -----Original Message-----
> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wu, Hao
> A
> Sent: Tuesday, August 10, 2021 12:12 PM
> To: Kinney, Michael D <michael.d.kinney@intel.com>; devel@edk2.groups.io;
> xiewenyi (A) <xiewenyi2@huawei.com>
> Cc: songdongkuang@huawei.com; Wang, Jian J <jian.j.wang@intel.com>
> Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
> MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
> 
> Sorry Mike,
> 
> Do you have advice on how to deal with ECC reporting function naming issue
> on the 'main' function for unit test cases?
> So far, I think Wenyi has tried following the same pattern in file
> MdeModulePkg\Universal\Variable\RuntimeDxe\RuntimeDxeUnitTest\Vari
> ableLockRequestToLockUnitTest.c:
> 
> ///
> /// Avoid ECC error for function name that starts with lower case letter ///
> #define Main 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
> Main (
>   IN INT32  Argc,
>   IN CHAR8  *Argv[]
>   )
> 
> But it looks like the ECC checker in the merge test is still complaining.
> 
> Best Regards,
> Hao Wu
> 
> > -----Original Message-----
> > From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wu,
> Hao
> > A
> > Sent: Wednesday, August 4, 2021 4:24 PM
> > To: xiewenyi (A) <xiewenyi2@huawei.com>; Kinney, Michael D
> > <michael.d.kinney@intel.com>; devel@edk2.groups.io
> > Cc: songdongkuang@huawei.com; Wang, Jian J <jian.j.wang@intel.com>
> > Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
> > MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
> >
> > > -----Original Message-----
> > > From: xiewenyi (A) <xiewenyi2@huawei.com>
> > > Sent: Wednesday, August 4, 2021 4:05 PM
> > > To: Wu, Hao A <hao.a.wu@intel.com>; devel@edk2.groups.io
> > > Cc: songdongkuang@huawei.com; Wang, Jian J <jian.j.wang@intel.com>
> > > Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
> > > MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
> > >
> > >
> > >
> > > On 2021/8/2 9:56, Wu, Hao A wrote:
> > > >> -----Original Message-----
> > > >> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
> > > >> Wu, Hao A
> > > >> Sent: Thursday, July 29, 2021 4:26 PM
> > > >> To: Wenyi Xie <xiewenyi2@huawei.com>; devel@edk2.groups.io;
> Wang,
> > > >> Jian J <jian.j.wang@intel.com>
> > > >> Cc: songdongkuang@huawei.com
> > > >> Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
> > > >> MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
> > > >>
> > > >>> -----Original Message-----
> > > >>> From: Wenyi Xie <xiewenyi2@huawei.com>
> > > >>> Sent: Thursday, July 29, 2021 4:01 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 v2 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.
> > > >>
> > > >>
> > > >> Thanks.
> > > >> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
> > > >
> > > >
> > > > Sorry, I found that there are a couple of coding format style
> > > > check failures
> > > when merging the patch.
> > > > Could you help to resolve them and then create a test pull request
> > > > on the
> > > GitHub for verification? Thanks in advance.
> > > > (I think you can take the case under
> > > >
> MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/
> > for
> > > > reference.)
> > > >
> > >
> > > Hi, Wu Hao
> > >
> > > I try to deal with the coding format style check failures, and meet
> > > a failure which I am not sure how to solve.
> > > I take the case you told for reference, but still there's a failure
> > > said the define should be capital letters.
> > > but if change it to capital letters, there will be another error
> > > Function name does not follow the rules: 1. First character should
> > > be upper case 2. Must contain lower case characters 3. No white
> > > space characters
> > >
> > > #define Main main
> > >
> > > INT32
> > > Main (
> > >   IN INT32  Argc,
> > >   IN CHAR8  *Argv[]
> > >   )
> > > {
> > >   UnitTestingEntry ();
> > >   return 0;
> > > }
> >
> >
> > Hello Mike,
> >
> > I saw the below commit:
> >   SHA-1: dcaa93936591883aa7826eb45ef00416ad82ef08
> >   * MdeModulePkg/Variable/RuntimeDxe: Add Variable Lock Protocol Unit
> > Tests has a similar case that should involve the naming of the 'main'
> > function within the unit test codes.
> >
> > I am wondering how the open raised by Wenyi was handled back then.
> > Do you have suggestions for this case? Thanks in advance.
> >
> > Best Regards,
> > Hao Wu
> >
> >
> > >
> > > Thanks
> > > Wenyi
> > >
> > > > Error details:
> > > > 2021-08-02T01:09:28.5955820Z ##[section]Starting: Build and Test
> > > > MdeModulePkg IA32,X64,ARM,AARCH64,RISCV64 2021-08-
> > > 02T01:09:28.5960733Z
> > >
> >
> ==========================================================
> > =======
> > > =============
> > > > 2021-08-02T01:09:28.5961018Z Task         : Command Line
> > > > 2021-08-02T01:09:28.5961258Z Description  : Run a command line
> > > > with
> > > arguments
> > > > 2021-08-02T01:09:28.5961502Z Version      : 1.1.3
> > > > 2021-08-02T01:09:28.5961897Z Author       : Microsoft Corporation
> > > > 2021-08-02T01:09:28.5962259Z Help         : [More
> > > Information](https://go.microsoft.com/fwlink/?LinkID=613735)
> > > > 2021-08-02T01:09:28.5962678Z
> > > >
> > >
> >
> ==========================================================
> > =======
> > > =====
> > > > ======== 2021-08-02T01:09:29.3504946Z (node:3659) Warning: Use
> > > > Cipheriv for counter mode of aes-256-ctr
> > > > 2021-08-02T01:09:29.3510020Z
> > > > (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
> > > > 2021-08-02T01:09:29.3511551Z (node:3659) Warning: Use Cipheriv for
> > > > counter mode of aes-256-ctr 2021-08-02T01:09:29.3513605Z
> > > > (node:3659)
> > > > Warning: Use Cipheriv for counter mode of aes-256-ctr
> > > > 2021-08-02T01:09:29.3516798Z (node:3659) Warning: Use Cipheriv for
> > > > counter mode of aes-256-ctr 2021-08-02T01:09:29.3517536Z
> > > > (node:3659)
> > > > Warning: Use Cipheriv for counter mode of aes-256-ctr
> > > > 2021-08-02T01:09:29.3518178Z (node:3659) Warning: Use Cipheriv for
> > > > counter mode of aes-256-ctr 2021-08-02T01:09:29.3545461Z
> > > >
> [command]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_buil
> > > > d -c .pytool/CISettings.py -p MdeModulePkg -t RELEASE,NO-TARGET -a
> > > > IA32,X64,ARM,AARCH64,RISCV64 TOOL_CHAIN_TAG=GCC5
> > > > 2021-08-02T01:09:29.3546707Z SECTION - Init SDE
> > > > 2021-08-02T01:09:29.3547571Z WARNING - Using Pip Tools based
> > > > BaseTools 2021-08-02T01:09:29.3548395Z SECTION - Loading Plugins
> > > > 2021-08-02T01:09:29.3549212Z SECTION - Start Invocable Tool
> > > > 2021-08-02T01:09:29.3550018Z SECTION - Getting Environment
> > > > 2021-08-02T01:09:29.3550794Z SECTION - Loading plugins
> > > > 2021-08-02T01:09:29.3551675Z SECTION - Building MdeModulePkg
> > Package
> > > > 2021-08-02T01:09:29.3552693Z PROGRESS - --Running MdeModulePkg:
> > > > EccCheck Test NO-TARGET -- 2021-08-02T01:09:33.0697006Z ERROR -
> > > > 2021-08-02T01:09:33.0698018Z ERROR - EFI coding style error
> > > > 2021-08-02T01:09:33.0698748Z ERROR - *Error code: 5007
> > > > 2021-08-02T01:09:33.0700631Z ERROR - *There should be no
> > > > initialization of a variable as part of its declaration
> > > > 2021-08-02T01:09:33.0702675Z ERROR - *file:
> > > >
> >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > > or tLibUnitTest.c 2021-08-02T01:09:33.0703421Z ERROR - *Line number:
> > > > 77 2021-08-02T01:09:33.0703929Z ERROR - *Variable Name: TestCount
> > > > 2021-08-02T01:09:33.0715684Z ERROR - 2021-08-02T01:09:33.0716634Z
> > > > ERROR - EFI coding style error 2021-08-02T01:09:33.0717372Z ERROR
> > > > - *Error code: 5007 2021-08-02T01:09:33.0718214Z ERROR - *There
> > > > should be no initialization of a variable as part of its
> > > > declaration 2021-08-02T01:09:33.0719195Z ERROR - *file:
> > > >
> >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > > or tLibUnitTest.c 2021-08-02T01:09:33.0720631Z ERROR - *Line number:
> > > > 78 2021-08-02T01:09:33.0721451Z ERROR - *Variable Name: TestBuffer
> > > > 2021-08-02T01:09:33.0722114Z ERROR - 2021-08-02T01:09:33.0724953Z
> > > > ERROR - EFI coding style error 2021-08-02T01:09:33.0725713Z ERROR
> > > > - *Error code: 5007 2021-08-02T01:09:33.0726562Z ERROR - *There
> > > > should be no initialization of a variable as part of its
> > > > declaration 2021-08-02T01:09:33.0727526Z ERROR - *file:
> > > >
> >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > > or tLibUnitTest.c 2021-08-02T01:09:33.0728345Z ERROR - *Line number:
> > > > 79 2021-08-02T01:09:33.0729046Z ERROR - *Variable Name: TestResult
> > > > 2021-08-02T01:09:33.0729694Z ERROR - 2021-08-02T01:09:33.0732496Z
> > > > ERROR - EFI coding style error 2021-08-02T01:09:33.0733224Z ERROR
> > > > - *Error code: 7001 2021-08-02T01:09:33.0734114Z ERROR - *There
> > > > should be no use of int, unsigned, char, void, long in any .c, .h
> > > > or .asl files 2021-08-02T01:09:33.0737620Z ERROR - *file:
> > > >
> >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > > or tLibUnitTest.c 2021-08-02T01:09:33.0739185Z ERROR - *Line number:
> > > > 117 2021-08-02T01:09:33.0741301Z ERROR - *[main] Return type int
> > > > 2021-08-02T01:09:33.0744099Z ERROR - 2021-08-02T01:09:33.0744829Z
> > > > ERROR - EFI coding style error 2021-08-02T01:09:33.0745459Z ERROR
> > > > - *Error code: 7001 2021-08-02T01:09:33.0746821Z ERROR - *There
> > > > should be no use of int, unsigned, char, void, long in any .c, .h
> > > > or .asl files 2021-08-02T01:09:33.0747774Z ERROR - *file:
> > > >
> >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > > or tLibUnitTest.c 2021-08-02T01:09:33.0749076Z ERROR - *Line number:
> > > > 117 2021-08-02T01:09:33.0749713Z ERROR - *Parameter argc
> > > > 2021-08-02T01:09:33.0750999Z ERROR - 2021-08-02T01:09:33.0751607Z
> > > > ERROR - EFI coding style error 2021-08-02T01:09:33.0754599Z ERROR
> > > > - *Error code: 7001 2021-08-02T01:09:33.0761175Z ERROR - *There
> > > > should be no use of int, unsigned, char, void, long in any .c, .h
> > > > or .asl files 2021-08-02T01:09:33.0762167Z ERROR - *file:
> > > >
> >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > > or tLibUnitTest.c 2021-08-02T01:09:33.0763160Z ERROR - *Line number:
> > > > 117 2021-08-02T01:09:33.0763741Z ERROR - *Parameter argv
> > > > 2021-08-02T01:09:33.0764290Z ERROR - 2021-08-02T01:09:33.0764843Z
> > > > ERROR - EFI coding style error 2021-08-02T01:09:33.0766810Z ERROR
> > > > - *Error code: 8006 2021-08-02T01:09:33.0767819Z ERROR - *Function
> > > > name does not follow the rules: 1. First character should be upper case
> 2.
> > > > Must contain lower case characters 3. No white space characters
> > > > 2021-08-02T01:09:33.0768881Z ERROR - *file:
> > > >
> >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > > or tLibUnitTest.c 2021-08-02T01:09:33.0769619Z ERROR - *Line number:
> > > > 181 2021-08-02T01:09:33.0773329Z ERROR - *The function name [main]
> > > > does not follow the rules 2021-08-02T01:09:33.0791935Z ERROR -
> > > > 2021-08-02T01:09:33.0793865Z ERROR - EFI coding style error
> > > > 2021-08-02T01:09:33.0794555Z ERROR - *Error code: 9002
> > > > 2021-08-02T01:09:33.0795350Z ERROR - *The function headers should
> > > > follow Doxygen special documentation blocks in section 2.3.5
> > > > 2021-08-02T01:09:33.0796271Z ERROR - *file:
> > > >
> >
> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
> > > > or tLibUnitTest.c 2021-08-02T01:09:33.0796985Z ERROR - *Line number:
> > > > 178 2021-08-02T01:09:33.0797610Z ERROR - *No doxygen tags in
> > > > comment 2021-08-02T01:09:33.0798208Z ERROR -
> > > > 2021-08-02T01:09:33.0798859Z ERROR - --->Test Failed: EccCheck
> > > > Test NO-TARGET returned 1 2021-08-02T01:09:33.0807351Z PROGRESS -
> --Running MdeModulePkg:
> > Dsc
> > > > Complete Check Test NO-TARGET -- 2021-08-02T01:09:33.1524790Z
> > > PROGRESS
> > > > - --->Test Success: Dsc Complete Check Test NO-TARGET
> > > > 2021-08-02T01:09:33.1536004Z PROGRESS - --Running MdeModulePkg:
> > Char
> > > > Encoding Check Test NO-TARGET -- 2021-08-02T01:09:33.6280380Z
> > > PROGRESS
> > > > - --->Test Success: Char Encoding Check Test NO-TARGET
> > > > 2021-08-02T01:09:33.6289076Z PROGRESS - --Running MdeModulePkg:
> > > > License Check Test NO-TARGET -- 2021-08-02T01:09:33.6495642Z
> > > > PROGRESS
> > > > - --->Test Success: License Check Test NO-TARGET
> > > > 2021-08-02T01:09:33.6508125Z PROGRESS - --Running MdeModulePkg:
> > > > Compiler Plugin RELEASE -- 2021-08-02T01:09:33.6785178Z PROGRESS -
> > > > Start time: 2021-08-02 01:09:33.677952
> > > > 2021-08-02T01:09:33.6787716Z
> > > PROGRESS - Setting up the Environment 2021-08-02T01:09:33.7725244Z
> > > PROGRESS - Running Pre Build 2021-08-02T01:09:33.7740357Z PROGRESS -
> > > Running Build RELEASE 2021-08-02T01:17:18.5479885Z PROGRESS -
> > > Running Post Build
> > > > 2021-08-02T01:17:18.5511807Z PROGRESS - End time: 2021-08-02
> > > 01:17:18.549974	 Total time Elapsed: 0:07:44
> > > > 2021-08-02T01:17:18.5512997Z PROGRESS - --->Test Success: Compiler
> > > > Plugin RELEASE 2021-08-02T01:17:18.5519284Z PROGRESS - --Running
> > > > MdeModulePkg: Library Class Check Test NO-TARGET --
> > > > 2021-08-02T01:17:18.5639216Z PROGRESS - --->Test Success: Library
> > > > Class Check Test NO-TARGET 2021-08-02T01:17:18.5648791Z PROGRESS -
> > > > --Running MdeModulePkg: Dependency Check Test NO-TARGET --
> > > > 2021-08-02T01:17:18.7306611Z PROGRESS - --->Test Success:
> > > > Dependency Check Test NO-TARGET 2021-08-02T01:17:18.7316162Z
> > > > PROGRESS - --Running
> > > > MdeModulePkg: Spell Check Test NO-TARGET --
> > > > 2021-08-02T01:17:23.7922166Z WARNING - --->Test Skipped: in plugin!
> > > > Spell Check Test NO-TARGET 2021-08-02T01:17:23.7934112Z PROGRESS -
> > > > --Running MdeModulePkg: Guid Check Test NO-TARGET --
> > > > 2021-08-02T01:17:27.1928850Z PROGRESS - --->Test Success: Guid
> > > > Check Test NO-TARGET 2021-08-02T01:17:27.1939129Z PROGRESS -
> > > > --Running
> > > > MdeModulePkg: Host Unit Test Dsc Complete Check Test NO-TARGET --
> > > > 2021-08-02T01:17:27.3703640Z PROGRESS - --->Test Success: Host
> > > > Unit Test Dsc Complete Check Test NO-TARGET
> > > > 2021-08-02T01:17:27.3731676Z ERROR - Overall Build Status: Error
> > > > 2021-08-02T01:17:27.3733283Z PROGRESS - There were 1 failures out
> > > > of 10 attempts 2021-08-02T01:17:27.3734501Z SECTION - Summary
> > > > 2021-08-02T01:17:27.3735613Z ERROR - Error
> > > > 2021-08-02T01:17:27.4159842Z
> > > > ##[error]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_buil
> > > > d failed with return code: 1 2021-08-02T01:17:27.4173134Z
> > > > ##[error]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_buil
> > > > d
> > > > failed with error:
> > > > /opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build failed
> > > > with return code: 1 2021-08-02T01:17:27.4178252Z ##[section]Finishing:
> > > > Build and Test MdeModulePkg IA32,X64,ARM,AARCH64,RISCV64
> > > >
> > > > Best Regards,
> > > > Hao Wu
> > > >
> > > >
> > > >>
> > > >> I will wait a couple days before merging to see if any additional
> > > >> comment from other reviewers.
> > > >>
> > > >> Best Regards,
> > > >> Hao Wu
> > > >>
> > > >>
> > > >>>
> > > >>> 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.in
> > > >>> f
> > > >>> |
> > > >>> 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.PcdAllowVariablePolicyEnforcementDis
> > > >>> able|TRUE
> > > >>>    }
> > > >>> +
> > > >>> +
> > MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf {
> > > >>> +    <LibraryClasses>
> > > >>> +
> > > >>> + UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
> > > >>> +
> > > >>> +
> > DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib
> > > >>> + DevicePathLib|.i
> > > >>> + DevicePathLib|nf
> > > >>> +  }
> > > >>> diff --git
> > > >>> a/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.
> > > >>> in
> > > >>> f
> > > >>>
> > b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.in
> > > >>> f
> > > >>> new file mode 100644
> > > >>> index 000000000000..85d8dcd69619
> > > >>> --- /dev/null
> > > >>> +++
> > > >> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.i
> > > >> n
> > > >>> +++ f
> > > >>> @@ -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 000000000000..71f30d8b9f7f
> > > >>> --- /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--------
> > > >>> + --
> > > >>> + --
> > > >>> + --
> > > >>> + 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] 9+ messages in thread

* Re: [edk2-devel] [PATCH EDK2 v2 1/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
  2021-08-11  1:50             ` Wu, Hao A
@ 2021-08-11  1:59               ` wenyi,xie
  0 siblings, 0 replies; 9+ messages in thread
From: wenyi,xie @ 2021-08-11  1:59 UTC (permalink / raw)
  To: Wu, Hao A, devel@edk2.groups.io
  Cc: songdongkuang@huawei.com, Wang, Jian J, Kinney, Michael D

Hi Wu Hao,

Thank you for your help. I will have a try and send a V3 patch later.

Best Regards,
Wenyi

On 2021/8/11 9:50, Wu, Hao A wrote:
> Seems no help is received so far.
> The approach I can think of is to add this to the ECC exception list defined in file MdeModulePkg.ci.yaml.
> 
> Hello Wenyi,
> 
> Could you help to check if the code changes in https://github.com/tianocore/edk2/pull/1883 works for you?
> If so, could you update a V3 version of the patch? Thanks in advance.
> 
> Best Regards,
> Hao Wu
> 
>> -----Original Message-----
>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wu, Hao
>> A
>> Sent: Tuesday, August 10, 2021 12:12 PM
>> To: Kinney, Michael D <michael.d.kinney@intel.com>; devel@edk2.groups.io;
>> xiewenyi (A) <xiewenyi2@huawei.com>
>> Cc: songdongkuang@huawei.com; Wang, Jian J <jian.j.wang@intel.com>
>> Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
>> MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
>>
>> Sorry Mike,
>>
>> Do you have advice on how to deal with ECC reporting function naming issue
>> on the 'main' function for unit test cases?
>> So far, I think Wenyi has tried following the same pattern in file
>> MdeModulePkg\Universal\Variable\RuntimeDxe\RuntimeDxeUnitTest\Vari
>> ableLockRequestToLockUnitTest.c:
>>
>> ///
>> /// Avoid ECC error for function name that starts with lower case letter ///
>> #define Main 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
>> Main (
>>   IN INT32  Argc,
>>   IN CHAR8  *Argv[]
>>   )
>>
>> But it looks like the ECC checker in the merge test is still complaining.
>>
>> Best Regards,
>> Hao Wu
>>
>>> -----Original Message-----
>>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of Wu,
>> Hao
>>> A
>>> Sent: Wednesday, August 4, 2021 4:24 PM
>>> To: xiewenyi (A) <xiewenyi2@huawei.com>; Kinney, Michael D
>>> <michael.d.kinney@intel.com>; devel@edk2.groups.io
>>> Cc: songdongkuang@huawei.com; Wang, Jian J <jian.j.wang@intel.com>
>>> Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
>>> MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
>>>
>>>> -----Original Message-----
>>>> From: xiewenyi (A) <xiewenyi2@huawei.com>
>>>> Sent: Wednesday, August 4, 2021 4:05 PM
>>>> To: Wu, Hao A <hao.a.wu@intel.com>; devel@edk2.groups.io
>>>> Cc: songdongkuang@huawei.com; Wang, Jian J <jian.j.wang@intel.com>
>>>> Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
>>>> MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
>>>>
>>>>
>>>>
>>>> On 2021/8/2 9:56, Wu, Hao A wrote:
>>>>>> -----Original Message-----
>>>>>> From: devel@edk2.groups.io <devel@edk2.groups.io> On Behalf Of
>>>>>> Wu, Hao A
>>>>>> Sent: Thursday, July 29, 2021 4:26 PM
>>>>>> To: Wenyi Xie <xiewenyi2@huawei.com>; devel@edk2.groups.io;
>> Wang,
>>>>>> Jian J <jian.j.wang@intel.com>
>>>>>> Cc: songdongkuang@huawei.com
>>>>>> Subject: Re: [edk2-devel] [PATCH EDK2 v2 1/1]
>>>>>> MdeModulePkg/UefiSortLib:Add UefiSortLib unit test
>>>>>>
>>>>>>> -----Original Message-----
>>>>>>> From: Wenyi Xie <xiewenyi2@huawei.com>
>>>>>>> Sent: Thursday, July 29, 2021 4:01 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 v2 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.
>>>>>>
>>>>>>
>>>>>> Thanks.
>>>>>> Reviewed-by: Hao A Wu <hao.a.wu@intel.com>
>>>>>
>>>>>
>>>>> Sorry, I found that there are a couple of coding format style
>>>>> check failures
>>>> when merging the patch.
>>>>> Could you help to resolve them and then create a test pull request
>>>>> on the
>>>> GitHub for verification? Thanks in advance.
>>>>> (I think you can take the case under
>>>>>
>> MdeModulePkg/Universal/Variable/RuntimeDxe/RuntimeDxeUnitTest/
>>> for
>>>>> reference.)
>>>>>
>>>>
>>>> Hi, Wu Hao
>>>>
>>>> I try to deal with the coding format style check failures, and meet
>>>> a failure which I am not sure how to solve.
>>>> I take the case you told for reference, but still there's a failure
>>>> said the define should be capital letters.
>>>> but if change it to capital letters, there will be another error
>>>> Function name does not follow the rules: 1. First character should
>>>> be upper case 2. Must contain lower case characters 3. No white
>>>> space characters
>>>>
>>>> #define Main main
>>>>
>>>> INT32
>>>> Main (
>>>>   IN INT32  Argc,
>>>>   IN CHAR8  *Argv[]
>>>>   )
>>>> {
>>>>   UnitTestingEntry ();
>>>>   return 0;
>>>> }
>>>
>>>
>>> Hello Mike,
>>>
>>> I saw the below commit:
>>>   SHA-1: dcaa93936591883aa7826eb45ef00416ad82ef08
>>>   * MdeModulePkg/Variable/RuntimeDxe: Add Variable Lock Protocol Unit
>>> Tests has a similar case that should involve the naming of the 'main'
>>> function within the unit test codes.
>>>
>>> I am wondering how the open raised by Wenyi was handled back then.
>>> Do you have suggestions for this case? Thanks in advance.
>>>
>>> Best Regards,
>>> Hao Wu
>>>
>>>
>>>>
>>>> Thanks
>>>> Wenyi
>>>>
>>>>> Error details:
>>>>> 2021-08-02T01:09:28.5955820Z ##[section]Starting: Build and Test
>>>>> MdeModulePkg IA32,X64,ARM,AARCH64,RISCV64 2021-08-
>>>> 02T01:09:28.5960733Z
>>>>
>>>
>> ==========================================================
>>> =======
>>>> =============
>>>>> 2021-08-02T01:09:28.5961018Z Task         : Command Line
>>>>> 2021-08-02T01:09:28.5961258Z Description  : Run a command line
>>>>> with
>>>> arguments
>>>>> 2021-08-02T01:09:28.5961502Z Version      : 1.1.3
>>>>> 2021-08-02T01:09:28.5961897Z Author       : Microsoft Corporation
>>>>> 2021-08-02T01:09:28.5962259Z Help         : [More
>>>> Information](https://go.microsoft.com/fwlink/?LinkID=613735)
>>>>> 2021-08-02T01:09:28.5962678Z
>>>>>
>>>>
>>>
>> ==========================================================
>>> =======
>>>> =====
>>>>> ======== 2021-08-02T01:09:29.3504946Z (node:3659) Warning: Use
>>>>> Cipheriv for counter mode of aes-256-ctr
>>>>> 2021-08-02T01:09:29.3510020Z
>>>>> (node:3659) Warning: Use Cipheriv for counter mode of aes-256-ctr
>>>>> 2021-08-02T01:09:29.3511551Z (node:3659) Warning: Use Cipheriv for
>>>>> counter mode of aes-256-ctr 2021-08-02T01:09:29.3513605Z
>>>>> (node:3659)
>>>>> Warning: Use Cipheriv for counter mode of aes-256-ctr
>>>>> 2021-08-02T01:09:29.3516798Z (node:3659) Warning: Use Cipheriv for
>>>>> counter mode of aes-256-ctr 2021-08-02T01:09:29.3517536Z
>>>>> (node:3659)
>>>>> Warning: Use Cipheriv for counter mode of aes-256-ctr
>>>>> 2021-08-02T01:09:29.3518178Z (node:3659) Warning: Use Cipheriv for
>>>>> counter mode of aes-256-ctr 2021-08-02T01:09:29.3545461Z
>>>>>
>> [command]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_buil
>>>>> d -c .pytool/CISettings.py -p MdeModulePkg -t RELEASE,NO-TARGET -a
>>>>> IA32,X64,ARM,AARCH64,RISCV64 TOOL_CHAIN_TAG=GCC5
>>>>> 2021-08-02T01:09:29.3546707Z SECTION - Init SDE
>>>>> 2021-08-02T01:09:29.3547571Z WARNING - Using Pip Tools based
>>>>> BaseTools 2021-08-02T01:09:29.3548395Z SECTION - Loading Plugins
>>>>> 2021-08-02T01:09:29.3549212Z SECTION - Start Invocable Tool
>>>>> 2021-08-02T01:09:29.3550018Z SECTION - Getting Environment
>>>>> 2021-08-02T01:09:29.3550794Z SECTION - Loading plugins
>>>>> 2021-08-02T01:09:29.3551675Z SECTION - Building MdeModulePkg
>>> Package
>>>>> 2021-08-02T01:09:29.3552693Z PROGRESS - --Running MdeModulePkg:
>>>>> EccCheck Test NO-TARGET -- 2021-08-02T01:09:33.0697006Z ERROR -
>>>>> 2021-08-02T01:09:33.0698018Z ERROR - EFI coding style error
>>>>> 2021-08-02T01:09:33.0698748Z ERROR - *Error code: 5007
>>>>> 2021-08-02T01:09:33.0700631Z ERROR - *There should be no
>>>>> initialization of a variable as part of its declaration
>>>>> 2021-08-02T01:09:33.0702675Z ERROR - *file:
>>>>>
>>>
>> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
>>>>> or tLibUnitTest.c 2021-08-02T01:09:33.0703421Z ERROR - *Line number:
>>>>> 77 2021-08-02T01:09:33.0703929Z ERROR - *Variable Name: TestCount
>>>>> 2021-08-02T01:09:33.0715684Z ERROR - 2021-08-02T01:09:33.0716634Z
>>>>> ERROR - EFI coding style error 2021-08-02T01:09:33.0717372Z ERROR
>>>>> - *Error code: 5007 2021-08-02T01:09:33.0718214Z ERROR - *There
>>>>> should be no initialization of a variable as part of its
>>>>> declaration 2021-08-02T01:09:33.0719195Z ERROR - *file:
>>>>>
>>>
>> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
>>>>> or tLibUnitTest.c 2021-08-02T01:09:33.0720631Z ERROR - *Line number:
>>>>> 78 2021-08-02T01:09:33.0721451Z ERROR - *Variable Name: TestBuffer
>>>>> 2021-08-02T01:09:33.0722114Z ERROR - 2021-08-02T01:09:33.0724953Z
>>>>> ERROR - EFI coding style error 2021-08-02T01:09:33.0725713Z ERROR
>>>>> - *Error code: 5007 2021-08-02T01:09:33.0726562Z ERROR - *There
>>>>> should be no initialization of a variable as part of its
>>>>> declaration 2021-08-02T01:09:33.0727526Z ERROR - *file:
>>>>>
>>>
>> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
>>>>> or tLibUnitTest.c 2021-08-02T01:09:33.0728345Z ERROR - *Line number:
>>>>> 79 2021-08-02T01:09:33.0729046Z ERROR - *Variable Name: TestResult
>>>>> 2021-08-02T01:09:33.0729694Z ERROR - 2021-08-02T01:09:33.0732496Z
>>>>> ERROR - EFI coding style error 2021-08-02T01:09:33.0733224Z ERROR
>>>>> - *Error code: 7001 2021-08-02T01:09:33.0734114Z ERROR - *There
>>>>> should be no use of int, unsigned, char, void, long in any .c, .h
>>>>> or .asl files 2021-08-02T01:09:33.0737620Z ERROR - *file:
>>>>>
>>>
>> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
>>>>> or tLibUnitTest.c 2021-08-02T01:09:33.0739185Z ERROR - *Line number:
>>>>> 117 2021-08-02T01:09:33.0741301Z ERROR - *[main] Return type int
>>>>> 2021-08-02T01:09:33.0744099Z ERROR - 2021-08-02T01:09:33.0744829Z
>>>>> ERROR - EFI coding style error 2021-08-02T01:09:33.0745459Z ERROR
>>>>> - *Error code: 7001 2021-08-02T01:09:33.0746821Z ERROR - *There
>>>>> should be no use of int, unsigned, char, void, long in any .c, .h
>>>>> or .asl files 2021-08-02T01:09:33.0747774Z ERROR - *file:
>>>>>
>>>
>> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
>>>>> or tLibUnitTest.c 2021-08-02T01:09:33.0749076Z ERROR - *Line number:
>>>>> 117 2021-08-02T01:09:33.0749713Z ERROR - *Parameter argc
>>>>> 2021-08-02T01:09:33.0750999Z ERROR - 2021-08-02T01:09:33.0751607Z
>>>>> ERROR - EFI coding style error 2021-08-02T01:09:33.0754599Z ERROR
>>>>> - *Error code: 7001 2021-08-02T01:09:33.0761175Z ERROR - *There
>>>>> should be no use of int, unsigned, char, void, long in any .c, .h
>>>>> or .asl files 2021-08-02T01:09:33.0762167Z ERROR - *file:
>>>>>
>>>
>> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
>>>>> or tLibUnitTest.c 2021-08-02T01:09:33.0763160Z ERROR - *Line number:
>>>>> 117 2021-08-02T01:09:33.0763741Z ERROR - *Parameter argv
>>>>> 2021-08-02T01:09:33.0764290Z ERROR - 2021-08-02T01:09:33.0764843Z
>>>>> ERROR - EFI coding style error 2021-08-02T01:09:33.0766810Z ERROR
>>>>> - *Error code: 8006 2021-08-02T01:09:33.0767819Z ERROR - *Function
>>>>> name does not follow the rules: 1. First character should be upper case
>> 2.
>>>>> Must contain lower case characters 3. No white space characters
>>>>> 2021-08-02T01:09:33.0768881Z ERROR - *file:
>>>>>
>>>
>> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
>>>>> or tLibUnitTest.c 2021-08-02T01:09:33.0769619Z ERROR - *Line number:
>>>>> 181 2021-08-02T01:09:33.0773329Z ERROR - *The function name [main]
>>>>> does not follow the rules 2021-08-02T01:09:33.0791935Z ERROR -
>>>>> 2021-08-02T01:09:33.0793865Z ERROR - EFI coding style error
>>>>> 2021-08-02T01:09:33.0794555Z ERROR - *Error code: 9002
>>>>> 2021-08-02T01:09:33.0795350Z ERROR - *The function headers should
>>>>> follow Doxygen special documentation blocks in section 2.3.5
>>>>> 2021-08-02T01:09:33.0796271Z ERROR - *file:
>>>>>
>>>
>> //home/vsts/work/1/s/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiS
>>>>> or tLibUnitTest.c 2021-08-02T01:09:33.0796985Z ERROR - *Line number:
>>>>> 178 2021-08-02T01:09:33.0797610Z ERROR - *No doxygen tags in
>>>>> comment 2021-08-02T01:09:33.0798208Z ERROR -
>>>>> 2021-08-02T01:09:33.0798859Z ERROR - --->Test Failed: EccCheck
>>>>> Test NO-TARGET returned 1 2021-08-02T01:09:33.0807351Z PROGRESS -
>> --Running MdeModulePkg:
>>> Dsc
>>>>> Complete Check Test NO-TARGET -- 2021-08-02T01:09:33.1524790Z
>>>> PROGRESS
>>>>> - --->Test Success: Dsc Complete Check Test NO-TARGET
>>>>> 2021-08-02T01:09:33.1536004Z PROGRESS - --Running MdeModulePkg:
>>> Char
>>>>> Encoding Check Test NO-TARGET -- 2021-08-02T01:09:33.6280380Z
>>>> PROGRESS
>>>>> - --->Test Success: Char Encoding Check Test NO-TARGET
>>>>> 2021-08-02T01:09:33.6289076Z PROGRESS - --Running MdeModulePkg:
>>>>> License Check Test NO-TARGET -- 2021-08-02T01:09:33.6495642Z
>>>>> PROGRESS
>>>>> - --->Test Success: License Check Test NO-TARGET
>>>>> 2021-08-02T01:09:33.6508125Z PROGRESS - --Running MdeModulePkg:
>>>>> Compiler Plugin RELEASE -- 2021-08-02T01:09:33.6785178Z PROGRESS -
>>>>> Start time: 2021-08-02 01:09:33.677952
>>>>> 2021-08-02T01:09:33.6787716Z
>>>> PROGRESS - Setting up the Environment 2021-08-02T01:09:33.7725244Z
>>>> PROGRESS - Running Pre Build 2021-08-02T01:09:33.7740357Z PROGRESS -
>>>> Running Build RELEASE 2021-08-02T01:17:18.5479885Z PROGRESS -
>>>> Running Post Build
>>>>> 2021-08-02T01:17:18.5511807Z PROGRESS - End time: 2021-08-02
>>>> 01:17:18.549974	 Total time Elapsed: 0:07:44
>>>>> 2021-08-02T01:17:18.5512997Z PROGRESS - --->Test Success: Compiler
>>>>> Plugin RELEASE 2021-08-02T01:17:18.5519284Z PROGRESS - --Running
>>>>> MdeModulePkg: Library Class Check Test NO-TARGET --
>>>>> 2021-08-02T01:17:18.5639216Z PROGRESS - --->Test Success: Library
>>>>> Class Check Test NO-TARGET 2021-08-02T01:17:18.5648791Z PROGRESS -
>>>>> --Running MdeModulePkg: Dependency Check Test NO-TARGET --
>>>>> 2021-08-02T01:17:18.7306611Z PROGRESS - --->Test Success:
>>>>> Dependency Check Test NO-TARGET 2021-08-02T01:17:18.7316162Z
>>>>> PROGRESS - --Running
>>>>> MdeModulePkg: Spell Check Test NO-TARGET --
>>>>> 2021-08-02T01:17:23.7922166Z WARNING - --->Test Skipped: in plugin!
>>>>> Spell Check Test NO-TARGET 2021-08-02T01:17:23.7934112Z PROGRESS -
>>>>> --Running MdeModulePkg: Guid Check Test NO-TARGET --
>>>>> 2021-08-02T01:17:27.1928850Z PROGRESS - --->Test Success: Guid
>>>>> Check Test NO-TARGET 2021-08-02T01:17:27.1939129Z PROGRESS -
>>>>> --Running
>>>>> MdeModulePkg: Host Unit Test Dsc Complete Check Test NO-TARGET --
>>>>> 2021-08-02T01:17:27.3703640Z PROGRESS - --->Test Success: Host
>>>>> Unit Test Dsc Complete Check Test NO-TARGET
>>>>> 2021-08-02T01:17:27.3731676Z ERROR - Overall Build Status: Error
>>>>> 2021-08-02T01:17:27.3733283Z PROGRESS - There were 1 failures out
>>>>> of 10 attempts 2021-08-02T01:17:27.3734501Z SECTION - Summary
>>>>> 2021-08-02T01:17:27.3735613Z ERROR - Error
>>>>> 2021-08-02T01:17:27.4159842Z
>>>>> ##[error]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_buil
>>>>> d failed with return code: 1 2021-08-02T01:17:27.4173134Z
>>>>> ##[error]/opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_buil
>>>>> d
>>>>> failed with error:
>>>>> /opt/hostedtoolcache/Python/3.8.11/x64/bin/stuart_ci_build failed
>>>>> with return code: 1 2021-08-02T01:17:27.4178252Z ##[section]Finishing:
>>>>> Build and Test MdeModulePkg IA32,X64,ARM,AARCH64,RISCV64
>>>>>
>>>>> Best Regards,
>>>>> Hao Wu
>>>>>
>>>>>
>>>>>>
>>>>>> I will wait a couple days before merging to see if any additional
>>>>>> comment from other reviewers.
>>>>>>
>>>>>> Best Regards,
>>>>>> Hao Wu
>>>>>>
>>>>>>
>>>>>>>
>>>>>>> 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.in
>>>>>>> f
>>>>>>> |
>>>>>>> 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.PcdAllowVariablePolicyEnforcementDis
>>>>>>> able|TRUE
>>>>>>>    }
>>>>>>> +
>>>>>>> +
>>> MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.inf {
>>>>>>> +    <LibraryClasses>
>>>>>>> +
>>>>>>> + UefiSortLib|MdeModulePkg/Library/UefiSortLib/UefiSortLib.inf
>>>>>>> +
>>>>>>> +
>>> DevicePathLib|MdePkg/Library/UefiDevicePathLib/UefiDevicePathLib
>>>>>>> + DevicePathLib|.i
>>>>>>> + DevicePathLib|nf
>>>>>>> +  }
>>>>>>> diff --git
>>>>>>> a/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.
>>>>>>> in
>>>>>>> f
>>>>>>>
>>> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.in
>>>>>>> f
>>>>>>> new file mode 100644
>>>>>>> index 000000000000..85d8dcd69619
>>>>>>> --- /dev/null
>>>>>>> +++
>>>>>> b/MdeModulePkg/Library/UefiSortLib/UnitTest/UefiSortLibUnitTest.i
>>>>>> n
>>>>>>> +++ f
>>>>>>> @@ -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 000000000000..71f30d8b9f7f
>>>>>>> --- /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--------
>>>>>>> + --
>>>>>>> + --
>>>>>>> + --
>>>>>>> + 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] 9+ messages in thread

end of thread, other threads:[~2021-08-11  1:59 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-29  8:01 [PATCH EDK2 v2 0/1] MdeModulePkg/UefiSortLib:Add UefiSortLib unit test wenyi,xie
2021-07-29  8:01 ` [PATCH EDK2 v2 1/1] " wenyi,xie
2021-07-29  8:25   ` Wu, Hao A
2021-08-02  1:56     ` [edk2-devel] " Wu, Hao A
2021-08-04  8:04       ` wenyi,xie
2021-08-04  8:24         ` Wu, Hao A
2021-08-10  4:11           ` Wu, Hao A
2021-08-11  1:50             ` Wu, Hao A
2021-08-11  1:59               ` wenyi,xie

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox