Skip to content

Commit

Permalink
Add mock functions under MockUefiLib and Create Mock for AcpiTable, F…
Browse files Browse the repository at this point in the history
…irmwareVolume2 and AcpiSystemDescriptionTable protocol (#1106)

## Description

Add mock functions under MockUefiLib and Create Mock for AcpiTable,
FirmwareVolume2 and AcpiSystemDescriptionTable protocol

- [ ] Impacts functionality?
- [ ] Impacts security?
- [ ] Breaking change?
- [x] Includes tests?
- [ ] Includes documentation?

## How This Was Tested

Unit tests component can call these mock functions success

## Integration Instructions

N/A

---------

Signed-off-by: dependabot[bot] <support@github.com>
Signed-off-by: Ethan Hsu <Eathonhsu@gmail.com>
Signed-off-by: Vivian Nowka-Keane <vnowkakeane@microsoft.com>
Signed-off-by: TsunFeng <v-tshuang@microsoft.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Aaron Pop <aaronpop@microsoft.com>
Co-authored-by: Michael Kubacki <michael.kubacki@microsoft.com>
Co-authored-by: Taylor Beebe <tabeebe@microsoft.com>
Co-authored-by: pohanch <125842322+pohanch@users.noreply.github.com>
Co-authored-by: kenlautner <85201046+kenlautner@users.noreply.github.com>
Co-authored-by: Oliver Smith-Denny <osde@linux.microsoft.com>
Co-authored-by: Sean Brogan <sean.brogan@microsoft.com>
Co-authored-by: Aaron <105021049+apop5@users.noreply.github.com>
Co-authored-by: yhsu3 <yhsu3@lenovo.com>
Co-authored-by: Vivian Nowka-Keane <vnowkakeane@microsoft.com>
Co-authored-by: v-sbolisetti <v-sbolisetti@microsoft.com>
Co-authored-by: YiTa-AMI <v-yitawu@microsoft.com>
  • Loading branch information
14 people committed Sep 25, 2024
1 parent a952e84 commit 456eada
Show file tree
Hide file tree
Showing 21 changed files with 657 additions and 5 deletions.
2 changes: 1 addition & 1 deletion MdeModulePkg/Bus/Pci/PciBusDxe/PciLib.c
Original file line number Diff line number Diff line change
Expand Up @@ -1306,7 +1306,7 @@ PciScanBus (
PciDevice->DevicePath,
PciAddress,
&State,
(VOID **)&Descriptors, // MU_CHANGE - CodeQL Change
(VOID **)&DescriptorsBuffer, // MU_CHANGE - CodeQL Change
&Attributes
);

Expand Down
1 change: 1 addition & 0 deletions MdePkg/Test/MdePkgHostTest.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@
MdePkg/Test/Mock/Library/Stub/StubUefiLib/StubUefiLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockPciExpressLib/MockPciExpressLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockUefiDevicePathLib/MockUefiDevicePathLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockDxeServicesTableLib/MockDxeServicesTableLib.inf
MdePkg/Test/Mock/Library/GoogleTest/MockPciLib/MockPciLib.inf
# MU_CHANGE [END]
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** @file MockDxeServicesTableLib.h
Google Test mocks for DxeServicesTableLib
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_DXE_SERVICES_TABLE_LIB_H_
#define MOCK_DXE_SERVICES_TABLE_LIB_H_

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

//
// Declarations to handle usage of the DxeServicesTableLib by creating mock
//
struct MockDxeServicesTableLib {
MOCK_INTERFACE_DECLARATION (MockDxeServicesTableLib);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gDS_Dispatch,
()
);
};

