| Age | Commit message (Collapse) | Author |
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
Fix markdownlint formatting issues in README.
Signed-off-by: Sherry Fan <sherryfan@microsoft.com>
|
|
Signed-off-by: Mike Beaton <mjsbeaton@gmail.com>
|
|
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>
|
|
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>
|
|
* Add checks for VS2026.
* Enable Address Sanitizer for VS2026.
Signed-off-by: Daniel Grobert <danalexgro@gmail.com>
|
|
* 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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
Add "uintn" to extended words in ci.yaml and fix typos.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
|
|
Signed-off-by: Philipp Schuster <philipp.schuster@cyberus-technology.de>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
Add missing override keyword to c++ classes. Found by the clang++
compiler.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
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>
|
|
* 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>
|
|
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>
|
|
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>
|
|
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>
|
|
This PR updates the CI pipelines to use VS2022 instead of VS2019
as that is the latest supported VS toolchain on edk2.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Oliver Smith-Denny <osde@microsoft.com>
|
|
Now that the ResetVectors are USER_DEFINED modules, they will not
be linked against StackCheckLibNull, which were the only modules
causing issues. So, we can now remove the kludge we had before
and the requirement for every DSC to include StackCheckLibNull
for SEC modules and just apply StackCheckLibNull globally.
This also changes every DSC to drop the SEC definition of
StackCheckLibNull.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
|
|
Change subhook url from https://github.com/Zeex/subhook to
https://github.com/tianocore/edk2-subhook because old url is
no longer available.
Also align .gitmodules file to use consistent LF line endings.
Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
|
|
Currently EDK2 is supporting VS2022, with VS2022 UnitTestFrameworkPkg
build is failing, this patch is to add the VS2022 support for UnitTest
Signed-off-by: Ashraf Ali S <ashraf.ali.s@intel.com>
|
|
Currently, there is a mismatch of allowed string sizes in UnitTestLib.
The UT_LOG_* macros allow a string size of 512, but failure messages
are constrained to 120 characters and some other string lengths are
similarly constrained. 120 characters is too few for some longer
error messages, particularly the ones that print out the path to
the failing line. This can result in the actual error not getting
printed in the log.
This patch updates all UnitTestLib allowed string lengths to be 512
characters.
Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
|
|
Add StackCheckLib for Target and Host based unit tests. Host
based unit tests are treated specially, because MSVC built
host based unit tests use the MSVC C runtime lib to provide
the stack cookie definitions, but GCC built host based unit
tests use our implementation, as we do not link against a
C runtime lib that provides the definitions.
Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
|
|
Previously, the UnitTestFrameworkPkgHost.dsc.inc included the entire
UnitTestFrameworkPkgTarget.dsc.inc file. This is unnecessary for
most configurations, so copy the relevant common components to a
separate file.
This is required for stack cookies so that we can have stack
cookies on target based test apps but not on host base test apps.
Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
|
|
As per the emailed RFC in
https://edk2.groups.io/g/devel/topic/rfc_move/107675828,
this patch moves CompilerIntrinsicsLib from ArmPkg to
MdePkg as this library provides compiler intrinsics, which
are industry standard.
This aligns with the goal of integrating ArmPkg into existing
packages: https://bugzilla.tianocore.org/show_bug.cgi?id=4121.
The newly placed CompilerIntrinsicsLib is added to MdeLibs.dsc.inc
as every DSC that builds ARM/AARCH64 needs this library added. The
old location is removed from every DSC in edk2 in this commit also
to not break bisectability with minimal hoop jumping.
Continuous-integration-options: PatchCheck.ignore-multi-package
Signed-off-by: Oliver Smith-Denny <osde@linux.microsoft.com>
|
|
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>
|