-
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.
Add mock functions under MockUefiLib and Create Mock for CapsuleLib, …
…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
1 parent
a6e05a7
commit 750b5cd
Showing
14 changed files
with
690 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
71 changes: 71 additions & 0 deletions
71
MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockCapsuleLib.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,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 |
234 changes: 234 additions & 0 deletions
234
MdeModulePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootManagerLib.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,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 |
20 changes: 20 additions & 0 deletions
20
MdeModulePkg/Test/Mock/Library/GoogleTest/MockCapsuleLib/MockCapsuleLib.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,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); |
35 changes: 35 additions & 0 deletions
35
MdeModulePkg/Test/Mock/Library/GoogleTest/MockCapsuleLib/MockCapsuleLib.inf
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,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 |
Oops, something went wrong.