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
2 changes: 1 addition & 1 deletion BaseTools/Bin/iasl_ext_dep.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,6 @@
"type": "nuget",
"name": "edk2-acpica-iasl",
"source": "https://pkgs.dev.azure.com/projectmu/acpica/_packaging/mu_iasl/nuget/v3/index.json",
"version": "20200717.0.0",
"version": "20230628.0.1",
"flags": ["set_path", "host_specific"]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
## @file
# DBG2 Table Generator
#
# Copyright (c) 2017 - 2020, Arm Limited. All rights reserved.<BR>
# Copyright (C) 2025 Advanced Micro Devices, Inc. All rights reserved.
#
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010019
BASE_NAME = AcpiDbg2Lib
FILE_GUID = A9C39504-531B-49E1-B639-25A86B85DAA1
VERSION_STRING = 1.0
MODULE_TYPE = DXE_DRIVER
LIBRARY_CLASS = NULL|HOST_APPLICATION
CONSTRUCTOR = AcpiDbg2LibConstructor
DESTRUCTOR = AcpiDbg2LibDestructor

[Sources]
Dbg2Generator.c
Dbg2Generator.h
Dbg2GeneratorNull.c

[Packages.ARM, Packages.AARCH64]
ArmPlatformPkg/ArmPlatformPkg.dec

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
EmbeddedPkg/EmbeddedPkg.dec
DynamicTablesPkg/DynamicTablesPkg.dec

[LibraryClasses]
BaseLib
PrintLib
SsdtSerialPortFixupLib

[FixedPcd]
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultBaudRate
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultDataBits
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultParity
gEfiMdePkgTokenSpaceGuid.PcdUartDefaultStopBits
4 changes: 2 additions & 2 deletions DynamicTablesPkg/Test/DynamicTablesPkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
PLATFORM_VERSION = 0.1
DSC_SPECIFICATION = 0x00010005
OUTPUT_DIRECTORY = Build/DynamicTablesPkg/HostTest
SUPPORTED_ARCHITECTURES = X64
SUPPORTED_ARCHITECTURES = X64|AARCH64
BUILD_TARGETS = NOOPT
SKUID_IDENTIFIER = DEFAULT

Expand All @@ -31,7 +31,7 @@
[Components]
DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/GoogleTest/Dbg2GeneratorGoogleTest.inf {
<LibraryClasses>
NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/AcpiDbg2Lib.inf
NULL|DynamicTablesPkg/Library/Acpi/Common/AcpiDbg2Lib/AcpiDbg2LibHostTest.inf
}
DynamicTablesPkg/Library/Acpi/Common/AcpiCedtLib/GoogleTest/CedtGeneratorGoogleTest.inf {
<LibraryClasses>
Expand Down
2 changes: 1 addition & 1 deletion FmpDevicePkg/Test/FmpDeviceHostPkgTest.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/FmpDevicePkg/HostTest
SUPPORTED_ARCHITECTURES = IA32|X64
SUPPORTED_ARCHITECTURES = IA32|X64|AARCH64
BUILD_TARGETS = NOOPT
SKUID_IDENTIFIER = DEFAULT

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
};
27 changes: 3 additions & 24 deletions MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
LIBRARY_CLASS = UnitTestHostBaseLib|HOST_APPLICATION

#
# VALID_ARCHITECTURES = IA32 X64
# VALID_ARCHITECTURES = IA32 X64 AARCH64
#

[Sources]
Expand Down Expand Up @@ -63,6 +63,7 @@
SafeString.c
String.c
FilePaths.c
Unaligned.c
BaseLibInternals.h
UnitTestHost.c
UnitTestHost.h
Expand Down Expand Up @@ -121,7 +122,6 @@
Ia32/InternalSwitchStack.c | MSFT
Ia32/InternalSwitchStack.nasm | GCC
Ia32/Non-existing.c
Unaligned.c
X86MemoryFence.c | MSFT
X86FxSave.c
X86FxRestore.c
Expand Down Expand Up @@ -160,7 +160,6 @@
X64/ReadEflags.nasm| MSFT
X64/Non-existing.c
Math64.c
Unaligned.c
X86MemoryFence.c | MSFT
X86FxSave.c
X86FxRestore.c
Expand All @@ -173,17 +172,8 @@
IntelTdxNull.c
AmdSevNull.c

[Sources.EBC]
Ebc/CpuBreakpoint.c
Ebc/SetJumpLongJump.c
Ebc/SwitchStack.c
Ebc/SpeculationBarrier.c
Unaligned.c
Math64.c

[Sources.AARCH64]
AArch64/InternalSwitchStack.c
AArch64/Unaligned.c
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

NIT:
It seems that this patch does 2 things:

  1. Add preprocessor for AArch64 instances
  2. Cleanup some unnecessary files

Maybe this patch should be split in 2 and also remove the following unused sections:

  • [Sources.RISCV64]
  • [Sources.EBC]

NIT2:
The following function are not supported by the UnitTestHost BaseLib implementation:

  • AArch64/ArmReadCntPctReg.S
  • AArch64/ArmReadIdAA64Isar0Reg.S

It doesn't seem it is required right now and it will still be possible to add it later if needed, so just making a note of it.


NIT3:
Also, the VALID_ARCHITECTURES might be updated to add AARCH64

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your comments and testing this.

