Skip to content

Commit

Permalink
MdePkg: Test: Add Mock interface for MmServices Table
Browse files Browse the repository at this point in the history
Add the initial Mock interface for the MmServices Table. Currently
Only the MmLocateProtocol has been mocked.

Signed-off-by: Girish Mahadevan <[email protected]>
Reviewed-by: Jeff Brasen <[email protected]>
  • Loading branch information
gmahadevan authored and UEFI Builder committed Dec 8, 2023
1 parent 9cc98f1 commit 741afa7
Show file tree
Hide file tree
Showing 3 changed files with 122 additions and 0 deletions.
40 changes: 40 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Library/MockMmStTableLib.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#ifndef MOCK_MMST_TABLE_LIB_H
#define MOCK_MMST_TABLE_LIB_H

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

struct MockMmStTableLib {
MOCK_INTERFACE_DECLARATION (MockMmStTableLib);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gMmst_MmLocateProtocol,
(IN EFI_GUID *Protocol,
IN VOID *Registration OPTIONAL,
OUT VOID **Interface)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gMmst_MmInstallProtocolInterface,
(IN OUT EFI_HANDLE *UserHandle,
IN EFI_GUID *Protocol,
IN EFI_INTERFACE_TYPE InterfaceType,
IN VOID *Interface)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
gMmst_MmRegisterProtocolNotify,
(IN CONST EFI_GUID *Protocol,
IN EFI_MM_NOTIFY_FN Function,
OUT VOID **Registration)
);
};

#endif // MOCK_MMST_TABLE_LIB_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/** @file
Google Test mocks for Mm Services Table
SPDX-FileCopyrightText: Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/
#include <GoogleTest/Library/MockMmStTableLib.h>

MOCK_INTERFACE_DEFINITION(MockMmStTableLib);

MOCK_FUNCTION_DEFINITION(MockMmStTableLib, gMmst_MmLocateProtocol, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION(MockMmStTableLib, gMmst_MmInstallProtocolInterface, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION(MockMmStTableLib, gMmst_MmRegisterProtocolNotify, 3, EFIAPI);

static EFI_MM_SYSTEM_TABLE localMmSt = {
{0}, // EFI_TABLE_HEADER

NULL, // MmFirmwareVendor
0, // MmFirmwareRevision
NULL, // MmInstallConfigurationTable
{ // MmIo
NULL,
NULL
},
NULL, // MmAllocatePool
NULL, // MmFreePool
NULL, // MmAllocatePages
NULL, // MmFreePages
NULL, // MmStartupThisAp
0, // CurrentlyExecutingCpu
0, // NumberOfCpus
NULL, // CpuSaveStateSize
NULL, // CpuSaveState
0, // NumberOfTableEntries
NULL, // MmConfigurationTable
gMmst_MmInstallProtocolInterface, // MmInstallProtocolInterface
NULL, // MmUninstallProtocolInterface
NULL, // MmHandleProtocol
gMmst_MmRegisterProtocolNotify, // MmRegisterProtocolNotify
NULL, // MmLocateHandle
gMmst_MmLocateProtocol, // MmLocateProtocol
NULL, // MmiManage
NULL, // MmiHandlerRegister
NULL, // MmiHandlerUnRegister
};

extern "C" {
EFI_MM_SYSTEM_TABLE* gMmst = &localMmSt;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
## @file
#Google Test mocks for Mm Services Table
#
# SPDX-FileCopyrightText: Copyright (c) 2023, NVIDIA CORPORATION & AFFILIATES. All rights reserved.
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = MockMmStTableLib
FILE_GUID = 9d5acf7f-64cd-44b3-a0f6-99e6c30dd6ae
MODULE_TYPE = HOST_APPLICATION
VERSION_STRING = 1.0
LIBRARY_CLASS = MmServicesTableLib

#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = IA32 X64
#

[Sources]
MockMmStTableLib.cpp

[Packages]
MdePkg/MdePkg.dec
UnitTestFrameworkPkg/UnitTestFrameworkPkg.dec

[LibraryClasses]
GoogleTestLib

[BuildOptions]
MSFT:*_*_*_CC_FLAGS = /EHsc

0 comments on commit 741afa7

Please sign in to comment.