Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CryptoPkg/Test/CryptoPkgHostUnitTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
PLATFORM_VERSION = 0.1
DSC_SPECIFICATION = 0x00010005
OUTPUT_DIRECTORY = Build/CryptoPkg/HostTest
SUPPORTED_ARCHITECTURES = IA32|X64
SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64
BUILD_TARGETS = NOOPT
SKUID_IDENTIFIER = DEFAULT

Expand All @@ -33,7 +33,7 @@
# Build HOST_APPLICATION that tests the SampleUnitTest
#
CryptoPkg/Test/UnitTest/Library/BaseCryptLib/TestBaseCryptLibHost.inf
[Components.IA32, Components.X64]
[Components.IA32, Components.X64, Components.AARCH64]
#
# Build HOST_APPLICATION that tests the SampleUnitTest
#
Expand Down
2 changes: 1 addition & 1 deletion MdeModulePkg/Test/MdeModulePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
PLATFORM_VERSION = 0.1
DSC_SPECIFICATION = 0x00010005
OUTPUT_DIRECTORY = Build/MdeModulePkg/HostTest
SUPPORTED_ARCHITECTURES = IA32|X64
SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64
BUILD_TARGETS = NOOPT
SKUID_IDENTIFIER = DEFAULT

Expand Down
30 changes: 30 additions & 0 deletions MdePkg/Library/BaseLib/AArch64UnitTestHost.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/** @file
IA32/X64 specific Unit Test Host functions.

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

**/

#include "UnitTestHost.h"

///
/// Common services
///
STATIC UNIT_TEST_HOST_BASE_LIB_COMMON mUnitTestHostBaseLibCommon = {
UnitTestHostBaseLibEnableInterrupts,
UnitTestHostBaseLibDisableInterrupts,
UnitTestHostBaseLibEnableDisableInterrupts,
UnitTestHostBaseLibGetInterruptState,
};

///
/// Structure of hook functions for BaseLib functions that can not be used from
/// a host application. A simple emulation of these function is provided by
/// default. A specific unit test can provide its own implementation for any
/// of these functions.
///
UNIT_TEST_HOST_BASE_LIB gUnitTestHostBaseLib = {
&mUnitTestHostBaseLibCommon
};
1 change: 1 addition & 0 deletions MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@
AArch64/SetJumpLongJump.asm | MSFT
AArch64/CpuBreakpoint.asm | MSFT
AArch64/SpeculationBarrier.asm | MSFT
AArch64UnitTestHost.c

[Sources.RISCV64]
Math64.c
Expand Down
2 changes: 1 addition & 1 deletion MdePkg/Test/MdePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
PLATFORM_VERSION = 0.1
DSC_SPECIFICATION = 0x00010005
OUTPUT_DIRECTORY = Build/MdePkg/HostTest
SUPPORTED_ARCHITECTURES = IA32|X64
SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64
BUILD_TARGETS = NOOPT
SKUID_IDENTIFIER = DEFAULT

Expand Down
10 changes: 10 additions & 0 deletions MdePkg/Test/UnitTest/Include/Library/UnitTestHostBaseLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ UINTN
IN UINTN Value
);

#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)

