Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Mock for Mock Smm Sw Dispatch2 Protocol #1217

Open
wants to merge 9 commits into
base: dev/202405
Choose a base branch
from
103 changes: 103 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockFirmwareVolumeBlock.h
Rasheed-Yusuf marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/** @file MockFirmwareVolumeBlock.h
This file declares a mock of Firmware Volume Block Protocol

Copyright (c) Microsoft Corporation.
Your use of this software is governed by the terms of the Microsoft agreement under which you obtained the software.
Rasheed-Yusuf marked this conversation as resolved.
Show resolved Hide resolved
**/

#ifndef MOCK_FIRMWARE_VOLUME_BLOCK_H_
#define MOCK_FIRMWARE_VOLUME_BLOCK_H_

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

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

//
// Declarations to handle usage of the FirmwareVolumeBlockProtocol
//
struct MockFirmwareVolumeBlockProtocol {
MOCK_INTERFACE_DECLARATION (MockFirmwareVolumeBlockProtocol);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
GetAttributes,
(
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
OUT EFI_FVB_ATTRIBUTES_2* Attributes)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
SetAttributes,
(
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
IN OUT EFI_FVB_ATTRIBUTES_2* Attributes)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
GetPhysicalAddress,
(
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
OUT EFI_PHYSICAL_ADDRESS* Address)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
GetBlockSize,
(
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
IN EFI_LBA Lba,
OUT UINTN* BlockSize,
OUT UINTN* NumberOfBlocks)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
Read,
(
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
IN EFI_LBA Lba,
IN UINTN Offset,
IN OUT UINTN* NumBytes,
IN OUT UINT8* Buffer)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
Write,
(
IN CONST EFI_FIRMWARE_VOLUME_BLOCK2_PROTOCOL* This,
IN EFI_LBA Lba,
IN UINTN Offset,
IN OUT UINTN* NumBytes,
IN UINT8* Buffer)
);
};

MOCK_INTERFACE_DEFINITION (MockFirmwareVolumeBlockProtocol);
MOCK_FUNCTION_DEFINITION (MockFirmwareVolumeBlockProtocol, GetAttributes, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockFirmwareVolumeBlockProtocol, SetAttributes, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockFirmwareVolumeBlockProtocol, GetPhysicalAddress, 2, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockFirmwareVolumeBlockProtocol, GetBlockSize, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockFirmwareVolumeBlockProtocol, Read, 5, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockFirmwareVolumeBlockProtocol, Write, 5, EFIAPI);

EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL FIRMWARE_VOLUME_BLOCK_PROTOCOL_MOCK = {
GetAttributes, // EFI_FVB_GET_ATTRIBUTES GetAttributes;
SetAttributes, // EFI_FVB_SET_ATTRIBUTES SetAttributes;
GetPhysicalAddress, // EFI_FVB_GET_PHYSICAL_ADDRESS GetPhysicalAddress;
GetBlockSize, // EFI_FVB_GET_BLOCK_SIZE GetBlockSize;
Read, // EFI_FVB_READ Read;
Write // EFI_FVB_WRITE Write;
};

extern "C" {
EFI_FIRMWARE_VOLUME_BLOCK_PROTOCOL *Fvb = &FIRMWARE_VOLUME_BLOCK_PROTOCOL_MOCK;
}

#endif // MOCK_FIRMWARE_VOLUME_BLOCK_H_
56 changes: 56 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockSmmSwDispatch2.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/** @file MockSmmSwDispatch2.h
This file declares a mock of SMM Software Dispatch Protocol

Copyright (c) Microsoft Corporation.
Your use of this software is governed by the terms of the Microsoft agreement under which you obtained the software.
Rasheed-Yusuf marked this conversation as resolved.
Show resolved Hide resolved
**/

#ifndef MOCK_SMM_SW_DISPATCH2_H_
#define MOCK_SMM_SW_DISPATCH2_H_

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

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

// Declarations to handle usage of the EFI_SMM_SW_DISPATCH2_PROTOCOL
struct MockSmmSwDispatch2Protocol {
MOCK_INTERFACE_DECLARATION (MockSmmSwDispatch2Protocol);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
MockRegister,
(
IN CONST EFI_SMM_SW_DISPATCH2_PROTOCOL *This,
IN EFI_SMM_HANDLER_ENTRY_POINT2 DispatchFunction,
IN OUT EFI_SMM_SW_REGISTER_CONTEXT *RegisterContext,
OUT EFI_HANDLE *DispatchHandle)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
MockUnRegister,
(
IN CONST EFI_SMM_SW_DISPATCH2_PROTOCOL *This,
IN EFI_HANDLE DispatchHandle)
);
};

MOCK_INTERFACE_DEFINITION (MockSmmSwDispatch2Protocol);
MOCK_FUNCTION_DEFINITION (MockSmmSwDispatch2Protocol, MockRegister, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockSmmSwDispatch2Protocol, MockUnRegister, 2, EFIAPI);

EFI_SMM_SW_DISPATCH2_PROTOCOL SMM_SW_DISPATCH2_PROTOCOL_MOCK = {
MockRegister, // EFI_SMM_SW_REGISTER2 Register;
MockUnRegister // EFI_SMM_SW_UNREGISTER2 UnRegister;
};


extern "C" {
EFI_SMM_SW_DISPATCH2_PROTOCOL *gSmmSwDispatch2 = &SMM_SW_DISPATCH2_PROTOCOL_MOCK;
}
#endif // MOCK_SMM_SW_DISPATCH2_H_

Loading