Skip to content

Commit

Permalink
MdePkg: Create Google Test mock for MpService Protocol
Browse files Browse the repository at this point in the history
For Google test used in our project

Signed-off-by: Jack Hsieh <[email protected]>
  • Loading branch information
v-chhsieh committed Sep 24, 2024
1 parent a131839 commit ee703db
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 0 deletions.
105 changes: 105 additions & 0 deletions MdePkg/Test/Mock/Include/GoogleTest/Protocol/MockMpService.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/** @file MockMpService.h
This file declares a mock of MP service Protocol.
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#ifndef MOCK_MP_SERVICE_H_
#define MOCK_MP_SERVICE_H_

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

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

struct MockMpService {
MOCK_INTERFACE_DECLARATION (MockMpService);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
GetNumberOfProcessors,
(
IN EFI_MP_SERVICES_PROTOCOL *This,
OUT UINTN *NumberOfProcessors,
OUT UINTN *NumberOfEnabledProcessors
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
GetProcessorInfo,
(
IN EFI_MP_SERVICES_PROTOCOL *This,
IN UINTN ProcessorNumber,
OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
StartupAllAPs,
(
IN EFI_MP_SERVICES_PROTOCOL *This,
IN EFI_AP_PROCEDURE Procedure,
IN BOOLEAN SingleThread,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroSeconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT UINTN **FailedCpuList OPTIONAL
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
StartupThisAP,
(
IN EFI_MP_SERVICES_PROTOCOL *This,
IN EFI_AP_PROCEDURE Procedure,
IN UINTN ProcessorNumber,
IN EFI_EVENT WaitEvent OPTIONAL,
IN UINTN TimeoutInMicroseconds,
IN VOID *ProcedureArgument OPTIONAL,
OUT BOOLEAN *Finished OPTIONAL
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
SwitchBSP,
(
IN EFI_MP_SERVICES_PROTOCOL *This,
IN UINTN ProcessorNumber,
IN BOOLEAN EnableOldBSP
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
EnableDisableAP,
(
IN EFI_MP_SERVICES_PROTOCOL *This,
IN UINTN ProcessorNumber,
IN BOOLEAN EnableAP,
IN UINT32 *HealthFlag OPTIONAL
)
);

MOCK_FUNCTION_DECLARATION (
EFI_STATUS,
WhoAmI,
(
IN EFI_MP_SERVICES_PROTOCOL *This,
OUT UINTN *ProcessorNumber
)
);
};

extern "C" {
extern EFI_MP_SERVICES_PROTOCOL *gMpServiceProtocol;
}

#endif // MOCK_RNG_H_
31 changes: 31 additions & 0 deletions MdePkg/Test/Mock/Library/GoogleTest/Protocol/MockMpService.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/** @file MockMpService.cpp
Google Test mock for MP service Protocol
Copyright (c) Microsoft Corporation.
SPDX-License-Identifier: BSD-2-Clause-Patent
**/

#include <GoogleTest/Protocol/MockMpService.h>

MOCK_INTERFACE_DEFINITION (MockMpService);
MOCK_FUNCTION_DEFINITION (MockMpService, GetNumberOfProcessors, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockMpService, GetProcessorInfo, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockMpService, StartupAllAPs, 7, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockMpService, StartupThisAP, 7, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockMpService, SwitchBSP, 3, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockMpService, EnableDisableAP, 4, EFIAPI);
MOCK_FUNCTION_DEFINITION (MockMpService, WhoAmI, 2, EFIAPI);

EFI_MP_SERVICES_PROTOCOL MP_SERVICE_PROTOCOL_INSTANCE = {
GetNumberOfProcessors,
GetProcessorInfo,
StartupAllAPs,
StartupThisAP,
SwitchBSP,
EnableDisableAP,
WhoAmI
};

extern "C" {
EFI_MP_SERVICES_PROTOCOL *gMpServiceProtocol = &MP_SERVICE_PROTOCOL_INSTANCE;
}

0 comments on commit ee703db

Please sign in to comment.