[edk2] [staging/edk2-test Patch 03/10] MsUnitTestPkg: Update for VS2017 and 32-bit apps

Kinney, Michael D posted 10 patches 7 years ago
[edk2] [staging/edk2-test Patch 03/10] MsUnitTestPkg: Update for VS2017 and 32-bit apps
Posted by Kinney, Michael D 7 years ago
From: Sean Brogan <sean.brogan@microsoft.com>

Cherry-picked from branch:
https://github.com/Microsoft/MS_UEFI/tree/share/XmlAndUnitTest

Commit:
https://github.com/Microsoft/MS_UEFI/commit/d2901abfc9823c21d3a962fa69e025a92832466b

* Update Unit Test framework with minor changes to allow
  32 bit apps to work.
* Update to support VS2017 compiler

Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Liming Gao <liming.gao@intel.com>
Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
---
 MsUnitTestPkg/Include/Library/UnitTestAssertLib.h            | 12 ++++++------
 MsUnitTestPkg/Library/UnitTestAssertLib/UnitTestAssertLib.c  |  8 ++++----
 .../Library/UnitTestBootUsbClassLib/UnitTestBootUsb.c        |  2 ++
 MsUnitTestPkg/Library/UnitTestLib/UnitTestLib.c              |  4 ++--
 MsUnitTestPkg/Library/UnitTestLib/UnitTestLib.inf            |  1 +
 MsUnitTestPkg/MsUnitTestPkg.dec                              |  7 +++++++
 6 files changed, 22 insertions(+), 12 deletions(-)

