Commit graph

115 commits

Author SHA1 Message Date
Kun Qin
8cdd6f77b7 UnitTestFrameworkPkg: Test: Adding AArch64 target
This change adds the AArch64 target for host based unit tests.

Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2026-07-31 15:16:47 +00:00
Kun Qin
56e1e04202 UnitTestFrameworkPkg: FunctionMockLib: Do not support AArch64
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-31 15:16:47 +00:00
Kun Qin
26800658df UnitTestFrameworkPkg: UnitTestDebugAssertLib: GCC support for AArch64
This change adds the GCC compiler flag for AArch64 targets.

Signed-off-by: Kun Qin <kun.qin@microsoft.com>
2026-07-31 15:16:47 +00:00
Kun Qin
476c89e564 UnitTestFrameworkPkg: CmockaLib: Support float operations
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-31 15:16:47 +00:00
Kun Qin
4d024b0cde UnitTestFrameworkPkg: SampleUnitTestGenerateException: Fix for AArch64
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-31 15:16:47 +00:00
Kun Qin
d47954ceb4 UnitTestFrameworkPkg: SampleGoogleTestGenerateException: Support AArch64
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-31 15:16:47 +00:00
Kun Qin
1fa1a89382 UnitTestFrameworkPkg: SampleGoogleTest: No divide-by-zero test for AArch64
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-31 15:16:47 +00:00
Michael Kubacki
df9111c2d3 Global: Set MarkdownLintCheck plugin to AuditOnly
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-29 12:32:09 +00:00
Oliver Smith-Denny
b5c33ab37f UnitTestFrameworkPkg: Update ReadMe for VS2026
edk2 is moving to VS2026 for the MSVC toolchain,
update the ReadMe accordingly.

Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
2026-07-27 19:09:16 +00:00
Abdul Lateef Attar
b9c072aad6 UnitTestFrameworkPkg: Allow platform DSC to override sanitizer and coverage
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-26 16:41:13 +00:00
Michael D Kinney
97aa85de72 UnitTestFrameworkPkg: Align C++ sign compare
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-21 21:36:55 +00:00
Michael D Kinney
7b6b0784a7 UnitTestFrameworkPkg/Test/GoogleTest/Sample: Add 0 tests
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-21 21:36:55 +00:00
Khalid Ali
2691afa269 UnitTestFrameworkPkg: Increment handle key outside if block
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-09 09:19:06 +00:00
Sherry Fan
fda4926b08 UnitTestFrameworkPkg: fix mdlint issues
Fix markdownlint formatting issues in README.

Signed-off-by: Sherry Fan <sherryfan@microsoft.com>
2026-03-04 22:02:33 +00:00
Mike Beaton
5c8403f767 UnitTestFrameworkPkg: Remove references to GCC5 in ReadMe and dsc comments
Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
2026-02-26 15:30:52 +00:00
Michael Kubacki
59f58197dd UnitTestFrameworkPkg: Replace include guards with #pragma once
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-02-23 21:01:28 +00:00
Michael D Kinney
0302aa5bca UnitTestFrameworkPkg: WIN_MINGW32_BUILD generate .exe
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-21 05:44:25 +00:00
Daniel
99f9327740 UnitTestFrameworkPkg: Add VS2026 Support
* Add checks for VS2026.
* Enable Address Sanitizer for VS2026.

