Re: [edk2-devel] [Patch v3 12/16] UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT()

2020-07-14 Thread Bret Barkelew via groups.io
Reviewed-by: Bret Barkelew 


- Bret

From: Michael D Kinney via 
groups.io<mailto:michael.d.kinney=intel@groups.io>
Sent: Tuesday, July 14, 2020 9:26 AM
To: liming.gao<mailto:liming@intel.com>; 
devel@edk2.groups.io<mailto:devel@edk2.groups.io>; Kinney, Michael 
D<mailto:michael.d.kin...@intel.com>
Cc: Sean Brogan<mailto:sean.bro...@microsoft.com>; Bret 
Barkelew<mailto:bret.barke...@microsoft.com>; Yao, 
Jiewen<mailto:jiewen....@intel.com>
Subject: [EXTERNAL] Re: [edk2-devel] [Patch v3 12/16] 
UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT()

Liming,

I will fix that one issue in the INF comment block
when I push the commits.

Thanks,

Mike

> -Original Message-
> From: Gao, Liming 
> Sent: Monday, July 13, 2020 11:57 PM
> To: devel@edk2.groups.io; Kinney, Michael D
> 
> Cc: Sean Brogan ; Bret
> Barkelew ; Yao, Jiewen
> 
> Subject: RE: [edk2-devel] [Patch v3 12/16]
> UnitTestFrameworkPkg/UnitTestLib: Add checks for
> ASSERT()
>
> Mike:
>
> -Original Message-
> From: devel@edk2.groups.io  On
> Behalf Of Michael D Kinney
> Sent: 2020年7月11日 10:09
> To: devel@edk2.groups.io
> Cc: Sean Brogan ; Bret
> Barkelew ; Yao, Jiewen
> 
> Subject: [edk2-devel] [Patch v3 12/16]
> UnitTestFrameworkPkg/UnitTestLib: Add checks for
> ASSERT()
>
> REF: REF:
> https://nam06.safelinks.protection.outlook.com/?url=https%3A%2F%2Fbugzilla.tianocore.org%2Fshow_bug.cgi%3Fid%3D2801data=02%7C01%7Cbret.barkelew%40microsoft.com%7C3b85c7dd72af42d6295508d82812a84a%7C72f988bf86f141af91ab2d7cd011db47%7C1%7C0%7C637303407889843281sdata=5fA35uRcosAAp0%2B1RVFoCLsGzAaqvc92dmxSVrwDJsY%3Dreserved=0
>
> Add UnitTestDebugAssertLib that provides the
> UnitTestDebugAssert() service and the
> gUnitTestExpectAssertFailureJumpBuffer global variable.
> This NULL library is linked against all host and target
> unit test builds.  This guarantees that the
> UnitTestDebugAssert() service is available to link
> against all libraries and modules that use the DebugLib
> class.
>
> EDKII_UNIT_TEST_FRAMEWORK_ENABLED must always be defined
> when building unit tests so the behavior of the DebugLib
> ASSERT() macros can be adjusted to allow the unit test
> framework to catch an ASSERT() if it is triggered by a
> function under test.
>
> Cc: Sean Brogan 
> Cc: Bret Barkelew 
> Cc: Jiewen Yao 
> Signed-off-by: Michael D Kinney
> 
> ---
>  .../UnitTestDebugAssertLib.c  |  49
> +
>  .../UnitTestDebugAssertLib.inf|  31 +++
>  .../UnitTestDebugAssertLib.uni|  11 +
>  .../Library/UnitTestLib/Assert.c  | 203
> --
>  .../Library/UnitTestLib/AssertCmocka.c|  68
> ++
>  .../Library/UnitTestLib/RunTests.c|  23 +-
>  .../UnitTestResultReportLib.c |   3 +-
>  .../PrivateInclude/UnitTestFrameworkTypes.h   |   1 +
>  .../Test/UnitTestFrameworkPkgHostTest.dsc |   2 +-
>  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc |   1 +
>  .../UnitTestFrameworkPkgTarget.dsc.inc|   6 +-
>  11 files changed, 328 insertions(+), 70 deletions(-)
> create mode 100644
> UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Unit
> TestDebugAssertLib.c
>  create mode 100644
> UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Unit
> TestDebugAssertLib.inf
>  create mode 100644
> UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Unit
> TestDebugAssertLib.uni
>
> diff --git
> a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugAssertLib.c
> b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugAssertLib.c
> new file mode 100644
> index 00..0a4001e182
> --- /dev/null
> +++
> b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugA
> +++ ssertLib.c
> @@ -0,0 +1,49 @@
> +/** @file
> +  Unit Test Debug Assert Library
> +
> +  Copyright (c) 2020, Intel Corporation. All rights
> reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include 
> +#include 
> +#include 
> +
> +///
> +/// Point to jump buffer used with SetJump()/LongJump()
> to test if a
> +function /// under test generates an expected ASSERT()
> condition.
> +///
> +BASE_LIBRARY_JUMP_BUFFER
> *gUnitTestExpectAssertFailureJumpBuffer =
> +NULL;
> +
> +/**
> +  Unit test library replacement for DebugAssert() in
> DebugLib.
> +
> +  If FileName is NULL, then a  string of
> "(NULL) Filename" is printed.
> +  If Description is NULL, then a  string
> of "(NULL) Description" is printed.
> +
> +  @param  FileName The pointer to the name of t

Re: [edk2-devel] [Patch v3 12/16] UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT()

2020-07-14 Thread Michael D Kinney
Liming,

I will fix that one issue in the INF comment block
when I push the commits.

Thanks,

Mike

> -Original Message-
> From: Gao, Liming 
> Sent: Monday, July 13, 2020 11:57 PM
> To: devel@edk2.groups.io; Kinney, Michael D
> 
> Cc: Sean Brogan ; Bret
> Barkelew ; Yao, Jiewen
> 
> Subject: RE: [edk2-devel] [Patch v3 12/16]
> UnitTestFrameworkPkg/UnitTestLib: Add checks for
> ASSERT()
> 
> Mike:
> 
> -Original Message-
> From: devel@edk2.groups.io  On
> Behalf Of Michael D Kinney
> Sent: 2020年7月11日 10:09
> To: devel@edk2.groups.io
> Cc: Sean Brogan ; Bret
> Barkelew ; Yao, Jiewen
> 
> Subject: [edk2-devel] [Patch v3 12/16]
> UnitTestFrameworkPkg/UnitTestLib: Add checks for
> ASSERT()
> 
> REF: REF:
> https://bugzilla.tianocore.org/show_bug.cgi?id=2801
> 
> Add UnitTestDebugAssertLib that provides the
> UnitTestDebugAssert() service and the
> gUnitTestExpectAssertFailureJumpBuffer global variable.
> This NULL library is linked against all host and target
> unit test builds.  This guarantees that the
> UnitTestDebugAssert() service is available to link
> against all libraries and modules that use the DebugLib
> class.
> 
> EDKII_UNIT_TEST_FRAMEWORK_ENABLED must always be defined
> when building unit tests so the behavior of the DebugLib
> ASSERT() macros can be adjusted to allow the unit test
> framework to catch an ASSERT() if it is triggered by a
> function under test.
> 
> Cc: Sean Brogan 
> Cc: Bret Barkelew 
> Cc: Jiewen Yao 
> Signed-off-by: Michael D Kinney
> 
> ---
>  .../UnitTestDebugAssertLib.c  |  49
> +
>  .../UnitTestDebugAssertLib.inf|  31 +++
>  .../UnitTestDebugAssertLib.uni|  11 +
>  .../Library/UnitTestLib/Assert.c  | 203
> --
>  .../Library/UnitTestLib/AssertCmocka.c|  68
> ++
>  .../Library/UnitTestLib/RunTests.c|  23 +-
>  .../UnitTestResultReportLib.c |   3 +-
>  .../PrivateInclude/UnitTestFrameworkTypes.h   |   1 +
>  .../Test/UnitTestFrameworkPkgHostTest.dsc |   2 +-
>  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc |   1 +
>  .../UnitTestFrameworkPkgTarget.dsc.inc|   6 +-
>  11 files changed, 328 insertions(+), 70 deletions(-)
> create mode 100644
> UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Unit
> TestDebugAssertLib.c
>  create mode 100644
> UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Unit
> TestDebugAssertLib.inf
>  create mode 100644
> UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Unit
> TestDebugAssertLib.uni
> 
> diff --git
> a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugAssertLib.c
> b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugAssertLib.c
> new file mode 100644
> index 00..0a4001e182
> --- /dev/null
> +++
> b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/Un
> itTestDebugA
> +++ ssertLib.c
> @@ -0,0 +1,49 @@
> +/** @file
> +  Unit Test Debug Assert Library
> +
> +  Copyright (c) 2020, Intel Corporation. All rights
> reserved.
> +  SPDX-License-Identifier: BSD-2-Clause-Patent
> +
> +**/
> +
> +#include 
> +#include 
> +#include 
> +
> +///
> +/// Point to jump buffer used with SetJump()/LongJump()
> to test if a
> +function /// under test generates an expected ASSERT()
> condition.
> +///
> +BASE_LIBRARY_JUMP_BUFFER
> *gUnitTestExpectAssertFailureJumpBuffer =
> +NULL;
> +
> +/**
> +  Unit test library replacement for DebugAssert() in
> DebugLib.
> +
> +  If FileName is NULL, then a  string of
> "(NULL) Filename" is printed.
> +  If Description is NULL, then a  string
> of "(NULL) Description" is printed.
> +
> +  @param  FileName The pointer to the name of the
> source file that generated the assert condition.
> +  @param  LineNumber   The line number in the source
> file that generated the assert condition
> +  @param  Description  The pointer to the description
> of the assert condition.
> +
> +**/
> +VOID
> +EFIAPI
> +UnitTestDebugAssert (
> +  IN CONST CHAR8  *FileName,
> +  IN UINTNLineNumber,
> +  IN CONST CHAR8  *Description
> +  )
> +{
> +  CHAR8  Message[256];
> +
> +  if (gUnitTestExpectAssertFailureJumpBuffer != NULL) {
> +UT_LOG_INFO ("Detected expected ASSERT: %a(%d):
> %a\n", FileName, LineNumber, Description);
> +LongJump (gUnitTestExpectAssertFailureJumpBuffer,
> 1);
> +  } else {
> +AsciiStrCpyS (Message, sizeof(Message), "Detected
> unexpected ASSERT(");
> +AsciiStrCatS (Message, sizeof(Message),
> Description);
> +

Re: [edk2-devel] [Patch v3 12/16] UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT()

2020-07-14 Thread Liming Gao
Mike:

-Original Message-
From: devel@edk2.groups.io  On Behalf Of Michael D Kinney
Sent: 2020年7月11日 10:09
To: devel@edk2.groups.io
Cc: Sean Brogan ; Bret Barkelew 
; Yao, Jiewen 
Subject: [edk2-devel] [Patch v3 12/16] UnitTestFrameworkPkg/UnitTestLib: Add 
checks for ASSERT()

REF: REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2801

Add UnitTestDebugAssertLib that provides the UnitTestDebugAssert() service and 
the gUnitTestExpectAssertFailureJumpBuffer global variable.  This NULL library 
is linked against all host and target unit test builds.  This guarantees that 
the UnitTestDebugAssert() service is available to link against all libraries 
and modules that use the DebugLib class.

EDKII_UNIT_TEST_FRAMEWORK_ENABLED must always be defined when building unit 
tests so the behavior of the DebugLib ASSERT() macros can be adjusted to allow 
the unit test framework to catch an ASSERT() if it is triggered by a function 
under test.

Cc: Sean Brogan 
Cc: Bret Barkelew 
Cc: Jiewen Yao 
Signed-off-by: Michael D Kinney 
---
 .../UnitTestDebugAssertLib.c  |  49 +
 .../UnitTestDebugAssertLib.inf|  31 +++
 .../UnitTestDebugAssertLib.uni|  11 +
 .../Library/UnitTestLib/Assert.c  | 203 --
 .../Library/UnitTestLib/AssertCmocka.c|  68 ++
 .../Library/UnitTestLib/RunTests.c|  23 +-
 .../UnitTestResultReportLib.c |   3 +-
 .../PrivateInclude/UnitTestFrameworkTypes.h   |   1 +
 .../Test/UnitTestFrameworkPkgHostTest.dsc |   2 +-
 UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc |   1 +
 .../UnitTestFrameworkPkgTarget.dsc.inc|   6 +-
 11 files changed, 328 insertions(+), 70 deletions(-)  create mode 100644 
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c
 create mode 100644 
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
 create mode 100644 
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.uni

diff --git 
a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c 
b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c
new file mode 100644
index 00..0a4001e182
--- /dev/null
+++ b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugA
+++ ssertLib.c
@@ -0,0 +1,49 @@
+/** @file
+  Unit Test Debug Assert Library
+
+  Copyright (c) 2020, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+
+///
+/// Point to jump buffer used with SetJump()/LongJump() to test if a 
+function /// under test generates an expected ASSERT() condition.
+///
+BASE_LIBRARY_JUMP_BUFFER  *gUnitTestExpectAssertFailureJumpBuffer = 
+NULL;
+
+/**
+  Unit test library replacement for DebugAssert() in DebugLib.
+
+  If FileName is NULL, then a  string of "(NULL) Filename" is 
printed.
+  If Description is NULL, then a  string of "(NULL) Description" 
is printed.
+
+  @param  FileName The pointer to the name of the source file that 
generated the assert condition.
+  @param  LineNumber   The line number in the source file that generated the 
assert condition
+  @param  Description  The pointer to the description of the assert condition.
+
+**/
+VOID
+EFIAPI
+UnitTestDebugAssert (
+  IN CONST CHAR8  *FileName,
+  IN UINTNLineNumber,
+  IN CONST CHAR8  *Description
+  )
+{
+  CHAR8  Message[256];
+
+  if (gUnitTestExpectAssertFailureJumpBuffer != NULL) {
+UT_LOG_INFO ("Detected expected ASSERT: %a(%d): %a\n", FileName, 
LineNumber, Description);
+LongJump (gUnitTestExpectAssertFailureJumpBuffer, 1);
+  } else {
+AsciiStrCpyS (Message, sizeof(Message), "Detected unexpected ASSERT(");
+AsciiStrCatS (Message, sizeof(Message), Description);
+AsciiStrCatS (Message, sizeof(Message), ")");
+UnitTestAssertTrue (FALSE, "", LineNumber, FileName, Message);
+  }
+}
diff --git 
a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
 
b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
new file mode 100644
index 00..e6ccab0dd9
--- /dev/null
+++ b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugA
+++ ssertLib.inf
@@ -0,0 +1,31 @@
+## @file
+#  Unit Test Debug Assert Library
+#
+#  Copyright (c) 2020, Intel Corporation. All rights reserved. #
+SPDX-License-Identifier: BSD-2-Clause-Patent # ##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = UnitTestDebugAssertLib
+  MODULE_UNI_FILE= UnitTestDebugAssertLib.uni
+  FILE_GUID  = 9D53AD0D-5416-451F-A5BF-E5420051A99B
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = NULL
+
+#
+#  VALID_ARCHITECTURES   = ARM AARCH64
+#

Seemly, this comment 

[edk2-devel] [Patch v3 12/16] UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT()

2020-07-10 Thread Michael D Kinney
REF: REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2801

Add UnitTestDebugAssertLib that provides the UnitTestDebugAssert()
service and the gUnitTestExpectAssertFailureJumpBuffer global
variable.  This NULL library is linked against all host and target
unit test builds.  This guarantees that the UnitTestDebugAssert()
service is available to link against all libraries and modules that
use the DebugLib class.

EDKII_UNIT_TEST_FRAMEWORK_ENABLED must always be defined when
building unit tests so the behavior of the DebugLib ASSERT()
macros can be adjusted to allow the unit test framework to
catch an ASSERT() if it is triggered by a function under test.

Cc: Sean Brogan 
Cc: Bret Barkelew 
Cc: Jiewen Yao 
Signed-off-by: Michael D Kinney 
---
 .../UnitTestDebugAssertLib.c  |  49 +
 .../UnitTestDebugAssertLib.inf|  31 +++
 .../UnitTestDebugAssertLib.uni|  11 +
 .../Library/UnitTestLib/Assert.c  | 203 --
 .../Library/UnitTestLib/AssertCmocka.c|  68 ++
 .../Library/UnitTestLib/RunTests.c|  23 +-
 .../UnitTestResultReportLib.c |   3 +-
 .../PrivateInclude/UnitTestFrameworkTypes.h   |   1 +
 .../Test/UnitTestFrameworkPkgHostTest.dsc |   2 +-
 UnitTestFrameworkPkg/UnitTestFrameworkPkg.dsc |   1 +
 .../UnitTestFrameworkPkgTarget.dsc.inc|   6 +-
 11 files changed, 328 insertions(+), 70 deletions(-)
 create mode 100644 
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c
 create mode 100644 
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
 create mode 100644 
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.uni

diff --git 
a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c 
b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c
new file mode 100644
index 00..0a4001e182
--- /dev/null
+++ 
b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.c
@@ -0,0 +1,49 @@
+/** @file
+  Unit Test Debug Assert Library
+
+  Copyright (c) 2020, Intel Corporation. All rights reserved.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include 
+#include 
+#include 
+
+///
+/// Point to jump buffer used with SetJump()/LongJump() to test if a function
+/// under test generates an expected ASSERT() condition.
+///
+BASE_LIBRARY_JUMP_BUFFER  *gUnitTestExpectAssertFailureJumpBuffer = NULL;
+
+/**
+  Unit test library replacement for DebugAssert() in DebugLib.
+
+  If FileName is NULL, then a  string of "(NULL) Filename" is 
printed.
+  If Description is NULL, then a  string of "(NULL) Description" 
is printed.
+
+  @param  FileName The pointer to the name of the source file that 
generated the assert condition.
+  @param  LineNumber   The line number in the source file that generated the 
assert condition
+  @param  Description  The pointer to the description of the assert condition.
+
+**/
+VOID
+EFIAPI
+UnitTestDebugAssert (
+  IN CONST CHAR8  *FileName,
+  IN UINTNLineNumber,
+  IN CONST CHAR8  *Description
+  )
+{
+  CHAR8  Message[256];
+
+  if (gUnitTestExpectAssertFailureJumpBuffer != NULL) {
+UT_LOG_INFO ("Detected expected ASSERT: %a(%d): %a\n", FileName, 
LineNumber, Description);
+LongJump (gUnitTestExpectAssertFailureJumpBuffer, 1);
+  } else {
+AsciiStrCpyS (Message, sizeof(Message), "Detected unexpected ASSERT(");
+AsciiStrCatS (Message, sizeof(Message), Description);
+AsciiStrCatS (Message, sizeof(Message), ")");
+UnitTestAssertTrue (FALSE, "", LineNumber, FileName, Message);
+  }
+}
diff --git 
a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
 
b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
new file mode 100644
index 00..e6ccab0dd9
--- /dev/null
+++ 
b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.inf
@@ -0,0 +1,31 @@
+## @file
+#  Unit Test Debug Assert Library
+#
+#  Copyright (c) 2020, Intel Corporation. All rights reserved.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION= 0x00010005
+  BASE_NAME  = UnitTestDebugAssertLib
+  MODULE_UNI_FILE= UnitTestDebugAssertLib.uni
+  FILE_GUID  = 9D53AD0D-5416-451F-A5BF-E5420051A99B
+  MODULE_TYPE= BASE
+  VERSION_STRING = 1.0
+  LIBRARY_CLASS  = NULL
+
+#
+#  VALID_ARCHITECTURES   = ARM AARCH64
+#
+
+[Sources]
+  UnitTestDebugAssertLib.c
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+  BaseLib
+  UnitTestLib
diff --git 
a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.uni
 
b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLib.uni
new file mode 100644
index