#endif // MOCK_UEFI_DXE_SERVICES_TABLE_LIB_H_
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,14 @@ struct MockUefiBootServicesTableLib {
OUT VOID **Interface)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gBS_RegisterProtocolNotify,
(IN EFI_GUID *Protocol,
IN EFI_EVENT Event,
OUT VOID **Registration)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gBS_LocateHandleBuffer,
Expand Down Expand Up @@ -179,6 +187,23 @@ struct MockUefiBootServicesTableLib {
IN OUT UINTN *BufferSize,
OUT EFI_HANDLE *Buffer)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gBS_ConnectController,
(IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE *DriverImageHandle OPTIONAL,
IN EFI_DEVICE_PATH_PROTOCOL *RemainingDevicePath OPTIONAL,
IN BOOLEAN Recursive)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gBS_DisconnectController,
(IN EFI_HANDLE ControllerHandle,
IN EFI_HANDLE DriverImageHandle OPTIONAL,
IN EFI_HANDLE ChildHandle OPTIONAL)
);
};

#endif // MOCK_UEFI_BOOT_SERVICES_TABLE_LIB_H_
9 changes: 9 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Library/MockUefiLib.h
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@ struct MockUefiLib {
IN CONST EFI_COMPONENT_NAME_PROTOCOL *ComponentName OPTIONAL,
IN CONST EFI_COMPONENT_NAME2_PROTOCOL *ComponentName2 OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EfiCreateEventReadyToBootEx,
(IN EFI_TPL NotifyTpl,
IN EFI_EVENT_NOTIFY NotifyFunction OPTIONAL,
IN VOID *NotifyContext OPTIONAL,
OUT EFI_EVENT *ReadyToBootEvent)
);
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,15 @@ struct MockUefiRuntimeServicesTableLib {
(OUT EFI_TIME *Time,
OUT EFI_TIME_CAPABILITIES *Capabilities OPTIONAL)
);

