diff --git a/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc b/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc
index b59a1b0ab13..b1b26283dcc 100644
--- a/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc
+++ b/CryptoPkg/Test/CryptoPkgHostUnitTest.dsc
@@ -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
@@ -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
#
diff --git a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
index a26c3cb991a..4d0d383c1b4 100644
--- a/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
+++ b/MdeModulePkg/Test/MdeModulePkgHostTest.dsc
@@ -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
diff --git a/MdePkg/Library/BaseLib/AArch64UnitTestHost.c b/MdePkg/Library/BaseLib/AArch64UnitTestHost.c
new file mode 100644
index 00000000000..353510f65be
--- /dev/null
+++ b/MdePkg/Library/BaseLib/AArch64UnitTestHost.c
@@ -0,0 +1,30 @@
+/** @file
+ IA32/X64 specific Unit Test Host functions.
+
+ Copyright (c) 2020, Intel Corporation. All rights reserved.
+ 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
+};
diff --git a/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf b/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
index 1d53f940f5d..81660010db3 100644
--- a/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
+++ b/MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
@@ -215,6 +215,7 @@
AArch64/SetJumpLongJump.asm | MSFT
AArch64/CpuBreakpoint.asm | MSFT
AArch64/SpeculationBarrier.asm | MSFT
+ AArch64UnitTestHost.c
[Sources.RISCV64]
Math64.c
diff --git a/MdePkg/Test/MdePkgHostTest.dsc b/MdePkg/Test/MdePkgHostTest.dsc
index 006a61c2a44..caf90d9c833 100644
--- a/MdePkg/Test/MdePkgHostTest.dsc
+++ b/MdePkg/Test/MdePkgHostTest.dsc
@@ -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
diff --git a/MdePkg/Test/UnitTest/Include/Library/UnitTestHostBaseLib.h b/MdePkg/Test/UnitTest/Include/Library/UnitTestHostBaseLib.h
index fb9bfd39478..59ea8349cf7 100644
--- a/MdePkg/Test/UnitTest/Include/Library/UnitTestHostBaseLib.h
+++ b/MdePkg/Test/UnitTest/Include/Library/UnitTestHostBaseLib.h
@@ -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.
@@ -491,6 +493,8 @@ VOID
IN UINTN ValueSize
);
+#endif // MDE_CPU_IA32 || MDE_CPU_X64
+
///
/// Common services
///
@@ -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
///
@@ -567,6 +573,8 @@ 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
@@ -574,7 +582,9 @@ typedef struct {
///
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;
diff --git a/PolicyServicePkg/Test/PolicyServicePkgHostTest.dsc b/PolicyServicePkg/Test/PolicyServicePkgHostTest.dsc
index 20096657820..8191e98b428 100644
--- a/PolicyServicePkg/Test/PolicyServicePkgHostTest.dsc
+++ b/PolicyServicePkg/Test/PolicyServicePkgHostTest.dsc
@@ -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
diff --git a/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h b/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h
index bf7a7066560..01015141c9d 100644
--- a/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h
+++ b/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h
@@ -9,7 +9,9 @@
#define FUNCTION_MOCK_LIB_H_
#include
-#include
+#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64)
+ #include
+#endif
#include
//////////////////////////////////////////////////////////////////////////////
@@ -53,6 +55,7 @@
//////////////////////////////////////////////////////////////////////////////
// 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 { \
@@ -60,6 +63,9 @@
~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
diff --git a/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf b/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
index 357883752a3..7b9430302e1 100644
--- a/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
+++ b/UnitTestFrameworkPkg/Library/CmockaLib/CmockaLib.inf
@@ -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
diff --git a/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf b/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf
index 44c5946be53..9f7dc60bcdc 100644
--- a/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf
+++ b/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf
@@ -24,6 +24,8 @@
[LibraryClasses]
GoogleTestLib
+
+[LibraryClasses.IA32, LibraryClasses.X64]
SubhookLib
[Packages]
diff --git a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf
index 7458df79486..4db7bd349f1 100644
--- a/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf
+++ b/UnitTestFrameworkPkg/Library/UnitTestDebugAssertLib/UnitTestDebugAssertLibHost.inf
@@ -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))"
diff --git a/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTest.cpp b/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTest.cpp
index c13c66f97a5..c043b8a07ab 100644
--- a/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTest.cpp
+++ b/UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTest/SampleGoogleTest.cpp
@@ -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
}
/**
diff --git a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc
index 1d45d4ba477..46d5a13cbb0 100644
--- a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc
+++ b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc
@@ -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
@@ -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
diff --git a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTestExpectFail.dsc b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTestExpectFail.dsc
index 73b4cb1b929..d53e01111ad 100644
--- a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTestExpectFail.dsc
+++ b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTestExpectFail.dsc
@@ -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
diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml
index 4ad09337e97..e391c96195d 100644
--- a/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml
+++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkg.ci.yaml
@@ -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)
diff --git a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
index 7090dda019b..0b157f7f632 100644
--- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
+++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc
@@ -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
@@ -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
@@ -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"
@@ -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.