summaryrefslogtreecommitdiff
path: root/UnitTestFrameworkPkg/Test
AgeCommit message (Collapse)AuthorFilesLines
2026-09-06UnitTestFrameworkPkg: TimerLibPosix: Add TimerLib for host-based unit testKun Qin1-0/+1
This change introduces an instance of TimerLib based on the host's standard C library to provide a free running performance counter and calibrated delays for host-based unit tests. This change paves way to support other host based tests that depends on the availability of this interface. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2026-07-31UnitTestFrameworkPkg: Test: Adding AArch64 targetKun Qin2-2/+2
This change adds the AArch64 target for host based unit tests. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2026-07-31UnitTestFrameworkPkg: FunctionMockLib: Do not support AArch64Kun Qin1-2/+4
Current FunctionMockLib is relying on the subhoob module to support the backend operation by bitbanging the binary post-disassembly. However subhook module is a x64 centric module and does not support AArch64 usage. This change removes the mock function support for AArch64. The functionality will need other solutions to be properly supported. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2026-07-31UnitTestFrameworkPkg: SampleUnitTestGenerateException: Fix for AArch64Kun Qin8-49/+162
AArch64 does not generate divide-by-zero exceptions like x86. Yet the current generate exception test is using this operation to attempt triggering exceptions. This change abstracted the exception generation logic into per-arch files and use undefined instruction to trigger AArch64 exceptions. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2026-07-31UnitTestFrameworkPkg: SampleGoogleTestGenerateException: Support AArch64Kun Qin3-15/+29
The SampleGoogleTestGenerateException GoogleTest sample previously generated a CPU exception by performing an integer divide by zero. That mechanism is X86-specific: the AArch64 architecture defines SDIV/UDIV by zero to return zero rather than raising a synchronous abort, so the sample produced no exception when built and run on AArch64 hosts and the test failed due to the test assert instead of triggering an exception through the framework. This change replaces the divide-by-zero with a NULL pointer write performed through a small volatile helper, which is expected to work on all host systems. The MSVC '/wd4723' build option is no longer needed because it was added to silence the divide-by-zero compile-time warning. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2026-07-31UnitTestFrameworkPkg: SampleGoogleTest: No divide-by-zero test for AArch64Kun Qin3-23/+43
AArch64 does not have divide-by-zero exception. This change modifies the corresponding test to work with AArch64. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2026-03-22UnitTestFrameworkPkg/Test/GoogleTest/Sample: Add 0 testsMichael D Kinney1-0/+132
Add tests that check a local variable against 0 for values of type UINT8, UINT16, UINT32, UINT64, UINTN, UINT32 bitfields, and UINT64 bitfields. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-11-22UnitTestFrameworkPkg: fix various typosPhilipp Schuster1-1/+1
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2025-09-19UnitTestFrameworkPkg/SampleGoogleTest: Add missing override keywordMichael D Kinney2-2/+2
Add missing override keyword to c++ classes. Found by the clang++ compiler. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-01-21UnitTestFrameworkPkg/MemoryAllocationLibPosix: Add allocate below addressMichael D Kinney1-0/+210
Add HostMemoryAllocationBelowAddressLib class and implementation that uses OS specific services to perform pool and page allocations below a specified address in a host based unit test application execution environment. This library class is only required for mocking buffers that are assumed to be below a specific address by code under test. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-01-21UnitTestFrameworkPkg: Add failing unit tests cases for sanitizerMichael D Kinney12-1/+883
Add GoogleTest and Framework based unit tests that are expected to fail and be caught by Address Sanitizer. These unit tests verify that an address sanitizer is enabled and detecting the following conditions. It also provide examples of the expected output when an Address Sanitizer detected these types of issues. * double free * buffer overflow * buffer underflow * null ptr * invalid address * divide by zero Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-01-21UnitTestFraworkPkg: Enable DEBUG_CLEAR_MEMORY in host testsMichael D Kinney2-2/+2
Update DSC files to always enable DEBUG_CLEAR_MEMORY() macros so memory is cleared on every memory allocation/free operation. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2024-02-14UnitTestFrameworkPkg: Add DSC and host tests that always failMichael D Kinney17-0/+1976
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>
2024-02-14UnitTestFrameworkPkg/SampleGoogleTest: Use EXPECT_ANY_THROW()Michael D Kinney1-5/+31
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 <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>
2024-02-14UnitTestFrameworkPkg/UnitTestDebugAssertLib: Add GoogleTest supportMichael D Kinney1-0/+1
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 <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>
2023-10-27UnitTestFrameworkPkg: Apply uncrustify formatting to relevant filesVivian Nowka-Keane1-31/+47
Apply uncrustify formatting to GoogleTest cpp and header files. Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Vivian Nowka-Keane <vnowkakeane@linux.microsoft.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com>
2023-04-10UnitTestFrameworkPkg: Add gmock support to GoogleTestLibChris Johnson1-1/+2
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4389 * Add gmock support to GoogleTestLib * Add FunctionMockLib library class and library instance * Add GoogleTest extension to GoogleTestLib.h for CHAR16 type * Add GoogleTest extension to GoogleTestLib.h for buffer types * HOST_APPLICATION only supports IA32/X64 Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Chris Johnson <chris.n.johnson@intel.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Oliver Smith-Denny <osde@linux.microsoft.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2023-04-10UnitTestFrameworkPkg: Add subhook submodule required for gmockChris Johnson1-0/+1
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4389 Add subhook submodule that is required to hook internal functions when using gmock. https://github.com/Zeex/subhook Add SubhookLib library class and SubhookLib library instance. Include the SUBHOOK_STATIC define in the SubhookLib INF file so it builds as a static library. Also include the SUBHOOK_STATIC define in SubhookLib.h so all modules using SubhookLib properly link SubhookLib as a static library. Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <quic_llindhol@quicinc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Signed-off-by: Chris Johnson <chris.n.johnson@intel.com> Reviewed-by: Leif Lindholm <quic_llindhol@quicinc.com> Reviewed-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Oliver Smith-Denny <osde@linux.microsoft.com> Reviewed-by: Michael D Kinney <michael.d.kinney@intel.com>
2022-11-11UnitTestFrameworkPkg: Add googletest submodule and GoogleTestLibMichael D Kinney3-1/+301
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4134 Add submodule for googletest and add GoogleTestLib that is required for GoogleTest based unit tests. Add GoogleTest documentation to Readme.md along with a port of the sample unit test to the GoogleTest style. A few typos in Readme.md are also fixed. Cc: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <quic_llindhol@quicinc.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <mikuback@linux.microsoft.com> Acked-by: Leif Lindholm <quic_llindhol@quicinc.com>
2021-12-07UnitTestFrameworkPkg: Apply uncrustify changesMichael Kubacki1-24/+28
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=3737 Apply uncrustify changes to .c/.h files in the UnitTestFrameworkPkg package Cc: Andrew Fish <afish@apple.com> Cc: Leif Lindholm <leif@nuviainc.com> Cc: Michael D Kinney <michael.d.kinney@intel.com> Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com> Reviewed-by: Bret Barkelew <bret.barkelew@microsoft.com>
2020-07-15UnitTestFramewokPkg/SampleUnitTest: Use UT_EXPECT_ASSERT_FAILURE()Michael D Kinney7-0/+528
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=2801 Add samples for all UnitTestLib macros including using UT_EXPECT_ASSERT_FAILURE() for positive test cases where an ASSERT() is triggered and detected correctly. Additional test cases are added that disable ASSERT()s and verify that UT_EXPECT_ASSERT_FAILURE() macros are skipped. 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>
2020-07-15UnitTestFrameworkPkg/UnitTestLib: Add checks for ASSERT()Michael D Kinney1-1/+1
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 <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> Reviewed-by: Bret Barkelew <Bret.Barkelew@microsoft.com>
2020-02-07UnitTestFrameworkPkg: Add DSC, DSC INC, and YAML filesMichael D Kinney1-0/+33
https://bugzilla.tianocore.org/show_bug.cgi?id=2505 * DSC in root of package file to perform a package build of the UnitTestFrameworkPkg and build sample unit test for all supported target environments. * DSC file in Test directory to build the sample unit test for the host environment. * UnitTestFrameworkPkgTarget.dsc.inc - DSC include file to !include when building unit tests for target environments. * UnitTestFrameworkPkgHost.dsc.inc - DSC include file to !include when building unit tests for target environments. * YAML file with set of CI checks to perform on UnitTestFrameworkPkg. Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Bret Barkelew <Bret.Barkelew@microsoft.com> Reviewed-by: Sean Brogan <sean.brogan@microsoft.com>
2020-02-07UnitTestFrameworkPkg/Test: Add unit test samplesMichael D Kinney6-0/+461
https://bugzilla.tianocore.org/show_bug.cgi?id=2505 Add an implementation of a sample unit test that demonstrates the use of the UnitTestLib services and macros and supports being built for execution in a host environment or for execution on a target in PEI, DXE, SMM, or UEFI Shell. Cc: Sean Brogan <sean.brogan@microsoft.com> Cc: Bret Barkelew <Bret.Barkelew@microsoft.com> Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Bret Barkelew <Bret.Barkelew@microsoft.com>