MOCK_FUNCTION_DECLARATION (
VOID,
gRT_ResetSystem,
(IN EFI_RESET_TYPE ResetType,
IN EFI_STATUS ResetStatus,
IN UINTN DataSize,
IN VOID *ResetData OPTIONAL)
);
};

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/** @file MockPeiReportStatusCodeHandler.h
This file declares a mock of Report Status Code Handler PPI.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_PEI_REPORT_STATUS_CODE_HANDLER_PPI_H
#define MOCK_PEI_REPORT_STATUS_CODE_HANDLER_PPI_H

#include <Library/GoogleTestLib.h>
#include <Library/FunctionMockLib.h>
extern "C" {
#include <Uefi.h>
#include <Pi/PiPeiCis.h>
#include <Ppi/ReportStatusCodeHandler.h>
}

struct MockPeiReportStatusCodeHandler {
MOCK_INTERFACE_DECLARATION (MockPeiReportStatusCodeHandler);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
Register,
(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
Unregister,
(IN EFI_PEI_RSC_HANDLER_CALLBACK Callback)
);
};

MOCK_INTERFACE_DEFINITION (MockPeiReportStatusCodeHandler);
MOCK_FUNCTION_DEFINITION (MockPeiReportStatusCodeHandler, Register, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockPeiReportStatusCodeHandler, Unregister, 1, EFIAPI);

EFI_PEI_RSC_HANDLER_PPI PeiRscHandlerPpi = {
Register,
Unregister
};

extern "C" {
EFI_PEI_RSC_HANDLER_PPI *PeiRscHandlerPpiServices = &PeiRscHandlerPpi;
}

#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,139 @@
/** @file MockAcpiSystemDescriptionTable.h
This file declares a mock of ACPI system description tables protocol.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_ACPI_SYSTEM_DESCRIPTION_TABLE_H_
#define MOCK_ACPI_SYSTEM_DESCRIPTION_TABLE_H_

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

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

struct MockAcpiSdtProtocol {
MOCK_INTERFACE_DECLARATION (MockAcpiSdtProtocol);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
GetAcpiTable,
(
IN UINTN Index,
OUT EFI_ACPI_SDT_HEADER **Table,
OUT EFI_ACPI_TABLE_VERSION *Version,
OUT UINTN *TableKey
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
RegisterNotify,
(
IN BOOLEAN Register,
IN EFI_ACPI_NOTIFICATION_FN Notification
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
Open,
(
IN VOID *Buffer,
OUT EFI_ACPI_HANDLE *Handle
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
OpenSdt,
(
IN UINTN TableKey,
OUT EFI_ACPI_HANDLE *Handle
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
Close,
(
IN EFI_ACPI_HANDLE Handle
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
GetChild,
(
IN EFI_ACPI_HANDLE ParentHandle,
IN OUT EFI_ACPI_HANDLE *Handle
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
GetOption,
(
IN EFI_ACPI_HANDLE Handle,
IN UINTN Index,
OUT EFI_ACPI_DATA_TYPE *DataType,
OUT CONST VOID **Data,
OUT UINTN *DataSize
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
SetOption,
(
IN EFI_ACPI_HANDLE Handle,
IN UINTN Index,
IN CONST VOID *Data,
IN UINTN DataSize
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
FindPath,
(
IN EFI_ACPI_HANDLE HandleIn,
IN VOID *AcpiPath,
OUT EFI_ACPI_HANDLE *HandleOut
)
);
};

MOCK_INTERFACE_DEFINITION (MockAcpiSdtProtocol);
MOCK_FUNCTION_DEFINITION (MockAcpiSdtProtocol, GetAcpiTable, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAcpiSdtProtocol, RegisterNotify, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAcpiSdtProtocol, Open, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAcpiSdtProtocol, OpenSdt, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAcpiSdtProtocol, Close, 1, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAcpiSdtProtocol, GetChild, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAcpiSdtProtocol, GetOption, 5, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAcpiSdtProtocol, SetOption, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAcpiSdtProtocol, FindPath, 3, EFIAPI);

EFI_ACPI_SDT_PROTOCOL ACPI_SDT_PROTOCOL_INSTANCE = {
0,
GetAcpiTable, // EFI_ACPI_TABLE_INSTALL_ACPI_TABLE
RegisterNotify, // EFI_ACPI_TABLE_UNINSTALL_ACPI_TABLE
Open,
OpenSdt,
Close,
GetChild,
GetOption,
SetOption,
FindPath
};

extern "C" {
EFI_ACPI_SDT_PROTOCOL *gAcpiSdtProtocol = &ACPI_SDT_PROTOCOL_INSTANCE;
}

#endif // MOCK_ACPI_SYSTEM_DESCRIPTION_TABLE_H_
56 changes: 56 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockAcpiTable.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/** @file MockAcpiTable.h
This file declares a mock of Acpi table protocol.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_ACPI_TABLE_H_
#define MOCK_ACPI_TABLE_H_

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

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

struct MockAcpiTableProtocol {
MOCK_INTERFACE_DECLARATION (MockAcpiTableProtocol);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
InstallAcpiTable,
(
IN EFI_ACPI_TABLE_PROTOCOL *This,
IN VOID *AcpiTableBuffer,
IN UINTN AcpiTableBufferSize,
OUT UINTN *TableKey
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
UninstallAcpiTable,
(
IN EFI_ACPI_TABLE_PROTOCOL *This,
IN UINTN TableKey
)
);
};

MOCK_INTERFACE_DEFINITION (MockAcpiTableProtocol);
MOCK_FUNCTION_DEFINITION (MockAcpiTableProtocol, InstallAcpiTable, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockAcpiTableProtocol, UninstallAcpiTable, 2, EFIAPI);

EFI_ACPI_TABLE_PROTOCOL ACPI_TABLE_PROTOCOL_INSTANCE = {
InstallAcpiTable, // EFI_ACPI_TABLE_INSTALL_ACPI_TABLE
UninstallAcpiTable // EFI_ACPI_TABLE_UNINSTALL_ACPI_TABLE
};

extern "C" {
EFI_ACPI_TABLE_PROTOCOL *gAcpiTableProtocol = &ACPI_TABLE_PROTOCOL_INSTANCE;
}

#endif // MOCK_ACPI_TABLE_H_
Loading

0 comments on commit 456eada

Please sign in to comment.