summaryrefslogtreecommitdiffstats
path: root/UnitTestFrameworkPkg/Library/UnitTestPeiServicesTablePointerLib/UnitTestPeiServicesTablePointerLib.c
diff options
context:
space:
mode:
authorZhiguang Liu <zhiguang.liu@intel.com>2023-05-26 13:51:09 +0800
committermergify[bot] <37929162+mergify[bot]@users.noreply.github.com>2023-06-13 02:53:40 +0000
commit530f5b0912c1c3837337baeec66eb7b0a90d9969 (patch)
tree9bbbda8d131f898673686849224464144b2ced8f /UnitTestFrameworkPkg/Library/UnitTestPeiServicesTablePointerLib/UnitTestPeiServicesTablePointerLib.c
parent8314a85893f5b75baa0031a5138028188a626243 (diff)
downloadedk2-530f5b0912c1c3837337baeec66eb7b0a90d9969.tar.gz
edk2-530f5b0912c1c3837337baeec66eb7b0a90d9969.tar.bz2
edk2-530f5b0912c1c3837337baeec66eb7b0a90d9969.zip
UnitTestFrameworkPkg: Add UnitTestPeiServicesTablePointerLib
This library supports a PeiServicesTablePointerLib implementation that allows code dependent upon PeiServicesTable to operate in an isolated execution environment such as within the context of a host-based unit test framework. The unit test should initialize the PeiServicesTable database with any required elements (e.g. PPIs, Hob etc.) prior to the services being invoked by code under test. It is strongly recommended to clean any global databases by using EFI_PEI_SERVICES.ResetSystem2 after every unit test so the tests execute in a predictable manner from a clean state. Cc: Michael D Kinney <michael.d.kinney@intel.com> Reviewed-by: Michael Kubacki <mikuback@linux.microsoft.com> Cc: Sean Brogan <sean.brogan@microsoft.com> Reviewed-by: Ray Ni <ray.ni@intel.com> Signed-off-by: Zhiguang Liu <zhiguang.liu@intel.com>
Diffstat (limited to 'UnitTestFrameworkPkg/Library/UnitTestPeiServicesTablePointerLib/UnitTestPeiServicesTablePointerLib.c')
-rw-r--r--UnitTestFrameworkPkg/Library/UnitTestPeiServicesTablePointerLib/UnitTestPeiServicesTablePointerLib.c187
1 files changed, 187 insertions, 0 deletions
diff --git a/UnitTestFrameworkPkg/Library/UnitTestPeiServicesTablePointerLib/UnitTestPeiServicesTablePointerLib.c b/UnitTestFrameworkPkg/Library/UnitTestPeiServicesTablePointerLib/UnitTestPeiServicesTablePointerLib.c
new file mode 100644
index 0000000000..a1b982fbae
--- /dev/null
+++ b/UnitTestFrameworkPkg/Library/UnitTestPeiServicesTablePointerLib/UnitTestPeiServicesTablePointerLib.c
@@ -0,0 +1,187 @@
+/** @file
+ This library supports a PEI Service table Pointer library implementation that
+ allows code dependent upon PEI Service to operate in an isolated execution environment
+ such as within the context of a host-based unit test framework.
+
+ Copyright (c) 2023, Intel Corporation. All rights reserved.<BR>
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+
+**/
+
+#include "UnitTestPeiServicesTablePointerLib.h"
+
+///
+/// Pei service instance
+///
+EFI_PEI_SERVICES mPeiServices = {
+ {
+ PEI_SERVICES_SIGNATURE,
+ PEI_SERVICES_REVISION,
+ sizeof (EFI_PEI_SERVICES),
+ 0,
+ 0
+ },
+ UnitTestInstallPpi, // InstallPpi
+ UnitTestReInstallPpi, // ReInstallPpi
+ UnitTestLocatePpi, // LocatePpi
+ UnitTestNotifyPpi, // NotifyPpi
+
+ UnitTestGetBootMode, // GetBootMode
+ UnitTestSetBootMode, // SetBootMode
+
+ UnitTestGetHobList, // GetHobList
+ UnitTestCreateHob, // CreateHob
+
+ UnitTestFfsFindNextVolume, // FfsFindNextVolume
+ UnitTestFfsFindNextFile, // FfsFindNextFile
+ UnitTestFfsFindSectionData, // FfsFindSectionData
+
+ UnitTestInstallPeiMemory, // InstallPeiMemory
+ UnitTestAllocatePages, // AllocatePages
+ UnitTestAllocatePool, // AllocatePool
+ (EFI_PEI_COPY_MEM)CopyMem,
+ (EFI_PEI_SET_MEM)SetMem,
+
+ UnitTestReportStatusCode, // ReportStatusCode
+ UnitTestResetSystem, // ResetSystem
+
+ NULL, // CpuIo
+ NULL, // PciCfg
+
+ UnitTestFfsFindFileByName, // FfsFindFileByName
+ UnitTestFfsGetFileInfo, // FfsGetFileInfo
+ UnitTestFfsGetVolumeInfo, // FfsGetVolumeInfo
+ UnitTestRegisterForShadow, // RegisterForShadow
+ UnitTestFfsFindSectionData3, // FfsFindSectionData3
+ UnitTestFfsGetFileInfo2, // FfsGetFileInfo2
+ UnitTestResetSystem2, // ResetSystem2
+ UnitTestFreePages, // FreePages
+};
+
+PEI_CORE_INSTANCE mPrivateData;
+UINT8 mHobBuffer[MAX_HOB_SIZE];
+VOID *mPeiServicesPointer;
+
+/**
+ Clear Buffer For Global Data.
+**/
+VOID
+ClearGlobalData (
+ VOID
+ )
+{
+ ZeroMem (&mPrivateData, sizeof (mPrivateData));
+ mPrivateData.PpiData.PpiList.MaxCount = MAX_PPI_COUNT;
+ mPrivateData.PpiData.CallbackNotifyList.MaxCount = MAX_PPI_COUNT;
+ mPrivateData.PpiData.DispatchNotifyList.MaxCount = MAX_PPI_COUNT;
+
+ ZeroMem (mHobBuffer, MAX_HOB_SIZE);
+ mPrivateData.HobList.Raw = mHobBuffer;
+ UnitTestCoreBuildHobHandoffInfoTable (0, (EFI_PHYSICAL_ADDRESS)(UINTN)mHobBuffer, MAX_HOB_SIZE);
+}
+
+/**
+ Resets the entire platform.
+
+ @param[in] ResetType The type of reset to perform.
+ @param[in] ResetStatus The status code for the reset.
+ @param[in] DataSize The size, in bytes, of ResetData.
+ @param[in] ResetData For a ResetType of EfiResetCold, EfiResetWarm, or EfiResetShutdown
+ the data buffer starts with a Null-terminated string, optionally
+ followed by additional binary data. The string is a description
+ that the caller may use to further indicate the reason for the
+ system reset.
+
+**/
+VOID
+EFIAPI
+UnitTestResetSystem2 (
+ IN EFI_RESET_TYPE ResetType,
+ IN EFI_STATUS ResetStatus,
+ IN UINTN DataSize,
+ IN VOID *ResetData OPTIONAL
+ )
+{
+ ClearGlobalData ();
+}
+
+/**
+ Retrieves the cached value of the PEI Services Table pointer.
+
+ Returns the cached value of the PEI Services Table pointer in a CPU specific manner
+ as specified in the CPU binding section of the Platform Initialization Pre-EFI
+ Initialization Core Interface Specification.
+
+ If the cached PEI Services Table pointer is NULL, then ASSERT().
+
+ @return The pointer to PeiServices.
+
+**/
+CONST EFI_PEI_SERVICES **
+EFIAPI
+GetPeiServicesTablePointer (
+ VOID
+ )
+{
+ mPeiServicesPointer = &mPeiServices;
+ return (CONST EFI_PEI_SERVICES **)&mPeiServicesPointer;
+}
+
+/**
+ Caches a pointer PEI Services Table.
+
+ Caches the pointer to the PEI Services Table specified by PeiServicesTablePointer
+ in a CPU specific manner as specified in the CPU binding section of the Platform Initialization
+ Pre-EFI Initialization Core Interface Specification.
+
+ If PeiServicesTablePointer is NULL, then ASSERT().
+
+ @param PeiServicesTablePointer The address of PeiServices pointer.
+**/
+VOID
+EFIAPI
+SetPeiServicesTablePointer (
+ IN CONST EFI_PEI_SERVICES **PeiServicesTablePointer
+ )
+{
+ ASSERT (FALSE);
+}
+
+/**
+ Perform CPU specific actions required to migrate the PEI Services Table
+ pointer from temporary RAM to permanent RAM.
+
+ For IA32 CPUs, the PEI Services Table pointer is stored in the 4 bytes
+ immediately preceding the Interrupt Descriptor Table (IDT) in memory.
+ For X64 CPUs, the PEI Services Table pointer is stored in the 8 bytes
+ immediately preceding the Interrupt Descriptor Table (IDT) in memory.
+ For Itanium and ARM CPUs, a the PEI Services Table Pointer is stored in
+ a dedicated CPU register. This means that there is no memory storage
+ associated with storing the PEI Services Table pointer, so no additional
+ migration actions are required for Itanium or ARM CPUs.
+
+**/
+VOID
+EFIAPI
+MigratePeiServicesTablePointer (
+ VOID
+ )
+{
+ ASSERT (FALSE);
+}
+
+/**
+ The constructor function init PeiServicesTable with clean buffer.
+
+ @retval EFI_SUCCESS The constructor always returns EFI_SUCCESS.
+
+**/
+EFI_STATUS
+EFIAPI
+UnitTestPeiServicesTablePointerLibConstructor (
+ VOID
+ )
+{
+ ClearGlobalData ();
+ return EFI_SUCCESS;
+}