Skip to content

Commit

Permalink
[Cherry-Pick] MdePkg: Add rest mock functions for Mock UefiRuntimeSer…
Browse files Browse the repository at this point in the history
…vicesTableLib (#1256)

## Description
Add rest mock functions for Mock UefiRuntimeServicesTableLib for google
test.

- [ ] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [X] Includes tests?
- [ ] Includes documentation?
- [X] Backport to release branch?

## How This Was Tested
Tested in module integrated with this MockUefiRuntimeServicesTableLib
and the result is passed.

## Integration Instructions
Include the MockUefiRuntimeServicesTableLib.inf in the LibraryClasses
section of a dsc file.

---------

Signed-off-by: v-frankchou <v-frankchou@microsoft.com>
  • Loading branch information
v-frankchou authored and ProjectMuBot committed Jan 23, 2025
1 parent aeb3281 commit 99af5d5
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,50 @@ extern "C" {
struct MockUefiRuntimeServicesTableLib {
MOCK_INTERFACE_DECLARATION (MockUefiRuntimeServicesTableLib);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_GetTime,
(OUT EFI_TIME *Time,
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_SetTime,
(IN EFI_TIME *Time)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_GetWakeupTime,
(OUT BOOLEAN *Enabled,
OUT BOOLEAN *Pending,
OUT EFI_TIME *Time)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_SetWakeupTime,
(IN BOOLEAN Enable,
IN EFI_TIME *Time OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_SetVirtualAddressMap,
(IN UINTN MemoryMapSize,
IN UINTN DescriptorSize,
IN UINT32 DescriptorVersion,
IN EFI_MEMORY_DESCRIPTOR *VirtualMap)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_ConvertPointer,
(IN UINTN DebugDisposition,
IN OUT VOID **Address)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_GetVariable,
Expand All @@ -28,6 +72,14 @@ struct MockUefiRuntimeServicesTableLib {
OUT VOID *Data)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_GetNextVariableName,
(IN OUT UINTN *VariableNameSize,
IN OUT CHAR16 *VariableName,
IN OUT EFI_GUID *VendorGuid)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_SetVariable,
Expand All @@ -40,9 +92,8 @@ struct MockUefiRuntimeServicesTableLib {

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_GetTime,
(OUT EFI_TIME *Time,
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL)
gRT_GetNextHighMonotonicCount,
(OUT UINT32 *HighCount)
);

MOCK_FUNCTION_DECLARATION (
Expand All @@ -53,6 +104,32 @@ struct MockUefiRuntimeServicesTableLib {
IN UINTN DataSize,
IN VOID *ResetData OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_UpdateCapsule,
(IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
IN UINTN CapsuleCount,
IN EFI_PHYSICAL_ADDRESS ScatterGatherList OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_QueryCapsuleCapabilities,
(IN EFI_CAPSULE_HEADER **CapsuleHeaderArray,
IN UINTN CapsuleCount,
OUT UINT64 *MaximumCapsuleSize,
OUT EFI_RESET_TYPE *ResetType)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gRT_QueryVariableInfo,
(IN UINT32 Attributes,
OUT UINT64 *MaximumVariableStorageSize,
OUT UINT64 *RemainingVariableStorageSize,
OUT UINT64 *MaximumVariableSize)
);
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -8,33 +8,48 @@

MOCK_INTERFACE_DEFINITION (MockUefiRuntimeServicesTableLib);

MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_GetTime, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_SetTime, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_GetWakeupTime, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_SetWakeupTime, 2, EFIAPI);

MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_SetVirtualAddressMap, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_ConvertPointer, 2, EFIAPI);

MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_GetVariable, 5, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_GetNextVariableName, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_SetVariable, 5, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_GetTime, 2, EFIAPI);

MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_GetNextHighMonotonicCount, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_ResetSystem, 4, EFIAPI);

MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_UpdateCapsule, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_QueryCapsuleCapabilities, 4, EFIAPI);

MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_QueryVariableInfo, 4, EFIAPI);

static EFI_RUNTIME_SERVICES localRt = {
{ 0 }, // EFI_TABLE_HEADER
{ 0 }, // EFI_TABLE_HEADER

gRT_GetTime, // EFI_GET_TIME
NULL, // EFI_SET_TIME
NULL, // EFI_GET_WAKEUP_TIME
NULL, // EFI_SET_WAKEUP_TIME
gRT_GetTime, // EFI_GET_TIME
gRT_SetTime, // EFI_SET_TIME
gRT_GetWakeupTime, // EFI_GET_WAKEUP_TIME
gRT_SetWakeupTime, // EFI_SET_WAKEUP_TIME

NULL, // EFI_SET_VIRTUAL_ADDRESS_MAP
NULL, // EFI_CONVERT_POINTER
gRT_SetVirtualAddressMap, // EFI_SET_VIRTUAL_ADDRESS_MAP
gRT_ConvertPointer, // EFI_CONVERT_POINTER

gRT_GetVariable, // EFI_GET_VARIABLE
NULL, // EFI_GET_NEXT_VARIABLE_NAME
gRT_SetVariable, // EFI_SET_VARIABLE
gRT_GetVariable, // EFI_GET_VARIABLE
gRT_GetNextVariableName, // EFI_GET_NEXT_VARIABLE_NAME
gRT_SetVariable, // EFI_SET_VARIABLE

NULL, // EFI_GET_NEXT_HIGH_MONO_COUNT
gRT_ResetSystem, // EFI_RESET_SYSTEM
gRT_GetNextHighMonotonicCount, // EFI_GET_NEXT_HIGH_MONO_COUNT
gRT_ResetSystem, // EFI_RESET_SYSTEM

NULL, // EFI_UPDATE_CAPSULE
NULL, // EFI_QUERY_CAPSULE_CAPABILITIES
gRT_UpdateCapsule, // EFI_UPDATE_CAPSULE
gRT_QueryCapsuleCapabilities, // EFI_QUERY_CAPSULE_CAPABILITIES

NULL, // EFI_QUERY_VARIABLE_INFO
gRT_QueryVariableInfo, // EFI_QUERY_VARIABLE_INFO
};

extern "C" {
Expand Down

0 comments on commit 99af5d5

Please sign in to comment.