Skip to content

Commit

Permalink
Add mock functions under MockUefiRuntimeServicesTableLib, MockUefiRun…
Browse files Browse the repository at this point in the history
…timeServicesTableLib and Create Mock for DxeServicesTableLib (#1109)

## Description

Add mock functions under MockUefiRuntimeServicesTableLib,
MockUefiRuntimeServicesTableLib and Create Mock for DxeServicesTableLib

For details on how to complete to complete these options and their
meaning refer to
[CONTRIBUTING.md](https://github.com/microsoft/mu/blob/HEAD/CONTRIBUTING.md).

- [ ] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [ ] Includes tests?
- [ ] Includes documentation?

## How This Was Tested

Unit tests component can call these mock functions success

## Integration Instructions

N/A

---------

Signed-off-by: YiTa-AMI <[email protected]>
  • Loading branch information
YiTa-AMI authored Sep 9, 2024
1 parent 104c355 commit 5aa1be5
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 3 deletions.
2 changes: 2 additions & 0 deletions MdePkg/Test/MdePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -57,5 +57,7 @@
MdePkg/Test/Mock/Library/GoogleTest/MockMemoryAllocationLib/MockMemoryAllocationLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockPciExpressLib/MockPciExpressLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockUefiDevicePathLib/MockUefiDevicePathLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockDxeServicesTableLib/MockDxeServicesTableLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockPerformanceLib/MockPerformanceLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockPciLib/MockPciLib.inf

Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** @file MockDxeServicesTableLib.h
Google Test mocks for DxeServicesTableLib
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_DXE_SERVICES_TABLE_LIB_H_
#define MOCK_DXE_SERVICES_TABLE_LIB_H_

#include <Library/GoogleTestLib.h>
#include <Library/FunctionMockLib.h>
extern "C" {
#include <Uefi.h>
#include <Pi/PiDxeCis.h>
}

//
// Declarations to handle usage of the DxeServicesTableLib by creating mock
//
struct MockDxeServicesTableLib {
MOCK_INTERFACE_DECLARATION (MockDxeServicesTableLib);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gDS_Dispatch,
()
);
};

#endif // MOCK_UEFI_DXE_SERVICES_TABLE_LIB_H_
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,23 @@ struct MockUefiBootServicesTableLib {
IN OUT UINTN *BufferSize,
OUT EFI_HANDLE *Buffer)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gBS_ConnectController,
(IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE *DriverImageHandle OPTIONAL,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,
IN BOOLEAN Recursive)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gBS_DisconnectController,
(IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE DriverImageHandle OPTIONAL,
IN EFI_HANDLE ChildHandle OPTIONAL)
);
};

#endif // MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,15 @@ struct MockUefiRuntimeServicesTableLib {
(OUT EFI_TIME *Time,
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
VOID,
gRT_ResetSystem,
(IN EFI_RESET_TYPE ResetType,
IN EFI_STATUS ResetStatus,
IN UINTN DataSize,
IN VOID *ResetData OPTIONAL)
);
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/** @file MockDxeServicesTableLib.cpp
Google Test mocks for DxeServicesTableLib
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <GoogleTest/Library/MockDxeServicesTableLib.h>

MOCK_INTERFACE_DEFINITION (MockDxeServicesTableLib);
MOCK_FUNCTION_DEFINITION (MockDxeServicesTableLib, gDS_Dispatch, 0, EFIAPI);

static EFI_DXE_SERVICES LocalDs = {
{ 0, 0, 0, 0, 0 }, // EFI_TABLE_HEADER
NULL, // EFI_ADD_MEMORY_SPACE
NULL, // EFI_ALLOCATE_MEMORY_SPACE
NULL, // EFI_FREE_MEMORY_SPACE
NULL, // EFI_REMOVE_MEMORY_SPACE
NULL, // EFI_GET_MEMORY_SPACE_DESCRIPTOR
NULL, // EFI_SET_MEMORY_SPACE_ATTRIBUTES
NULL, // EFI_GET_MEMORY_SPACE_MAP
NULL, // EFI_ADD_IO_SPACE
NULL, // EFI_ALLOCATE_IO_SPACE
NULL, // EFI_FREE_IO_SPACE
NULL, // EFI_REMOVE_IO_SPACE
NULL, // EFI_GET_IO_SPACE_DESCRIPTOR
NULL, // EFI_GET_IO_SPACE_MAP
gDS_Dispatch, // EFI_DISPATCH
NULL, // EFI_SCHEDULE
NULL, // EFI_TRUST
NULL, // EFI_PROCESS_FIRMWARE_VOLUME
NULL // EFI_SET_MEMORY_SPACE_CAPABILITIES
};

extern "C" {
EFI_DXE_SERVICES *gDS = &LocalDs;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
## @file MockDxeServicesTableLib.inf
# Mock implementation of the DXE Services Table Library.
#
# Copyright (c) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
#
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MockDxeServicesTableLib
FILE_GUID = 8d9ce22b-2cf3-4646-ad0b-ce3cf1aea84d
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = DxeServicesTableLib

#
# VALID_ARCHITECTURES = IA32 X64 EBC
#

[Sources]
MockDxeServicesTableLib.cpp

[LibraryClasses]
GoogleTestLib

[Packages]
MdePkg/MdePkg.dec
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec

[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /EHsc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_LocateDevicePath, 3,
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_ReinstallProtocolInterface, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_AllocatePool, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_LocateHandle, 5, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_ConnectController, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_DisconnectController, 3, EFIAPI);

extern "C" {
EFI_STATUS
Expand Down Expand Up @@ -130,8 +132,8 @@ static EFI_BOOT_SERVICES LocalBs = {
NULL, // EFI_GET_NEXT_MONOTONIC_COUNT
NULL, // EFI_STALL
NULL, // EFI_SET_WATCHDOG_TIMER
NULL, // EFI_CONNECT_CONTROLLER
NULL, // EFI_DISCONNECT_CONTROLLER
gBS_ConnectController, // EFI_CONNECT_CONTROLLER
gBS_DisconnectController, // EFI_DISCONNECT_CONTROLLER
gBS_OpenProtocol, // EFI_OPEN_PROTOCOL
gBS_CloseProtocol, // EFI_CLOSE_PROTOCOL
NULL, // EFI_OPEN_PROTOCOL_INFORMATION
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ MOCK_INTERFACE_DEFINITION (MockUefiRuntimeServicesTableLib);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_GetVariable, 5, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_SetVariable, 5, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_GetTime, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiRuntimeServicesTableLib, gRT_ResetSystem, 4, EFIAPI);

static EFI_RUNTIME_SERVICES localRt = {
{ 0 }, // EFI_TABLE_HEADER
Expand All @@ -27,7 +28,7 @@ static EFI_RUNTIME_SERVICES localRt = {
gRT_SetVariable, // EFI_SET_VARIABLE

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

NULL, // EFI_UPDATE_CAPSULE
NULL, // EFI_QUERY_CAPSULE_CAPABILITIES
Expand Down

0 comments on commit 5aa1be5

Please sign in to comment.