Skip to content

Conversation

@VivianNK
Copy link
Contributor

@VivianNK VivianNK commented Feb 29, 2024

Description

Cherry pick from: tianocore/edk2#5345

  • Impacts functionality?
    • Functionality - Does the change ultimately impact how firmware functions?
    • Examples: Add a new library, publish a new PPI, update an algorithm, ...
  • Impacts security?
    • Security - Does the change have a direct security impact on an application,
      flow, or firmware?
    • Examples: Crypto algorithm change, buffer overflow fix, parameter
      validation improvement, ...
  • Breaking change?
    • Breaking change - Will anyone consuming this change experience a break
      in build or boot behavior?
    • Examples: Add a new library class, move a module to a different repo, call
      a function in a new library class in a pre-existing module, ...
  • Includes tests?
    • Tests - Does the change include any explicit test code?
    • Examples: Unit tests, integration tests, robot tests, ...
  • Includes documentation?
    • Documentation - Does the change contain explicit documentation additions
      outside direct code modifications (and comments)?
    • Examples: Update readme file, add feature readme file, link to documentation
      on an a separate Web page, ...

How This Was Tested

Local builds and CI tests ran.

Integration Instructions

N/A

mdkinney and others added 8 commits February 29, 2024 14:03
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4683

When VS20xx host-based unit tests are built with debug
libraries a name collision occurs with the DebugLib.h
internal macro _DEBUG(). Rename this internal macro
to _DEBUGLIB_DEBUG() to address the name collision.

Cc: Liming Gao <[email protected]>
Cc: Zhiguang Liu <[email protected]>
Signed-off-by: Michael D Kinney <[email protected]>
Reviewed-by: Leif Lindholm <[email protected]>
… builds

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

Add /MT to MSFT CC_FLAGS to always use release libraries
when building host-based unit tests so any exceptions
generated during host-based test execution generate an
error message in stderr instead of a popup window.

Use /MTd when -D UNIT_TESTING_DEBUG is to use debug
libraries when building host-based unit tests so any
exceptions generated during host-based test execution
generate a popup window with option to attach a debugger.

Cc: Michael Kubacki <[email protected]>
Cc: Sean Brogan <[email protected]>
Signed-off-by: Michael D Kinney <[email protected]>
Reviewed-by: Michael Kubacki <[email protected]>
…ing and gcov

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

Update MSFT CC_FLAGS for host-based unit tests to use /EHs
instead of /EHsc to support building C functions with SEH
(Structured Exception Handling) enabled.  This is required to
build UnitTestDebugAssertLibHost.inf.

Update GCC CC_FLAGS for host-based unit tests to use -fexceptions
to support catching exceptions.

Update GoogleTestLib.h to include Throws() APIs that enable
unit tests to use EXPECT_THAT() to check for expected ASSERT()
conditions for a specific ASSERT() expression.

Update GCC CC_FLAGS to add --coverage for host-based builds
for all GCC tool chains.

Cc: Michael Kubacki <[email protected]>
Cc: Sean Brogan <[email protected]>
Signed-off-by: Michael D Kinney <[email protected]>
Reviewed-by: Michael Kubacki <[email protected]>
…dle() no ASSERT()

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

Update GetActiveFrameworkHandle() to remove ASSERT() and require
caller to check for NULL.

This allows GetActiveFrameworkHandle() to be used to determine if the
current host-based test environment is framework/cmocka or gtest. In
the framework/cmocka host-based environment GetActiveFrameworkHandle()
returns non-NULL. In the gtest host-based environment
GetActiveFrameworkHandle() returns NULL.

Cc: Michael Kubacki <[email protected]>
Cc: Sean Brogan <[email protected]>
Signed-off-by: Michael D Kinney <[email protected]>
Reviewed-by: Michael Kubacki <[email protected]>
…Test support

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

Add an C++ implementation of UnitTestDebugAssert() API for
host-based environments. GoogleTest based environments throw
a C++ exception of type std::runtime_error when an ASSERT() is
triggered with a description that contains the filename, line
number, and the expression that triggered the ASSERT().

Cc: Michael Kubacki <[email protected]>
Cc: Sean Brogan <[email protected]>
Signed-off-by: Michael D Kinney <[email protected]>
Reviewed-by: Michael Kubacki <[email protected]>
…HROW()

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

Update GoogleTest samples to use EXPECT_ANY_THROW() instead
of ASSERT_DEATH(). ASSERT_DEATH() is a very slow method to
detect an expected ASSERT() condition. Throwing an exception
from ASSERT() and using EXPECT_ANY_THROW() is several orders
of magnitude faster.

Update GoogleTest sample with example of using EXPECT_THROW()
and EXPECT_THAT() to check for more specific ASSERT() conditions
that allow unit test cases to test functions that contain
more than one ASSERT() statement and verify that the expected
ASSERT() is the one that was actually triggered.

Update library mappings so target-based unit tests use
UnitTestDebugAssertLib.inf and host-based unit tests use
UnitTestDebugAssertLibHost.inf

Cc: Michael Kubacki <[email protected]>
Cc: Sean Brogan <[email protected]>
Signed-off-by: Michael D Kinney <[email protected]>
Reviewed-by: Michael Kubacki <[email protected]>
…s fail

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

Add sample unit tests that always fail or generate unexpected
exceptions along with a new DSC file to build the unit tests
that always fail or generate unexpected exceptions. This can
be used to verify the log information on failures is accurate
and provides the correct information to determine the source
of the unit test failure.

Divide by zero is used to generate unexpected exceptions.  The
compiler warnings for divide by zero are disables for the unit
tests that generate divide by zero exceptions on purpose.

These tests are not added to CI because CI would always fail.

The UnitTestFrameworkPkg.ci.yaml file is updated to ignore the
INF files for host-based testing that always fail.

Cc: Michael Kubacki <[email protected]>
Cc: Sean Brogan <[email protected]>
Signed-off-by: Michael D Kinney <[email protected]>
Reviewed-by: Michael Kubacki <[email protected]>
@github-actions github-actions bot added the impact:non-functional Does not have a functional impact label Feb 29, 2024
@VivianNK VivianNK changed the title [CHERRY-PICK] Unit Test Unexpected Condition [CHERRY-PICK] Unit Test Unexpected Exception Feb 29, 2024
@codecov-commenter
Copy link

codecov-commenter commented Feb 29, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 1.23%. Comparing base (b778f1e) to head (025bd42).
Report is 216 commits behind head on release/202311.

Additional details and impacted files
@@                Coverage Diff                 @@
##           release/202311     #756      +/-   ##
==================================================
- Coverage            1.24%    1.23%   -0.01%     
==================================================
  Files                1301     1301              
  Lines              332064   332064              
  Branches             5127     6683    +1556     
==================================================
- Hits                 4126     4117       -9     
+ Misses             327891   327871      -20     
- Partials               47       76      +29     
Flag Coverage Δ
MdeModulePkg 0.69% <ø> (∅)
MdePkg 5.37% <ø> (+<0.01%) ⬆️
NetworkPkg ∅ <ø> (∅)
PolicyServicePkg ∅ <ø> (∅)
UnitTestFrameworkPkg ∅ <ø> (∅)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@VivianNK VivianNK marked this pull request as ready for review February 29, 2024 22:57
@VivianNK VivianNK merged commit 4907b58 into microsoft:release/202311 Mar 1, 2024
@VivianNK VivianNK deleted the personal/vnowkakeane/cherry_unittestdebug branch March 1, 2024 23:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

impact:non-functional Does not have a functional impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants