]> git.proxmox.com Git - mirror_edk2.git/blob - UefiCpuPkg/Test/UnitTest/EfiMpServicesPpiProtocol/EfiMpServicesUnitTestCommom.c
UefiCpuPkg/Test: Add unit tests for MP service PPI and Protocol
[mirror_edk2.git] / UefiCpuPkg / Test / UnitTest / EfiMpServicesPpiProtocol / EfiMpServicesUnitTestCommom.c
1 /** @file
2 Common code to test EdkiiPeiMpServices2Ppi and EfiMpServiceProtocol.
3
4 Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
5
6 SPDX-License-Identifier: BSD-2-Clause-Patent
7
8 **/
9
10 #include "EfiMpServicesUnitTestCommom.h"
11
12 /**
13 Prep routine for Unit test function.
14 To save the ProcessorNumber of disabled AP and temporarily enable it.
15
16 @param[in] Context Context pointer for this test.
17
18 @retval UNIT_TEST_PASSED Prep routine runs successful.
19 @retval UNIT_TEST_ERROR_TEST_FAILED Prep routine runs unsuccessful.
20 **/
21 UNIT_TEST_STATUS
22 EFIAPI
23 InitUTContext (
24 IN UNIT_TEST_CONTEXT Context
25 )
26 {
27 EFI_STATUS Status;
28 UINTN NumberOfProcessors;
29 UINTN NumberOfEnabledProcessors;
30 UINTN NumberOfDisabledAPs;
31 UINTN IndexOfDisabledAPs;
32 UINTN BspNumber;
33 UINTN ProcessorNumber;
34 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer;
35 MP_SERVICE_UT_CONTEXT *LocalContext;
36
37 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
38
39 if (LocalContext->MpServices.Ppi != NULL) {
40 return UNIT_TEST_PASSED;
41 }
42
43 Status = MpServicesUnitTestGetMpServices (&LocalContext->MpServices);
44 UT_ASSERT_NOT_EFI_ERROR (Status);
45
46 Status = MpServicesUnitTestWhoAmI (LocalContext->MpServices, &BspNumber);
47 UT_ASSERT_NOT_EFI_ERROR (Status);
48 DEBUG ((DEBUG_INFO, "%a: BspNumber = 0x%x\n", __FUNCTION__, BspNumber));
49
50 Status = MpServicesUnitTestGetNumberOfProcessors (
51 LocalContext->MpServices,
52 &NumberOfProcessors,
53 &NumberOfEnabledProcessors
54 );
55 UT_ASSERT_NOT_EFI_ERROR (Status);
56 DEBUG ((
57 DEBUG_INFO,
58 "%a: NumberOfProcessors = 0x%x, NumberOfEnabledProcessors = 0x%x\n",
59 __FUNCTION__,
60 NumberOfProcessors,
61 NumberOfEnabledProcessors
62 ));
63
64 LocalContext->BspNumber = BspNumber;
65 LocalContext->NumberOfProcessors = NumberOfProcessors;
66 LocalContext->NumberOfEnabledProcessors = NumberOfEnabledProcessors;
67
68 LocalContext->CommonBuffer = AllocatePages (EFI_SIZE_TO_PAGES (NumberOfProcessors * sizeof (*LocalContext->CommonBuffer)));
69 UT_ASSERT_NOT_NULL (LocalContext->CommonBuffer);
70
71 NumberOfDisabledAPs = NumberOfProcessors - NumberOfEnabledProcessors;
72 if ((NumberOfDisabledAPs > 0) && (LocalContext->DisabledApNumber == NULL)) {
73 LocalContext->DisabledApNumber = AllocatePages (EFI_SIZE_TO_PAGES (NumberOfDisabledAPs * sizeof (*LocalContext->DisabledApNumber)));
74 UT_ASSERT_NOT_NULL (LocalContext->DisabledApNumber);
75 ZeroMem (LocalContext->DisabledApNumber, NumberOfDisabledAPs * sizeof (*LocalContext->DisabledApNumber));
76
77 for (ProcessorNumber = 0, IndexOfDisabledAPs = 0; ProcessorNumber < LocalContext->NumberOfProcessors; ProcessorNumber++) {
78 Status = MpServicesUnitTestGetProcessorInfo (
79 LocalContext->MpServices,
80 ProcessorNumber,
81 &ProcessorInfoBuffer
82 );
83 UT_ASSERT_NOT_EFI_ERROR (Status);
84
85 if (!(ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT)) {
86 //
87 // Save ProcessorNumber of disabled AP.
88 //
89 LocalContext->DisabledApNumber[IndexOfDisabledAPs] = ProcessorNumber;
90 IndexOfDisabledAPs++;
91
92 DEBUG ((DEBUG_INFO, "%a: AP(0x%x) is disabled and temporarily enable it.\n", __FUNCTION__, ProcessorNumber));
93 Status = MpServicesUnitTestEnableDisableAP (
94 LocalContext->MpServices,
95 ProcessorNumber,
96 TRUE,
97 NULL
98 );
99 UT_ASSERT_NOT_EFI_ERROR (Status);
100 }
101 }
102
103 UT_ASSERT_TRUE (IndexOfDisabledAPs == NumberOfDisabledAPs);
104 }
105
106 return UNIT_TEST_PASSED;
107 }
108
109 /**
110 Cleanup routine for Unit test function.
111 If any processor is disabled unexpectedly then reenable it.
112
113 @param[in] Context Context pointer for this test.
114 **/
115 VOID
116 EFIAPI
117 CheckUTContext (
118 IN UNIT_TEST_CONTEXT Context
119 )
120 {
121 EFI_STATUS Status;
122 UINTN NumberOfProcessors;
123 UINTN NumberOfEnabledProcessors;
124 UINTN BspNumber;
125 UINTN ProcessorNumber;
126 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer;
127 MP_SERVICE_UT_CONTEXT *LocalContext;
128
129 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
130 ASSERT (LocalContext->MpServices.Ppi != NULL);
131
132 Status = MpServicesUnitTestWhoAmI (LocalContext->MpServices, &BspNumber);
133 ASSERT_EFI_ERROR (Status);
134
135 if (BspNumber != LocalContext->BspNumber) {
136 LocalContext->BspNumber = BspNumber;
137 DEBUG ((DEBUG_INFO, "%a: New BspNumber = 0x%x\n", __FUNCTION__, BspNumber));
138 }
139
140 ASSERT (BspNumber == LocalContext->BspNumber);
141
142 Status = MpServicesUnitTestGetNumberOfProcessors (
143 LocalContext->MpServices,
144 &NumberOfProcessors,
145 &NumberOfEnabledProcessors
146 );
147 ASSERT_EFI_ERROR (Status);
148
149 if (NumberOfProcessors != LocalContext->NumberOfProcessors) {
150 LocalContext->NumberOfProcessors = NumberOfProcessors;
151 DEBUG ((DEBUG_INFO, "%a: New NumberOfProcessors = 0x%x\n", __FUNCTION__, NumberOfProcessors));
152 }
153
154 if (NumberOfEnabledProcessors != LocalContext->NumberOfProcessors) {
155 DEBUG ((DEBUG_INFO, "%a: New NumberOfEnabledProcessors = 0x%x\n", __FUNCTION__, NumberOfEnabledProcessors));
156
157 for (ProcessorNumber = 0; ProcessorNumber < LocalContext->NumberOfProcessors; ProcessorNumber++) {
158 Status = MpServicesUnitTestGetProcessorInfo (
159 LocalContext->MpServices,
160 ProcessorNumber,
161 &ProcessorInfoBuffer
162 );
163 ASSERT_EFI_ERROR (Status);
164
165 if (!(ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT)) {
166 DEBUG ((DEBUG_INFO, "%a: AP(0x%x) is disabled unexpectedly and reenable it.\n", __FUNCTION__, ProcessorNumber));
167 Status = MpServicesUnitTestEnableDisableAP (
168 LocalContext->MpServices,
169 ProcessorNumber,
170 TRUE,
171 NULL
172 );
173 ASSERT_EFI_ERROR (Status);
174 }
175 }
176 }
177 }
178
179 /**
180 Cleanup routine for Unit test function.
181 It will be called by the last "AddTestCase" to restore AP state and free pointer.
182
183 @param[in] Context Context pointer for this test.
184 **/
185 VOID
186 EFIAPI
187 FreeUTContext (
188 IN UNIT_TEST_CONTEXT Context
189 )
190 {
191 EFI_STATUS Status;
192 UINTN NumberOfDisabledAPs;
193 UINTN IndexOfDisabledAPs;
194 MP_SERVICE_UT_CONTEXT *LocalContext;
195
196 CheckUTContext (Context);
197
198 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
199 ASSERT (LocalContext->MpServices.Ppi != NULL);
200
201 if (LocalContext->DisabledApNumber != NULL) {
202 NumberOfDisabledAPs = LocalContext->NumberOfProcessors - LocalContext->NumberOfEnabledProcessors;
203 for (IndexOfDisabledAPs = 0; IndexOfDisabledAPs < NumberOfDisabledAPs; IndexOfDisabledAPs++) {
204 DEBUG ((
205 DEBUG_INFO,
206 "%a: Disable AP(0x%x) to restore its state.\n",
207 __FUNCTION__,
208 LocalContext->DisabledApNumber[IndexOfDisabledAPs]
209 ));
210
211 Status = MpServicesUnitTestEnableDisableAP (
212 LocalContext->MpServices,
213 LocalContext->DisabledApNumber[IndexOfDisabledAPs],
214 FALSE,
215 NULL
216 );
217 ASSERT_EFI_ERROR (Status);
218 }
219
220 FreePages (LocalContext->DisabledApNumber, EFI_SIZE_TO_PAGES (NumberOfDisabledAPs * sizeof (*LocalContext->DisabledApNumber)));
221 }
222
223 if (LocalContext->CommonBuffer != NULL) {
224 FreePages (LocalContext->CommonBuffer, EFI_SIZE_TO_PAGES (LocalContext->NumberOfProcessors * sizeof (*LocalContext->CommonBuffer)));
225 }
226 }
227
228 /**
229 Produce to store ProcessorNumber in the corresponding location of CommonBuffer.
230
231 @param[in,out] Buffer The pointer to private data buffer.
232 **/
233 VOID
234 StoreCpuNumbers (
235 IN OUT VOID *Buffer
236 )
237 {
238 EFI_STATUS Status;
239 UINTN ProcessorNumber;
240 MP_SERVICE_UT_CONTEXT *LocalContext;
241
242 LocalContext = (MP_SERVICE_UT_CONTEXT *)Buffer;
243
244 Status = MpServicesUnitTestWhoAmI (LocalContext->MpServices, &ProcessorNumber);
245 ASSERT_EFI_ERROR (Status);
246
247 //
248 // The layout of CommonBuffer (E.g. BspNumber = 2 and NumberOfProcessors = 6)
249 // Index 00 01 02 03 04 05
250 // Value 00 01 02 03 04 05
251 //
252 if (ProcessorNumber < LocalContext->NumberOfProcessors) {
253 LocalContext->CommonBuffer[ProcessorNumber] = ProcessorNumber;
254 }
255 }
256
257 /**
258 Produce to store the ProcessorNumber of AP execution order in CommonBuffer.
259
260 @param[in,out] Buffer The pointer to private data buffer.
261 **/
262 VOID
263 StoreAPsExecutionOrder (
264 IN OUT VOID *Buffer
265 )
266 {
267 EFI_STATUS Status;
268 UINTN ProcessorNumber;
269 UINTN *ApCounter;
270 MP_SERVICE_UT_CONTEXT *LocalContext;
271
272 LocalContext = (MP_SERVICE_UT_CONTEXT *)Buffer;
273
274 Status = MpServicesUnitTestWhoAmI (LocalContext->MpServices, &ProcessorNumber);
275 ASSERT_EFI_ERROR (Status);
276
277 //
278 // The layout of CommonBuffer (E.g. BspNumber = 2 and NumberOfProcessors = 6)
279 // Index 00 01 02 03 04 05
280 // Value 00 01 03 04 05 ApCounter(5)
281 //
282 ApCounter = &(LocalContext->CommonBuffer[LocalContext->NumberOfProcessors - 1]);
283 LocalContext->CommonBuffer[*ApCounter] = ProcessorNumber;
284 (*ApCounter)++;
285 }
286
287 /**
288 Infinite loop procedure to be run on specified CPU.
289
290 @param[in,out] Buffer The pointer to private data buffer.
291 **/
292 VOID
293 InfiniteLoopProcedure (
294 IN OUT VOID *Buffer
295 )
296 {
297 volatile BOOLEAN InfiniteLoop;
298
299 InfiniteLoop = TRUE;
300
301 while (InfiniteLoop) {
302 }
303 }
304
305 /**
306 Empty procedure to be run on specified CPU.
307
308 @param[in,out] Buffer The pointer to private data buffer.
309 **/
310 VOID
311 EmptyProcedure (
312 IN OUT VOID *Buffer
313 )
314 {
315 }
316
317 /**
318 Procedure to run MP service GetNumberOfProcessors on AP.
319
320 @param[in,out] Buffer The pointer to private data buffer.
321 **/
322 VOID
323 RunMpServiceGetNumberOfProcessorsOnAp (
324 IN OUT VOID *Buffer
325 )
326 {
327 UINTN NumberOfProcessors;
328 UINTN NumberOfEnabledProcessors;
329 MP_SERVICE_UT_CONTEXT *LocalContext;
330
331 LocalContext = (MP_SERVICE_UT_CONTEXT *)Buffer;
332
333 LocalContext->ApProcedureReturnStatus = MpServicesUnitTestGetNumberOfProcessors (
334 LocalContext->MpServices,
335 &NumberOfProcessors,
336 &NumberOfEnabledProcessors
337 );
338 }
339
340 /**
341 Procedure to run MP service GetProcessorInfo on AP.
342
343 @param[in,out] Buffer The pointer to private data buffer.
344 **/
345 VOID
346 RunMpServiceGetProcessorInfoOnAp (
347 IN OUT VOID *Buffer
348 )
349 {
350 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer;
351 MP_SERVICE_UT_CONTEXT *LocalContext;
352
353 LocalContext = (MP_SERVICE_UT_CONTEXT *)Buffer;
354
355 LocalContext->ApProcedureReturnStatus = MpServicesUnitTestGetProcessorInfo (
356 LocalContext->MpServices,
357 LocalContext->ApNumber,
358 &ProcessorInfoBuffer
359 );
360 }
361
362 /**
363 Procedure to run MP service EnableDisableAP on AP.
364
365 @param[in,out] Buffer The pointer to private data buffer.
366 **/
367 VOID
368 RunMpServiceEnableDisableAPOnAp (
369 IN OUT VOID *Buffer
370 )
371 {
372 MP_SERVICE_UT_CONTEXT *LocalContext;
373
374 LocalContext = (MP_SERVICE_UT_CONTEXT *)Buffer;
375
376 LocalContext->ApProcedureReturnStatus = MpServicesUnitTestEnableDisableAP (
377 LocalContext->MpServices,
378 LocalContext->ApNumber,
379 FALSE,
380 NULL
381 );
382 }
383
384 /**
385 Procedure to run MP service StartupThisAP on AP.
386
387 @param[in,out] Buffer The pointer to private data buffer.
388 **/
389 VOID
390 RunMpServiceStartupThisAPOnAp (
391 IN OUT VOID *Buffer
392 )
393 {
394 MP_SERVICE_UT_CONTEXT *LocalContext;
395
396 LocalContext = (MP_SERVICE_UT_CONTEXT *)Buffer;
397
398 LocalContext->ApProcedureReturnStatus = MpServicesUnitTestStartupThisAP (
399 LocalContext->MpServices,
400 (EFI_AP_PROCEDURE)EmptyProcedure,
401 LocalContext->ApNumber,
402 0,
403 NULL
404 );
405 }
406
407 /**
408 Procedure to run MP service StartupAllAPs on AP.
409
410 @param[in,out] Buffer The pointer to private data buffer.
411 **/
412 VOID
413 RunMpServiceStartupAllAPsOnAp (
414 IN OUT VOID *Buffer
415 )
416 {
417 MP_SERVICE_UT_CONTEXT *LocalContext;
418
419 LocalContext = (MP_SERVICE_UT_CONTEXT *)Buffer;
420
421 LocalContext->ApProcedureReturnStatus = MpServicesUnitTestStartupAllAPs (
422 LocalContext->MpServices,
423 (EFI_AP_PROCEDURE)EmptyProcedure,
424 FALSE,
425 0,
426 NULL
427 );
428 }
429
430 /**
431 Procedure to run MP service SwitchBSP on AP.
432
433 @param[in,out] Buffer The pointer to private data buffer.
434 **/
435 VOID
436 RunMpServiceSwitchBSPOnAp (
437 IN OUT VOID *Buffer
438 )
439 {
440 MP_SERVICE_UT_CONTEXT *LocalContext;
441
442 LocalContext = (MP_SERVICE_UT_CONTEXT *)Buffer;
443
444 LocalContext->ApProcedureReturnStatus = MpServicesUnitTestSwitchBSP (
445 LocalContext->MpServices,
446 LocalContext->ApNumber,
447 TRUE
448 );
449 }
450
451 /**
452 Unit test of MP service WhoAmI.
453 The range of ProcessorNumber should be from 0 to NumberOfCPUs minus 1.
454 The ProcessorNumbers of all CPUs are unique.
455
456 @param[in] Context Context pointer for this test.
457
458 @retval UNIT_TEST_PASSED The Unit test has completed and the test
459 case was successful.
460 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
461 **/
462 UNIT_TEST_STATUS
463 EFIAPI
464 TestWhoAmI1 (
465 IN UNIT_TEST_CONTEXT Context
466 )
467 {
468 EFI_STATUS Status;
469 UINTN ProcessorNumber;
470 UINTN ProcessorIndex;
471 MP_SERVICE_UT_CONTEXT *LocalContext;
472
473 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
474
475 Status = MpServicesUnitTestWhoAmI (
476 LocalContext->MpServices,
477 &ProcessorNumber
478 );
479 UT_ASSERT_NOT_EFI_ERROR (Status);
480 UT_ASSERT_TRUE (ProcessorNumber < LocalContext->NumberOfProcessors);
481
482 SetMem (LocalContext->CommonBuffer, LocalContext->NumberOfProcessors * sizeof (*LocalContext->CommonBuffer), 0xFF);
483 LocalContext->CommonBuffer[ProcessorNumber] = ProcessorNumber;
484
485 Status = MpServicesUnitTestStartupAllAPs (
486 LocalContext->MpServices,
487 (EFI_AP_PROCEDURE)StoreCpuNumbers,
488 FALSE,
489 0,
490 (VOID *)LocalContext
491 );
492 UT_ASSERT_NOT_EFI_ERROR (Status);
493
494 //
495 // The layout of CommonBuffer (E.g. BspNumber = 2 and NumberOfProcessors = 6)
496 // Index 00 01 02 03 04 05
497 // Value 00 01 02 03 04 05
498 //
499 for (ProcessorIndex = 0; ProcessorIndex < LocalContext->NumberOfProcessors; ProcessorIndex++) {
500 UT_ASSERT_TRUE (LocalContext->CommonBuffer[ProcessorIndex] == ProcessorIndex);
501 }
502
503 return UNIT_TEST_PASSED;
504 }
505
506 /**
507 Unit test of MP service GetNumberOfProcessors.
508 NumberOfProcessors should be greater that 0 and not less than NumberOfEnabledProcessors.
509
510 @param[in] Context Context pointer for this test.
511
512 @retval UNIT_TEST_PASSED The Unit test has completed and the test
513 case was successful.
514 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
515 **/
516 UNIT_TEST_STATUS
517 EFIAPI
518 TestGetNumberOfProcessors1 (
519 IN UNIT_TEST_CONTEXT Context
520 )
521 {
522 EFI_STATUS Status;
523 UINTN NumberOfProcessors;
524 UINTN NumberOfEnabledProcessors;
525 MP_SERVICE_UT_CONTEXT *LocalContext;
526
527 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
528
529 Status = MpServicesUnitTestGetNumberOfProcessors (
530 LocalContext->MpServices,
531 &NumberOfProcessors,
532 &NumberOfEnabledProcessors
533 );
534 UT_ASSERT_NOT_EFI_ERROR (Status);
535 UT_ASSERT_TRUE (NumberOfProcessors > 0 && NumberOfProcessors >= NumberOfEnabledProcessors);
536
537 return UNIT_TEST_PASSED;
538 }
539
540 /**
541 Unit test of MP service GetNumberOfProcessors.
542 When this service is called from an AP, the return status should be EFI_DEVICE_ERROR.
543
544 @param[in] Context Context pointer for this test.
545
546 @retval UNIT_TEST_PASSED The Unit test has completed and the test
547 case was successful.
548 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
549 **/
550 UNIT_TEST_STATUS
551 EFIAPI
552 TestGetNumberOfProcessors2 (
553 IN UNIT_TEST_CONTEXT Context
554 )
555 {
556 EFI_STATUS Status;
557 UINTN ApNumber;
558 MP_SERVICE_UT_CONTEXT *LocalContext;
559
560 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
561
562 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
563 LocalContext->ApNumber = ApNumber;
564 Status = MpServicesUnitTestStartupThisAP (
565 LocalContext->MpServices,
566 (EFI_AP_PROCEDURE)RunMpServiceGetNumberOfProcessorsOnAp,
567 ApNumber,
568 0,
569 (VOID *)LocalContext
570 );
571
572 if (ApNumber == LocalContext->BspNumber) {
573 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
574 } else {
575 UT_ASSERT_NOT_EFI_ERROR (Status);
576 UT_ASSERT_STATUS_EQUAL (LocalContext->ApProcedureReturnStatus, EFI_DEVICE_ERROR);
577 }
578 }
579
580 return UNIT_TEST_PASSED;
581 }
582
583 /**
584 Unit test of MP service GetNumberOfProcessors.
585 Call EnableDisableAP() to change the number of enabled AP.
586
587 @param[in] Context Context pointer for this test.
588
589 @retval UNIT_TEST_PASSED The Unit test has completed and the test
590 case was successful.
591 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
592 **/
593 UNIT_TEST_STATUS
594 EFIAPI
595 TestGetNumberOfProcessors3 (
596 IN UNIT_TEST_CONTEXT Context
597 )
598 {
599 EFI_STATUS Status;
600 UINTN ApNumber;
601 UINTN NumberOfProcessors;
602 UINTN NumberOfEnabledProcessors;
603 MP_SERVICE_UT_CONTEXT *LocalContext;
604
605 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
606
607 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
608 Status = MpServicesUnitTestEnableDisableAP (
609 LocalContext->MpServices,
610 ApNumber,
611 FALSE,
612 NULL
613 );
614
615 if (ApNumber == LocalContext->BspNumber) {
616 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
617 } else {
618 UT_ASSERT_NOT_EFI_ERROR (Status);
619
620 Status = MpServicesUnitTestGetNumberOfProcessors (
621 LocalContext->MpServices,
622 &NumberOfProcessors,
623 &NumberOfEnabledProcessors
624 );
625 UT_ASSERT_NOT_EFI_ERROR (Status);
626 UT_ASSERT_TRUE (NumberOfProcessors == LocalContext->NumberOfProcessors);
627
628 if (ApNumber < LocalContext->BspNumber) {
629 UT_ASSERT_TRUE (NumberOfEnabledProcessors == LocalContext->NumberOfProcessors - (ApNumber + 1));
630 } else {
631 UT_ASSERT_TRUE (NumberOfEnabledProcessors == LocalContext->NumberOfProcessors - ApNumber);
632 }
633 }
634 }
635
636 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
637 Status = MpServicesUnitTestEnableDisableAP (
638 LocalContext->MpServices,
639 ApNumber,
640 TRUE,
641 NULL
642 );
643
644 if (ApNumber == LocalContext->BspNumber) {
645 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
646 } else {
647 UT_ASSERT_NOT_EFI_ERROR (Status);
648
649 Status = MpServicesUnitTestGetNumberOfProcessors (
650 LocalContext->MpServices,
651 &NumberOfProcessors,
652 &NumberOfEnabledProcessors
653 );
654 UT_ASSERT_NOT_EFI_ERROR (Status);
655 UT_ASSERT_TRUE (NumberOfProcessors == LocalContext->NumberOfProcessors);
656
657 if (ApNumber < LocalContext->BspNumber) {
658 UT_ASSERT_TRUE (NumberOfEnabledProcessors == ApNumber + 2);
659 } else {
660 UT_ASSERT_TRUE (NumberOfEnabledProcessors == ApNumber + 1);
661 }
662 }
663 }
664
665 return UNIT_TEST_PASSED;
666 }
667
668 /**
669 Unit test of MP service GetProcessorInfo.
670 When all the parameters are valid, all reserved bits of StatusFlag in ProcessorInfoBuffer should be set to zero.
671 When all the parameters are valid, the StatusFlag should not have an invalid value (The BSP can never be in the disabled state.).
672 When called with nonexistent processor handle, the return status should be EFI_NOT_FOUND.
673
674 @param[in] Context Context pointer for this test.
675
676 @retval UNIT_TEST_PASSED The Unit test has completed and the test
677 case was successful.
678 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
679 **/
680 UNIT_TEST_STATUS
681 EFIAPI
682 TestGetProcessorInfo1 (
683 IN UNIT_TEST_CONTEXT Context
684 )
685 {
686 EFI_STATUS Status;
687 UINTN ProcessorNumber;
688 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer;
689 MP_SERVICE_UT_CONTEXT *LocalContext;
690
691 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
692
693 for (ProcessorNumber = 0; ProcessorNumber <= LocalContext->NumberOfProcessors; ProcessorNumber++) {
694 Status = MpServicesUnitTestGetProcessorInfo (
695 LocalContext->MpServices,
696 ProcessorNumber,
697 &ProcessorInfoBuffer
698 );
699
700 if (ProcessorNumber == LocalContext->NumberOfProcessors) {
701 UT_ASSERT_STATUS_EQUAL (Status, EFI_NOT_FOUND);
702 } else {
703 UT_ASSERT_NOT_EFI_ERROR (Status);
704 UT_ASSERT_TRUE ((ProcessorInfoBuffer.StatusFlag & (UINT32) ~(PROCESSOR_AS_BSP_BIT|PROCESSOR_ENABLED_BIT|PROCESSOR_HEALTH_STATUS_BIT)) == 0);
705
706 if (ProcessorNumber == LocalContext->BspNumber) {
707 UT_ASSERT_TRUE ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) && (ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT));
708 } else {
709 UT_ASSERT_TRUE (!(ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT));
710 }
711 }
712 }
713
714 return UNIT_TEST_PASSED;
715 }
716
717 /**
718 Unit test of MP service GetProcessorInfo.
719 When this service is called from an AP, the return status should be EFI_DEVICE_ERROR.
720
721 @param[in] Context Context pointer for this test.
722
723 @retval UNIT_TEST_PASSED The Unit test has completed and the test
724 case was successful.
725 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
726 **/
727 UNIT_TEST_STATUS
728 EFIAPI
729 TestGetProcessorInfo2 (
730 IN UNIT_TEST_CONTEXT Context
731 )
732 {
733 EFI_STATUS Status;
734 UINTN ApNumber;
735 MP_SERVICE_UT_CONTEXT *LocalContext;
736
737 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
738
739 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
740 LocalContext->ApNumber = ApNumber;
741 Status = MpServicesUnitTestStartupThisAP (
742 LocalContext->MpServices,
743 (EFI_AP_PROCEDURE)RunMpServiceGetProcessorInfoOnAp,
744 ApNumber,
745 0,
746 (VOID *)LocalContext
747 );
748
749 if (ApNumber == LocalContext->BspNumber) {
750 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
751 } else {
752 UT_ASSERT_NOT_EFI_ERROR (Status);
753 UT_ASSERT_STATUS_EQUAL (LocalContext->ApProcedureReturnStatus, EFI_DEVICE_ERROR);
754 }
755 }
756
757 return UNIT_TEST_PASSED;
758 }
759
760 /**
761 Unit test of MP service EnableDisableAP.
762 When called with BSP number, the return status should be EFI_INVALID_PARAMETER.
763 When called with a nonexistent processor handle, the return status should be EFI_NOT_FOUND.
764 The AP should be really Enable/Disabled.
765
766 @param[in] Context Context pointer for this test.
767
768 @retval UNIT_TEST_PASSED The Unit test has completed and the test
769 case was successful.
770 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
771 **/
772 UNIT_TEST_STATUS
773 EFIAPI
774 TestEnableDisableAP1 (
775 IN UNIT_TEST_CONTEXT Context
776 )
777 {
778 EFI_STATUS Status;
779 UINTN ApNumber;
780 MP_SERVICE_UT_CONTEXT *LocalContext;
781
782 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
783
784 for (ApNumber = 0; ApNumber <= LocalContext->NumberOfProcessors; ApNumber++) {
785 Status = MpServicesUnitTestEnableDisableAP (
786 LocalContext->MpServices,
787 ApNumber,
788 FALSE,
789 NULL
790 );
791
792 if (ApNumber == LocalContext->BspNumber) {
793 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
794 } else if (ApNumber == LocalContext->NumberOfProcessors) {
795 UT_ASSERT_STATUS_EQUAL (Status, EFI_NOT_FOUND);
796 } else {
797 UT_ASSERT_NOT_EFI_ERROR (Status);
798
799 Status = MpServicesUnitTestStartupThisAP (
800 LocalContext->MpServices,
801 (EFI_AP_PROCEDURE)EmptyProcedure,
802 ApNumber,
803 0,
804 NULL
805 );
806 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
807
808 Status = MpServicesUnitTestEnableDisableAP (
809 LocalContext->MpServices,
810 ApNumber,
811 TRUE,
812 NULL
813 );
814 UT_ASSERT_NOT_EFI_ERROR (Status);
815
816 Status = MpServicesUnitTestStartupThisAP (
817 LocalContext->MpServices,
818 (EFI_AP_PROCEDURE)EmptyProcedure,
819 ApNumber,
820 0,
821 NULL
822 );
823 UT_ASSERT_NOT_EFI_ERROR (Status);
824 }
825 }
826
827 return UNIT_TEST_PASSED;
828 }
829
830 /**
831 Unit test of MP service EnableDisableAP.
832 When run this procedure on AP, the return status should be EFI_DEVICE_ERROR.
833
834 @param[in] Context Context pointer for this test.
835
836 @retval UNIT_TEST_PASSED The Unit test has completed and the test
837 case was successful.
838 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
839 **/
840 UNIT_TEST_STATUS
841 EFIAPI
842 TestEnableDisableAP2 (
843 IN UNIT_TEST_CONTEXT Context
844 )
845 {
846 EFI_STATUS Status;
847 UINTN ApNumber;
848 MP_SERVICE_UT_CONTEXT *LocalContext;
849
850 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
851
852 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
853 LocalContext->ApNumber = ApNumber;
854 Status = MpServicesUnitTestStartupThisAP (
855 LocalContext->MpServices,
856 (EFI_AP_PROCEDURE)RunMpServiceEnableDisableAPOnAp,
857 ApNumber,
858 0,
859 (VOID *)LocalContext
860 );
861
862 if (ApNumber == LocalContext->BspNumber) {
863 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
864 } else {
865 UT_ASSERT_NOT_EFI_ERROR (Status);
866 UT_ASSERT_STATUS_EQUAL (LocalContext->ApProcedureReturnStatus, EFI_DEVICE_ERROR);
867 }
868 }
869
870 return UNIT_TEST_PASSED;
871 }
872
873 /**
874 Unit test of MP service EnableDisableAP.
875 When run this procedure on AP, the return status should be EFI_DEVICE_ERROR.
876
877 @param[in] Context Context pointer for this test.
878
879 @retval UNIT_TEST_PASSED The Unit test has completed and the test
880 case was successful.
881 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
882 **/
883 UNIT_TEST_STATUS
884 EFIAPI
885 TestEnableDisableAP3 (
886 IN UNIT_TEST_CONTEXT Context
887 )
888 {
889 EFI_STATUS Status;
890 UINTN ApNumber;
891 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer;
892 UINT32 OldHealthFlag;
893 UINT32 NewHealthFlag;
894 MP_SERVICE_UT_CONTEXT *LocalContext;
895
896 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
897
898 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
899 Status = MpServicesUnitTestGetProcessorInfo (
900 LocalContext->MpServices,
901 ApNumber,
902 &ProcessorInfoBuffer
903 );
904 UT_ASSERT_NOT_EFI_ERROR (Status);
905
906 OldHealthFlag = ProcessorInfoBuffer.StatusFlag & PROCESSOR_HEALTH_STATUS_BIT;
907 NewHealthFlag = OldHealthFlag ^ PROCESSOR_HEALTH_STATUS_BIT;
908 Status = MpServicesUnitTestEnableDisableAP (
909 LocalContext->MpServices,
910 ApNumber,
911 TRUE,
912 &NewHealthFlag
913 );
914
915 if (ApNumber == LocalContext->BspNumber) {
916 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
917 } else {
918 UT_ASSERT_NOT_EFI_ERROR (Status);
919
920 Status = MpServicesUnitTestGetProcessorInfo (
921 LocalContext->MpServices,
922 ApNumber,
923 &ProcessorInfoBuffer
924 );
925 UT_ASSERT_NOT_EFI_ERROR (Status);
926 UT_ASSERT_TRUE ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_HEALTH_STATUS_BIT) == NewHealthFlag);
927
928 Status = MpServicesUnitTestEnableDisableAP (
929 LocalContext->MpServices,
930 ApNumber,
931 TRUE,
932 &OldHealthFlag
933 );
934 UT_ASSERT_NOT_EFI_ERROR (Status);
935 }
936 }
937
938 return UNIT_TEST_PASSED;
939 }
940
941 /**
942 Unit test of MP service StartupThisAP.
943 When called to startup a BSP, the return status should be EFI_INVALID_PARAMETER.
944 When called with a nonexistent processor handle, the return status should be EFI_NOT_FOUND.
945 The requested AP should execute the Procedure when called by StartupThisAP.
946
947 @param[in] Context Context pointer for this test.
948
949 @retval UNIT_TEST_PASSED The Unit test has completed and the test
950 case was successful.
951 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
952 **/
953 UNIT_TEST_STATUS
954 EFIAPI
955 TestStartupThisAP1 (
956 IN UNIT_TEST_CONTEXT Context
957 )
958 {
959 EFI_STATUS Status;
960 UINTN ApNumber;
961 UINTN ProcessorIndex;
962 MP_SERVICE_UT_CONTEXT *LocalContext;
963
964 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
965
966 for (ApNumber = 0; ApNumber <= LocalContext->NumberOfProcessors; ApNumber++) {
967 SetMem (LocalContext->CommonBuffer, LocalContext->NumberOfProcessors * sizeof (*LocalContext->CommonBuffer), 0xFF);
968 Status = MpServicesUnitTestStartupThisAP (
969 LocalContext->MpServices,
970 (EFI_AP_PROCEDURE)StoreCpuNumbers,
971 ApNumber,
972 0,
973 (VOID *)LocalContext
974 );
975
976 if (ApNumber == LocalContext->BspNumber) {
977 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
978 } else if (ApNumber == LocalContext->NumberOfProcessors) {
979 UT_ASSERT_STATUS_EQUAL (Status, EFI_NOT_FOUND);
980 } else {
981 UT_ASSERT_NOT_EFI_ERROR (Status);
982
983 for (ProcessorIndex = 0; ProcessorIndex < LocalContext->NumberOfProcessors; ProcessorIndex++) {
984 UT_ASSERT_TRUE (
985 ((ProcessorIndex == ApNumber) && (LocalContext->CommonBuffer[ProcessorIndex] == ProcessorIndex)) ||
986 ((ProcessorIndex != ApNumber) && (LocalContext->CommonBuffer[ProcessorIndex] == (UINTN) ~0))
987 );
988 }
989 }
990 }
991
992 return UNIT_TEST_PASSED;
993 }
994
995 /**
996 Unit test of MP service StartupThisAP.
997 When this service is called from an AP, the return status should be EFI_DEVICE_ERROR.
998
999 @param[in] Context Context pointer for this test.
1000
1001 @retval UNIT_TEST_PASSED The Unit test has completed and the test
1002 case was successful.
1003 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
1004 **/
1005 UNIT_TEST_STATUS
1006 EFIAPI
1007 TestStartupThisAP2 (
1008 IN UNIT_TEST_CONTEXT Context
1009 )
1010 {
1011 EFI_STATUS Status;
1012 UINTN ApNumber;
1013 MP_SERVICE_UT_CONTEXT *LocalContext;
1014
1015 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
1016
1017 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
1018 LocalContext->ApNumber = ApNumber;
1019 Status = MpServicesUnitTestStartupThisAP (
1020 LocalContext->MpServices,
1021 (EFI_AP_PROCEDURE)RunMpServiceStartupThisAPOnAp,
1022 ApNumber,
1023 0,
1024 (VOID *)LocalContext
1025 );
1026
1027 if (ApNumber == LocalContext->BspNumber) {
1028 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1029 } else {
1030 UT_ASSERT_NOT_EFI_ERROR (Status);
1031 UT_ASSERT_STATUS_EQUAL (LocalContext->ApProcedureReturnStatus, EFI_DEVICE_ERROR);
1032 }
1033 }
1034
1035 return UNIT_TEST_PASSED;
1036 }
1037
1038 /**
1039 Unit test of MP service StartupThisAP.
1040 When timeout expired before the requested AP has finished, the return status should be EFI_TIMEOUT.
1041
1042 @param[in] Context Context pointer for this test.
1043
1044 @retval UNIT_TEST_PASSED The Unit test has completed and the test
1045 case was successful.
1046 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
1047 **/
1048 UNIT_TEST_STATUS
1049 EFIAPI
1050 TestStartupThisAP3 (
1051 IN UNIT_TEST_CONTEXT Context
1052 )
1053 {
1054 EFI_STATUS Status;
1055 UINTN ApNumber;
1056 MP_SERVICE_UT_CONTEXT *LocalContext;
1057
1058 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
1059
1060 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
1061 Status = MpServicesUnitTestStartupThisAP (
1062 LocalContext->MpServices,
1063 (EFI_AP_PROCEDURE)InfiniteLoopProcedure,
1064 ApNumber,
1065 RUN_PROCEDURE_TIMEOUT_VALUE,
1066 NULL
1067 );
1068
1069 if (ApNumber == LocalContext->BspNumber) {
1070 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1071 } else {
1072 UT_ASSERT_STATUS_EQUAL (Status, EFI_TIMEOUT);
1073 }
1074 }
1075
1076 return UNIT_TEST_PASSED;
1077 }
1078
1079 /**
1080 Unit test of MP service StartupThisAP.
1081 When called with disabled AP, the return status should be EFI_INVALID_PARAMETER.
1082
1083 @param[in] Context Context pointer for this test.
1084
1085 @retval UNIT_TEST_PASSED The Unit test has completed and the test
1086 case was successful.
1087 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
1088 **/
1089 UNIT_TEST_STATUS
1090 EFIAPI
1091 TestStartupThisAP4 (
1092 IN UNIT_TEST_CONTEXT Context
1093 )
1094 {
1095 EFI_STATUS Status;
1096 UINTN ApNumber;
1097 MP_SERVICE_UT_CONTEXT *LocalContext;
1098
1099 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
1100
1101 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
1102 Status = MpServicesUnitTestEnableDisableAP (
1103 LocalContext->MpServices,
1104 ApNumber,
1105 FALSE,
1106 NULL
1107 );
1108
1109 if (ApNumber == LocalContext->BspNumber) {
1110 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1111 } else {
1112 UT_ASSERT_NOT_EFI_ERROR (Status);
1113
1114 Status = MpServicesUnitTestStartupThisAP (
1115 LocalContext->MpServices,
1116 (EFI_AP_PROCEDURE)EmptyProcedure,
1117 ApNumber,
1118 0,
1119 NULL
1120 );
1121 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1122
1123 Status = MpServicesUnitTestEnableDisableAP (
1124 LocalContext->MpServices,
1125 ApNumber,
1126 TRUE,
1127 NULL
1128 );
1129 UT_ASSERT_NOT_EFI_ERROR (Status);
1130
1131 Status = MpServicesUnitTestStartupThisAP (
1132 LocalContext->MpServices,
1133 (EFI_AP_PROCEDURE)EmptyProcedure,
1134 ApNumber,
1135 0,
1136 NULL
1137 );
1138 UT_ASSERT_NOT_EFI_ERROR (Status);
1139 }
1140 }
1141
1142 return UNIT_TEST_PASSED;
1143 }
1144
1145 /**
1146 Unit test of MP service StartupAllAPs.
1147 All APs should execute the Procedure when called by StartupAllAPs.
1148
1149 @param[in] Context Context pointer for this test.
1150
1151 @retval UNIT_TEST_PASSED The Unit test has completed and the test
1152 case was successful.
1153 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
1154 **/
1155 UNIT_TEST_STATUS
1156 EFIAPI
1157 TestStartupAllAPs1 (
1158 IN UNIT_TEST_CONTEXT Context
1159 )
1160 {
1161 EFI_STATUS Status;
1162 UINTN ProcessorIndex;
1163 MP_SERVICE_UT_CONTEXT *LocalContext;
1164
1165 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
1166
1167 SetMem (LocalContext->CommonBuffer, LocalContext->NumberOfProcessors * sizeof (*LocalContext->CommonBuffer), 0xFF);
1168 Status = MpServicesUnitTestStartupAllAPs (
1169 LocalContext->MpServices,
1170 (EFI_AP_PROCEDURE)StoreCpuNumbers,
1171 FALSE,
1172 0,
1173 (VOID *)LocalContext
1174 );
1175 UT_ASSERT_NOT_EFI_ERROR (Status);
1176
1177 for (ProcessorIndex = 0; ProcessorIndex < LocalContext->NumberOfProcessors; ProcessorIndex++) {
1178 UT_ASSERT_TRUE (
1179 ((ProcessorIndex == LocalContext->BspNumber) && (LocalContext->CommonBuffer[ProcessorIndex] == (UINTN) ~0)) ||
1180 ((ProcessorIndex != LocalContext->BspNumber) && (LocalContext->CommonBuffer[ProcessorIndex] == ProcessorIndex))
1181 );
1182 }
1183
1184 return UNIT_TEST_PASSED;
1185 }
1186
1187 /**
1188 Unit test of MP service StartupAllAPs.
1189 When called in single thread, the return status should be EFI_SUCCESS and AP executes in ascending order
1190 of processor handle number.
1191
1192 @param[in] Context Context pointer for this test.
1193
1194 @retval UNIT_TEST_PASSED The Unit test has completed and the test
1195 case was successful.
1196 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
1197 **/
1198 UNIT_TEST_STATUS
1199 EFIAPI
1200 TestStartupAllAPs2 (
1201 IN UNIT_TEST_CONTEXT Context
1202 )
1203 {
1204 EFI_STATUS Status;
1205 UINTN ProcessorIndex;
1206 MP_SERVICE_UT_CONTEXT *LocalContext;
1207
1208 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
1209
1210 ZeroMem (LocalContext->CommonBuffer, LocalContext->NumberOfProcessors * sizeof (*LocalContext->CommonBuffer));
1211 Status = MpServicesUnitTestStartupAllAPs (
1212 LocalContext->MpServices,
1213 (EFI_AP_PROCEDURE)StoreAPsExecutionOrder,
1214 TRUE,
1215 0,
1216 (VOID *)LocalContext
1217 );
1218 UT_ASSERT_NOT_EFI_ERROR (Status);
1219
1220 //
1221 // The layout of CommonBuffer (E.g. BspNumber = 2 and NumberOfProcessors = 6)
1222 // Index 00 01 02 03 04 05
1223 // Value 00 01 03 04 05 ApCounter(5)
1224 //
1225 for (ProcessorIndex = 0; ProcessorIndex < LocalContext->NumberOfProcessors - 2; ProcessorIndex++) {
1226 UT_ASSERT_TRUE (LocalContext->CommonBuffer[ProcessorIndex] < LocalContext->CommonBuffer[ProcessorIndex + 1]);
1227 }
1228
1229 UT_ASSERT_EQUAL (LocalContext->CommonBuffer[LocalContext->NumberOfProcessors - 1], LocalContext->NumberOfProcessors - 1);
1230
1231 return UNIT_TEST_PASSED;
1232 }
1233
1234 /**
1235 Unit test of MP service StartupAllAPs.
1236 When this service is called from an AP, the return status should be EFI_DEVICE_ERROR.
1237
1238 @param[in] Context Context pointer for this test.
1239
1240 @retval UNIT_TEST_PASSED The Unit test has completed and the test
1241 case was successful.
1242 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
1243 **/
1244 UNIT_TEST_STATUS
1245 EFIAPI
1246 TestStartupAllAPs3 (
1247 IN UNIT_TEST_CONTEXT Context
1248 )
1249 {
1250 EFI_STATUS Status;
1251 UINTN ApNumber;
1252 MP_SERVICE_UT_CONTEXT *LocalContext;
1253
1254 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
1255
1256 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
1257 LocalContext->ApNumber = ApNumber;
1258 Status = MpServicesUnitTestStartupThisAP (
1259 LocalContext->MpServices,
1260 (EFI_AP_PROCEDURE)RunMpServiceStartupAllAPsOnAp,
1261 ApNumber,
1262 0,
1263 (VOID *)LocalContext
1264 );
1265
1266 if (ApNumber == LocalContext->BspNumber) {
1267 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1268 } else {
1269 UT_ASSERT_NOT_EFI_ERROR (Status);
1270 UT_ASSERT_STATUS_EQUAL (LocalContext->ApProcedureReturnStatus, EFI_DEVICE_ERROR);
1271 }
1272 }
1273
1274 return UNIT_TEST_PASSED;
1275 }
1276
1277 /**
1278 Unit test of MP service StartupAllAPs.
1279 When called with all AP timeout, the return status should be EFI_TIMEOUT.
1280
1281 @param[in] Context Context pointer for this test.
1282
1283 @retval UNIT_TEST_PASSED The Unit test has completed and the test
1284 case was successful.
1285 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
1286 **/
1287 UNIT_TEST_STATUS
1288 EFIAPI
1289 TestStartupAllAPs4 (
1290 IN UNIT_TEST_CONTEXT Context
1291 )
1292 {
1293 EFI_STATUS Status;
1294 MP_SERVICE_UT_CONTEXT *LocalContext;
1295
1296 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
1297
1298 Status = MpServicesUnitTestStartupAllAPs (
1299 LocalContext->MpServices,
1300 (EFI_AP_PROCEDURE)InfiniteLoopProcedure,
1301 TRUE,
1302 RUN_PROCEDURE_TIMEOUT_VALUE,
1303 NULL
1304 );
1305 UT_ASSERT_STATUS_EQUAL (Status, EFI_TIMEOUT);
1306
1307 Status = MpServicesUnitTestStartupAllAPs (
1308 LocalContext->MpServices,
1309 (EFI_AP_PROCEDURE)InfiniteLoopProcedure,
1310 FALSE,
1311 RUN_PROCEDURE_TIMEOUT_VALUE,
1312 NULL
1313 );
1314 UT_ASSERT_STATUS_EQUAL (Status, EFI_TIMEOUT);
1315
1316 return UNIT_TEST_PASSED;
1317 }
1318
1319 /**
1320 Unit test of MP service StartupAllAPs.
1321 When called with the empty Procedure on all disabled APs, the return status should be EFI_NOT_STARTED.
1322
1323 @param[in] Context Context pointer for this test.
1324
1325 @retval UNIT_TEST_PASSED The Unit test has completed and the test
1326 case was successful.
1327 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
1328 **/
1329 UNIT_TEST_STATUS
1330 EFIAPI
1331 TestStartupAllAPs5 (
1332 IN UNIT_TEST_CONTEXT Context
1333 )
1334 {
1335 EFI_STATUS Status;
1336 UINTN ApNumber;
1337 MP_SERVICE_UT_CONTEXT *LocalContext;
1338
1339 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
1340
1341 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
1342 Status = MpServicesUnitTestEnableDisableAP (
1343 LocalContext->MpServices,
1344 ApNumber,
1345 FALSE,
1346 NULL
1347 );
1348
1349 if (ApNumber == LocalContext->BspNumber) {
1350 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1351 } else {
1352 UT_ASSERT_NOT_EFI_ERROR (Status);
1353 }
1354 }
1355
1356 Status = MpServicesUnitTestStartupAllAPs (
1357 LocalContext->MpServices,
1358 (EFI_AP_PROCEDURE)EmptyProcedure,
1359 FALSE,
1360 0,
1361 NULL
1362 );
1363 UT_ASSERT_STATUS_EQUAL (Status, EFI_NOT_STARTED);
1364
1365 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
1366 Status = MpServicesUnitTestEnableDisableAP (
1367 LocalContext->MpServices,
1368 ApNumber,
1369 TRUE,
1370 NULL
1371 );
1372
1373 if (ApNumber == LocalContext->BspNumber) {
1374 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1375 } else {
1376 UT_ASSERT_NOT_EFI_ERROR (Status);
1377 }
1378 }
1379
1380 return UNIT_TEST_PASSED;
1381 }
1382
1383 /**
1384 Unit test of MP service SwitchBSP.
1385 When switch current BSP to be BSP, the return status should be EFI_INVALID_PARAMETER.
1386 When switch nonexistent processor to be BSP, the return status should be EFI_NOT_FOUND.
1387 After switch BSP, all APs(includes new AP) should execute the Procedure when called by StartupAllAP.
1388
1389 @param[in] Context Context pointer for this test.
1390
1391 @retval UNIT_TEST_PASSED The Unit test has completed and the test
1392 case was successful.
1393 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
1394 **/
1395 UNIT_TEST_STATUS
1396 EFIAPI
1397 TestSwitchBSP1 (
1398 IN UNIT_TEST_CONTEXT Context
1399 )
1400 {
1401 EFI_STATUS Status;
1402 UINTN NewBspNumber;
1403 UINTN ProcessorIndex;
1404 MP_SERVICE_UT_CONTEXT *LocalContext;
1405
1406 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
1407
1408 for (NewBspNumber = 0; NewBspNumber <= LocalContext->NumberOfProcessors; NewBspNumber++) {
1409 Status = MpServicesUnitTestSwitchBSP (
1410 LocalContext->MpServices,
1411 NewBspNumber,
1412 TRUE
1413 );
1414
1415 if (NewBspNumber == LocalContext->BspNumber) {
1416 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1417 } else if (NewBspNumber == LocalContext->NumberOfProcessors) {
1418 UT_ASSERT_STATUS_EQUAL (Status, EFI_NOT_FOUND);
1419 } else {
1420 UT_ASSERT_NOT_EFI_ERROR (Status);
1421
1422 SetMem (LocalContext->CommonBuffer, LocalContext->NumberOfProcessors * sizeof (*LocalContext->CommonBuffer), 0xFF);
1423 Status = MpServicesUnitTestStartupAllAPs (
1424 LocalContext->MpServices,
1425 (EFI_AP_PROCEDURE)StoreCpuNumbers,
1426 FALSE,
1427 0,
1428 (VOID *)LocalContext
1429 );
1430 UT_ASSERT_NOT_EFI_ERROR (Status);
1431
1432 for (ProcessorIndex = 0; ProcessorIndex < LocalContext->NumberOfProcessors; ProcessorIndex++) {
1433 UT_ASSERT_TRUE (
1434 ((ProcessorIndex == NewBspNumber) && (LocalContext->CommonBuffer[ProcessorIndex] == (UINTN) ~0)) ||
1435 ((ProcessorIndex != NewBspNumber) && (LocalContext->CommonBuffer[ProcessorIndex] == ProcessorIndex))
1436 );
1437 }
1438
1439 Status = MpServicesUnitTestSwitchBSP (
1440 LocalContext->MpServices,
1441 LocalContext->BspNumber,
1442 TRUE
1443 );
1444 UT_ASSERT_NOT_EFI_ERROR (Status);
1445 }
1446 }
1447
1448 return UNIT_TEST_PASSED;
1449 }
1450
1451 /**
1452 Unit test of MP service SwitchBSP.
1453 When run this procedure on AP, the return status should be EFI_DEVICE_ERROR.
1454
1455 @param[in] Context Context pointer for this test.
1456
1457 @retval UNIT_TEST_PASSED The Unit test has completed and the test
1458 case was successful.
1459 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
1460 **/
1461 UNIT_TEST_STATUS
1462 EFIAPI
1463 TestSwitchBSP2 (
1464 IN UNIT_TEST_CONTEXT Context
1465 )
1466 {
1467 EFI_STATUS Status;
1468 UINTN ApNumber;
1469 MP_SERVICE_UT_CONTEXT *LocalContext;
1470
1471 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
1472
1473 for (ApNumber = 0; ApNumber < LocalContext->NumberOfProcessors; ApNumber++) {
1474 LocalContext->ApNumber = ApNumber;
1475 Status = MpServicesUnitTestStartupThisAP (
1476 LocalContext->MpServices,
1477 (EFI_AP_PROCEDURE)RunMpServiceSwitchBSPOnAp,
1478 ApNumber,
1479 0,
1480 (VOID *)LocalContext
1481 );
1482
1483 if (ApNumber == LocalContext->BspNumber) {
1484 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1485 } else {
1486 UT_ASSERT_NOT_EFI_ERROR (Status);
1487 UT_ASSERT_STATUS_EQUAL (LocalContext->ApProcedureReturnStatus, EFI_DEVICE_ERROR);
1488 }
1489 }
1490
1491 return UNIT_TEST_PASSED;
1492 }
1493
1494 /**
1495 Unit test of MP service SwitchBSP.
1496 When switch a disabled AP to be BSP, the return status should be EFI_INVALID_PARAMETER.
1497
1498 @param[in] Context Context pointer for this test.
1499
1500 @retval UNIT_TEST_PASSED The Unit test has completed and the test
1501 case was successful.
1502 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
1503 **/
1504 UNIT_TEST_STATUS
1505 EFIAPI
1506 TestSwitchBSP3 (
1507 IN UNIT_TEST_CONTEXT Context
1508 )
1509 {
1510 EFI_STATUS Status;
1511 UINTN NewBspNumber;
1512 MP_SERVICE_UT_CONTEXT *LocalContext;
1513
1514 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
1515
1516 for (NewBspNumber = 0; NewBspNumber < LocalContext->NumberOfProcessors; NewBspNumber++) {
1517 Status = MpServicesUnitTestEnableDisableAP (
1518 LocalContext->MpServices,
1519 NewBspNumber,
1520 FALSE,
1521 NULL
1522 );
1523
1524 if (NewBspNumber == LocalContext->BspNumber) {
1525 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1526 } else {
1527 UT_ASSERT_NOT_EFI_ERROR (Status);
1528
1529 Status = MpServicesUnitTestSwitchBSP (
1530 LocalContext->MpServices,
1531 NewBspNumber,
1532 TRUE
1533 );
1534 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1535
1536 Status = MpServicesUnitTestEnableDisableAP (
1537 LocalContext->MpServices,
1538 NewBspNumber,
1539 TRUE,
1540 NULL
1541 );
1542 UT_ASSERT_NOT_EFI_ERROR (Status);
1543 }
1544 }
1545
1546 return UNIT_TEST_PASSED;
1547 }
1548
1549 /**
1550 Unit test of MP service SwitchBSP.
1551 When SwitchBSP and EnableOldBSP is TRUE, the new BSP should be in the enabled state and the old BSP should
1552 be in the enabled state.
1553 When SwitchBSP and EnableOldBSP is False, the new BSP should be in the enabled state and the old BSP should
1554 be in the disabled state.
1555
1556 @param[in] Context Context pointer for this test.
1557
1558 @retval UNIT_TEST_PASSED The Unit test has completed and the test
1559 case was successful.
1560 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
1561 **/
1562 UNIT_TEST_STATUS
1563 EFIAPI
1564 TestSwitchBSP4 (
1565 IN UNIT_TEST_CONTEXT Context
1566 )
1567 {
1568 EFI_STATUS Status;
1569 UINTN NewBspNumber;
1570 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer;
1571 MP_SERVICE_UT_CONTEXT *LocalContext;
1572
1573 LocalContext = (MP_SERVICE_UT_CONTEXT *)Context;
1574
1575 for (NewBspNumber = 0; NewBspNumber < LocalContext->NumberOfProcessors; NewBspNumber++) {
1576 Status = MpServicesUnitTestSwitchBSP (
1577 LocalContext->MpServices,
1578 NewBspNumber,
1579 FALSE
1580 );
1581
1582 if (NewBspNumber == LocalContext->BspNumber) {
1583 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1584 } else {
1585 UT_ASSERT_NOT_EFI_ERROR (Status);
1586
1587 Status = MpServicesUnitTestGetProcessorInfo (
1588 LocalContext->MpServices,
1589 NewBspNumber,
1590 &ProcessorInfoBuffer
1591 );
1592 UT_ASSERT_NOT_EFI_ERROR (Status);
1593 UT_ASSERT_TRUE (
1594 (ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) &&
1595 (ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT)
1596 );
1597
1598 Status = MpServicesUnitTestGetProcessorInfo (
1599 LocalContext->MpServices,
1600 LocalContext->BspNumber,
1601 &ProcessorInfoBuffer
1602 );
1603 UT_ASSERT_NOT_EFI_ERROR (Status);
1604 UT_ASSERT_TRUE (
1605 !(ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) &&
1606 !(ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT)
1607 );
1608
1609 Status = MpServicesUnitTestEnableDisableAP (
1610 LocalContext->MpServices,
1611 LocalContext->BspNumber,
1612 TRUE,
1613 NULL
1614 );
1615 UT_ASSERT_NOT_EFI_ERROR (Status);
1616
1617 Status = MpServicesUnitTestSwitchBSP (
1618 LocalContext->MpServices,
1619 LocalContext->BspNumber,
1620 TRUE
1621 );
1622 UT_ASSERT_NOT_EFI_ERROR (Status);
1623
1624 Status = MpServicesUnitTestGetProcessorInfo (
1625 LocalContext->MpServices,
1626 LocalContext->BspNumber,
1627 &ProcessorInfoBuffer
1628 );
1629 UT_ASSERT_NOT_EFI_ERROR (Status);
1630 UT_ASSERT_TRUE (
1631 (ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) &&
1632 (ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT)
1633 );
1634
1635 Status = MpServicesUnitTestGetProcessorInfo (
1636 LocalContext->MpServices,
1637 NewBspNumber,
1638 &ProcessorInfoBuffer
1639 );
1640 UT_ASSERT_NOT_EFI_ERROR (Status);
1641 UT_ASSERT_TRUE (
1642 !(ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) &&
1643 (ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT)
1644 );
1645 }
1646 }
1647
1648 return UNIT_TEST_PASSED;
1649 }
1650
1651 /**
1652 Create test suite and unit tests for both EdkiiPeiMpServices2Ppi and EfiMpServiceProtocol.
1653
1654 @param[in] Framework A pointer to the framework that is being persisted.
1655 @param[in] Context A pointer to the private data buffer.
1656
1657 @retval EFI_SUCCESS Create test suite and unit tests successfully.
1658 @retval Others Create test suite and unit tests unsuccessfully.
1659 **/
1660 EFI_STATUS
1661 AddCommonTestCase (
1662 IN UNIT_TEST_FRAMEWORK_HANDLE Framework,
1663 IN MP_SERVICE_UT_CONTEXT *Context
1664 )
1665 {
1666 EFI_STATUS Status;
1667 UNIT_TEST_SUITE_HANDLE MpServiceWhoAmITestSuite;
1668 UNIT_TEST_SUITE_HANDLE MpServiceGetNumberOfProcessorsTestSuite;
1669 UNIT_TEST_SUITE_HANDLE MpServiceGetProcessorInfoTestSuite;
1670 UNIT_TEST_SUITE_HANDLE MpServiceEnableDisableAPTestSuite;
1671 UNIT_TEST_SUITE_HANDLE MpServiceStartupThisAPTestSuite;
1672 UNIT_TEST_SUITE_HANDLE MpServiceStartupAllAPsTestSuite;
1673 UNIT_TEST_SUITE_HANDLE MpServiceSwitchBSPTestSuite;
1674
1675 MpServiceWhoAmITestSuite = NULL;
1676 MpServiceGetNumberOfProcessorsTestSuite = NULL;
1677 MpServiceGetProcessorInfoTestSuite = NULL;
1678 MpServiceEnableDisableAPTestSuite = NULL;
1679 MpServiceStartupThisAPTestSuite = NULL;
1680 MpServiceStartupAllAPsTestSuite = NULL;
1681 MpServiceSwitchBSPTestSuite = NULL;
1682
1683 //
1684 // Test WhoAmI function
1685 //
1686 Status = CreateUnitTestSuite (&MpServiceWhoAmITestSuite, Framework, "Identify the currently executing processor", "MpServices.WhoAmI", NULL, NULL);
1687 if (EFI_ERROR (Status)) {
1688 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for MpServiceWhoAmI Test Suite\n"));
1689 return Status;
1690 }
1691
1692 AddTestCase (MpServiceWhoAmITestSuite, "Test WhoAmI 1", "TestWhoAmI1", TestWhoAmI1, InitUTContext, CheckUTContext, Context);
1693
1694 //
1695 // Test GetNumberOfProcessors function
1696 //
1697 Status = CreateUnitTestSuite (&MpServiceGetNumberOfProcessorsTestSuite, Framework, "Retrieve the number of logical processor", "MpServices.GetNumberOfProcessors", NULL, NULL);
1698 if (EFI_ERROR (Status)) {
1699 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for MpServiceGetNumberOfProcessors Test Suite\n"));
1700 return Status;
1701 }
1702
1703 AddTestCase (MpServiceGetNumberOfProcessorsTestSuite, "Test GetNumberOfProcessors 1", "TestGetNumberOfProcessors1", TestGetNumberOfProcessors1, InitUTContext, CheckUTContext, Context);
1704 AddTestCase (MpServiceGetNumberOfProcessorsTestSuite, "Test GetNumberOfProcessors 2", "TestGetNumberOfProcessors2", TestGetNumberOfProcessors2, InitUTContext, CheckUTContext, Context);
1705 AddTestCase (MpServiceGetNumberOfProcessorsTestSuite, "Test GetNumberOfProcessors 3", "TestGetNumberOfProcessors3", TestGetNumberOfProcessors3, InitUTContext, CheckUTContext, Context);
1706
1707 //
1708 // Test GetProcessorInfo function
1709 //
1710 Status = CreateUnitTestSuite (&MpServiceGetProcessorInfoTestSuite, Framework, "Get detailed information on the requested logical processor", "MpServices.GetProcessorInfo", NULL, NULL);
1711 if (EFI_ERROR (Status)) {
1712 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for MpServiceGetProcessorInfo Test Suite\n"));
1713 return Status;
1714 }
1715
1716 AddTestCase (MpServiceGetProcessorInfoTestSuite, "Test GetProcessorInfo 1", "TestGetProcessorInfo1", TestGetProcessorInfo1, InitUTContext, CheckUTContext, Context);
1717 AddTestCase (MpServiceGetProcessorInfoTestSuite, "Test GetProcessorInfo 2", "TestGetProcessorInfo2", TestGetProcessorInfo2, InitUTContext, CheckUTContext, Context);
1718
1719 //
1720 // Test EnableDisableAP function
1721 //
1722 Status = CreateUnitTestSuite (&MpServiceEnableDisableAPTestSuite, Framework, "Caller enables or disables an AP from this point onward", "MpServices.EnableDisableAP", NULL, NULL);
1723 if (EFI_ERROR (Status)) {
1724 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for MpServiceEnableDisableAP Test Suite\n"));
1725 return Status;
1726 }
1727
1728 AddTestCase (MpServiceEnableDisableAPTestSuite, "Test EnableDisableAP 1", "TestEnableDisableAP1", TestEnableDisableAP1, InitUTContext, CheckUTContext, Context);
1729 AddTestCase (MpServiceEnableDisableAPTestSuite, "Test EnableDisableAP 2", "TestEnableDisableAP2", TestEnableDisableAP2, InitUTContext, CheckUTContext, Context);
1730 AddTestCase (MpServiceEnableDisableAPTestSuite, "Test EnableDisableAP 3", "TestEnableDisableAP3", TestEnableDisableAP3, InitUTContext, CheckUTContext, Context);
1731
1732 //
1733 // Test StartupThisAP function
1734 //
1735 Status = CreateUnitTestSuite (&MpServiceStartupThisAPTestSuite, Framework, "Get the requested AP to execute a caller-provided function", "MpServices.StartupThisAP", NULL, NULL);
1736 if (EFI_ERROR (Status)) {
1737 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for MpServiceStartupThisAP Test Suite\n"));
1738 return Status;
1739 }
1740
1741 AddTestCase (MpServiceStartupThisAPTestSuite, "Test StartupThisAP 1", "TestStartupThisAP1", TestStartupThisAP1, InitUTContext, CheckUTContext, Context);
1742 AddTestCase (MpServiceStartupThisAPTestSuite, "Test StartupThisAP 2", "TestStartupThisAP2", TestStartupThisAP2, InitUTContext, CheckUTContext, Context);
1743 AddTestCase (MpServiceStartupThisAPTestSuite, "Test StartupThisAP 3", "TestStartupThisAP3", TestStartupThisAP3, InitUTContext, CheckUTContext, Context);
1744 AddTestCase (MpServiceStartupThisAPTestSuite, "Test StartupThisAP 4", "TestStartupThisAP4", TestStartupThisAP4, InitUTContext, CheckUTContext, Context);
1745
1746 //
1747 // Test StartupAllAPs function
1748 //
1749 Status = CreateUnitTestSuite (&MpServiceStartupAllAPsTestSuite, Framework, "Execute a caller provided function on all enabled APs", "MpServices.StartupAllAPs", NULL, NULL);
1750 if (EFI_ERROR (Status)) {
1751 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for MpServiceStartupAllAPs Test Suite\n"));
1752 return Status;
1753 }
1754
1755 AddTestCase (MpServiceStartupAllAPsTestSuite, "Test StartupAllAPs 1", "TestStartupAllAPs1", TestStartupAllAPs1, InitUTContext, CheckUTContext, Context);
1756 AddTestCase (MpServiceStartupAllAPsTestSuite, "Test StartupAllAPs 2", "TestStartupAllAPs2", TestStartupAllAPs2, InitUTContext, CheckUTContext, Context);
1757 AddTestCase (MpServiceStartupAllAPsTestSuite, "Test StartupAllAPs 3", "TestStartupAllAPs3", TestStartupAllAPs3, InitUTContext, CheckUTContext, Context);
1758 AddTestCase (MpServiceStartupAllAPsTestSuite, "Test StartupAllAPs 4", "TestStartupAllAPs4", TestStartupAllAPs4, InitUTContext, CheckUTContext, Context);
1759 AddTestCase (MpServiceStartupAllAPsTestSuite, "Test StartupAllAPs 5", "TestStartupAllAPs5", TestStartupAllAPs5, InitUTContext, CheckUTContext, Context);
1760
1761 //
1762 // Test SwitchBSP function
1763 //
1764 Status = CreateUnitTestSuite (&MpServiceSwitchBSPTestSuite, Framework, "Switch the requested AP to be the BSP from that point onward", "MpServices.SwitchBSP", NULL, NULL);
1765 if (EFI_ERROR (Status)) {
1766 DEBUG ((DEBUG_ERROR, "Failed in CreateUnitTestSuite for MpServiceSwitchBSP Test Suite\n"));
1767 return Status;
1768 }
1769
1770 AddTestCase (MpServiceSwitchBSPTestSuite, "Test SwitchBSP 1", "TestSwitchBSP1", TestSwitchBSP1, InitUTContext, CheckUTContext, Context);
1771 AddTestCase (MpServiceSwitchBSPTestSuite, "Test SwitchBSP 2", "TestSwitchBSP2", TestSwitchBSP2, InitUTContext, CheckUTContext, Context);
1772 AddTestCase (MpServiceSwitchBSPTestSuite, "Test SwitchBSP 3", "TestSwitchBSP3", TestSwitchBSP3, InitUTContext, CheckUTContext, Context);
1773 AddTestCase (MpServiceSwitchBSPTestSuite, "Test SwitchBSP 4", "TestSwitchBSP4", TestSwitchBSP4, InitUTContext, FreeUTContext, Context);
1774
1775 return EFI_SUCCESS;
1776 }