From 56e1e042025707c48715186e50efba4d6b7613b9 Mon Sep 17 00:00:00 2001 From: Kun Qin Date: Tue, 31 Mar 2026 10:50:57 -0700 Subject: [PATCH] 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 --- .../Include/Library/FunctionMockLib.h | 12 ++++++- .../FunctionMockLib/FunctionMockLib.inf | 2 ++ .../Test/UnitTestFrameworkPkgHostTest.dsc | 6 ++-- .../UnitTestFrameworkPkgHost.dsc.inc | 32 ++++++++++--------- 4 files changed, 34 insertions(+), 18 deletions(-) diff --git a/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h b/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h index 9303542fcb..74c8a659ab 100644 --- a/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h +++ b/UnitTestFrameworkPkg/Include/Library/FunctionMockLib.h @@ -8,7 +8,9 @@ #pragma once #include -#include +#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) + #include +#endif #include ////////////////////////////////////////////////////////////////////////////// @@ -52,6 +54,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 { \ @@ -59,11 +62,15 @@ ~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 // MOCK_FUNC() when the mock object is instantiated in scope and automatic // removal when the instantiated mock object goes out of scope. +#if defined (MDE_CPU_IA32) || defined (MDE_CPU_X64) #define MOCK_FUNCTION_HOOK_DEFINITIONS(MOCK, FUNC) \ subhook :: Hook MOCK :: Hook##FUNC; \ MOCK :: MockContainer_##FUNC :: MockContainer_##FUNC () { \ @@ -83,6 +90,9 @@ "different return type, arguments, or calling convention. See " \ "associated 'MOCK_FUNCTION_INTERNAL_DECLARATION' macro invocation " \ "for more details."); +#else +#define MOCK_FUNCTION_HOOK_DEFINITIONS(MOCK, FUNC) +#endif #define MOCK_FUNCTION_TYPE_DEFINITIONS(RET_TYPE, FUNC, ARGS) \ using FUNC##_ret_type = RET_TYPE; \ diff --git a/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf b/UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf index 44c5946be5..9f7dc60bcd 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/Test/UnitTestFrameworkPkgHostTest.dsc b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc index 1d45d4ba47..d9262a126c 100644 --- a/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc +++ b/UnitTestFrameworkPkg/Test/UnitTestFrameworkPkgHostTest.dsc @@ -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/UnitTestFrameworkPkgHost.dsc.inc b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc index d44bee505c..77221b2ebc 100644 --- a/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc +++ b/UnitTestFrameworkPkg/UnitTestFrameworkPkgHost.dsc.inc @@ -37,8 +37,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 @@ -54,19 +52,19 @@ # Operating System and Compiler Compatibility Matrix for Host-based unit tests # NOTE: Only NOOPT build target is supported for unit test builds # -# +--------------------+--------+----------+------------+-----+----+--------+ -# | OS/Compiler | VS2019 | CLANGPDB | CLANGDWARF | GCC | XCODE5 | -# | | VS2022 | | | GCCNOLTO | | -# | | VS2026 | | | | | -# +--------------------+--------+----------+------------+----------+--------+ -# | Windows/VS |IA32/X64| | | | | -# | Windows/LLVM/VS | | IA32/X64 | | | | -# | Windows/LLVM/MSYS2 | | | X64 | | | -# | Windows/LLVM/MINGW | | | IA32/X64 | | | -# | Linux/LLVM | | | IA32/X64 | | | -# | Linux/GCC | | | | IA32/X64 | | -# | macOS/XCODE5 | | | | |IA32/X64| -# +--------------------+--------+----------+------------+----------+--------+ +# +--------------------+--------+----------+------------+------------------+--------+ +# | OS/Compiler | VS2019 | CLANGPDB | CLANGDWARF | GCC | XCODE5 | +# | | VS2022 | | | GCCNOLTO | | +# | | VS2026 | | | | | +# +--------------------+--------+----------+------------+------------------+--------+ +# | Windows/VS |IA32/X64| | | | | +# | Windows/LLVM/VS | | IA32/X64 | | | | +# | Windows/LLVM/MSYS2 | | | X64 | | | +# | Windows/LLVM/MINGW | | | IA32/X64 | | | +# | Linux/LLVM | | | IA32/X64 | | | +# | Linux/GCC | | | | IA32/X64/AARCH64 | | +# | macOS/XCODE5 | | | | |IA32/X64| +# +--------------------+--------+----------+------------+------------------+--------+ # # * Windows/VS: Windows environment with Visual Studio installed # * Windows/LLVM/VS: Windows environment with Visual Studio and LLVM 20.1.8 or @@ -125,6 +123,10 @@ !endif !endif +[LibraryClasses.IA32.HOST_APPLICATION, LibraryClasses.X64.HOST_APPLICATION] + SubhookLib|UnitTestFrameworkPkg/Library/SubhookLib/SubhookLib.inf + FunctionMockLib|UnitTestFrameworkPkg/Library/FunctionMockLib/FunctionMockLib.inf + [BuildOptions] !if $(WIN_MINGW32_BUILD) GCC:*_CLANGDWARF_IA32_PP_FLAGS = -target i686-w64-mingw32