-
Notifications
You must be signed in to change notification settings - Fork 127
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add mock functions under MockPciIoProtocol and Create Mock for Smbio,…
… UsbIo and NvmExpressPassthru protocol Signed-off-by: TsunFeng <v-tshuang@microsoft.com>
- Loading branch information
Showing
8 changed files
with
418 additions
and
1 deletion.
There are no files selected for viewing
67 changes: 67 additions & 0 deletions
67
MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockNvmExpressPassthru.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
/** @file MockNvmExpressPassthru.h | ||
This file declares a mock of NvmExpress Pass Thru Protocol. | ||
Copyright (c) Microsoft Corporation. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#ifndef MOCK_NVM_EXPRESS_PASS_THRU_H | ||
#define MOCK_NVM_EXPRESS_PASS_THRU_H | ||
|
||
#include <Library/GoogleTestLib.h> | ||
#include <Library/FunctionMockLib.h> | ||
|
||
extern "C" { | ||
#include <Uefi.h> | ||
#include <Protocol/NvmExpressPassthru.h> | ||
} | ||
|
||
struct MockNvmePassThruProtocol { | ||
MOCK_INTERFACE_DECLARATION (MockNvmePassThruProtocol); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
PassThru, | ||
( | ||
IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This, | ||
IN UINT32 NamespaceId, | ||
IN OUT EFI_NVM_EXPRESS_PASS_THRU_COMMAND_PACKET *Packet, | ||
IN EFI_EVENT Event OPTIONAL | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
GetNextNamespace, | ||
( | ||
IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This, | ||
IN OUT UINT32 *NamespaceId | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
BuildDevicePath, | ||
( | ||
IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This, | ||
IN UINT32 NamespaceId, | ||
OUT EFI_DEVICE_PATH_PROTOCOL **DevicePath | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
GetNamespace, | ||
( | ||
IN EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *This, | ||
IN EFI_DEVICE_PATH_PROTOCOL *DevicePath, | ||
OUT UINT32 *NamespaceId | ||
) | ||
); | ||
}; | ||
|
||
extern "C" { | ||
extern EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *gNvmePassThruProtocol; | ||
} | ||
|
||
#endif // NVM_EXPRESS_PASS_THRU_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
/** @file MockSmbios.h | ||
This file declares a mock of SMBIOS Protocol. | ||
Copyright (c) Microsoft Corporation. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#ifndef MOCK_SMBIOS_PROTOCOL_H | ||
#define MOCK_SMBIOS_PROTOCOL_H | ||
|
||
#include <Library/GoogleTestLib.h> | ||
#include <Library/FunctionMockLib.h> | ||
|
||
extern "C" { | ||
#include <Uefi.h> | ||
#include <Protocol/Smbios.h> | ||
} | ||
|
||
struct MockSmbiosProtocol { | ||
MOCK_INTERFACE_DECLARATION (MockSmbiosProtocol); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
Add, | ||
( | ||
IN CONST EFI_SMBIOS_PROTOCOL *This, | ||
IN EFI_HANDLE ProducerHandle OPTIONAL, | ||
IN OUT EFI_SMBIOS_HANDLE *SmbiosHandle, | ||
IN EFI_SMBIOS_TABLE_HEADER *Record | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UpdateString, | ||
( | ||
IN CONST EFI_SMBIOS_PROTOCOL *This, | ||
IN EFI_SMBIOS_HANDLE *SmbiosHandle, | ||
IN UINTN *StringNumber, | ||
IN CHAR8 *String | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
Remove, | ||
( | ||
IN CONST EFI_SMBIOS_PROTOCOL *This, | ||
IN EFI_SMBIOS_HANDLE SmbiosHandle | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
GetNext, | ||
( | ||
IN CONST EFI_SMBIOS_PROTOCOL *This, | ||
IN OUT EFI_SMBIOS_HANDLE *SmbiosHandle, | ||
IN EFI_SMBIOS_TYPE *Type OPTIONAL, | ||
OUT EFI_SMBIOS_TABLE_HEADER **Record, | ||
OUT EFI_HANDLE *ProducerHandle OPTIONAL | ||
) | ||
); | ||
}; | ||
|
||
extern "C" { | ||
extern EFI_SMBIOS_PROTOCOL *gSmbiosProtocol; | ||
} | ||
|
||
#endif // MOCK_SMBIOS_PROTOCOL_H |
172 changes: 172 additions & 0 deletions
172
MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockUsbIo.h
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,172 @@ | ||
/** @file MockUsbIo.h | ||
This file declares a mock of Usb Io Protocol. | ||
Copyright (c) Microsoft Corporation. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#ifndef MOCK_USB_IO_H | ||
#define MOCK_USB_IO_H | ||
|
||
#include <Library/GoogleTestLib.h> | ||
#include <Library/FunctionMockLib.h> | ||
|
||
extern "C" { | ||
#include <Uefi.h> | ||
#include <Protocol/UsbIo.h> | ||
} | ||
|
||
struct MockUsbIoProtocol { | ||
MOCK_INTERFACE_DECLARATION (MockUsbIoProtocol); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbControlTransfer, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This, | ||
IN EFI_USB_DEVICE_REQUEST *Request, | ||
IN EFI_USB_DATA_DIRECTION Direction, | ||
IN UINT32 Timeout, | ||
IN OUT VOID *Data OPTIONAL, | ||
IN UINTN DataLength OPTIONAL, | ||
OUT UINT32 *Status | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbBulkTransfer, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This, | ||
IN UINT8 DeviceEndpoint, | ||
IN OUT VOID *Data, | ||
IN OUT UINTN *DataLength, | ||
IN UINTN Timeout, | ||
OUT UINT32 *Status | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbAsyncInterruptTransfer, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This, | ||
IN UINT8 DeviceEndpoint, | ||
IN BOOLEAN IsNewTransfer, | ||
IN UINTN PollingInterval OPTIONAL, | ||
IN UINTN DataLength OPTIONAL, | ||
IN EFI_ASYNC_USB_TRANSFER_CALLBACK InterruptCallBack OPTIONAL, | ||
IN VOID *Context OPTIONAL | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbSyncInterruptTransfer, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This, | ||
IN UINT8 DeviceEndpoint, | ||
IN OUT VOID *Data, | ||
IN OUT UINTN *DataLength, | ||
IN UINTN Timeout, | ||
OUT UINT32 *Status | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbIsochronousTransfer, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This, | ||
IN UINT8 DeviceEndpoint, | ||
IN OUT VOID *Data, | ||
IN UINTN DataLength, | ||
OUT UINT32 *Status | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbAsyncIsochronousTransfer, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This, | ||
IN UINT8 DeviceEndpoint, | ||
IN OUT VOID *Data, | ||
IN UINTN DataLength, | ||
IN EFI_ASYNC_USB_TRANSFER_CALLBACK IsochronousCallBack, | ||
IN VOID *Context OPTIONAL | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbGetDeviceDescriptor, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This, | ||
OUT EFI_USB_DEVICE_DESCRIPTOR *DeviceDescriptor | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbGetConfigDescriptor, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This, | ||
OUT EFI_USB_CONFIG_DESCRIPTOR *ConfigurationDescriptor | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbGetInterfaceDescriptor, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This, | ||
OUT EFI_USB_INTERFACE_DESCRIPTOR *InterfaceDescriptor | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbGetEndpointDescriptor, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This, | ||
IN UINT8 EndpointIndex, | ||
OUT EFI_USB_ENDPOINT_DESCRIPTOR *EndpointDescriptor | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbGetStringDescriptor, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This, | ||
IN UINT16 LangID, | ||
IN UINT8 StringID, | ||
OUT CHAR16 **String | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbGetSupportedLanguages, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This, | ||
OUT UINT16 **LangIDTable, | ||
OUT UINT16 *TableSize | ||
) | ||
); | ||
|
||
MOCK_FUNCTION_DECLARATION ( | ||
EFI_STATUS, | ||
UsbPortReset, | ||
( | ||
IN EFI_USB_IO_PROTOCOL *This | ||
) | ||
); | ||
}; | ||
|
||
extern "C" { | ||
extern EFI_USB_IO_PROTOCOL *gUsbIoProtocol; | ||
} | ||
|
||
#endif // MOCK_USB_IO_H |
26 changes: 26 additions & 0 deletions
26
MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockNvmExpressPassthru.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/** @file MockNvmExpressPassthru.cpp | ||
Google Test mock for NvmExpress Pass Thru Protocol. | ||
Copyright (c) Microsoft Corporation. | ||
SPDX-License-Identifier: BSD-2-Clause-Patent | ||
**/ | ||
|
||
#include <GoogleTest/Protocol/MockNvmExpressPassthru.h> | ||
|
||
MOCK_INTERFACE_DEFINITION (MockNvmePassThruProtocol); | ||
MOCK_FUNCTION_DEFINITION (MockNvmePassThruProtocol, PassThru, 4, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION (MockNvmePassThruProtocol, GetNextNamespace, 2, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION (MockNvmePassThruProtocol, BuildDevicePath, 3, EFIAPI); | ||
MOCK_FUNCTION_DEFINITION (MockNvmePassThruProtocol, GetNamespace, 3, EFIAPI); | ||
|
||
EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL NVME_PASSTHRU_PROTOCOL_INSTANCE = { | ||
{ 0 }, // EFI_NVM_EXPRESS_PASS_THRU_MODE *Mode; | ||
PassThru, // EFI_NVM_EXPRESS_PASS_THRU_PASSTHRU PassThru; | ||
GetNextNamespace, // EFI_NVM_EXPRESS_PASS_THRU_GET_NEXT_NAMESPACE GetNextNamespace; | ||
BuildDevicePath, // EFI_NVM_EXPRESS_PASS_THRU_BUILD_DEVICE_PATH BuildDevicePath; | ||
GetNamespace // EFI_NVM_EXPRESS_PASS_THRU_GET_NAMESPACE GetNamespace; | ||
}; | ||
|
||
extern "C" { | ||
EFI_NVM_EXPRESS_PASS_THRU_PROTOCOL *gNvmePassThruProtocol = &NVME_PASSTHRU_PROTOCOL_INSTANCE; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.