Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
v-boscochen committed Nov 11, 2024
1 parent 86d984c commit dfa8b62
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,18 @@ struct MockUefiBootServicesTableLib {
IN EFI_HANDLE DriverImageHandle OPTIONAL,
IN EFI_HANDLE ChildHandle OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
EFI_TPL,
gBS_RasieTpl,
(IN EFI_TPL NewTpl)
);

MOCK_FUNCTION_DECLARATION (
VOID,
gBS_RestoreTpl,
(IN EFI_TPL OldTpl)
);
};

#endif // MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/** @file
This file declares a mock of PCI Root Bridge IO Protocol.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_PCIROOTBRIDGEIOPROTOCOL_H
#define MOCK_PCIROOTBRIDGEIOPROTOCOL_H

#include <Library/GoogleTestLib.h>
#include <Library/FunctionMockLib.h>

extern "C" {
#include <Uefi.h>
#include <Protocol/PciRootBridgeIo.h>
}

//
// Declarations to handle usage of the Pci Root Bridge Io Protocol by creating mock
//
struct MockPciRootBridgeIoConfigAccess {
MOCK_INTERFACE_DECLARATION (MockPciRootBridgeIoConfigAccess);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
MockPciRootBridgeIoRead,
(IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer)
);
MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
MockPciRootBridgeIoWrite,
(IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *This,
IN EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_WIDTH Width,
IN UINT64 Address,
IN UINTN Count,
IN OUT VOID *Buffer)
);
};

MOCK_INTERFACE_DEFINITION (MockPciRootBridgeIoConfigAccess);
MOCK_FUNCTION_DEFINITION (MockPciRootBridgeIoConfigAccess, MockPciRootBridgeIoRead, 5, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPciRootBridgeIoConfigAccess, MockPciRootBridgeIoWrite, 5, EFIAPI);

EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL PCI_ROOT_BRIDGE_IO_PROTOCOL_MOCK = {
NULL, // EFI_HANDLE ParentHandle;
NULL, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_POLL_IO_MEM PollMem;
NULL, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_POLL_IO_MEM PollIo;
{ NULL, NULL }, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS Mem;
{ NULL, NULL }, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS Io;
{ MockPciRootBridgeIoRead, MockPciRootBridgeIoWrite }, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ACCESS Pci;
NULL, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_COPY_MEM CopyMem;
NULL, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_MAP Map;
NULL, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_UNMAP Unmap;
NULL, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_ALLOCATE_BUFFER AllocateBuffer;
NULL, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FREE_BUFFER FreeBuffer;
NULL, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_FLUSH Flush;
NULL, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_GET_ATTRIBUTES GetAttributes;
NULL, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_SET_ATTRIBUTES SetAttributes;
NULL, // EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL_CONFIGURATION Configuration;
};

extern "C" {
extern EFI_PCI_ROOT_BRIDGE_IO_PROTOCOL *gPciRootBridgeIoProtocol = &PCI_ROOT_BRIDGE_IO_PROTOCOL_MOCK;
}

#endif // MOCK_PCIIOPROTOCOL_H
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_AllocatePool, 3, EFI
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_LocateHandle, 5, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_ConnectController, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_DisconnectController, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_RasieTpl, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockUefiBootServicesTableLib, gBS_RestoreTpl, 1, EFIAPI);

extern "C" {
EFI_STATUS
Expand Down Expand Up @@ -103,8 +105,8 @@ extern "C" {

static EFI_BOOT_SERVICES LocalBs = {
{ 0, 0, 0, 0, 0 }, // EFI_TABLE_HEADER
NULL, // EFI_RAISE_TPL
NULL, // EFI_RESTORE_TPL
gBS_RasieTpl, // EFI_RAISE_TPL
gBS_RestoreTpl, // EFI_RESTORE_TPL
NULL, // EFI_ALLOCATE_PAGES
NULL, // EFI_FREE_PAGES
gBS_GetMemoryMap, // EFI_GET_MEMORY_MAP
Expand Down

0 comments on commit dfa8b62

Please sign in to comment.