Signed-off-by: Daniel Grobert <danalexgro@gmail.com>
2026-01-07 20:19:12 +00:00
Michael D Kinney
d97d93bba8 UnitTestFrameworkPkg: Add MINGW CLANG Support
* 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-07 00:56:11 +00:00
Michael D Kinney
27020f33a1 UnitTestFrameworkPkg: Add Windows host-based unit test define
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-06 09:48:10 +00:00
Michael D Kinney
e622a4221a UnitTestFrameworkPkg: Fix StackCheckLib class mapping
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>
2026-01-05 17:25:50 +00:00
Michael D Kinney
e6fa2e3268 UnitTestFrameworkPkg/Include/Library: Remove _MSC_VER workaround
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-24 03:36:31 +00:00
Michael D Kinney
d29ff296fb UnitTestFrameworkPkg/UnitTestDebugAssertLibHost: Fix clang error
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-23 01:10:46 +00:00
Michael D Kinney
8c8aea0e0a UnitTestFrameworkPkg/UnitTestLib: Fix printf() error from clang
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-23 01:10:46 +00:00
Michael D Kinney
9013d867ae UnitTestFrameworkPkg: Fix spelling issues
Add "uintn" to extended words in ci.yaml and fix typos.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-12-20 18:49:01 +00:00
Philipp Schuster
e8ee86d566 UnitTestFrameworkPkg: fix various typos
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
2025-11-21 21:49:59 +00:00
Michael D Kinney
2522020ee1 UnitTestFrameworkPkg: Use 8MB stack for MSFT and CLANGPDB
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-10-15 16:21:17 +00:00
Michael D Kinney
55a5ec63fe UnitTestFrameworkPkg/UnitTestDebugAddressLib: Remove extra options
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-28 23:38:21 +00:00
Michael D Kinney
07da104cfb UnitTestFrameworkPkg/GoogleTestLib: Remove extra options
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-28 23:38:21 +00:00
Michael D Kinney
0838bf1531 UnitTestFrameworkPkg/SubhookLib: Update GCC defines
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-28 23:38:21 +00:00
Michael D Kinney
6e65f7df90 UnitTestFrameworkPkg/CmockaLib: Add CLANGPDB support
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-28 23:38:21 +00:00
Michael D Kinney
81a7efddd5 UnitTestFrameworkPkg/Include: Update GoogleTestLib for CLANG
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-28 23:38:21 +00:00
Michael D Kinney
9731114a00 UnitTestFrameworkPkg: Add CLANGDWARF and CLANGPDB support
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-28 23:38:21 +00:00
Michael D Kinney
f832329add UnitTestFrameworkPkg: Set defines for CLANGPDB builds
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-28 23:38:21 +00:00
Oliver Smith-Denny
5f9e2eac7a UnitTestFrameworkPkg: Remove ARM32 Support
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-25 22:04:10 +00:00
Michael D Kinney
0bc550f466 UnitTestFrameworkPkg/SampleGoogleTest: Add missing override keyword
Add missing override keyword to c++ classes. Found by the clang++
compiler.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-09-19 13:45:44 +00:00
Michael D Kinney
a2e4ee7ed2 UnitTestFrameworkPkg: Add -Wno-write-strings to host unit tests
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-25 21:40:50 +00:00
Michael D Kinney
272c1b2b5f UnitTestFrameworkPkg: Add -pie to ASLCC_FLAGS for unit tests
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-24 19:32:41 +00:00
Michael D Kinney
b4e5860fd5 UnitTestFrameworkPkg/GoogleTestLib: Enhance unit test NULL checks
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-06-24 19:32:41 +00:00
Phil Noh
f47d897f93 UnitTestFrameworkPkg: Avoid duplicate library function names
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-14 15:20:24 +00:00
Michael D Kinney
de13423277 UnitTestFrameworkPkg: Fix host test /WHOLEARCHIVE regression
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-03-10 20:04:38 +00:00
Michael D Kinney
2cb8bf6c69 UnitTestFrameworkPkg: Fix false positives from address sanitizer
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-29 19:35:30 +00:00
INDIA\sachinganesh
d35899b6d2 UnitTestFrameworkPkg: Add SafeIntLib to Common Includes
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-26 17:15:56 +00:00
Michael D Kinney
e78fb8a366 UnitTestFrameworkPkg/MemoryAllocationLibPosix: Add allocate below address
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-21 05:02:38 +00:00
Michael D Kinney
5f97d5391e UnitTestFrameworkPkg/UnitTestLib: Reduce sanitizer false positive
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-21 05:02:38 +00:00
Michael D Kinney
1c73f0e71d UnitTestFrameworkPkg: Add failing unit tests cases for sanitizer
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-21 05:02:38 +00:00
Michael D Kinney
de06288019 UnitTestFrameworkPkg: Use /MTd and enable Address Sanitizers
* 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-21 05:02:38 +00:00
Michael D Kinney
ca4e19ccc2 UnitTestFraworkPkg: Enable DEBUG_CLEAR_MEMORY in host tests
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>
2025-01-21 05:02:38 +00:00
Michael D Kinney
30b10dcdd0 UnitTestFrameworkPkg/UnitTestLib: Implement Free*() services
Implement FreeUnitTestEntry(), FreeUnitTestSuiteEntry(), and
FreeUnitTestFramework() so the UnitTestLib does not introduce
any memory leaks.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-01-21 05:02:38 +00:00
Michael D Kinney
182dbe79a0 UnitTestFrameworkPkg/MemoryAllocationLibPosix: Add DEBUG_CLEAR_MEMORY()
Add use of DEBUG_CLEAR_MEMORY() macros on all allocation and free
operations in MemoryAllocationLibPosix to match behavior of all other
MemoryAllocationLib instances.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
2025-01-21 05:02:38 +00:00