diff options
author | Alexander Gryanko <xpahos@gmail.com> | 2025-06-22 15:35:31 +0300 |
---|---|---|
committer | mergify[bot] <37929162+mergify[bot]@users.noreply.github.com> | 2025-08-07 01:18:26 +0000 |
commit | d55642f53785f316c5aa790522b6d5133c5b78cc (patch) | |
tree | a15156453a49b067462d3adf6028e07c472e83d3 | |
parent | 1c3a22059b2da70832d4097141281d309a025c37 (diff) | |
download | edk2-d55642f53785f316c5aa790522b6d5133c5b78cc.zip edk2-d55642f53785f316c5aa790522b6d5133c5b78cc.tar.gz edk2-d55642f53785f316c5aa790522b6d5133c5b78cc.tar.bz2 |
MdePkg: added mocks for DevicePathLib and OpenProtocol
Added Google Mock test support for DevicePathLib.
Added OpenProtocol and CloseProtocol for UefiBootServicesTableLib
mock library.
Signed-off-by: Alexander Gryanko <xpahos@gmail.com>
6 files changed, 282 insertions, 3 deletions
diff --git a/MdePkg/Test/MdePkgHostTest.dsc b/MdePkg/Test/MdePkgHostTest.dsc index 6616463..e6e1829 100644 --- a/MdePkg/Test/MdePkgHostTest.dsc +++ b/MdePkg/Test/MdePkgHostTest.dsc @@ -53,5 +53,6 @@ MdePkg/Test/Mock/Library/GoogleTest/MockPciSegmentLib/MockPciSegmentLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockReportStatusCodeLib/MockReportStatusCodeLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockSafeIntLib/MockSafeIntLib.inf
+ MdePkg/Test/Mock/Library/GoogleTest/MockDevicePathLib/MockDevicePathLib.inf
MdePkg/Library/StackCheckLibNull/StackCheckLibNullHostApplication.inf
diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockDevicePathLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockDevicePathLib.h new file mode 100644 index 0000000..1a6a080 --- /dev/null +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockDevicePathLib.h @@ -0,0 +1,179 @@ +/** @file
+ Google Test mocks for DevicePathLib
+
+ Copyright (c) 2025, Yandex. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_DEVICE_PATH_LIB_LIB_H_
+#define MOCK_DEVICE_PATH_LIB_LIB_H_
+
+#include <Library/GoogleTestLib.h>
+#include <Library/FunctionMockLib.h>
+extern "C" {
+ #include <Uefi.h>
+ #include <Library/DevicePathLib.h>
+}
+
+struct MockDevicePathLib {
+ MOCK_INTERFACE_DECLARATION (MockDevicePathLib);
+
+ MOCK_FUNCTION_DECLARATION (
+ BOOLEAN,
+ IsDevicePathValid,
+ (IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN UINTN MaxSize)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8,
+ DevicePathType,
+ (IN CONST VOID *Node)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT8,
+ DevicePathSubType,
+ (IN CONST VOID *Node)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINTN,
+ DevicePathNodeLength,
+ (IN CONST VOID *Node)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_DEVICE_PATH_PROTOCOL *,
+ NextDevicePathNode,
+ (IN CONST VOID *Node)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ BOOLEAN,
+ IsDevicePathEndType,
+ (IN CONST VOID *Node)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ BOOLEAN,
+ IsDevicePathEnd,
+ (IN CONST VOID *Node)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ BOOLEAN,
+ IsDevicePathEndInstance,
+ (IN CONST VOID *Node)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINT16,
+ SetDevicePathNodeLength,
+ (IN OUT VOID *Node,
+ IN UINTN Length)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ VOID,
+ SetDevicePathEndNode,
+ (OUT VOID *Node)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ UINTN,
+ GetDevicePathSize,
+ (IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_DEVICE_PATH_PROTOCOL *,
+ DuplicateDevicePath,
+ (IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_DEVICE_PATH_PROTOCOL *,
+ AppendDevicePath,
+ (IN CONST EFI_DEVICE_PATH_PROTOCOL *FirstDevicePath OPTIONAL,
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *SecondDevicePath OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_DEVICE_PATH_PROTOCOL *,
+ AppendDevicePathNode,
+ (IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathNode OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_DEVICE_PATH_PROTOCOL *,
+ AppendDevicePathInstance,
+ (IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath OPTIONAL,
+ IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePathInstance OPTIONAL)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_DEVICE_PATH_PROTOCOL *,
+ GetNextDevicePathInstance,
+ (IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
+ OUT UINTN *Size)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_DEVICE_PATH_PROTOCOL *,
+ CreateDeviceNode,
+ (IN UINT8 NodeType,
+ IN UINT8 NodeSubType,
+ IN UINT16 NodeLength)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ BOOLEAN,
+ IsDevicePathMultiInstance,
+ (IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_DEVICE_PATH_PROTOCOL *,
+ DevicePathFromHandle,
+ (IN EFI_HANDLE Handle)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_DEVICE_PATH_PROTOCOL *,
+ FileDevicePath,
+ (IN EFI_HANDLE Device OPTIONAL,
+ IN CONST CHAR16 *FileName)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ CHAR16 *,
+ ConvertDevicePathToText,
+ (IN CONST EFI_DEVICE_PATH_PROTOCOL *DevicePath,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ CHAR16 *,
+ ConvertDeviceNodeToText,
+ (IN CONST EFI_DEVICE_PATH_PROTOCOL *DeviceNode,
+ IN BOOLEAN DisplayOnly,
+ IN BOOLEAN AllowShortcuts)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_DEVICE_PATH_PROTOCOL *,
+ ConvertTextToDeviceNode,
+ (IN CONST CHAR16 *TextDeviceNode)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_DEVICE_PATH_PROTOCOL *,
+ ConvertTextToDevicePath,
+ (IN CONST CHAR16 *TextDevicePath)
+ );
+};
+
+#endif // MOCK_DEVICE_PATH_LIB_H_
diff --git a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h index d72b941..7f60da3 100644 --- a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h +++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h @@ -73,6 +73,34 @@ struct MockUefiBootServicesTableLib { IN CONST EFI_GUID *EventGroup OPTIONAL,
OUT EFI_EVENT *Event)
);
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ gBS_LocateDevicePath,
+ (IN EFI_GUID *Protocol,
+ IN OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath,
+ OUT EFI_HANDLE *Device)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ gBS_OpenProtocol,
+ (IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ OUT VOID **Interface OPTIONAL,
+ IN EFI_HANDLE ImageHandle,
+ IN EFI_HANDLE ControllerHandle,
+ IN UINT32 Attributes)
+ );
+
+ MOCK_FUNCTION_DECLARATION (
+ EFI_STATUS,
+ gBS_CloseProtocol,
+ (IN EFI_HANDLE UserHandle,
+ IN EFI_GUID *Protocol,
+ IN EFI_HANDLE AgentHandle,
+ IN EFI_HANDLE ControllerHandle)
+ );
};
#endif // MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
diff --git a/MdePkg/Test/Mock/Library/GoogleTest/MockDevicePathLib/MockDevicePathLib.cpp b/MdePkg/Test/Mock/Library/GoogleTest/MockDevicePathLib/MockDevicePathLib.cpp new file mode 100644 index 0000000..8f07d30 --- /dev/null +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockDevicePathLib/MockDevicePathLib.cpp @@ -0,0 +1,35 @@ +/** @file
+ Google Test mocks for DevicePathLib
+
+ Copyright (c) 2025, Yandex. All rights reserved.
+ SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#include <GoogleTest/Library/MockDevicePathLib.h>
+
+MOCK_INTERFACE_DEFINITION (MockDevicePathLib);
+
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, IsDevicePathValid, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, DevicePathType, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, DevicePathSubType, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, DevicePathNodeLength, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, NextDevicePathNode, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, IsDevicePathEndType, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, IsDevicePathEnd, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, IsDevicePathEndInstance, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, SetDevicePathNodeLength, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, SetDevicePathEndNode, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, GetDevicePathSize, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, DuplicateDevicePath, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, AppendDevicePath, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, AppendDevicePathNode, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, AppendDevicePathInstance, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, GetNextDevicePathInstance, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, CreateDeviceNode, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, IsDevicePathMultiInstance, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, DevicePathFromHandle, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, FileDevicePath, 2, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, ConvertDevicePathToText, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, ConvertDeviceNodeToText, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, ConvertTextToDeviceNode, 1, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockDevicePathLib, ConvertTextToDevicePath, 1, EFIAPI);
diff --git a/MdePkg/Test/Mock/Library/GoogleTest/MockDevicePathLib/MockDevicePathLib.inf b/MdePkg/Test/Mock/Library/GoogleTest/MockDevicePathLib/MockDevicePathLib.inf new file mode 100644 index 0000000..542a252 --- /dev/null +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockDevicePathLib/MockDevicePathLib.inf @@ -0,0 +1,33 @@ +## @file
+# Google Test mocks for DevicePathLib
+#
+# Copyright (c) 2025, Yandex. All rights reserved.
+# SPDX-License-Identifier: BSD-2-Clause-Patent
+##
+
+[Defines]
+ INF_VERSION = 0x00010005
+ BASE_NAME = MockDevicePathLib
+ FILE_GUID = 56A63D54-644B-4769-88BC-AB2DCDADE351
+ MODULE_TYPE = HOST_APPLICATION
+ VERSION_STRING = 1.0
+ LIBRARY_CLASS = DevicePathLib
+
+#
+# The following information is for reference only and not required by the build tools.
+#
+# VALID_ARCHITECTURES = IA32 X64
+#
+
+[Sources]
+ MockDevicePathLib.cpp
+
+[Packages]
+ MdePkg/MdePkg.dec
+ UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[LibraryClasses]
+ GoogleTestLib
+
+[BuildOptions]
+ MSFT:*_*_*_CC_FLAGS = /EHsc
diff --git a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp index ced6255..64df07e 100644 --- a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp +++ b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp @@ -13,6 +13,9 @@ MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_CloseEvent, 1, EFIAP MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_HandleProtocol, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_LocateProtocol, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_CreateEventEx, 6, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_LocateDevicePath, 3, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_OpenProtocol, 6, EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_CloseProtocol, 4, EFIAPI);
static EFI_BOOT_SERVICES LocalBs = {
{ 0, 0, 0, 0, 0 }, // EFI_TABLE_HEADER
@@ -36,7 +39,7 @@ static EFI_BOOT_SERVICES LocalBs = { NULL, // VOID
NULL, // EFI_REGISTER_PROTOCOL_NOTIFY
NULL, // EFI_LOCATE_HANDLE
- NULL, // EFI_LOCATE_DEVICE_PATH
+ gBS_LocateDevicePath, // EFI_LOCATE_DEVICE_PATH
NULL, // EFI_INSTALL_CONFIGURATION_TABLE
NULL, // EFI_IMAGE_LOAD
NULL, // EFI_IMAGE_START
@@ -48,8 +51,8 @@ static EFI_BOOT_SERVICES LocalBs = { NULL, // EFI_SET_WATCHDOG_TIMER
NULL, // EFI_CONNECT_CONTROLLER
NULL, // EFI_DISCONNECT_CONTROLLER
- NULL, // EFI_OPEN_PROTOCOL
- NULL, // EFI_CLOSE_PROTOCOL
+ gBS_OpenProtocol, // EFI_OPEN_PROTOCOL
+ gBS_CloseProtocol, // EFI_CLOSE_PROTOCOL
NULL, // EFI_OPEN_PROTOCOL_INFORMATION
NULL, // EFI_PROTOCOLS_PER_HANDLE
NULL, // EFI_LOCATE_HANDLE_BUFFER
|