]> git.proxmox.com Git - mirror_edk2.git/commitdiff
MdePkg/Include: Hook DebugLib _ASSERT() for unit tests
authorMichael D Kinney <michael.d.kinney@intel.com>
Thu, 11 Jun 2020 01:00:37 +0000 (18:00 -0700)
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
Wed, 15 Jul 2020 05:25:21 +0000 (05:25 +0000)
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2801

Update DebugLib.h _ASSERT() macro to check if unit testing
is enabled and call UnitTestDebugAssert() instead of
DebugAssert() so the an ASSERT() condition that is triggered
by a function under test can be handled by the Unit Test
Framework.

If EDKII_UNIT_TEST_FRAMEWORK_ENABLED is not defined, then
the existing DebugLib behavior is preserved.

Cc: Liming Gao <liming.gao@intel.com>
Cc: Sean Brogan <sean.brogan@microsoft.com>
Cc: Bret Barkelew <Bret.Barkelew@microsoft.com>
Cc: Jiewen Yao <jiewen.yao@intel.com>
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
Reviewed-by: Liming Gao <liming.gao@intel.com>
MdePkg/Include/Library/DebugLib.h

index baab34bf0528c380d879107be89aaaedd1a2773e..4cacd4b8e2437270baac9174978c0ffa70308b78 100644 (file)
@@ -289,12 +289,38 @@ DebugPrintLevelEnabled (
   @param  Expression  Boolean expression that evaluated to FALSE\r
 \r
 **/\r
+#if defined (EDKII_UNIT_TEST_FRAMEWORK_ENABLED)\r
+/**\r
+  Unit test library replacement for DebugAssert() in DebugLib.\r
+\r
+  If FileName is NULL, then a <FileName> string of "(NULL) Filename" is printed.\r
+  If Description is NULL, then a <Description> string of "(NULL) Description" is printed.\r
+\r
+  @param  FileName     The pointer to the name of the source file that generated the assert condition.\r
+  @param  LineNumber   The line number in the source file that generated the assert condition\r
+  @param  Description  The pointer to the description of the assert condition.\r
+\r
+**/\r
+VOID\r
+EFIAPI\r
+UnitTestDebugAssert (\r
+  IN CONST CHAR8  *FileName,\r
+  IN UINTN        LineNumber,\r
+  IN CONST CHAR8  *Description\r
+  );\r
+\r
+#if defined(__clang__) && defined(__FILE_NAME__)\r
+#define _ASSERT(Expression)  UnitTestDebugAssert (__FILE_NAME__, __LINE__, #Expression)\r
+#else\r
+#define _ASSERT(Expression)  UnitTestDebugAssert (__FILE__, __LINE__, #Expression)\r
+#endif\r
+#else\r
 #if defined(__clang__) && defined(__FILE_NAME__)\r
 #define _ASSERT(Expression)  DebugAssert (__FILE_NAME__, __LINE__, #Expression)\r
 #else\r
 #define _ASSERT(Expression)  DebugAssert (__FILE__, __LINE__, #Expression)\r
 #endif\r
-\r
+#endif\r
 \r
 /**\r
   Internal worker macro that calls DebugPrint().\r