From: Doug Flick <dougfl...@microsoft.com>

This commit adds a mock library for UefiBootServicesTableLib.

Cc: Michael D Kinney <michael.d.kin...@intel.com>
Cc: Liming Gao <gaolim...@byosoft.com.cn>
Cc: Zhiguang Liu <zhiguang....@intel.com>

Signed-off-by: Doug Flick [MSFT] <doug.e...@gmail.com>
---
 MdePkg/Test/MdePkgHostTest.dsc                                                 
                   |  1 +
 
MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
 | 32 ++++++++
 MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h     
                   | 78 ++++++++++++++++++++
 
MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp
 | 69 +++++++++++++++++
 4 files changed, 180 insertions(+)

diff --git a/MdePkg/Test/MdePkgHostTest.dsc b/MdePkg/Test/MdePkgHostTest.dsc
index e666636b7c55..6a85d02236a0 100644
--- a/MdePkg/Test/MdePkgHostTest.dsc
+++ b/MdePkg/Test/MdePkgHostTest.dsc
@@ -43,6 +43,7 @@ [Components]
   MdePkg/Library/BaseLib/UnitTestHostBaseLib.inf
   MdePkg/Test/Mock/Library/GoogleTest/MockUefiLib/MockUefiLib.inf
   
MdePkg/Test/Mock/Library/GoogleTest/MockUefiRuntimeServicesTableLib/MockUefiRuntimeServicesTableLib.inf
+  
MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
   MdePkg/Test/Mock/Library/GoogleTest/MockPeiServicesLib/MockPeiServicesLib.inf
   MdePkg/Test/Mock/Library/GoogleTest/MockHobLib/MockHobLib.inf
   MdePkg/Test/Mock/Library/GoogleTest/MockFdtLib/MockFdtLib.inf
diff --git 
a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
 
