UnitTestFrameworkPkg: Add DSC and host tests that always 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 <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com>
This commit is contained in:
committed by
mergify[bot]
parent
0a989069df
commit
a1c426e844
@ -0,0 +1,54 @@
|
||||
/** @file
|
||||
This is a sample to demonstrates the use of GoogleTest that supports host
|
||||
execution environments for test case that generates an exception. For some
|
||||
host-based environments, this is a fatal condition that terminates the unit
|
||||
tests and no additional test cases are executed. On other environments, this
|
||||
condition may be report a unit test failure and continue with additional unit
|
||||
tests.
|
||||
|
||||
Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
**/
|
||||
|
||||
#include <Library/GoogleTestLib.h>
|
||||
extern "C" {
|
||||
#include <Uefi.h>
|
||||
#include <Library/BaseLib.h>
|
||||
#include <Library/DebugLib.h>
|
||||
}
|
||||
|
||||
UINTN
|
||||
DivideWithNoParameterChecking (
|
||||
UINTN Dividend,
|
||||
UINTN Divisor
|
||||
)
|
||||
{
|
||||
//
|
||||
// Perform integer division with no check for divide by zero
|
||||
//
|
||||
return (Dividend / Divisor);
|
||||
}
|
||||
|
||||
/**
|
||||
Sample unit test that generates an unexpected exception
|
||||
**/
|
||||
TEST (ExceptionTest, GenerateExceptionExpectTestFail) {
|
||||
//
|
||||
// Assertion that passes without generating an exception
|
||||
//
|
||||
EXPECT_EQ (DivideWithNoParameterChecking (20, 1), (UINTN)20);
|
||||
//
|
||||
// Assertion that generates divide by zero exception before result evaluated
|
||||
//
|
||||
EXPECT_EQ (DivideWithNoParameterChecking (20, 0), MAX_UINTN);
|
||||
}
|
||||
|
||||
int
|
||||
main (
|
||||
int argc,
|
||||
char *argv[]
|
||||
)
|
||||
{
|
||||
testing::InitGoogleTest (&argc, argv);
|
||||
return RUN_ALL_TESTS ();
|
||||
}
|
@ -0,0 +1,39 @@
|
||||
## @file
|
||||
# This is a sample to demonstrates the use of GoogleTest that supports host
|
||||
# execution environments for test case that generates an exception. For some
|
||||
# host-based environments, this is a fatal condition that terminates the unit
|
||||
# tests and no additional test cases are executed. On other environments, this
|
||||
# condition may be report a unit test failure and continue with additional unit
|
||||
# tests.
|
||||
#
|
||||
# Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
|
||||
# SPDX-License-Identifier: BSD-2-Clause-Patent
|
||||
##
|
||||
|
||||
[Defines]
|
||||
INF_VERSION = 0x00010005
|
||||
BASE_NAME = SampleGoogleTestHostGenerateException
|
||||
FILE_GUID = 037A3C56-44C5-4899-AC4D-911943E6FBA1
|
||||
MODULE_TYPE = HOST_APPLICATION
|
||||
VERSION_STRING = 1.0
|
||||
|
||||
#
|
||||
# The following information is for reference only and not required by the build tools.
|
||||
#
|
||||
# VALID_ARCHITECTURES = IA32 X64
|
||||
#
|
||||
|
||||
[Sources]
|
||||
SampleGoogleTestGenerateException.cpp
|
||||
|
||||
[Packages]
|
||||
MdePkg/MdePkg.dec
|
||||
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
|
||||
|
||||
[LibraryClasses]
|
||||
GoogleTestLib
|
||||
BaseLib
|
||||
DebugLib
|
||||
|
||||
[Pcd]
|
||||
gEfiMdePkgTokenSpaceGuid.PcdDebugPropertyMask
|
Reference in New Issue
Block a user