summaryrefslogtreecommitdiff
path: root/UnitTestFrameworkPkg
AgeCommit message (Collapse)AuthorFilesLines
12 daysUnitTestFrameworkPkg/TimerLibPosix: Enable 64-bit time_t for IA32 buildsMichael D Kinney1-0/+6
On 32-bit architectures (IA32), standard C library headers may default to 32-bit time_t and file offsets. Define _FILE_OFFSET_BITS=64 and _TIME_BITS=64 under [BuildOptions] for IA32 builds in TimerLibPosix.inf to use 64-bit time_t and struct timespec. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-09-06UnitTestFrameworkPkg: TimerLibPosix: Add TimerLib for host-based unit testKun Qin3-0/+223
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 Qin4-18/+34
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: UnitTestDebugAssertLib: GCC support for AArch64Kun Qin1-0/+1
This change adds the GCC compiler flag for AArch64 targets. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2026-07-31UnitTestFrameworkPkg: CmockaLib: Support float operationsKun Qin2-2/+6
This change adds the support of float operations for AArch64 host based unit tests by overriding the compiler flags. Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2026-07-31UnitTestFrameworkPkg: SampleUnitTestGenerateException: Fix for AArch64Kun Qin9-51/+167
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-07-29Global: Set MarkdownLintCheck plugin to AuditOnlyMichael Kubacki1-0/+9
In preparation for the MarkdownLintCheck plugin being added to the repo, this change defaults the plugin to `AuditOnly` mode in each package. This allows package maintainers to enable the plugin as they see fit. Continuous-integration-options: PatchCheck.ignore-multi-package Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-07-27UnitTestFrameworkPkg: Update ReadMe for VS2026Oliver Smith-Denny1-14/+14
edk2 is moving to VS2026 for the MSVC toolchain, update the ReadMe accordingly. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2026-03-26UnitTestFrameworkPkg: Allow platform DSC to override sanitizer and coverageAbdul Lateef Attar1-2/+10
UNIT_TESTING_CODE_COVERAGE_ENABLE and UNIT_TESTING_ADDRESS_SANITIZER_ENABLE are unconditionally set to TRUE in UnitTestFrameworkPkgHost.dsc.inc, preventing platform DSC files from disabling them. Wrap both assignments with !ifndef so platforms can override the values by pre-defining these macros before the !include directive. Signed-off-by: Abdul Lateef Attar <AbdulLateef.Attar@amd.com>
2026-03-22UnitTestFrameworkPkg: Align C++ sign compareMichael D Kinney1-3/+3
GCC enables -Wsign-compare by default but CLANG does not enable -Wsign-compare by default. This causes GCC unit test builds to fail with a signed/unsigned mismatch when using EXPECT_EQ(), ASSERT_EQ(), EXPECT_NE() or ASSERT_NE() with one of the items being compared being literal 0. However, CLANG does not fail for these builds. Add -Wsign-compare to CXX_FLAGS for CLANGDWARF and CLANGPDB to align CLANG error checking with GCC. Add /w44388 and /w44389 to MSFT family compiler CXX_FLAGS to align VS20xx error checking with GCC. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.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>
2026-03-09UnitTestFrameworkPkg: Increment handle key outside if blockKhalid Ali1-6/+6
Fixes: #11113 Currently, the global handle key and key inside handle structure is incremented only when a new handle is allocated for protocol interface to be installed. However, when caller already supplies a handle gHandleDatabaseKey never get incremented. Move handle key incremental outside if block, just below the else statement which allows gHandleDatabaseKey to always incremented whether handle is supplied or not. Signed-off-by: Khalid Ali <khaliidcaliy@gmail.com>
2026-03-05UnitTestFrameworkPkg: fix mdlint issuesSherry Fan1-106/+111
Fix markdownlint formatting issues in README. Signed-off-by: Sherry Fan <sherryfan@microsoft.com>
2026-02-26UnitTestFrameworkPkg: Remove references to GCC5 in ReadMe and dsc commentsMike Beaton2-8/+8
Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
2026-02-24UnitTestFrameworkPkg: Replace include guards with #pragma onceMichael Kubacki11-44/+11
Replace traditional `#ifndef`/`#define`/`#endif` include guards with `#pragma` once. `#pragma once` is a widely supported preprocessor directive that prevents header files from being included multiple times. It is supported by all toolchains used to build edk2: GCC, Clang/LLVM, and MSVC. Compared to macro-based include guards, `#pragma once`: - Eliminates the risk of macro name collisions or copy/paste errors where two headers inadvertently use the same guard macro. - Eliminate inconsistency in the way include guard macros are named (e.g., some files use `__FILE_H__`, others use `FILE_H_`, etc.). - Reduces boilerplate (three lines replaced by one). - Avoids polluting the macro namespace with guard symbols. - Can improve build times as the preprocessor can skip re-opening the file entirely, rather than re-reading it to find the matching `#endif` ("multiple-include optimization"). - Note that some compilers may already optimize traditional include guards, by recognzining the idiomatic pattern. This change is made acknowledging that overall portability of the code will technically be reduced, as `#pragma once` is not part of the C/C++ standards. However, this is considered acceptable given: 1. edk2 already defines a subset of supported compilers in BaseTools/Conf/tools_def.template, all of which have supported `#pragma once` for over two decades. 2. There have been concerns raised to the project about inconsistent include guard naming and potential macro collisions. Approximate compiler support dates: - MSVC: Supported since Visual C++ 4.2 (1996) - GCC: Supported since 3.4 (2004) (http://gnu.ist.utl.pt/software/gcc/gcc-3.4/changes.html) - Clang (LLVM based): Since initial release in 2007 Signed-off-by: Michael Kubacki <michael.kubacki@microsoft.com>
2026-01-21UnitTestFrameworkPkg: WIN_MINGW32_BUILD generate .exeMichael D Kinney1-6/+6
Add .exe file extension to host-based unit test applications built in a Windows Mingw build environment to match host-based unit test applications generated in VS20xx environments. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-01-07UnitTestFrameworkPkg: Add VS2026 SupportDaniel1-4/+5
* Add checks for VS2026. * Enable Address Sanitizer for VS2026. Signed-off-by: Daniel Grobert <danalexgro@gmail.com>
2026-01-07UnitTestFrameworkPkg: Add MINGW CLANG SupportMichael D Kinney1-33/+157
* Add checks for supported tool chains with error messages. * Add support for MINGW CLANGDWARF builds * Fix IA32 C++ alignment errors using CLANGDWARF * Add CLANG native code coverage compiler/linker options * Reduce Visual Studio support to VS2019 and VS2022 and simplify linker options for VS20xx and CLANGPDB using VS libraries. * Add correct ASAN libraries for IA32/X64 CLANGPDB builds * Add -z noexectstack linker option for all Linux builds. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-01-06UnitTestFrameworkPkg: Add Windows host-based unit test defineMichael D Kinney1-0/+10
There are cases where DSC files must have logic to detect if host-based unit tests are being built in a Windows environment. Add HOST_BASED_UNIT_TESTING_ENABLED define set to TRUE if that condition is detected. One example is the optimized assembly files from Openssl project that generate NASM source files that assume Windows calling convention. Those NASM files must be used for both firmware builds where the default compiler calling convention is the Windows calling convention and host-based unit tests built using any of the compilers supported in Windows environment. Also update UnitTestFrameworkPkgHost.dsc.inc to set BUILD_TARGETS to NOOPT because host-based unit tests only support NOOPT. If the DSC file that includes UnitTestFrameworkPkgHost.dsc.inc uses a BUILD_TARGETS other than NOOPT, this will override the DSC setting. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2026-01-05UnitTestFrameworkPkg: Fix StackCheckLib class mappingMichael D Kinney1-1/+8
Update UnitTestFrameworkPkgHost.dsc.inc DSC file to use the correct StackCheckLib class instead of NULL. This guarantees that the StackCheckLib is only linked with modules that have a StackCheckLib class dependency. Must also add -fno-stack-protector to GCC and CLANGPDB to disable use of stack checks by the compiler. ASAN provides better coverage for access outside stack frames. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-12-24UnitTestFrameworkPkg/Include/Library: Remove _MSC_VER workaroundMichael D Kinney1-10/+0
Remove workaround to define _MSC_VER when it is not defined when building with clang on Windows. This workaround was required when CLANGPDB undefined _MSC_VER in tools_def.txt. With -U _MSC_VER removed from tools_def.txt, this workaround for host-based unit test builds is no longer required. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-12-23UnitTestFrameworkPkg/UnitTestDebugAssertLibHost: Fix clang errorMichael D Kinney1-0/+1
Fix error reported by clang in UnitTestDebugAssertLibHost that the function snprintf() is undefined. Add include of <stdio.h> to resolve error. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-12-23UnitTestFrameworkPkg/UnitTestLib: Fix printf() error from clangMichael D Kinney1-1/+2
Update UnitTestLib to not pass UnitTest->Log as the format string to printf(). If UnitTest->Log contains any printf() format specifiers, then printf() will look for arguments that are not present and will read beyond the stack frame. Change use of printf() to an fwrite() to stdout followed by an fflush() to stdout. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-12-20UnitTestFrameworkPkg: Fix spelling issuesMichael D Kinney2-3/+4
Add "uintn" to extended words in ci.yaml and fix typos. 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-10-15UnitTestFrameworkPkg: Use 8MB stack for MSFT and CLANGPDBMichael D Kinney1-2/+2
Linux/GCC host-based unit test application builds use a default stack size of 8MB. Windows/VS20xx and Windows/CLANGPDB host-based unit test application builds use a default stack size of 1MB. This can allow Linux unit tests to pass and Windows unit tests to fail with stack overflow if large local variables are used. ASAN increases stack usage, so this condition can occur more frequently when ASAN enabled. Update MSFT and CLANGPDB for host-based unit tests to use a default stack size of 8MB so all tool chains use the same default stack size for host-based unit tests. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-09-29UnitTestFrameworkPkg/UnitTestDebugAddressLib: Remove extra optionsMichael D Kinney1-1/+1
Remove /EHsc from CC_FLAGS. /EHs is added to CC_FLAGS in UnitTestFrameworkPkgHost.dsc.inc for all components. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-09-29UnitTestFrameworkPkg/GoogleTestLib: Remove extra optionsMichael D Kinney1-1/+1
Update MSFT CC_FLAGS options to remove /EHs and /MTd that are added by UnitTestFrameworkPkgHost.dsc.inc for all components. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-09-29UnitTestFrameworkPkg/SubhookLib: Update GCC definesMichael D Kinney1-3/+3
Add -DSUBHOOK_STATIC to all GCC family builds to match defines in MSFT family builds. Also remove /EHsc from MSFT CC_FLAGS. /EHs is added to CC_FLAGS in UnitTestFrameworkPkgHost.dsc.inc for all components. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-09-29UnitTestFrameworkPkg/CmockaLib: Add CLANGPDB supportMichael D Kinney1-0/+1
Add CLANGPDB family defines to match MSFT family defines. Also add -Wno-deprecated-declarations to CLANGPDB family to ignore warnings detected when building cmocka sources with clang compiler. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-09-29UnitTestFrameworkPkg/Include: Update GoogleTestLib for CLANGMichael D Kinney1-2/+50
Update GoogleTestLib.h to support Windows/CLANGPDB build. When using Windows/CLANGPDB, _MSC_VER is not defined. If it is not defined, then set to 1900 for Visual Studio 2015 or newer compatibility when using windows include files for host based unit test application builds. If _MSC_VER is not set, then those application fail to build. Also address a Windows/CLANG issue when ASAN is enabled by providing an alternate implementation of the EXPECT_THROW_MESSAGE() and ASSERT_THROW_MESSAGE() macros. Without this alternate implementation, an exception is generated due to the description of the ASSERT() condition being NULL. Update all implementations of EXPECT_THROW_MESSAGE() and ASSERT_THROW_MESSAGE() to support parameters to the statement executed to return values. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-09-29UnitTestFrameworkPkg: Add CLANGDWARF and CLANGPDB supportMichael D Kinney1-20/+71
Update host-based unit test [BuildOptions] to support CLANGDWARF and CLANGPDB. * Use CLANG specific code coverage options * Map CLANG trap function to abort() to resolve link issues when building Google Test based unit tests. The default mapping from tools_def.txt is to an unresolved function to generate a build failure. Mapping to abort() overrides the default mapping. If a unit test introduces undefined behavior in a code path that is executed, then abort() is called and the unit test application exits with an error and fails the unit test. * Update GCC to pass --coverage in link command so the linker automatically includes -lgcov. The explicit linking of -lgcov is removed. * Add /EHs to all MSFT components instead of only components of type HOST_APPLICATION. * Add CXX_FLAGS for all tool chain families. Use c++ 20 for MSFT and GCC and c++ 17 for clang. Clang generates errors compiling Google Test with c++ 20. * Add -z noexecstack to all GCC builds to reduce warnings. * Add UNIT_TESTING_CODE_COVERAGE_ENABLE that is enabled by default. Can be used to temporarily disable code coverage when debugging interactions between unit testing features. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-09-29UnitTestFrameworkPkg: Set defines for CLANGPDB buildsMichael D Kinney1-3/+4
Set same defines for CLANGPDB tool chain family as all tool chain other families. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-09-26UnitTestFrameworkPkg: Remove ARM32 SupportOliver Smith-Denny3-9/+1
edk2 is dropping support for the ARM32 architecture. This commit removes ARM32 code from UnitTestFrameworkPkg. It also drops irrelevant VALID_ARCHITECTURES comments from infs that are not arch specific. Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
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-06-26UnitTestFrameworkPkg: Add -Wno-write-strings to host unit testsMichael D Kinney1-0/+1
Disable write strings warning for host-based unit test builds when building modules of type HOST_APPLICATION. Modules of type HOST_APPLICATION may compile and link code under test into the host-based unit test. When building GoogleTest based unit tests, the G++ compiler is used. The G++ compiler is stricter than GCC for passing a const string into a function parameter that is not const. This is not a warning for GCC build of firmware code. But GoogleTest builds that use g++ detect as a warning and that breaks the build. The firmware code under test can not be changed, so the warning -Wno-write-strings is added to CC_FLAGS to ignore this warning. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-06-24UnitTestFrameworkPkg: Add -pie to ASLCC_FLAGS for unit testsMichael D Kinney1-0/+1
For Linux/GCC host-based unit tests, -fno-pei is added to CC_FLAGS and this causes builds of .aslc/.act files for ACPI tables used in host-based unit tests to fail. Add -fpie to ASLCC_FLAGS in UnitTestFrameworkPkgHost.dsc.inc to override this CC_FLAGS setting and resolve the build issue. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-06-24UnitTestFrameworkPkg/GoogleTestLib: Enhance unit test NULL checksMichael D Kinney1-0/+9
gtest.h uses standard includes that define NULL to __null. This is different that the C++ standard that uses nullptr. Redefine NULL in GoogleTestLib.h to use C++ form of nullptr. This allows NULL to be used in checks and mocks without explicit typecasts. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-03-14UnitTestFrameworkPkg: Avoid duplicate library function namesPhil Noh3-9/+9
There are duplicate library function names between 2 Unit Test libraries (UnitTestPeiServicesTablePointerLib and UnitTestUefiBootServicesTableLib). There are 3 functions (UnitTestAllocatePages, UnitTestAllocatePool and UnitTestFreePage). This update avoids the duplication and prevents a build error when building a Unit Test application that links the libraries based on UnitTestFrameworkPkg. Signed-off-by: Phil Noh <Phil.Noh@amd.com>
2025-03-10UnitTestFrameworkPkg: Fix host test /WHOLEARCHIVE regressionMichael D Kinney1-1/+1
PR #6408 introduced a regression by removing /WHOLEARCHIVE from VS20xx DLINK_FLAGS when building host based unit tests. PR #5098 added /WHOLEARCHIVE to resolve issues when building host based unit tests with GoogleTest. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-01-29UnitTestFrameworkPkg: Fix false positives from address sanitizerMichael D Kinney1-23/+23
PR #6408 introduced a host specific NORETURN function to resolve false positives from the address sanitizer when LongJump() is called and the stack is reset to a previous stack frame. This approach was discussed here: https://github.com/tianocore/edk2/pull/6408/files#r1918810499 False positives are still being observed with this initial solution. The address sanitizer provides __asan_handle_no_return() to clean up shadow memory before a NORETURN function is called and provides a simpler implementation for this issue without having to introduce a host specific NORETURN function. https://github.com/llvm/llvm-project/blob/main/compiler-rt/include/sanitizer/asan_interface.h Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-01-26UnitTestFrameworkPkg: Add SafeIntLib to Common IncludesINDIA\sachinganesh1-0/+1
SafeIntLib has been added to UnitTestFrameworkPkg Common Includes DSC for usage in host and target based tests. Signed-off-by: Sachin Ganesh <sachinganesh@ami.com>
2025-01-21UnitTestFrameworkPkg/MemoryAllocationLibPosix: Add allocate below addressMichael D Kinney8-1/+778
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/UnitTestLib: Reduce sanitizer false positiveMichael D Kinney3-11/+43
Use snprintf() in host based unit tests to format log messages and add host specific wrapper for LongJump() that is decorated with NORETURN to provide hint to address sanitizer that LongJump() never returns. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-01-21UnitTestFrameworkPkg: Add failing unit tests cases for sanitizerMichael D Kinney13-2/+889
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-21UnitTestFrameworkPkg: Use /MTd and enable Address SanitizersMichael D Kinney4-9/+71
* Update host based unit test VS20xx builds to use /MTd instead of /MT to enable use of debug libraries for host based unit tests. * Enable /fsanitize=address for host based unit test VS2019 builds * Enable /fsanitize=address for host based unit test VS2022 builds * Enable -fsanitize=address for host based unit test GCC builds * Add UNIT_TESTING_ADDRESS_SANITIZER_ENABLE define that is set to TRUE by default so it is always enabled, but can be set to FALSE to temporarily disable during development/debug of unit tests. * Add address sanitizer information to ReadMe.md Enabling the Address Sanitizer can detect double frees, buffer overflow, buffer underflow, access to invalid addresses, and various exceptions. These can be detected in both the unit test case sources as well as the code under test. Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-01-21UnitTestFraworkPkg: Enable DEBUG_CLEAR_MEMORY in host testsMichael D Kinney4-4/+4
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>