diff --git a/MsUnitTestPkg/Include/Library/UnitTestAssertLib.h b/MsUnitTestPkg/Include/Library/UnitTestAssertLib.h
index 9f942848f9..2ebc61b5ab 100644
--- a/MsUnitTestPkg/Include/Library/UnitTestAssertLib.h
+++ b/MsUnitTestPkg/Include/Library/UnitTestAssertLib.h
@@ -37,13 +37,13 @@ ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
   if(!UnitTestAssertFalse( Framework, (Expression), __FUNCTION__, __LINE__, #Expression )) { return UNIT_TEST_ERROR_TEST_FAILED;}
 
 #define UT_ASSERT_EQUAL(ValueA, ValueB)           \
-  if(!UnitTestAssertEqual( Framework, (UINTN)ValueA, (UINTN)ValueB, __FUNCTION__, __LINE__, #ValueA, #ValueB )) { return UNIT_TEST_ERROR_TEST_FAILED;}
+  if(!UnitTestAssertEqual( Framework, (UINT64)ValueA, (UINT64)ValueB, __FUNCTION__, __LINE__, #ValueA, #ValueB )) { return UNIT_TEST_ERROR_TEST_FAILED;}
 
 #define UT_ASSERT_MEM_EQUAL(ValueA, ValueB, Length) \
   if(!UnitTestAssertMemEqual( Framework, (UINTN)ValueA, (UINTN)ValueB, (UINTN)Length, __FUNCTION__, __LINE__, #ValueA, #ValueB )) { return UNIT_TEST_ERROR_TEST_FAILED;}
 
 #define UT_ASSERT_NOT_EQUAL(ValueA, ValueB)       \
-  if(!UnitTestAssertNotEqual( Framework, ValueA, ValueB, __FUNCTION__, __LINE__, #ValueA, #ValueB )) { return UNIT_TEST_ERROR_TEST_FAILED;}
+  if(!UnitTestAssertNotEqual( Framework, (UINT64)ValueA, (UINT64)ValueB, __FUNCTION__, __LINE__, #ValueA, #ValueB )) { return UNIT_TEST_ERROR_TEST_FAILED;}
 
 #define UT_ASSERT_NOT_EFI_ERROR(Status)           \
   if(!UnitTestAssertNotEfiError( Framework, Status, __FUNCTION__, __LINE__, #Status )) { return UNIT_TEST_ERROR_TEST_FAILED;}
@@ -89,8 +89,8 @@ BOOLEAN
 EFIAPI
 UnitTestAssertEqual (
   IN UNIT_TEST_FRAMEWORK_HANDLE Framework,
-  IN UINTN                      ValueA,
-  IN UINTN                      ValueB,
+  IN UINT64                     ValueA,
+  IN UINT64                     ValueB,
   IN CONST CHAR8                *FunctionName,
   IN UINTN                      LineNumber,
   IN CONST CHAR8                *DescriptionA,
@@ -114,8 +114,8 @@ BOOLEAN
 EFIAPI
 UnitTestAssertNotEqual (
   IN UNIT_TEST_FRAMEWORK_HANDLE Framework,
-  IN UINTN                      ValueA,
-  IN UINTN                      ValueB,
+  IN UINT64                     ValueA,
+  IN UINT64                     ValueB,
   IN CONST CHAR8                *FunctionName,
   IN UINTN                      LineNumber,
   IN CONST CHAR8                *DescriptionA,
diff --git a/MsUnitTestPkg/Library/UnitTestAssertLib/UnitTestAssertLib.c b/MsUnitTestPkg/Library/UnitTestAssertLib/UnitTestAssertLib.c
index 94279c7056..5721102818 100644
--- a/MsUnitTestPkg/Library/UnitTestAssertLib/UnitTestAssertLib.c
+++ b/MsUnitTestPkg/Library/UnitTestAssertLib/UnitTestAssertLib.c
@@ -93,8 +93,8 @@ BOOLEAN
 EFIAPI
 UnitTestAssertEqual (
   IN UNIT_TEST_FRAMEWORK_HANDLE Framework,
-  IN UINTN                      ValueA,
-  IN UINTN                      ValueB,
+  IN UINT64                     ValueA,
+  IN UINT64                     ValueB,
   IN CONST CHAR8                *FunctionName,
   IN UINTN                      LineNumber,
   IN CONST CHAR8                *DescriptionA,
@@ -136,8 +136,8 @@ BOOLEAN
 EFIAPI
 UnitTestAssertNotEqual (
   IN UNIT_TEST_FRAMEWORK_HANDLE Framework,
-  IN UINTN                      ValueA,
-  IN UINTN                      ValueB,
+  IN UINT64                     ValueA,
+  IN UINT64                     ValueB,
   IN CONST CHAR8                *FunctionName,
   IN UINTN                      LineNumber,
   IN CONST CHAR8                *DescriptionA,
diff --git a/MsUnitTestPkg/Library/UnitTestBootUsbClassLib/UnitTestBootUsb.c b/MsUnitTestPkg/Library/UnitTestBootUsbClassLib/UnitTestBootUsb.c
index c176de726f..7fe82fb849 100644
--- a/MsUnitTestPkg/Library/UnitTestBootUsbClassLib/UnitTestBootUsb.c
+++ b/MsUnitTestPkg/Library/UnitTestBootUsbClassLib/UnitTestBootUsb.c
@@ -67,6 +67,7 @@ SetUsbBootNext(
   if (DpEnd == NULL)
   {
     DEBUG((DEBUG_ERROR, __FUNCTION__ ": Unable to create device path.  DpEnd is NULL.\n"));
+    Status = EFI_OUT_OF_RESOURCES;
     goto CLEANUP;
   }
 
@@ -74,6 +75,7 @@ SetUsbBootNext(
   if (Dp == NULL)
   {
     DEBUG((DEBUG_ERROR, __FUNCTION__ ": Unable to create device path.  Dp is NULL.\n"));
+    Status = EFI_OUT_OF_RESOURCES;
     goto CLEANUP;
   }
 
diff --git a/MsUnitTestPkg/Library/UnitTestLib/UnitTestLib.c b/MsUnitTestPkg/Library/UnitTestLib/UnitTestLib.c
index 53ce0792fb..bc4176d36e 100644
--- a/MsUnitTestPkg/Library/UnitTestLib/UnitTestLib.c
+++ b/MsUnitTestPkg/Library/UnitTestLib/UnitTestLib.c
@@ -654,7 +654,7 @@ UpdateTestFromSave (
     Test->Result = MatchingTest->Result;
 
     Test->FailureType = MatchingTest->FailureType;
-    StrnCpy(&Test->FailureMessage[0], &MatchingTest->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH);
+    StrnCpyS(&Test->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH, &MatchingTest->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH);
 
     // If there is a log string associated, grab that.
     // We can tell that there's a log string because the "size" will be larger than
@@ -795,7 +795,7 @@ SerializeState (
       // Save the result.
       TestSaveData->Result = UnitTest->Result;
       TestSaveData->FailureType = UnitTest->FailureType;
-      StrnCpy(&TestSaveData->FailureMessage[0], &UnitTest->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH);
+      StrnCpyS(&TestSaveData->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH, &UnitTest->FailureMessage[0], UNIT_TEST_TESTFAILUREMSG_LENGTH);
 
 
       // If there is a log, save the log.
diff --git a/MsUnitTestPkg/Library/UnitTestLib/UnitTestLib.inf b/MsUnitTestPkg/Library/UnitTestLib/UnitTestLib.inf
index d85db8ebb9..a6576e1b85 100644
--- a/MsUnitTestPkg/Library/UnitTestLib/UnitTestLib.inf
+++ b/MsUnitTestPkg/Library/UnitTestLib/UnitTestLib.inf
@@ -39,6 +39,7 @@ LIBRARY_CLASS   = UnitTestLib|DXE_DRIVER UEFI_APPLICATION
   DebugLib
   MemoryAllocationLib
   BaseMemoryLib
+  BaseLib
   UefiRuntimeServicesTableLib
   UefiLib
   UnitTestLogLib
diff --git a/MsUnitTestPkg/MsUnitTestPkg.dec b/MsUnitTestPkg/MsUnitTestPkg.dec
index 86c481d47d..9bc205c377 100644
--- a/MsUnitTestPkg/MsUnitTestPkg.dec
+++ b/MsUnitTestPkg/MsUnitTestPkg.dec
@@ -39,6 +39,13 @@
 
 [LibraryClasses]
 
+  ## @libraryclass Provides a unit test framework
+  #
+  UnitTestLib|Include\Library\UnitTestLib.h
+
+  ## @libraryclass Provide unit test assert helpers
+  #
+  UnitTestAssertLib|Include\Library\UnitTestAssertLib.h
 
 [Guids]
 
-- 
2.14.2.windows.3

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel