Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unit test framework pkg enable sanitize #6408

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
Open
7 changes: 7 additions & 0 deletions BaseTools/Conf/Empty_C_File_Host_Application_Build.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/** @file
This is an empty C source file used in VS20xx HOST_APPLICATION
builds.

Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
3 changes: 2 additions & 1 deletion BaseTools/Conf/build_rule.template
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,8 @@
$(DEBUG_DIR)(+)$(MODULE_NAME)

<Command.MSFT, Command.INTEL, Command.CLANGPDB>
"$(DLINK)" $(DLINK_FLAGS) $(DLINK_SPATH) @$(STATIC_LIBRARY_FILES_LIST)
"$(CC)" /Fo$$(OUTPUT_DIR)/Empty_C_File_Host_Application_Build.obj $(CC_FLAGS) $(INC) $(EDK_TOOLS_PATH)/Conf/Empty_C_File_Host_Application_Build.c
"$(DLINK)" $(DLINK_FLAGS) $(DLINK_SPATH) $(OUTPUT_DIR)/Empty_C_File_Host_Application_Build.obj @$(STATIC_LIBRARY_FILES_LIST)

<Command.GCC>
"$(DLINK)" $(DLINK_FLAGS) -Wl,--start-group,@$(STATIC_LIBRARY_FILES_LIST),--end-group $(DLINK2_FLAGS)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ def do_post_build(self, thebuilder):

failure_count = 0

# Do not catch exceptions in gtest so they are handled by address sanitizer
shell_env.set_shell_var('GTEST_CATCH_EXCEPTIONS', '0')

# Disable address sanitizer memory leak detection
shell_env.set_shell_var('ASAN_OPTIONS', 'detect_leaks=0')

# Set up the reporting type for Cmocka.
shell_env.set_shell_var('CMOCKA_MESSAGE_OUTPUT', 'xml')

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/** @file
HostMemoryAllocationBelowAddressLib class

Copyright (c) 2024, Intel Corporation. All rights reserved.<BR>
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef HOST_MEMORY_ALLOCATION_BELOW_ADDRESS_LIB_H_

/**
Allocate memory below a specifies address.

@param[in] MaximumAddress The address below which the memory allocation must
be performed.
@param[in] Length The size, in bytes, of the memory allocation.

@retval !NULL Pointer to the allocated memory.
@retval NULL The memory allocation failed.
**/
VOID *
EFIAPI
HostAllocatePoolBelowAddress (
IN UINT64 MaximumAddress,
IN UINT64 Length
);

/**
Free memory allocated with AllocateMemoryHostAllocatePoolBelowAddress().

@param[in] Address Pointer to buffer previously allocated with
HostAllocatePoolBelowAddress().

@retval TRUE The buffer was freed.
@retval FALSE The buffer could not be freed..
**/
VOID
EFIAPI
HostFreePoolBelowAddress (
IN VOID *Address
);

/**
Allocates one or more 4KB pages below a specified address at a specified
alignment.

Allocates the number of 4KB pages specified by Pages below MaximumAddress with
an alignment specified by Alignment. The allocated buffer is returned. If
Pages is 0, then NULL is returned. If there is not enough memory below the
requested address at the specified alignment remaining to satisfy the request,
then NULL is returned.

If Alignment is not a power of two and Alignment is not zero, then ASSERT().
If Pages plus EFI_SIZE_TO_PAGES (Alignment) overflows, then ASSERT().

@param[in] MaximumAddress The address below which the memory allocation must
@param[in] Pages The number of 4 KB pages to allocate.
@param[in] Alignment The requested alignment of the allocation. Must be
a power of two. If Alignment is zero, then byte
alignment is used.

@return A pointer to the allocated buffer or NULL if allocation fails.
**/
VOID *
EFIAPI
HostAllocateAlignedPagesBelowAddress (
IN UINT64 MaximumAddress,
IN UINTN Pages,
IN UINT64 Alignment
);

/**
Frees one or more 4KB pages that were previously allocated with
HostAllocateAlignedPagesBelowAddress().

Frees the number of 4KB pages specified by Pages from the buffer specified by
Buffer. Buffer must have been allocated with HostAllocateAlignedPagesBelowAddress().
If it is not possible to free allocated pages, then this function will perform
no actions.

If Buffer was not allocated with HostAllocateAlignedPagesBelowAddress(), then
ASSERT(). If Pages is zero, then ASSERT().

@param[in] Buffer The pointer to the buffer of pages to free.
@param[in] Pages The number of 4 KB pages to free.
**/
VOID
EFIAPI
HostFreeAlignedPagesBelowAddress (
IN VOID *Buffer,
IN UINTN Pages
);

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec

[BuildOptions]
MSFT:*_*_*_CC_FLAGS == /c /EHs /Zi /Od /MT
MSFT:*_*_*_CC_FLAGS == /c /EHs /Zi /Od /MTd
GCC:*_*_IA32_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m32 -malign-double -fno-pie
GCC:*_*_X64_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -m64 -fno-pie "-DEFIAPI=__attribute__((ms_abi))"
Loading
Loading