b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
new file mode 100644
index 000000000000..8b64fd195acd
--- /dev/null
+++ 
b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.inf
@@ -0,0 +1,32 @@
+## @file
+#  Mock implementation of the UEFI Boot Services Table Library.
+#
+#  Copyright (c) Microsoft Corporation.
+#  SPDX-License-Identifier: BSD-2-Clause-Patent
+#
+##
+
+[Defines]
+  INF_VERSION                    = 0x00010005
+  BASE_NAME                      = MockUefiBootServicesTableLib
+  FILE_GUID                      = 67EA4614-E276-49EC-9AE6-B97ACCEA676E
+  MODULE_TYPE                    = HOST_APPLICATION
+  VERSION_STRING                 = 1.0
+  LIBRARY_CLASS                  = UefiBootServicesTableLib|HOST_APPLICATION
+
+#
+#  VALID_ARCHITECTURES           = IA32 X64 EBC
+#
+
+[Sources]
+  MockUefiBootServicesTableLib.cpp
+
+[LibraryClasses]
+  GoogleTestLib
+
+[Packages]
+  MdePkg/MdePkg.dec
+  UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec
+
+[BuildOptions]
+  MSFT:*_*_*_CC_FLAGS = /EHsc
diff --git 
a/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h 
b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h
new file mode 100644
index 000000000000..d72b941323c1
--- /dev/null
+++ b/MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiBootServicesTableLib.h
@@ -0,0 +1,78 @@
+/** @file
+  Google Test mocks for UefiBootServicesTableLib
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+
+#ifndef MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
+#define MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
+
+#include <Library/GoogleTestLib.h>
+#include <Library/FunctionMockLib.h>
+extern "C" {
+  #include <Uefi.h>
+  #include <Library/UefiBootServicesTableLib.h>
+}
+
+//
+// Declarations to handle usage of the UefiBootServiceTableLib by creating mock
+//
+struct MockUefiBootServicesTableLib {
+  MOCK_INTERFACE_DECLARATION (MockUefiBootServicesTableLib);
+
+  MOCK_FUNCTION_DECLARATION (
+    EFI_STATUS,
+    gBS_GetMemoryMap,
+    (IN OUT UINTN                 *MemoryMapSize,
+     OUT    EFI_MEMORY_DESCRIPTOR *MemoryMap,
+     OUT    UINTN                 *MapKey,
+     OUT    UINTN                 *DescriptorSize,
+     OUT    UINT32                *DescriptorVersion)
+    );
+
+  MOCK_FUNCTION_DECLARATION (
+    EFI_STATUS,
+    gBS_CreateEvent,
+    (IN  UINT32           Type,
+     IN  EFI_TPL          NotifyTpl,
+     IN  EFI_EVENT_NOTIFY NotifyFunction,
+     IN  VOID             *NotifyContext,
+     OUT EFI_EVENT        *Event)
+    );
+
+  MOCK_FUNCTION_DECLARATION (
+    EFI_STATUS,
+    gBS_CloseEvent,
+    (IN EFI_EVENT Event)
+    );
+
+  MOCK_FUNCTION_DECLARATION (
+    EFI_STATUS,
+    gBS_HandleProtocol,
+    (IN  EFI_HANDLE Handle,
+     IN  EFI_GUID   *Protocol,
+     OUT VOID       **Interface)
+    );
+
+  MOCK_FUNCTION_DECLARATION (
+    EFI_STATUS,
+    gBS_LocateProtocol,
+    (IN  EFI_GUID *Protocol,
+     IN  VOID      *Registration  OPTIONAL,
+     OUT VOID      **Interface)
+    );
+
+  MOCK_FUNCTION_DECLARATION (
+    EFI_STATUS,
+    gBS_CreateEventEx,
+    (IN UINT32            Type,
+     IN EFI_TPL           NotifyTpl,
+     IN EFI_EVENT_NOTIFY  NotifyFunction OPTIONAL,
+     IN CONST VOID        *NotifyContext OPTIONAL,
+     IN CONST EFI_GUID    *EventGroup OPTIONAL,
+     OUT EFI_EVENT        *Event)
+    );
+};
+
+#endif // MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
diff --git 
a/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp
 
b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp
new file mode 100644
index 000000000000..ced6255418a2
--- /dev/null
+++ 
b/MdePkg/Test/Mock/Library/GoogleTest/MockUefiBootServicesTableLib/MockUefiBootServicesTableLib.cpp
@@ -0,0 +1,69 @@
+/** @file
+  Google Test mocks for UefiBootServicesTableLib
+
+  Copyright (c) Microsoft Corporation.
+  SPDX-License-Identifier: BSD-2-Clause-Patent
+**/
+#include <GoogleTest/Library/MockUefiBootServicesTableLib.h>
+
+MOCK_INTERFACE_DEFINITION (MockUefiBootServicesTableLib);
+MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_GetMemoryMap, 5, 
EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_CreateEvent, 5, 
EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_CloseEvent, 1, 
EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_HandleProtocol, 3, 
EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_LocateProtocol, 3, 
EFIAPI);
+MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_CreateEventEx, 6, 
EFIAPI);
+
+static EFI_BOOT_SERVICES  LocalBs = {
+  { 0, 0, 0, 0, 0 },    // EFI_TABLE_HEADER
+  NULL,                 // EFI_RAISE_TPL
+  NULL,                 // EFI_RESTORE_TPL
+  NULL,                 // EFI_ALLOCATE_PAGES
+  NULL,                 // EFI_FREE_PAGES
+  gBS_GetMemoryMap,     // EFI_GET_MEMORY_MAP
+  NULL,                 // EFI_ALLOCATE_POOL
+  NULL,                 // EFI_FREE_POOL
+  gBS_CreateEvent,      // EFI_CREATE_EVENT
+  NULL,                 // EFI_SET_TIMER
+  NULL,                 // EFI_WAIT_FOR_EVENT
+  NULL,                 // EFI_SIGNAL_EVENT
+  gBS_CloseEvent,       // EFI_CLOSE_EVENT
+  NULL,                 // EFI_CHECK_EVENT
+  NULL,                 // EFI_INSTALL_PROTOCOL_INTERFACE
+  NULL,                 // EFI_REINSTALL_PROTOCOL_INTERFACE
+  NULL,                 // EFI_UNINSTALL_PROTOCOL_INTERFACE
+  gBS_HandleProtocol,   // EFI_HANDLE_PROTOCOL
+  NULL,                 // VOID
+  NULL,                 // EFI_REGISTER_PROTOCOL_NOTIFY
+  NULL,                 // EFI_LOCATE_HANDLE
+  NULL,                 // EFI_LOCATE_DEVICE_PATH
+  NULL,                 // EFI_INSTALL_CONFIGURATION_TABLE
+  NULL,                 // EFI_IMAGE_LOAD
+  NULL,                 // EFI_IMAGE_START
+  NULL,                 // EFI_EXIT
+  NULL,                 // EFI_IMAGE_UNLOAD
+  NULL,                 // EFI_EXIT_BOOT_SERVICES
+  NULL,                 // EFI_GET_NEXT_MONOTONIC_COUNT
+  NULL,                 // EFI_STALL
+  NULL,                 // EFI_SET_WATCHDOG_TIMER
+  NULL,                 // EFI_CONNECT_CONTROLLER
+  NULL,                 // EFI_DISCONNECT_CONTROLLER
+  NULL,                 // EFI_OPEN_PROTOCOL
+  NULL,                 // EFI_CLOSE_PROTOCOL
+  NULL,                 // EFI_OPEN_PROTOCOL_INFORMATION
+  NULL,                 // EFI_PROTOCOLS_PER_HANDLE
+  NULL,                 // EFI_LOCATE_HANDLE_BUFFER
+  gBS_LocateProtocol,   // EFI_LOCATE_PROTOCOL
+  NULL,                 // EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES
+  NULL,                 // EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES
+  NULL,                 // EFI_CALCULATE_CRC32
+  NULL,                 // EFI_COPY_MEM
+  NULL,                 // EFI_SET_MEM
+  gBS_CreateEventEx     // EFI_CREATE_EVENT_EX
+};
+
+extern "C" {
+  EFI_BOOT_SERVICES  *gBS         = &LocalBs;
+  EFI_HANDLE         gImageHandle = NULL;
+  EFI_SYSTEM_TABLE   *gST         = NULL;
+}
-- 
2.34.1



-=-=-=-=-=-=-=-=-=-=-=-
Groups.io Links: You receive all messages sent to this group.
View/Reply Online (#118725): https://edk2.groups.io/g/devel/message/118725
Mute This Topic: https://groups.io/mt/105996588/21656
Group Owner: devel+ow...@edk2.groups.io
Unsubscribe: https://edk2.groups.io/g/devel/unsub [arch...@mail-archive.com]
-=-=-=-=-=-=-=-=-=-=-=-


Reply via email to