Skip to content

Commit

Permalink
Add mock functions under MockUefiLib and Create Mock for CapsuleLib, …
Browse files Browse the repository at this point in the history
…PerformanceLib, MockUefiBootManagerLib and GenericMemoryTestProtocol (#1111)

## Description

Add mock functions under MockUefiLib and Create Mock for CapsuleLib,
PerformanceLib and GenericMemoryTestProtocol

- [ ] 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: Vivian Nowka-Keane <[email protected]>
Co-authored-by: Michael Kubacki <[email protected]>
Co-authored-by: Vivian Nowka-Keane <[email protected]>
  • Loading branch information
3 people authored Aug 28, 2024
1 parent a6e05a7 commit 750b5cd
Show file tree
Hide file tree
Showing 14 changed files with 690 additions and 0 deletions.
2 changes: 2 additions & 0 deletions MdeModulePkg/Test/MdeModulePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -111,4 +111,6 @@
# Build HOST_APPLICATION Libraries
#
MdeModulePkg/Test/Mock/Library/GoogleTest/MockPciHostBridgeLib/MockPciHostBridgeLib.inf
MdeModulePkg/Test/Mock/Library/GoogleTest/MockCapsuleLib/MockCapsuleLib.inf
MdeModulePkg/Test/Mock/Library/GoogleTest/MockUefiBootManagerLib/MockUefiBootManagerLib.inf
MdeModulePkg/Test/Mock/Library/GoogleTest/MockPlatformHookLib/MockPlatformHookLib.inf
71 changes: 71 additions & 0 deletions MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockCapsuleLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/** @file
Google Test mocks for CapsuleLib
Copyright (c) 2022, Intel Corporation. All rights reserved.
Copyright (C) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_CAPSULE_LIB_H_
#define MOCK_CAPSULE_LIB_H_

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

struct MockCapsuleLib {
MOCK_INTERFACE_DECLARATION (MockCapsuleLib);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
SupportCapsuleImage,
(IN EFI_CAPSULE_HEADER *CapsuleHeader)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
ProcessCapsuleImage,
(IN EFI_CAPSULE_HEADER *CapsuleHeader)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
StageCapsuleImage,
(IN EFI_CAPSULE_HEADER *CapsuleHeader)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
ProcessCapsules,
()
);

MOCK_FUNCTION_DECLARATION (
BOOLEAN,
CoDCheckCapsuleOnDiskFlag,
()
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
CoDClearCapsuleOnDiskFlag,
()
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
CoDRelocateCapsule,
(UINTN MaxRetry)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
CoDRemoveTempFile,
(UINTN MaxRetry)
);
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,234 @@
/** @file
Google Test mocks for UefiBootManagerLib
Copyright (c) 2024, Intel Corporation. All rights reserved.
Copyright (C) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_UEFI_BOOT_MANAGER_LIB_H_
#define MOCK_UEFI_BOOT_MANAGER_LIB_H_

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

struct MockUefiBootManagerLib {
MOCK_INTERFACE_DECLARATION (MockUefiBootManagerLib);

MOCK_FUNCTION_DECLARATION (
EFI_BOOT_MANAGER_LOAD_OPTION *,
EfiBootManagerGetLoadOptions,
(OUT UINTN *LoadOptionCount,
IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE LoadOptionType)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerFreeLoadOptions,
(IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOptions,
IN UINTN LoadOptionCount)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerInitializeLoadOption,
(IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *Option,
IN UINTN OptionNumber,
IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType,
IN UINT32 Attributes,
IN CHAR16 *Description,
IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
IN UINT8 *OptionalData,
IN UINT32 OptionalDataSize)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerFreeLoadOption,
(IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerVariableToLoadOption,
(IN CHAR16 *VariableName,
IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerAddLoadOptionVariable,
(IN OUT EFI_BOOT_MANAGER_LOAD_OPTION *Option,
IN UINTN Position)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerDeleteLoadOptionVariable,
(IN UINTN OptionNumber,
IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType)
);

MOCK_FUNCTION_DECLARATION (
VOID,
EfiBootManagerSortLoadOptionVariable,
(IN EFI_BOOT_MANAGER_LOAD_OPTION_TYPE OptionType,
IN SORT_COMPARE CompareFunction)
);

MOCK_FUNCTION_DECLARATION (
INTN,
EfiBootManagerFindLoadOption,
(IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Key,
IN CONST EFI_BOOT_MANAGER_LOAD_OPTION *Array,
IN UINTN Count)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerStartHotkeyService,
(IN EFI_EVENT *HotkeyTriggered)
);

MOCK_FUNCTION_DECLARATION (
VOID,
EfiBootManagerHotkeyBoot,
()
);

MOCK_FUNCTION_DECLARATION (
VOID,
EfiBootManagerRefreshAllBootOption,
()
);

MOCK_FUNCTION_DECLARATION (
VOID,
EfiBootManagerBoot,
(IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerGetBootManagerMenu,
(IN EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
);

MOCK_FUNCTION_DECLARATION (
EFI_DEVICE_PATH_PROTOCOL *,
EfiBootManagerGetNextLoadOptionDevicePath,
(IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
IN EFI_DEVICE_PATH_PROTOCOL *FullPath)
);

MOCK_FUNCTION_DECLARATION (
VOID *,
EfiBootManagerGetLoadOptionBuffer,
(IN EFI_DEVICE_PATH_PROTOCOL *FilePath,
OUT EFI_DEVICE_PATH_PROTOCOL **FullPath,
OUT UINTN *FileSize)
);

MOCK_FUNCTION_DECLARATION (
VOID,
EfiBootManagerRegisterLegacyBootSupport,
(EFI_BOOT_MANAGER_REFRESH_LEGACY_BOOT_OPTION RefreshLegacyBootOption,
EFI_BOOT_MANAGER_LEGACY_BOOT LegacyBoot)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerRegisterBootDescriptionHandler,
(IN EFI_BOOT_MANAGER_BOOT_DESCRIPTION_HANDLER Handler)
);

MOCK_FUNCTION_DECLARATION (
VOID,
EfiBootManagerConnectAll,
()
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerConnectDevicePath,
(EFI_DEVICE_PATH_PROTOCOL *DevicePathToConnect,
EFI_HANDLE *MatchingHandle)
);

MOCK_FUNCTION_DECLARATION (
VOID,
EfiBootManagerDisconnectAll,
()
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerConnectAllDefaultConsoles,
()
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerUpdateConsoleVariable,
(IN CONSOLE_TYPE ConsoleType,
IN EFI_DEVICE_PATH_PROTOCOL *CustomizedConDevicePath,
IN EFI_DEVICE_PATH_PROTOCOL *ExclusiveDevicePath)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerConnectConsoleVariable,
(IN CONSOLE_TYPE ConsoleType)
);

MOCK_FUNCTION_DECLARATION (
EFI_DEVICE_PATH_PROTOCOL *,
EfiBootManagerGetGopDevicePath,
(IN EFI_HANDLE VideoController)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerConnectVideoController,
(EFI_HANDLE VideoController OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO *,
EfiBootManagerGetDriverHealthInfo,
(UINTN *Count)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerFreeDriverHealthInfo,
(EFI_BOOT_MANAGER_DRIVER_HEALTH_INFO *DriverHealthInfo,
UINTN Count)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerProcessLoadOption,
(EFI_BOOT_MANAGER_LOAD_OPTION *LoadOption)
);

MOCK_FUNCTION_DECLARATION (
BOOLEAN,
EfiBootManagerIsValidLoadOptionVariableName,
(IN CHAR16 *VariableName,
OUT EFI_BOOT_MANAGER_LOAD_OPTION_TYPE *OptionType OPTIONAL,
OUT UINT16 *OptionNumber OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiBootManagerDispatchDeferredImages,
()
);
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/** @file
Google Test mocks for CapsuleLib
Copyright (c) 2023, Intel Corporation. All rights reserved.
Copyright (C) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <GoogleTest/Library/MockCapsuleLib.h>

MOCK_INTERFACE_DEFINITION (MockCapsuleLib);

MOCK_FUNCTION_DEFINITION (MockCapsuleLib, SupportCapsuleImage, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockCapsuleLib, ProcessCapsuleImage, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockCapsuleLib, StageCapsuleImage, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockCapsuleLib, ProcessCapsules, 0, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockCapsuleLib, CoDCheckCapsuleOnDiskFlag, 0, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockCapsuleLib, CoDClearCapsuleOnDiskFlag, 0, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockCapsuleLib, CoDRelocateCapsule, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockCapsuleLib, CoDRemoveTempFile, 1, EFIAPI);
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## @file
# Google Test mocks for CapsuleLib
#
# Copyright (c) 2023, Intel Corporation. All rights reserved.
# Copyright (C) Microsoft Corporation.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MockCapsuleLib
FILE_GUID = 850d769f-d56f-4553-af6f-5704e24a2ef3
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = CapsuleLib

#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
#

[Sources]
MockCapsuleLib.cpp

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

[LibraryClasses]
GoogleTestLib

[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /EHsc
Loading

0 comments on commit 750b5cd

Please sign in to comment.