TianoCore EDK2 master
Loading...
Searching...
No Matches
EdkiiPeiMpServices2PpiUnitTest.c
Go to the documentation of this file.
1
13
14#define UNIT_TEST_NAME "EdkiiPeiMpServices2Ppi Unit Test"
15#define UNIT_TEST_VERSION "0.1"
16
27 OUT MP_SERVICES *MpServices
28 )
29{
30 return PeiServicesLocatePpi (&gEdkiiPeiMpServices2PpiGuid, 0, NULL, (VOID **)&MpServices->Ppi);
31}
32
47 IN MP_SERVICES MpServices,
48 OUT UINTN *NumberOfProcessors,
49 OUT UINTN *NumberOfEnabledProcessors
50 )
51{
52 return MpServices.Ppi->GetNumberOfProcessors (MpServices.Ppi, NumberOfProcessors, NumberOfEnabledProcessors);
53}
54
67 IN MP_SERVICES MpServices,
68 IN UINTN ProcessorNumber,
69 OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer
70 )
71{
72 return MpServices.Ppi->GetProcessorInfo (MpServices.Ppi, ProcessorNumber, ProcessorInfoBuffer);
73}
74
93 IN MP_SERVICES MpServices,
94 IN EFI_AP_PROCEDURE Procedure,
95 IN BOOLEAN SingleThread,
96 IN UINTN TimeoutInMicroSeconds,
97 IN VOID *ProcedureArgument
98 )
99{
100 return MpServices.Ppi->StartupAllAPs (MpServices.Ppi, Procedure, SingleThread, TimeoutInMicroSeconds, ProcedureArgument);
101}
102
119 IN MP_SERVICES MpServices,
120 IN EFI_AP_PROCEDURE Procedure,
121 IN UINTN ProcessorNumber,
122 IN UINTN TimeoutInMicroSeconds,
123 IN VOID *ProcedureArgument
124 )
125{
126 return MpServices.Ppi->StartupThisAP (MpServices.Ppi, Procedure, ProcessorNumber, TimeoutInMicroSeconds, ProcedureArgument);
127}
128
141 IN MP_SERVICES MpServices,
142 IN UINTN ProcessorNumber,
143 IN BOOLEAN EnableOldBSP
144 )
145{
146 return MpServices.Ppi->SwitchBSP (MpServices.Ppi, ProcessorNumber, EnableOldBSP);
147}
148
162 IN MP_SERVICES MpServices,
163 IN UINTN ProcessorNumber,
164 IN BOOLEAN EnableAP,
165 IN UINT32 *HealthFlag
166 )
167{
168 return MpServices.Ppi->EnableDisableAP (MpServices.Ppi, ProcessorNumber, EnableAP, HealthFlag);
169}
170
182 IN MP_SERVICES MpServices,
183 OUT UINTN *ProcessorNumber
184 )
185{
186 return MpServices.Ppi->WhoAmI (MpServices.Ppi, ProcessorNumber);
187}
188
203 IN MP_SERVICES MpServices,
204 IN EFI_AP_PROCEDURE Procedure,
205 IN UINTN TimeoutInMicroSeconds,
206 IN VOID *ProcedureArgument
207 )
208{
209 return MpServices.Ppi->StartupAllCPUs (MpServices.Ppi, Procedure, TimeoutInMicroSeconds, ProcedureArgument);
210}
211
217VOID
219 IN OUT VOID *Buffer
220 )
221{
222 EFI_STATUS Status;
223 UINTN ProcessorNumber;
224 volatile BOOLEAN InfiniteLoop;
225 MP_SERVICE_UT_CONTEXT *LocalContext;
226
227 LocalContext = (MP_SERVICE_UT_CONTEXT *)Buffer;
228
229 Status = MpServicesUnitTestWhoAmI (LocalContext->MpServices, &ProcessorNumber);
230 ASSERT_EFI_ERROR (Status);
231
232 if (ProcessorNumber == LocalContext->BspNumber) {
233 InfiniteLoop = FALSE;
234 } else {
235 InfiniteLoop = TRUE;
236 }
237
238 while (InfiniteLoop) {
239 }
240}
241
247VOID
249 IN OUT VOID *Buffer
250 )
251{
252 MP_SERVICE_UT_CONTEXT *LocalContext;
253
254 LocalContext = (MP_SERVICE_UT_CONTEXT *)Buffer;
255
256 LocalContext->ApProcedureReturnStatus = MpServicesUnitTestStartupAllCPUs (
257 LocalContext->MpServices,
259 0,
260 NULL
261 );
262}
263
275EFIAPI
277 IN UNIT_TEST_CONTEXT Context
278 )
279{
280 EFI_STATUS Status;
281 UINTN ProcessorIndex;
282 MP_SERVICE_UT_CONTEXT *LocalContext;
283
284 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
285
286 SetMem (LocalContext->CommonBuffer, LocalContext->NumberOfProcessors * sizeof (*LocalContext->CommonBuffer), 0xFF);
288 LocalContext->MpServices,
290 0,
291 (VOID *)LocalContext
292 );
294
295 for (ProcessorIndex = 0; ProcessorIndex < LocalContext->NumberOfProcessors; ProcessorIndex++) {
296 UT_ASSERT_TRUE (LocalContext->CommonBuffer[ProcessorIndex] == ProcessorIndex);
297 }
298
299 return UNIT_TEST_PASSED;
300}
301
313EFIAPI
315 IN UNIT_TEST_CONTEXT Context
316 )
317{
318 EFI_STATUS Status;
319 UINTN ApNumber;
320 MP_SERVICE_UT_CONTEXT *LocalContext;
321
322 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
323
324 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
325 LocalContext->ApNumber = ApNumber;
327 LocalContext->MpServices,
329 ApNumber,
330 0,
331 (VOID *)LocalContext
332 );
333
334 if (ApNumber == LocalContext->BspNumber) {
335 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
336 } else {
338 UT_ASSERT_STATUS_EQUAL (LocalContext->ApProcedureReturnStatus, EFI_DEVICE_ERROR);
339 }
340 }
341
342 return UNIT_TEST_PASSED;
343}
344
356EFIAPI
358 IN UNIT_TEST_CONTEXT Context
359 )
360{
361 EFI_STATUS Status;
362 MP_SERVICE_UT_CONTEXT *LocalContext;
363
364 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
365
367 LocalContext->MpServices,
369 RUN_PROCEDURE_TIMEOUT_VALUE,
370 (VOID *)LocalContext
371 );
372 UT_ASSERT_STATUS_EQUAL (Status, EFI_TIMEOUT);
373
374 return UNIT_TEST_PASSED;
375}
376
388 IN UNIT_TEST_FRAMEWORK_HANDLE Framework,
390 )
391{
392 EFI_STATUS Status;
393 UNIT_TEST_SUITE_HANDLE MpServiceStartupAllCPUsTestSuite;
394
395 MpServiceStartupAllCPUsTestSuite = NULL;
396
397 //
398 // Test StartupAllCPUs function
399 //
400 Status = CreateUnitTestSuite (&MpServiceStartupAllCPUsTestSuite, Framework, "Execute a caller provided function on all enabled CPUs", "MpServices.StartupAllCPUs", NULL, NULL);
401 if (EFI_ERROR (Status)) {
402 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for MpServiceStartupAllCPUs Test Suite\n"));
403 return Status;
404 }
405
406 AddTestCase (MpServiceStartupAllCPUsTestSuite, "Test StartupAllCPUs 1", "TestStartupAllCPUs1", TestStartupAllCPUs1, InitUTContext, CheckUTContext, Context);
407 AddTestCase (MpServiceStartupAllCPUsTestSuite, "Test StartupAllCPUs 2", "TestStartupAllCPUs2", TestStartupAllCPUs2, InitUTContext, CheckUTContext, Context);
408 AddTestCase (MpServiceStartupAllCPUsTestSuite, "Test StartupAllCPUs 3", "TestStartupAllCPUs3", TestStartupAllCPUs3, InitUTContext, CheckUTContext, Context);
409
410 return EFI_SUCCESS;
411}
412
422EFIAPI
424 IN EFI_PEI_FILE_HANDLE FileHandle,
425 IN CONST EFI_PEI_SERVICES **PeiServices
426 )
427{
428 EFI_STATUS Status;
429 UNIT_TEST_FRAMEWORK_HANDLE Framework;
430 MP_SERVICE_UT_CONTEXT Context;
431
432 Framework = NULL;
433 Context.MpServices.Ppi = NULL;
434 Context.CommonBuffer = NULL;
435 Context.DisabledApNumber = NULL;
436
437 DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_NAME, UNIT_TEST_VERSION));
438
439 //
440 // Start setting up the test framework for running the tests.
441 //
442 Status = InitUnitTestFramework (&Framework, UNIT_TEST_NAME, gEfiCallerBaseName, UNIT_TEST_VERSION);
443 if (EFI_ERROR (Status)) {
444 DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status));
445 goto EXIT;
446 }
447
448 //
449 // Create test suite and unit tests only for EdkiiPeiMpServices2Ppi.
450 //
451 Status = AddTestCaseOnlyForEdkiiPeiMpServices2Ppi (Framework, &Context);
452 if (EFI_ERROR (Status)) {
453 DEBUG ((DEBUG_ERROR, "Failed in AddTestCaseOnlyForEdkiiPeiMpServices2Ppi. Status = %r\n", Status));
454 goto EXIT;
455 }
456
457 //
458 // Create test suite and unit tests for both EdkiiPeiMpServices2Ppi and EfiMpServiceProtocol.
459 //
460 Status = AddCommonTestCase (Framework, &Context);
461 if (EFI_ERROR (Status)) {
462 DEBUG ((DEBUG_ERROR, "Failed in AddCommonTestCase. Status = %r\n", Status));
463 goto EXIT;
464 }
465
466 //
467 // Execute the tests.
468 //
469 Status = RunAllTestSuites (Framework);
470
471EXIT:
472 if (Framework != NULL) {
473 FreeUnitTestFramework (Framework);
474 }
475
476 return Status;
477}
UINT64 UINTN
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
EFI_STATUS AddCommonTestCase(IN UNIT_TEST_FRAMEWORK_HANDLE Framework)
EFI_STATUS MpServicesUnitTestWhoAmI(IN MP_SERVICES MpServices, OUT UINTN *ProcessorNumber)
UNIT_TEST_STATUS EFIAPI TestStartupAllCPUs1(IN UNIT_TEST_CONTEXT Context)
EFI_STATUS MpServicesUnitTestGetProcessorInfo(IN MP_SERVICES MpServices, IN UINTN ProcessorNumber, OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer)
VOID RunMpServiceStartupAllCPUsOnAp(IN OUT VOID *Buffer)
EFI_STATUS MpServicesUnitTestStartupAllAPs(IN MP_SERVICES MpServices, IN EFI_AP_PROCEDURE Procedure, IN BOOLEAN SingleThread, IN UINTN TimeoutInMicroSeconds, IN VOID *ProcedureArgument)
VOID ApInfiniteLoopProcedure(IN OUT VOID *Buffer)
EFI_STATUS MpServicesUnitTestGetNumberOfProcessors(IN MP_SERVICES MpServices, OUT UINTN *NumberOfProcessors, OUT UINTN *NumberOfEnabledProcessors)
EFI_STATUS MpServicesUnitTestEnableDisableAP(IN MP_SERVICES MpServices, IN UINTN ProcessorNumber, IN BOOLEAN EnableAP, IN UINT32 *HealthFlag)
EFI_STATUS AddTestCaseOnlyForEdkiiPeiMpServices2Ppi(IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN MP_SERVICE_UT_CONTEXT *Context)
UNIT_TEST_STATUS EFIAPI TestStartupAllCPUs3(IN UNIT_TEST_CONTEXT Context)
EFI_STATUS MpServicesUnitTestStartupAllCPUs(IN MP_SERVICES MpServices, IN EFI_AP_PROCEDURE Procedure, IN UINTN TimeoutInMicroSeconds, IN VOID *ProcedureArgument)
EFI_STATUS EFIAPI PeiEntryPoint(IN EFI_PEI_FILE_HANDLE FileHandle, IN CONST EFI_PEI_SERVICES **PeiServices)
EFI_STATUS MpServicesUnitTestSwitchBSP(IN MP_SERVICES MpServices, IN UINTN ProcessorNumber, IN BOOLEAN EnableOldBSP)
UNIT_TEST_STATUS EFIAPI TestStartupAllCPUs2(IN UNIT_TEST_CONTEXT Context)
EFI_STATUS MpServicesUnitTestStartupThisAP(IN MP_SERVICES MpServices, IN EFI_AP_PROCEDURE Procedure, IN UINTN ProcessorNumber, IN UINTN TimeoutInMicroSeconds, IN VOID *ProcedureArgument)
EFI_STATUS MpServicesUnitTestGetMpServices(OUT MP_SERVICES *MpServices)
VOID StoreCpuNumbers(IN OUT VOID *Buffer)
VOID EFIAPI CheckUTContext(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI InitUTContext(IN UNIT_TEST_CONTEXT Context)
VOID EmptyProcedure(IN OUT VOID *Buffer)
EFI_STATUS EFIAPI PeiServicesLocatePpi(IN CONST EFI_GUID *Guid, IN UINTN Instance, IN OUT EFI_PEI_PPI_DESCRIPTOR **PpiDescriptor, IN OUT VOID **Ppi)
#define NULL
Definition: Base.h:319
#define CONST
Definition: Base.h:259
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
VOID(EFIAPI * EFI_AP_PROCEDURE)(IN OUT VOID *Buffer)
Definition: PiMultiPhase.h:198
VOID * EFI_PEI_FILE_HANDLE
Definition: PiPeiCis.h:26
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
EFI_STATUS EFIAPI RunAllTestSuites(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
Definition: RunTests.c:145
VOID * UNIT_TEST_CONTEXT
Definition: UnitTestLib.h:54
#define UT_ASSERT_TRUE(Expression)
Definition: UnitTestLib.h:350
#define UT_ASSERT_STATUS_EQUAL(Status, Expected)
Definition: UnitTestLib.h:427
EFI_STATUS EFIAPI CreateUnitTestSuite(OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle, IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *Name, IN UNIT_TEST_SUITE_SETUP Setup OPTIONAL, IN UNIT_TEST_SUITE_TEARDOWN Teardown OPTIONAL)
Definition: UnitTestLib.c:326
EFI_STATUS EFIAPI FreeUnitTestFramework(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
Definition: UnitTestLib.c:150
EFI_STATUS EFIAPI AddTestCase(IN UNIT_TEST_SUITE_HANDLE SuiteHandle, IN CHAR8 *Description, IN CHAR8 *Name, IN UNIT_TEST_FUNCTION Function, IN UNIT_TEST_PREREQUISITE Prerequisite OPTIONAL, IN UNIT_TEST_CLEANUP CleanUp OPTIONAL, IN UNIT_TEST_CONTEXT Context OPTIONAL)
Definition: UnitTestLib.c:426
EFI_STATUS EFIAPI InitUnitTestFramework(OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *ShortTitle, IN CHAR8 *VersionString)
Definition: UnitTestLib.c:204
UINT32 UNIT_TEST_STATUS
Definition: UnitTestLib.h:16
#define UT_ASSERT_NOT_EFI_ERROR(Status)
Definition: UnitTestLib.h:414