I have updated this patch per your feedback. Specifically, I split the majority of the inf change into a separate commit and also removed the EBC and RISCV sections.

It was a good callout, but I did not add the CntPctReg and IdAA64Isar0Reg support in this patch set. I would like to add the timer related changes in a separate PR to resolve the lack of timer support on host-based tests. But please let me know if you have other thoughts.

Math64.c

AArch64/MemoryFence.S | GCC
Expand All @@ -197,18 +187,7 @@
AArch64/SetJumpLongJump.asm | MSFT
AArch64/CpuBreakpoint.asm | MSFT
AArch64/SpeculationBarrier.asm | MSFT

[Sources.RISCV64]
Math64.c
Unaligned.c
RiscV64/InternalSwitchStack.c
RiscV64/CpuBreakpoint.c
RiscV64/CpuPause.c
RiscV64/RiscVSetJumpLongJump.S | GCC
RiscV64/RiscVCpuBreakpoint.S | GCC
RiscV64/RiscVCpuPause.S | GCC
RiscV64/RiscVInterrupt.S | GCC
RiscV64/FlushCache.S | GCC
AArch64UnitTestHost.c

[Packages]
MdePkg/MdePkg.dec
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 @@ -76,6 +76,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 @@ -490,6 +492,8 @@ VOID
IN UINTN ValueSize
);

#endif // MDE_CPU_IA32 || MDE_CPU_X64

///
/// Common services
///
Expand All @@ -500,6 +504,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 @@ -566,14 +572,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;
2 changes: 1 addition & 1 deletion PrmPkg/Test/PrmPkgHostTest.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/$(PLATFORM_NAME)/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 @@ -8,7 +8,9 @@
#pragma once

#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 @@ -52,13 +54,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 @@ -34,3 +34,5 @@
GCC:*_*_IA32_CC_FLAGS = -m32
GCC:*_*_X64_CC_FLAGS = -m64
GCC:*_CLANGPDB_*_CC_FLAGS = -DHAVE_VSNPRINTF -DHAVE_SNPRINTF -Wno-deprecated-declarations
# 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 @@ -30,3 +30,4 @@
MSFT:*_*_*_CC_FLAGS == /c /Zi /Od
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
Original file line number Diff line number Diff line change
Expand Up @@ -544,28 +544,6 @@ TEST (SanitizerTests, InvalidPointerWriteDeathTest) {
EXPECT_DEATH (*(volatile UINT8 *)(-1) = 0, "ERROR: AddressSanitizer: ");
}

UINTN
DivideWithNoParameterChecking (
UINTN Dividend,
UINTN Divisor
)
{
//
// Perform integer division with no check for divide by zero
//
return (Dividend / Divisor);
}

/**
Sample unit test that performs a divide by 0
**/
TEST (SanitizerTests, DivideByZeroDeathTest) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems that the same division by 0 test exists in:
UnitTestFrameworkPkg/Test/GoogleTest/Sample/SampleGoogleTestGenerateException/ampleGoogleTestGenerateException.cpp

The test should generate an exception, but instead it should fail as the result is 0 (checked against MAX_UINTN). Maybe the test should be IA32/X64 only.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this feedback out for this round of push. The test is intended to generate an exception, but divide by 0 will not trip on any exception on AArch64 platforms. Should we switch to read from a null pointer instead in this case? @mdkinney any thoughts?

On the other hand, this test is not included in the unit test dsc file, so we do not have obvious way to mark this test as x86 specific, other than the inf's supported architecture, which is already configured as such.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left this feedback out for this round of push. The test is intended to generate an exception, but divide by 0 will not trip on any exception on AArch64 platforms. Should we switch to read from a null pointer instead in this case? @mdkinney any thoughts?

On the other hand, this test is not included in the unit test dsc file, so we do not have obvious way to mark this test as x86 specific, other than the inf's supported architecture, which is already configured as such.

Most of this file can work for all archs. Just this one test should be broken out into an x86 only cpp file and INF updated with main cpp file for all archs and the one special cpp file for IA32/X64 only.

//
// Divide by 0 should be caught by address sanitizer, log details, and exit
//
EXPECT_DEATH (DivideWithNoParameterChecking (10, 0), "ERROR: AddressSanitizer: ");
}

/**
Sample unit test that allocates and frees buffers below 4GB
**/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@
[Sources]
SampleGoogleTest.cpp

[Sources.IA32, Sources.X64]
SampleGoogleTestX86.cpp

[Packages]
MdePkg/MdePkg.dec
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/** @file
This is a sample to demonstrates the use of GoogleTest that supports host
execution environments.

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

**/

#include <Library/GoogleTestLib.h>
extern "C" {
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/DebugLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/HostMemoryAllocationBelowAddressLib.h>
}

UINTN
DivideWithNoParameterChecking (
UINTN Dividend,
UINTN Divisor
)
{
//
// Perform integer division with no check for divide by zero
//
return (Dividend / Divisor);
}

/**
Sample unit test that performs a divide by 0
**/
TEST (SanitizerTests, DivideByZeroDeathTest) {
//
// Divide by 0 should be caught by address sanitizer, log details, and exit
//
EXPECT_DEATH (DivideWithNoParameterChecking (10, 0), "ERROR: AddressSanitizer: ");
}
Loading
Loading