-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[CHERRY-PICK] MdePkg: Add more HobLib/PeiServicesLib gmock support
REF: https://bugzilla.tianocore.org/show_bug.cgi?id=4443 Add Google Mock Library for HobLib Add Google Mock Library for PeiServicesLib Cc: Michael D Kinney <[email protected]> Cc: Liming Gao <[email protected]> Cc: Zhiguang Liu <[email protected]> Cc: Chris Johnson <[email protected]> Signed-off-by: Gua Guo <[email protected]> Reviewed-by: Michael D Kinney <[email protected]> (cherry picked from commit ae2509385d54dc8468aef797c2a60cfbd965aebb)
- Loading branch information
1 parent
acccbda
commit 3b1475b
Showing
7 changed files
with
472 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
150 changes: 150 additions & 0 deletions
150
MdePkg/Test/Mock/Include/GoogleTest/Library/MockHobLib.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
/** @file | ||
Google Test mocks for HobLib | ||
Copyright (c) 2023, Intel Corporation. All rights reserved. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#ifndef MOCK_HOB_LIB_H_ | ||
#define MOCK_HOB_LIB_H_ | ||
|
||
#include <Library/GoogleTestLib.h> | ||
#include <Library/FunctionMockLib.h> | ||
extern "C" { | ||
#include <Pi/PiMultiPhase.h> | ||
#include <Uefi.h> | ||
#include <Library/HobLib.h> | ||
} | ||
|
||
struct MockHobLib { | ||
MOCK_INTERFACE_DECLARATION (MockHobLib); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
VOID *, | ||
GetHobList, | ||
() | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID *, | ||
GetNextHob, | ||
(IN UINT16 Type, | ||
IN CONST VOID *HobStart) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID *, | ||
GetFirstHob, | ||
(IN UINT16 Type) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID *, | ||
GetNextGuidHob, | ||
(IN CONST EFI_GUID *Guid, | ||
IN CONST VOID *HobStart) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID *, | ||
GetFirstGuidHob, | ||
(IN CONST EFI_GUID *Guid) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_BOOT_MODE, | ||
GetBootModeHob, | ||
() | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
BuildModuleHob, | ||
(IN CONST EFI_GUID *ModuleName, | ||
IN EFI_PHYSICAL_ADDRESS MemoryAllocationModule, | ||
IN UINT64 ModuleLength, | ||
IN EFI_PHYSICAL_ADDRESS EntryPoint) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
BuildResourceDescriptorWithOwnerHob, | ||
(IN EFI_RESOURCE_TYPE ResourceType, | ||
IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute, | ||
IN EFI_PHYSICAL_ADDRESS PhysicalStart, | ||
IN UINT64 NumberOfBytes, | ||
IN EFI_GUID *OwnerGUID) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
BuildResourceDescriptorHob, | ||
(IN EFI_RESOURCE_TYPE ResourceType, | ||
IN EFI_RESOURCE_ATTRIBUTE_TYPE ResourceAttribute, | ||
IN EFI_PHYSICAL_ADDRESS PhysicalStart, | ||
IN UINT64 NumberOfBytes) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID *, | ||
BuildGuidHob, | ||
(IN CONST EFI_GUID *Guid, | ||
IN UINTN DataLength) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID *, | ||
BuildGuidDataHob, | ||
(IN CONST EFI_GUID *Guid, | ||
IN VOID *Data, | ||
IN UINTN DataLength) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
BuildFvHob, | ||
(IN EFI_PHYSICAL_ADDRESS BaseAddress, | ||
IN UINT64 Length) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
BuildFv2Hob, | ||
(IN EFI_PHYSICAL_ADDRESS BaseAddress, | ||
IN UINT64 Length, | ||
IN CONST EFI_GUID *FvName, | ||
IN CONST EFI_GUID *FileName) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
BuildFv3Hob, | ||
(IN EFI_PHYSICAL_ADDRESS BaseAddress, | ||
IN UINT64 Length, | ||
IN UINT32 AuthenticationStatus, | ||
IN BOOLEAN ExtractedFv, | ||
IN CONST EFI_GUID *FvName OPTIONAL, | ||
IN CONST EFI_GUID *FileName OPTIONAL) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
BuildCvHob, | ||
(IN EFI_PHYSICAL_ADDRESS BaseAddress, | ||
IN UINT64 Length) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
BuildCpuHob, | ||
(IN UINT8 SizeOfMemorySpace, | ||
IN UINT8 SizeOfIoSpace) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
BuildStackHob, | ||
(IN EFI_PHYSICAL_ADDRESS BaseAddress, | ||
IN UINT64 Length) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
BuildBspStoreHob, | ||
(IN EFI_PHYSICAL_ADDRESS BaseAddress, | ||
IN UINT64 Length, | ||
IN EFI_MEMORY_TYPE MemoryType) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
BuildMemoryAllocationHob, | ||
(IN EFI_PHYSICAL_ADDRESS BaseAddress, | ||
IN UINT64 Length, | ||
IN EFI_MEMORY_TYPE MemoryType) | ||
); | ||
}; | ||
|
||
#endif |
189 changes: 189 additions & 0 deletions
189
MdePkg/Test/Mock/Include/GoogleTest/Library/MockPeiServicesLib.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,189 @@ | ||
/** @file | ||
Google Test mocks for PeiServicesLib | ||
Copyright (c) 2023, Intel Corporation. All rights reserved. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#ifndef MOCK_PEI_SERVICES_LIB_H_ | ||
#define MOCK_PEI_SERVICES_LIB_H_ | ||
|
||
#include <Library/GoogleTestLib.h> | ||
#include <Library/FunctionMockLib.h> | ||
extern "C" { | ||
#include <PiPei.h> | ||
#include <Uefi.h> | ||
#include <Library/PeiServicesLib.h> | ||
} | ||
|
||
struct MockPeiServicesLib { | ||
MOCK_INTERFACE_DECLARATION (MockPeiServicesLib); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesInstallPpi, | ||
(IN CONST EFI_PEI_PPI_DESCRIPTOR *PpiList) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesReInstallPpi, | ||
(IN CONST EFI_PEI_PPI_DESCRIPTOR *OldPpi, | ||
IN CONST EFI_PEI_PPI_DESCRIPTOR *NewPpi) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesLocatePpi, | ||
(IN CONST EFI_GUID *Guid, | ||
IN UINTN Instance, | ||
IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor OPTIONAL, | ||
IN OUT VOID **Ppi) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesNotifyPpi, | ||
(IN CONST EFI_PEI_NOTIFY_DESCRIPTOR *NotifyList) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesGetBootMode, | ||
(OUT EFI_BOOT_MODE *BootMode) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesSetBootMode, | ||
(IN EFI_BOOT_MODE BootMode) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesGetHobList, | ||
(OUT VOID **HobList) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesCreateHob, | ||
(IN UINT16 Type, | ||
IN UINT16 Length, | ||
OUT VOID **Hob) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesFfsFindNextVolume, | ||
(IN UINTN Instance, | ||
IN OUT EFI_PEI_FV_HANDLE *VolumeHandle) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesFfsFindNextFile, | ||
(IN EFI_FV_FILETYPE SearchType, | ||
IN EFI_PEI_FV_HANDLE VolumeHandle, | ||
IN OUT EFI_PEI_FILE_HANDLE *FileHandle) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesFfsFindSectionData, | ||
(IN EFI_SECTION_TYPE SectionType, | ||
IN EFI_PEI_FILE_HANDLE FileHandle, | ||
OUT VOID **SectionData) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesFfsFindSectionData3, | ||
(IN EFI_SECTION_TYPE SectionType, | ||
IN UINTN SectionInstance, | ||
IN EFI_PEI_FILE_HANDLE FileHandle, | ||
OUT VOID **SectionData, | ||
OUT UINT32 *AuthenticationStatus) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesInstallPeiMemory, | ||
(IN EFI_PHYSICAL_ADDRESS MemoryBegin, | ||
IN UINT64 MemoryLength) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesAllocatePages, | ||
(IN EFI_MEMORY_TYPE MemoryType, | ||
IN UINTN Pages, | ||
OUT EFI_PHYSICAL_ADDRESS *Memory) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesFreePages, | ||
(IN EFI_PHYSICAL_ADDRESS Memory, | ||
IN UINTN Pages) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesAllocatePool, | ||
(IN UINTN Size, | ||
OUT VOID **Buffer) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesResetSystem, | ||
() | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesFfsFindFileByName, | ||
(IN CONST EFI_GUID *FileName, | ||
IN CONST EFI_PEI_FV_HANDLE VolumeHandle, | ||
OUT EFI_PEI_FILE_HANDLE *FileHandle) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesFfsGetFileInfo, | ||
(IN CONST EFI_PEI_FILE_HANDLE FileHandle, | ||
OUT EFI_FV_FILE_INFO *FileInfo) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesFfsGetFileInfo2, | ||
(IN CONST EFI_PEI_FILE_HANDLE FileHandle, | ||
OUT EFI_FV_FILE_INFO2 *FileInfo) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesFfsGetVolumeInfo, | ||
(IN EFI_PEI_FV_HANDLE VolumeHandle, | ||
OUT EFI_FV_INFO *VolumeInfo) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PeiServicesRegisterForShadow, | ||
(IN EFI_PEI_FILE_HANDLE FileHandle) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
PeiServicesInstallFvInfoPpi, | ||
(IN CONST EFI_GUID *FvFormat OPTIONAL, | ||
IN CONST VOID *FvInfo, | ||
IN UINT32 FvInfoSize, | ||
IN CONST EFI_GUID *ParentFvName OPTIONAL, | ||
IN CONST EFI_GUID *ParentFileName OPTIONAL) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
PeiServicesInstallFvInfo2Ppi, | ||
(IN CONST EFI_GUID *FvFormat OPTIONAL, | ||
IN CONST VOID *FvInfo, | ||
IN UINT32 FvInfoSize, | ||
IN CONST EFI_GUID *ParentFvName OPTIONAL, | ||
IN CONST EFI_GUID *ParentFileName OPTIONAL, | ||
IN UINT32 AuthenticationStatus) | ||
); | ||
MOCK_FUNCTION_DECLARATION ( | ||
VOID, | ||
PeiServicesResetSystem2, | ||
(IN EFI_RESET_TYPE ResetType, | ||
IN EFI_STATUS ResetStatus, | ||
IN UINTN DataSize, | ||
IN VOID *ResetData OPTIONAL) | ||
); | ||
}; | ||
|
||
#endif |
30 changes: 30 additions & 0 deletions
30
MdePkg/Test/Mock/Library/GoogleTest/MockHobLib/MockHobLib.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/** @file | ||
Google Test mocks for HobLib | ||
Copyright (c) 2023, Intel Corporation. All rights reserved. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <GoogleTest/Library/MockHobLib.h> | ||
|
||
MOCK_INTERFACE_DEFINITION(MockHobLib); | ||
|
||
MOCK_FUNCTION_DEFINITION(MockHobLib, GetHobList, 0, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, GetNextHob, 2, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, GetFirstHob, 1, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, GetNextGuidHob, 2, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, GetFirstGuidHob, 1, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, GetBootModeHob, 0, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildModuleHob, 4, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildResourceDescriptorWithOwnerHob, 5, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildResourceDescriptorHob, 4, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildGuidHob, 2, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildGuidDataHob, 3, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildFvHob, 2, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildFv2Hob, 4, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildFv3Hob, 6, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildCvHob, 2, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildCpuHob, 2, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildStackHob, 2, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildBspStoreHob, 3, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION(MockHobLib, BuildMemoryAllocationHob, 3, EFIAPI); |
Oops, something went wrong.