2 PEI Module to test EfiMpServiceProtocol.
4 Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
11 #include <Library/UefiBootServicesTableLib.h>
12 #include "EfiMpServicesUnitTestCommom.h"
14 #define UNIT_TEST_NAME "EfiMpServiceProtocol Unit Test"
15 #define UNIT_TEST_VERSION "0.1"
18 Get EFI_MP_SERVICES_PROTOCOL pointer.
20 @param[out] MpServices Pointer to the buffer where EFI_MP_SERVICES_PROTOCOL is stored
22 @retval EFI_SUCCESS EFI_MP_SERVICES_PROTOCOL interface is returned
23 @retval EFI_NOT_FOUND EFI_MP_SERVICES_PROTOCOL interface is not found
26 MpServicesUnitTestGetMpServices (
27 OUT MP_SERVICES
*MpServices
30 return gBS
->LocateProtocol (&gEfiMpServiceProtocolGuid
, NULL
, (VOID
**)&MpServices
->Protocol
);
34 Retrieve the number of logical processor in the platform and the number of those logical processors that
35 are enabled on this boot.
37 @param[in] MpServices MP_SERVICES structure.
38 @param[out] NumberOfProcessors Pointer to the total number of logical processors in the system, including
39 the BSP and disabled APs.
40 @param[out] NumberOfEnabledProcessors Pointer to the number of processors in the system that are enabled.
42 @retval EFI_SUCCESS Retrieve the number of logical processor successfully
43 @retval Others Retrieve the number of logical processor unsuccessfully
46 MpServicesUnitTestGetNumberOfProcessors (
47 IN MP_SERVICES MpServices
,
48 OUT UINTN
*NumberOfProcessors
,
49 OUT UINTN
*NumberOfEnabledProcessors
52 return MpServices
.Protocol
->GetNumberOfProcessors (MpServices
.Protocol
, NumberOfProcessors
, NumberOfEnabledProcessors
);
56 Get detailed information on the requested logical processor.
58 @param[in] MpServices MP_SERVICES structure.
59 @param[in] ProcessorNumber The handle number of the processor.
60 @param[out] ProcessorInfoBuffer Pointer to the buffer where the processor information is stored.
62 @retval EFI_SUCCESS Get information on the requested logical processor successfully
63 @retval Others Get information on the requested logical processor unsuccessfully
66 MpServicesUnitTestGetProcessorInfo (
67 IN MP_SERVICES MpServices
,
68 IN UINTN ProcessorNumber
,
69 OUT EFI_PROCESSOR_INFORMATION
*ProcessorInfoBuffer
72 return MpServices
.Protocol
->GetProcessorInfo (MpServices
.Protocol
, ProcessorNumber
, ProcessorInfoBuffer
);
76 Execute a caller provided function on all enabled APs.
78 @param[in] MpServices MP_SERVICES structure.
79 @param[in] Procedure Pointer to the function to be run on enabled APs of the system.
80 @param[in] SingleThread If TRUE, then all the enabled APs execute the function specified by Procedure
81 one by one, in ascending order of processor handle number.
82 If FALSE, then all the enabled APs execute the function specified by Procedure
84 @param[in] TimeoutInMicroSeconds Indicates the time limit in microseconds for APs to return from Procedure,
85 for blocking mode only. Zero means infinity.
86 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
88 @retval EFI_SUCCESS Execute a caller provided function on all enabled APs successfully
89 @retval Others Execute a caller provided function on all enabled APs unsuccessfully
92 MpServicesUnitTestStartupAllAPs (
93 IN MP_SERVICES MpServices
,
94 IN EFI_AP_PROCEDURE Procedure
,
95 IN BOOLEAN SingleThread
,
96 IN UINTN TimeoutInMicroSeconds
,
97 IN VOID
*ProcedureArgument
100 return MpServices
.Protocol
->StartupAllAPs (MpServices
.Protocol
, Procedure
, SingleThread
, NULL
, TimeoutInMicroSeconds
, ProcedureArgument
, NULL
);
104 Caller gets one enabled AP to execute a caller-provided function.
106 @param[in] MpServices MP_SERVICES structure.
107 @param[in] Procedure Pointer to the function to be run on enabled APs of the system.
108 @param[in] ProcessorNumber The handle number of the AP.
109 @param[in] TimeoutInMicroSeconds Indicates the time limit in microseconds for APs to return from Procedure,
110 for blocking mode only. Zero means infinity.
111 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
114 @retval EFI_SUCCESS Caller gets one enabled AP to execute a caller-provided function successfully
115 @retval Others Caller gets one enabled AP to execute a caller-provided function unsuccessfully
118 MpServicesUnitTestStartupThisAP (
119 IN MP_SERVICES MpServices
,
120 IN EFI_AP_PROCEDURE Procedure
,
121 IN UINTN ProcessorNumber
,
122 IN UINTN TimeoutInMicroSeconds
,
123 IN VOID
*ProcedureArgument
126 return MpServices
.Protocol
->StartupThisAP (MpServices
.Protocol
, Procedure
, ProcessorNumber
, NULL
, TimeoutInMicroSeconds
, ProcedureArgument
, NULL
);
130 Switch the requested AP to be the BSP from that point onward.
132 @param[in] MpServices MP_SERVICES structure.
133 @param[in] ProcessorNumber The handle number of AP that is to become the new BSP.
134 @param[in] EnableOldBSP If TRUE, the old BSP will be listed as an enabled AP. Otherwise, it will be disabled.
136 @retval EFI_SUCCESS Switch the requested AP to be the BSP successfully
137 @retval Others Switch the requested AP to be the BSP unsuccessfully
140 MpServicesUnitTestSwitchBSP (
141 IN MP_SERVICES MpServices
,
142 IN UINTN ProcessorNumber
,
143 IN BOOLEAN EnableOldBSP
146 return MpServices
.Protocol
->SwitchBSP (MpServices
.Protocol
, ProcessorNumber
, EnableOldBSP
);
150 Caller enables or disables an AP from this point onward.
152 @param[in] MpServices MP_SERVICES structure.
153 @param[in] ProcessorNumber The handle number of the AP.
154 @param[in] EnableAP Specifies the new state for the processor for enabled, FALSE for disabled.
155 @param[in] HealthFlag If not NULL, a pointer to a value that specifies the new health status of the AP.
157 @retval EFI_SUCCESS Caller enables or disables an AP successfully.
158 @retval Others Caller enables or disables an AP unsuccessfully.
161 MpServicesUnitTestEnableDisableAP (
162 IN MP_SERVICES MpServices
,
163 IN UINTN ProcessorNumber
,
165 IN UINT32
*HealthFlag
168 return MpServices
.Protocol
->EnableDisableAP (MpServices
.Protocol
, ProcessorNumber
, EnableAP
, HealthFlag
);
172 Get the handle number for the calling processor.
174 @param[in] MpServices MP_SERVICES structure.
175 @param[out] ProcessorNumber The handle number for the calling processor.
177 @retval EFI_SUCCESS Get the handle number for the calling processor successfully.
178 @retval Others Get the handle number for the calling processor unsuccessfully.
181 MpServicesUnitTestWhoAmI (
182 IN MP_SERVICES MpServices
,
183 OUT UINTN
*ProcessorNumber
186 return MpServices
.Protocol
->WhoAmI (MpServices
.Protocol
, ProcessorNumber
);
190 Standard DXE driver or UEFI application entry point for unit test execution from DXE or UEFI Shell.
191 Initialize the unit test framework, suite, and unit tests for the EfiMpServiceProtocol and run the unit test.
193 @param[in] ImageHandle The firmware allocated handle for the EFI image.
194 @param[in] SystemTable A pointer to the EFI System Table.
200 IN EFI_HANDLE ImageHandle
,
201 IN EFI_SYSTEM_TABLE
*SystemTable
205 UNIT_TEST_FRAMEWORK_HANDLE Framework
;
206 MP_SERVICE_UT_CONTEXT Context
;
209 Context
.MpServices
.Ppi
= NULL
;
210 Context
.CommonBuffer
= NULL
;
211 Context
.DisabledApNumber
= NULL
;
213 DEBUG ((DEBUG_INFO
, "%a v%a\n", UNIT_TEST_NAME
, UNIT_TEST_VERSION
));
216 // Start setting up the test framework for running the tests.
218 Status
= InitUnitTestFramework (&Framework
, UNIT_TEST_NAME
, gEfiCallerBaseName
, UNIT_TEST_VERSION
);
219 if (EFI_ERROR (Status
)) {
220 DEBUG ((DEBUG_ERROR
, "Failed in InitUnitTestFramework. Status = %r\n", Status
));
225 // Create test suite and unit tests for both EdkiiPeiMpServices2Ppi and EfiMpServiceProtocol.
227 Status
= AddCommonTestCase (Framework
, &Context
);
228 if (EFI_ERROR (Status
)) {
229 DEBUG ((DEBUG_ERROR
, "Failed in AddCommonTestCase. Status = %r\n", Status
));
234 // Execute the tests.
236 Status
= RunAllTestSuites (Framework
);
239 if (Framework
!= NULL
) {
240 FreeUnitTestFramework (Framework
);