/**
Prototype of service that reads and returns an IA32_DESCRIPTOR.

Expand Down Expand Up @@ -491,6 +493,8 @@ VOID
IN UINTN ValueSize
);

#endif // MDE_CPU_IA32 || MDE_CPU_X64

///
/// Common services
///
Expand All @@ -501,6 +505,8 @@ typedef struct {
UNIT_TEST_HOST_BASE_LIB_READ_BOOLEAN GetInterruptState;
} UNIT_TEST_HOST_BASE_LIB_COMMON;

#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)

///
/// IA32/X64 services
///
Expand Down Expand Up @@ -567,14 +573,18 @@ typedef struct {
UNIT_TEST_HOST_BASE_LIB_ASM_PATCH_INSTRUCTION_X86 PatchInstructionX86;
} UNIT_TEST_HOST_BASE_LIB_X86;

#endif // MDE_CPU_IA32 || MDE_CPU_X64

///
/// Data structure that contains pointers structures of common services and CPU
/// architctuire specific services. Support for additional CPU architectures
/// can be added to the end of this structure.
///
typedef struct {
UNIT_TEST_HOST_BASE_LIB_COMMON *Common;
#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
UNIT_TEST_HOST_BASE_LIB_X86 *X86;
#endif
} UNIT_TEST_HOST_BASE_LIB;

extern UNIT_TEST_HOST_BASE_LIB gUnitTestHostBaseLib;
Expand Down
2 changes: 1 addition & 1 deletion PolicyServicePkg/Test/PolicyServicePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
PLATFORM_VERSION = 0.1
DSC_SPECIFICATION = 0x00010005
OUTPUT_DIRECTORY = Build/PolicyServicePkg/HostTest
SUPPORTED_ARCHITECTURES = IA32|X64
SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64
BUILD_TARGETS = NOOPT
SKUID_IDENTIFIER = DEFAULT

Expand Down
8 changes: 7 additions & 1 deletion UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#define FUNCTION_MOCK_LIB_H_

#include <Library/GoogleTestLib.h>
#include <Library/SubhookLib.h>
#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
#include <Library/SubhookLib.h>
#endif
#include <type_traits>

//////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -53,13 +55,17 @@
//////////////////////////////////////////////////////////////////////////////
// The below macros are private and should not be used outside this file.

#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
#define MOCK_FUNCTION_HOOK_DECLARATIONS(FUNC) \
static subhook::Hook Hook##FUNC; \
struct MockContainer_##FUNC { \
MockContainer_##FUNC (); \
~MockContainer_##FUNC (); \
}; \
MockContainer_##FUNC MockContainerInst_##FUNC;
#else
#define MOCK_FUNCTION_HOOK_DECLARATIONS(FUNC)
#endif

// This definition implements a constructor and destructor inside a nested
// class to enable automatic installation of the hooks to the associated
Expand Down
2 changes: 2 additions & 0 deletions UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@
GCC:NOOPT_*_*_CC_FLAGS = -O0
GCC:*_*_IA32_CC_FLAGS = -m32
GCC:*_*_X64_CC_FLAGS = -m64
# Need to use floats in this library. Got rid of -mgeneral-regs-only to do so.
GCC:*_*_AARCH64_CC_XIPFLAGS == -mstrict-align
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

[LibraryClasses]
GoogleTestLib

[LibraryClasses.IA32, LibraryClasses.X64]
SubhookLib

[Packages]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,4 @@
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))"
GCC:*_*_AARCH64_CC_FLAGS == -g -c -fshort-wchar -fexceptions -O0 -fno-pie "-DEFIAPI=__attribute__((ms_abi))"
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,12 @@ TEST (SanitizerTests, DivideByZeroDeathTest) {
//
// Divide by 0 should be caught by address sanitizer, log details, and exit
//
#if !defined (MDE_CPU_AARCH64) || !defined (__GNUC__)
EXPECT_DEATH (DivideWithNoParameterChecking (10, 0), "ERROR: AddressSanitizer: ");
#else
UINTN Ret = DivideWithNoParameterChecking (10, 0);
ASSERT_EQ (Ret, (UINTN)0);
#endif
}

/**
Expand Down
8 changes: 5 additions & 3 deletions UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
PLATFORM_VERSION = 0.1
DSC_SPECIFICATION = 0x00010005
OUTPUT_DIRECTORY = Build/UnitTestFrameworkPkg/HostTest
SUPPORTED_ARCHITECTURES = IA32|X64
SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64
BUILD_TARGETS = NOOPT
SKUID_IDENTIFIER = DEFAULT

Expand All @@ -32,10 +32,12 @@
# Build HOST_APPLICATION Libraries
#
UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf
UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf
UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf
UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf
UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf
UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf
UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf

[Components.IA32, Components.X64]
UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf
UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
PLATFORM_VERSION = 0.1
DSC_SPECIFICATION = 0x00010005
OUTPUT_DIRECTORY = Build/UnitTestFrameworkPkg/HostTestExpectFail
SUPPORTED_ARCHITECTURES = IA32|X64
SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64
BUILD_TARGETS = NOOPT
SKUID_IDENTIFIER = DEFAULT

Expand Down
2 changes: 2 additions & 0 deletions UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@
"loongarch",
"loongson",
"xunit",
"mgeneral", # build flag for AArch64 cmocka in the INF
"mstrict", # build flag for AArch64 cmocka in the INF
],
"IgnoreStandardPaths": [], # Standard Plugin defined paths that should be ignore
"AdditionalIncludePaths": [] # Additional paths to spell check (wildcards supported)
Expand Down
8 changes: 6 additions & 2 deletions UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
CacheMaintenanceLib|MdePkg/Library/BaseCacheMaintenanceLibNull/BaseCacheMaintenanceLibNull.inf
CmockaLib|UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
GoogleTestLib|UnitTestFrameworkPkg/Library/GoogleTestLib/GoogleTestLib.inf
SubhookLib|UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf
FunctionMockLib|UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf
UnitTestLib|UnitTestFrameworkPkg/Library/UnitTestLib/UnitTestLibCmocka.inf
DebugLib|UnitTestFrameworkPkg/Library/Posix/DebugLibPosix/DebugLibPosix.inf
MemoryAllocationLib|UnitTestFrameworkPkg/Library/Posix/MemoryAllocationLibPosix/MemoryAllocationLibPosix.inf
Expand All @@ -29,6 +27,10 @@
NULL|UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf
NULL|MdePkg/Library/StackCheckLibNull/StackCheckLibNullHostApplication.inf

[LibraryClasses.IA32.HOST_APPLICATION, LibraryClasses.X64.HOST_APPLICATION]
SubhookLib|UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf
FunctionMockLib|UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf

[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /MTd
GCC:*_*_*_CC_FLAGS = -fno-pie
Expand Down Expand Up @@ -57,6 +59,7 @@
MSFT:*_*_*_DLINK_FLAGS == /out:"$(BIN_DIR)\$(MODULE_NAME_GUID).exe" /pdb:"$(BIN_DIR)\$(MODULE_NAME_GUID).pdb" /IGNORE:4001 /NOLOGO /SUBSYSTEM:CONSOLE /DEBUG /STACK:0x40000,0x40000 /WHOLEARCHIVE
MSFT:*_*_IA32_DLINK_FLAGS = /MACHINE:I386
MSFT:*_*_X64_DLINK_FLAGS = /MACHINE:AMD64
MSFT:*_*_AARCH64_DLINK_FLAGS = /MACHINE:ARM64

MSFT:*_VS2015_IA32_DLINK_FLAGS = /LIBPATH:"%VS2015_PREFIX%Lib" /LIBPATH:"%VS2015_PREFIX%VC\Lib" /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x86" /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x86"
MSFT:*_VS2015x86_IA32_DLINK_FLAGS = /LIBPATH:"%VS2015_PREFIX%Lib" /LIBPATH:"%VS2015_PREFIX%VC\Lib" /LIBPATH:"%UniversalCRTSdkDir%lib\%UCRTVersion%\ucrt\x86" /LIBPATH:"%WindowsSdkDir%lib\%WindowsSDKLibVersion%\um\x86"
Expand All @@ -77,6 +80,7 @@
GCC:*_*_*_CC_FLAGS = -D GOOGLETEST_HOST_UNIT_TEST_BUILD=1
GCC:*_*_IA32_DLINK_FLAGS == -o $(BIN_DIR)/$(MODULE_NAME_GUID) -m32 -no-pie
GCC:*_*_X64_DLINK_FLAGS == -o $(BIN_DIR)/$(MODULE_NAME_GUID) -m64 -no-pie
GCC:*_*_AARCH64_DLINK_FLAGS == -o $(BIN_DIR)/$(MODULE_NAME_GUID) -no-pie
#
# Surround our static libraries with whole-archive, so constructor-based test registration works properly.
# Note that we need to --no-whole-archive before linking system libraries.
Expand Down