2 Common code to test EdkiiPeiMpServices2Ppi and EfiMpServiceProtocol.
4 Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
6 SPDX-License-Identifier: BSD-2-Clause-Patent
10 #include "EfiMpServicesUnitTestCommom.h"
13 Prep routine for Unit test function.
14 To save the ProcessorNumber of disabled AP and temporarily enable it.
16 @param[in] Context Context pointer for this test.
18 @retval UNIT_TEST_PASSED Prep routine runs successful.
19 @retval UNIT_TEST_ERROR_TEST_FAILED Prep routine runs unsuccessful.
24 IN UNIT_TEST_CONTEXT Context
28 UINTN NumberOfProcessors
;
29 UINTN NumberOfEnabledProcessors
;
30 UINTN NumberOfDisabledAPs
;
31 UINTN IndexOfDisabledAPs
;
33 UINTN ProcessorNumber
;
34 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer
;
35 MP_SERVICE_UT_CONTEXT
*LocalContext
;
37 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
39 if (LocalContext
->MpServices
.Ppi
!= NULL
) {
40 return UNIT_TEST_PASSED
;
43 Status
= MpServicesUnitTestGetMpServices (&LocalContext
->MpServices
);
44 UT_ASSERT_NOT_EFI_ERROR (Status
);
46 Status
= MpServicesUnitTestWhoAmI (LocalContext
->MpServices
, &BspNumber
);
47 UT_ASSERT_NOT_EFI_ERROR (Status
);
48 DEBUG ((DEBUG_INFO
, "%a: BspNumber = 0x%x\n", __FUNCTION__
, BspNumber
));
50 Status
= MpServicesUnitTestGetNumberOfProcessors (
51 LocalContext
->MpServices
,
53 &NumberOfEnabledProcessors
55 UT_ASSERT_NOT_EFI_ERROR (Status
);
58 "%a: NumberOfProcessors = 0x%x, NumberOfEnabledProcessors = 0x%x\n",
61 NumberOfEnabledProcessors
64 LocalContext
->BspNumber
= BspNumber
;
65 LocalContext
->NumberOfProcessors
= NumberOfProcessors
;
66 LocalContext
->NumberOfEnabledProcessors
= NumberOfEnabledProcessors
;
68 LocalContext
->CommonBuffer
= AllocatePages (EFI_SIZE_TO_PAGES (NumberOfProcessors
* sizeof (*LocalContext
->CommonBuffer
)));
69 UT_ASSERT_NOT_NULL (LocalContext
->CommonBuffer
);
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
));
77 for (ProcessorNumber
= 0, IndexOfDisabledAPs
= 0; ProcessorNumber
< LocalContext
->NumberOfProcessors
; ProcessorNumber
++) {
78 Status
= MpServicesUnitTestGetProcessorInfo (
79 LocalContext
->MpServices
,
83 UT_ASSERT_NOT_EFI_ERROR (Status
);
85 if (!(ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_ENABLED_BIT
)) {
87 // Save ProcessorNumber of disabled AP.
89 LocalContext
->DisabledApNumber
[IndexOfDisabledAPs
] = ProcessorNumber
;
92 DEBUG ((DEBUG_INFO
, "%a: AP(0x%x) is disabled and temporarily enable it.\n", __FUNCTION__
, ProcessorNumber
));
93 Status
= MpServicesUnitTestEnableDisableAP (
94 LocalContext
->MpServices
,
99 UT_ASSERT_NOT_EFI_ERROR (Status
);
103 UT_ASSERT_TRUE (IndexOfDisabledAPs
== NumberOfDisabledAPs
);
106 return UNIT_TEST_PASSED
;
110 Cleanup routine for Unit test function.
111 If any processor is disabled unexpectedly then reenable it.
113 @param[in] Context Context pointer for this test.
118 IN UNIT_TEST_CONTEXT Context
122 UINTN NumberOfProcessors
;
123 UINTN NumberOfEnabledProcessors
;
125 UINTN ProcessorNumber
;
126 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer
;
127 MP_SERVICE_UT_CONTEXT
*LocalContext
;
129 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
130 ASSERT (LocalContext
->MpServices
.Ppi
!= NULL
);
132 Status
= MpServicesUnitTestWhoAmI (LocalContext
->MpServices
, &BspNumber
);
133 ASSERT_EFI_ERROR (Status
);
135 if (BspNumber
!= LocalContext
->BspNumber
) {
136 LocalContext
->BspNumber
= BspNumber
;
137 DEBUG ((DEBUG_INFO
, "%a: New BspNumber = 0x%x\n", __FUNCTION__
, BspNumber
));
140 ASSERT (BspNumber
== LocalContext
->BspNumber
);
142 Status
= MpServicesUnitTestGetNumberOfProcessors (
143 LocalContext
->MpServices
,
145 &NumberOfEnabledProcessors
147 ASSERT_EFI_ERROR (Status
);
149 if (NumberOfProcessors
!= LocalContext
->NumberOfProcessors
) {
150 LocalContext
->NumberOfProcessors
= NumberOfProcessors
;
151 DEBUG ((DEBUG_INFO
, "%a: New NumberOfProcessors = 0x%x\n", __FUNCTION__
, NumberOfProcessors
));
154 if (NumberOfEnabledProcessors
!= LocalContext
->NumberOfProcessors
) {
155 DEBUG ((DEBUG_INFO
, "%a: New NumberOfEnabledProcessors = 0x%x\n", __FUNCTION__
, NumberOfEnabledProcessors
));
157 for (ProcessorNumber
= 0; ProcessorNumber
< LocalContext
->NumberOfProcessors
; ProcessorNumber
++) {
158 Status
= MpServicesUnitTestGetProcessorInfo (
159 LocalContext
->MpServices
,
163 ASSERT_EFI_ERROR (Status
);
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
,
173 ASSERT_EFI_ERROR (Status
);
180 Cleanup routine for Unit test function.
181 It will be called by the last "AddTestCase" to restore AP state and free pointer.
183 @param[in] Context Context pointer for this test.
188 IN UNIT_TEST_CONTEXT Context
192 UINTN NumberOfDisabledAPs
;
193 UINTN IndexOfDisabledAPs
;
194 MP_SERVICE_UT_CONTEXT
*LocalContext
;
196 CheckUTContext (Context
);
198 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
199 ASSERT (LocalContext
->MpServices
.Ppi
!= NULL
);
201 if (LocalContext
->DisabledApNumber
!= NULL
) {
202 NumberOfDisabledAPs
= LocalContext
->NumberOfProcessors
- LocalContext
->NumberOfEnabledProcessors
;
203 for (IndexOfDisabledAPs
= 0; IndexOfDisabledAPs
< NumberOfDisabledAPs
; IndexOfDisabledAPs
++) {
206 "%a: Disable AP(0x%x) to restore its state.\n",
208 LocalContext
->DisabledApNumber
[IndexOfDisabledAPs
]
211 Status
= MpServicesUnitTestEnableDisableAP (
212 LocalContext
->MpServices
,
213 LocalContext
->DisabledApNumber
[IndexOfDisabledAPs
],
217 ASSERT_EFI_ERROR (Status
);
220 FreePages (LocalContext
->DisabledApNumber
, EFI_SIZE_TO_PAGES (NumberOfDisabledAPs
* sizeof (*LocalContext
->DisabledApNumber
)));
223 if (LocalContext
->CommonBuffer
!= NULL
) {
224 FreePages (LocalContext
->CommonBuffer
, EFI_SIZE_TO_PAGES (LocalContext
->NumberOfProcessors
* sizeof (*LocalContext
->CommonBuffer
)));
229 Produce to store ProcessorNumber in the corresponding location of CommonBuffer.
231 @param[in,out] Buffer The pointer to private data buffer.
239 UINTN ProcessorNumber
;
240 MP_SERVICE_UT_CONTEXT
*LocalContext
;
242 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Buffer
;
244 Status
= MpServicesUnitTestWhoAmI (LocalContext
->MpServices
, &ProcessorNumber
);
245 ASSERT_EFI_ERROR (Status
);
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
252 if (ProcessorNumber
< LocalContext
->NumberOfProcessors
) {
253 LocalContext
->CommonBuffer
[ProcessorNumber
] = ProcessorNumber
;
258 Produce to store the ProcessorNumber of AP execution order in CommonBuffer.
260 @param[in,out] Buffer The pointer to private data buffer.
263 StoreAPsExecutionOrder (
268 UINTN ProcessorNumber
;
270 MP_SERVICE_UT_CONTEXT
*LocalContext
;
272 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Buffer
;
274 Status
= MpServicesUnitTestWhoAmI (LocalContext
->MpServices
, &ProcessorNumber
);
275 ASSERT_EFI_ERROR (Status
);
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)
282 ApCounter
= &(LocalContext
->CommonBuffer
[LocalContext
->NumberOfProcessors
- 1]);
283 LocalContext
->CommonBuffer
[*ApCounter
] = ProcessorNumber
;
288 Infinite loop procedure to be run on specified CPU.
290 @param[in,out] Buffer The pointer to private data buffer.
293 InfiniteLoopProcedure (
297 volatile BOOLEAN InfiniteLoop
;
301 while (InfiniteLoop
) {
306 Empty procedure to be run on specified CPU.
308 @param[in,out] Buffer The pointer to private data buffer.
318 Procedure to run MP service GetNumberOfProcessors on AP.
320 @param[in,out] Buffer The pointer to private data buffer.
323 RunMpServiceGetNumberOfProcessorsOnAp (
327 UINTN NumberOfProcessors
;
328 UINTN NumberOfEnabledProcessors
;
329 MP_SERVICE_UT_CONTEXT
*LocalContext
;
331 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Buffer
;
333 LocalContext
->ApProcedureReturnStatus
= MpServicesUnitTestGetNumberOfProcessors (
334 LocalContext
->MpServices
,
336 &NumberOfEnabledProcessors
341 Procedure to run MP service GetProcessorInfo on AP.
343 @param[in,out] Buffer The pointer to private data buffer.
346 RunMpServiceGetProcessorInfoOnAp (
350 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer
;
351 MP_SERVICE_UT_CONTEXT
*LocalContext
;
353 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Buffer
;
355 LocalContext
->ApProcedureReturnStatus
= MpServicesUnitTestGetProcessorInfo (
356 LocalContext
->MpServices
,
357 LocalContext
->ApNumber
,
363 Procedure to run MP service EnableDisableAP on AP.
365 @param[in,out] Buffer The pointer to private data buffer.
368 RunMpServiceEnableDisableAPOnAp (
372 MP_SERVICE_UT_CONTEXT
*LocalContext
;
374 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Buffer
;
376 LocalContext
->ApProcedureReturnStatus
= MpServicesUnitTestEnableDisableAP (
377 LocalContext
->MpServices
,
378 LocalContext
->ApNumber
,
385 Procedure to run MP service StartupThisAP on AP.
387 @param[in,out] Buffer The pointer to private data buffer.
390 RunMpServiceStartupThisAPOnAp (
394 MP_SERVICE_UT_CONTEXT
*LocalContext
;
396 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Buffer
;
398 LocalContext
->ApProcedureReturnStatus
= MpServicesUnitTestStartupThisAP (
399 LocalContext
->MpServices
,
400 (EFI_AP_PROCEDURE
)EmptyProcedure
,
401 LocalContext
->ApNumber
,
408 Procedure to run MP service StartupAllAPs on AP.
410 @param[in,out] Buffer The pointer to private data buffer.
413 RunMpServiceStartupAllAPsOnAp (
417 MP_SERVICE_UT_CONTEXT
*LocalContext
;
419 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Buffer
;
421 LocalContext
->ApProcedureReturnStatus
= MpServicesUnitTestStartupAllAPs (
422 LocalContext
->MpServices
,
423 (EFI_AP_PROCEDURE
)EmptyProcedure
,
431 Procedure to run MP service SwitchBSP on AP.
433 @param[in,out] Buffer The pointer to private data buffer.
436 RunMpServiceSwitchBSPOnAp (
440 MP_SERVICE_UT_CONTEXT
*LocalContext
;
442 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Buffer
;
444 LocalContext
->ApProcedureReturnStatus
= MpServicesUnitTestSwitchBSP (
445 LocalContext
->MpServices
,
446 LocalContext
->ApNumber
,
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.
456 @param[in] Context Context pointer for this test.
458 @retval UNIT_TEST_PASSED The Unit test has completed and the test
460 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
465 IN UNIT_TEST_CONTEXT Context
469 UINTN ProcessorNumber
;
470 UINTN ProcessorIndex
;
471 MP_SERVICE_UT_CONTEXT
*LocalContext
;
473 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
475 Status
= MpServicesUnitTestWhoAmI (
476 LocalContext
->MpServices
,
479 UT_ASSERT_NOT_EFI_ERROR (Status
);
480 UT_ASSERT_TRUE (ProcessorNumber
< LocalContext
->NumberOfProcessors
);
482 SetMem (LocalContext
->CommonBuffer
, LocalContext
->NumberOfProcessors
* sizeof (*LocalContext
->CommonBuffer
), 0xFF);
483 LocalContext
->CommonBuffer
[ProcessorNumber
] = ProcessorNumber
;
485 Status
= MpServicesUnitTestStartupAllAPs (
486 LocalContext
->MpServices
,
487 (EFI_AP_PROCEDURE
)StoreCpuNumbers
,
492 UT_ASSERT_NOT_EFI_ERROR (Status
);
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
499 for (ProcessorIndex
= 0; ProcessorIndex
< LocalContext
->NumberOfProcessors
; ProcessorIndex
++) {
500 UT_ASSERT_TRUE (LocalContext
->CommonBuffer
[ProcessorIndex
] == ProcessorIndex
);
503 return UNIT_TEST_PASSED
;
507 Unit test of MP service GetNumberOfProcessors.
508 NumberOfProcessors should be greater that 0 and not less than NumberOfEnabledProcessors.
510 @param[in] Context Context pointer for this test.
512 @retval UNIT_TEST_PASSED The Unit test has completed and the test
514 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
518 TestGetNumberOfProcessors1 (
519 IN UNIT_TEST_CONTEXT Context
523 UINTN NumberOfProcessors
;
524 UINTN NumberOfEnabledProcessors
;
525 MP_SERVICE_UT_CONTEXT
*LocalContext
;
527 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
529 Status
= MpServicesUnitTestGetNumberOfProcessors (
530 LocalContext
->MpServices
,
532 &NumberOfEnabledProcessors
534 UT_ASSERT_NOT_EFI_ERROR (Status
);
535 UT_ASSERT_TRUE (NumberOfProcessors
> 0 && NumberOfProcessors
>= NumberOfEnabledProcessors
);
537 return UNIT_TEST_PASSED
;
541 Unit test of MP service GetNumberOfProcessors.
542 When this service is called from an AP, the return status should be EFI_DEVICE_ERROR.
544 @param[in] Context Context pointer for this test.
546 @retval UNIT_TEST_PASSED The Unit test has completed and the test
548 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
552 TestGetNumberOfProcessors2 (
553 IN UNIT_TEST_CONTEXT Context
558 MP_SERVICE_UT_CONTEXT
*LocalContext
;
560 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
562 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
563 LocalContext
->ApNumber
= ApNumber
;
564 Status
= MpServicesUnitTestStartupThisAP (
565 LocalContext
->MpServices
,
566 (EFI_AP_PROCEDURE
)RunMpServiceGetNumberOfProcessorsOnAp
,
572 if (ApNumber
== LocalContext
->BspNumber
) {
573 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
575 UT_ASSERT_NOT_EFI_ERROR (Status
);
576 UT_ASSERT_STATUS_EQUAL (LocalContext
->ApProcedureReturnStatus
, EFI_DEVICE_ERROR
);
580 return UNIT_TEST_PASSED
;
584 Unit test of MP service GetNumberOfProcessors.
585 Call EnableDisableAP() to change the number of enabled AP.
587 @param[in] Context Context pointer for this test.
589 @retval UNIT_TEST_PASSED The Unit test has completed and the test
591 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
595 TestGetNumberOfProcessors3 (
596 IN UNIT_TEST_CONTEXT Context
601 UINTN NumberOfProcessors
;
602 UINTN NumberOfEnabledProcessors
;
603 MP_SERVICE_UT_CONTEXT
*LocalContext
;
605 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
607 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
608 Status
= MpServicesUnitTestEnableDisableAP (
609 LocalContext
->MpServices
,
615 if (ApNumber
== LocalContext
->BspNumber
) {
616 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
618 UT_ASSERT_NOT_EFI_ERROR (Status
);
620 Status
= MpServicesUnitTestGetNumberOfProcessors (
621 LocalContext
->MpServices
,
623 &NumberOfEnabledProcessors
625 UT_ASSERT_NOT_EFI_ERROR (Status
);
626 UT_ASSERT_TRUE (NumberOfProcessors
== LocalContext
->NumberOfProcessors
);
628 if (ApNumber
< LocalContext
->BspNumber
) {
629 UT_ASSERT_TRUE (NumberOfEnabledProcessors
== LocalContext
->NumberOfProcessors
- (ApNumber
+ 1));
631 UT_ASSERT_TRUE (NumberOfEnabledProcessors
== LocalContext
->NumberOfProcessors
- ApNumber
);
636 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
637 Status
= MpServicesUnitTestEnableDisableAP (
638 LocalContext
->MpServices
,
644 if (ApNumber
== LocalContext
->BspNumber
) {
645 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
647 UT_ASSERT_NOT_EFI_ERROR (Status
);
649 Status
= MpServicesUnitTestGetNumberOfProcessors (
650 LocalContext
->MpServices
,
652 &NumberOfEnabledProcessors
654 UT_ASSERT_NOT_EFI_ERROR (Status
);
655 UT_ASSERT_TRUE (NumberOfProcessors
== LocalContext
->NumberOfProcessors
);
657 if (ApNumber
< LocalContext
->BspNumber
) {
658 UT_ASSERT_TRUE (NumberOfEnabledProcessors
== ApNumber
+ 2);
660 UT_ASSERT_TRUE (NumberOfEnabledProcessors
== ApNumber
+ 1);
665 return UNIT_TEST_PASSED
;
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.
674 @param[in] Context Context pointer for this test.
676 @retval UNIT_TEST_PASSED The Unit test has completed and the test
678 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
682 TestGetProcessorInfo1 (
683 IN UNIT_TEST_CONTEXT Context
687 UINTN ProcessorNumber
;
688 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer
;
689 MP_SERVICE_UT_CONTEXT
*LocalContext
;
691 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
693 for (ProcessorNumber
= 0; ProcessorNumber
<= LocalContext
->NumberOfProcessors
; ProcessorNumber
++) {
694 Status
= MpServicesUnitTestGetProcessorInfo (
695 LocalContext
->MpServices
,
700 if (ProcessorNumber
== LocalContext
->NumberOfProcessors
) {
701 UT_ASSERT_STATUS_EQUAL (Status
, EFI_NOT_FOUND
);
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);
706 if (ProcessorNumber
== LocalContext
->BspNumber
) {
707 UT_ASSERT_TRUE ((ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) && (ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_ENABLED_BIT
));
709 UT_ASSERT_TRUE (!(ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_AS_BSP_BIT
));
714 return UNIT_TEST_PASSED
;
718 Unit test of MP service GetProcessorInfo.
719 When this service is called from an AP, the return status should be EFI_DEVICE_ERROR.
721 @param[in] Context Context pointer for this test.
723 @retval UNIT_TEST_PASSED The Unit test has completed and the test
725 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
729 TestGetProcessorInfo2 (
730 IN UNIT_TEST_CONTEXT Context
735 MP_SERVICE_UT_CONTEXT
*LocalContext
;
737 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
739 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
740 LocalContext
->ApNumber
= ApNumber
;
741 Status
= MpServicesUnitTestStartupThisAP (
742 LocalContext
->MpServices
,
743 (EFI_AP_PROCEDURE
)RunMpServiceGetProcessorInfoOnAp
,
749 if (ApNumber
== LocalContext
->BspNumber
) {
750 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
752 UT_ASSERT_NOT_EFI_ERROR (Status
);
753 UT_ASSERT_STATUS_EQUAL (LocalContext
->ApProcedureReturnStatus
, EFI_DEVICE_ERROR
);
757 return UNIT_TEST_PASSED
;
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.
766 @param[in] Context Context pointer for this test.
768 @retval UNIT_TEST_PASSED The Unit test has completed and the test
770 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
774 TestEnableDisableAP1 (
775 IN UNIT_TEST_CONTEXT Context
780 MP_SERVICE_UT_CONTEXT
*LocalContext
;
782 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
784 for (ApNumber
= 0; ApNumber
<= LocalContext
->NumberOfProcessors
; ApNumber
++) {
785 Status
= MpServicesUnitTestEnableDisableAP (
786 LocalContext
->MpServices
,
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
);
797 UT_ASSERT_NOT_EFI_ERROR (Status
);
799 Status
= MpServicesUnitTestStartupThisAP (
800 LocalContext
->MpServices
,
801 (EFI_AP_PROCEDURE
)EmptyProcedure
,
806 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
808 Status
= MpServicesUnitTestEnableDisableAP (
809 LocalContext
->MpServices
,
814 UT_ASSERT_NOT_EFI_ERROR (Status
);
816 Status
= MpServicesUnitTestStartupThisAP (
817 LocalContext
->MpServices
,
818 (EFI_AP_PROCEDURE
)EmptyProcedure
,
823 UT_ASSERT_NOT_EFI_ERROR (Status
);
827 return UNIT_TEST_PASSED
;
831 Unit test of MP service EnableDisableAP.
832 When run this procedure on AP, the return status should be EFI_DEVICE_ERROR.
834 @param[in] Context Context pointer for this test.
836 @retval UNIT_TEST_PASSED The Unit test has completed and the test
838 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
842 TestEnableDisableAP2 (
843 IN UNIT_TEST_CONTEXT Context
848 MP_SERVICE_UT_CONTEXT
*LocalContext
;
850 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
852 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
853 LocalContext
->ApNumber
= ApNumber
;
854 Status
= MpServicesUnitTestStartupThisAP (
855 LocalContext
->MpServices
,
856 (EFI_AP_PROCEDURE
)RunMpServiceEnableDisableAPOnAp
,
862 if (ApNumber
== LocalContext
->BspNumber
) {
863 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
865 UT_ASSERT_NOT_EFI_ERROR (Status
);
866 UT_ASSERT_STATUS_EQUAL (LocalContext
->ApProcedureReturnStatus
, EFI_DEVICE_ERROR
);
870 return UNIT_TEST_PASSED
;
874 Unit test of MP service EnableDisableAP.
875 When run this procedure on AP, the return status should be EFI_DEVICE_ERROR.
877 @param[in] Context Context pointer for this test.
879 @retval UNIT_TEST_PASSED The Unit test has completed and the test
881 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
885 TestEnableDisableAP3 (
886 IN UNIT_TEST_CONTEXT Context
891 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer
;
892 UINT32 OldHealthFlag
;
893 UINT32 NewHealthFlag
;
894 MP_SERVICE_UT_CONTEXT
*LocalContext
;
896 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
898 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
899 Status
= MpServicesUnitTestGetProcessorInfo (
900 LocalContext
->MpServices
,
904 UT_ASSERT_NOT_EFI_ERROR (Status
);
906 OldHealthFlag
= ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_HEALTH_STATUS_BIT
;
907 NewHealthFlag
= OldHealthFlag
^ PROCESSOR_HEALTH_STATUS_BIT
;
908 Status
= MpServicesUnitTestEnableDisableAP (
909 LocalContext
->MpServices
,
915 if (ApNumber
== LocalContext
->BspNumber
) {
916 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
918 UT_ASSERT_NOT_EFI_ERROR (Status
);
920 Status
= MpServicesUnitTestGetProcessorInfo (
921 LocalContext
->MpServices
,
925 UT_ASSERT_NOT_EFI_ERROR (Status
);
926 UT_ASSERT_TRUE ((ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_HEALTH_STATUS_BIT
) == NewHealthFlag
);
928 Status
= MpServicesUnitTestEnableDisableAP (
929 LocalContext
->MpServices
,
934 UT_ASSERT_NOT_EFI_ERROR (Status
);
938 return UNIT_TEST_PASSED
;
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.
947 @param[in] Context Context pointer for this test.
949 @retval UNIT_TEST_PASSED The Unit test has completed and the test
951 @retval UNIT_TEST_ERROR_TEST_FAILED A test case assertion has failed.
956 IN UNIT_TEST_CONTEXT Context
961 UINTN ProcessorIndex
;
962 MP_SERVICE_UT_CONTEXT
*LocalContext
;
964 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
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
,
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
);
981 UT_ASSERT_NOT_EFI_ERROR (Status
);
983 for (ProcessorIndex
= 0; ProcessorIndex
< LocalContext
->NumberOfProcessors
; ProcessorIndex
++) {
985 ((ProcessorIndex
== ApNumber
) && (LocalContext
->CommonBuffer
[ProcessorIndex
] == ProcessorIndex
)) ||
986 ((ProcessorIndex
!= ApNumber
) && (LocalContext
->CommonBuffer
[ProcessorIndex
] == (UINTN
) ~0))
992 return UNIT_TEST_PASSED
;
996 Unit test of MP service StartupThisAP.
997 When this service is called from an AP, the return status should be EFI_DEVICE_ERROR.
999 @param[in] Context Context pointer for this test.
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.
1007 TestStartupThisAP2 (
1008 IN UNIT_TEST_CONTEXT Context
1013 MP_SERVICE_UT_CONTEXT
*LocalContext
;
1015 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
1017 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
1018 LocalContext
->ApNumber
= ApNumber
;
1019 Status
= MpServicesUnitTestStartupThisAP (
1020 LocalContext
->MpServices
,
1021 (EFI_AP_PROCEDURE
)RunMpServiceStartupThisAPOnAp
,
1024 (VOID
*)LocalContext
1027 if (ApNumber
== LocalContext
->BspNumber
) {
1028 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
1030 UT_ASSERT_NOT_EFI_ERROR (Status
);
1031 UT_ASSERT_STATUS_EQUAL (LocalContext
->ApProcedureReturnStatus
, EFI_DEVICE_ERROR
);
1035 return UNIT_TEST_PASSED
;
1039 Unit test of MP service StartupThisAP.
1040 When timeout expired before the requested AP has finished, the return status should be EFI_TIMEOUT.
1042 @param[in] Context Context pointer for this test.
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.
1050 TestStartupThisAP3 (
1051 IN UNIT_TEST_CONTEXT Context
1056 MP_SERVICE_UT_CONTEXT
*LocalContext
;
1058 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
1060 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
1061 Status
= MpServicesUnitTestStartupThisAP (
1062 LocalContext
->MpServices
,
1063 (EFI_AP_PROCEDURE
)InfiniteLoopProcedure
,
1065 RUN_PROCEDURE_TIMEOUT_VALUE
,
1069 if (ApNumber
== LocalContext
->BspNumber
) {
1070 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
1072 UT_ASSERT_STATUS_EQUAL (Status
, EFI_TIMEOUT
);
1076 return UNIT_TEST_PASSED
;
1080 Unit test of MP service StartupThisAP.
1081 When called with disabled AP, the return status should be EFI_INVALID_PARAMETER.
1083 @param[in] Context Context pointer for this test.
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.
1091 TestStartupThisAP4 (
1092 IN UNIT_TEST_CONTEXT Context
1097 MP_SERVICE_UT_CONTEXT
*LocalContext
;
1099 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
1101 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
1102 Status
= MpServicesUnitTestEnableDisableAP (
1103 LocalContext
->MpServices
,
1109 if (ApNumber
== LocalContext
->BspNumber
) {
1110 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
1112 UT_ASSERT_NOT_EFI_ERROR (Status
);
1114 Status
= MpServicesUnitTestStartupThisAP (
1115 LocalContext
->MpServices
,
1116 (EFI_AP_PROCEDURE
)EmptyProcedure
,
1121 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
1123 Status
= MpServicesUnitTestEnableDisableAP (
1124 LocalContext
->MpServices
,
1129 UT_ASSERT_NOT_EFI_ERROR (Status
);
1131 Status
= MpServicesUnitTestStartupThisAP (
1132 LocalContext
->MpServices
,
1133 (EFI_AP_PROCEDURE
)EmptyProcedure
,
1138 UT_ASSERT_NOT_EFI_ERROR (Status
);
1142 return UNIT_TEST_PASSED
;
1146 Unit test of MP service StartupAllAPs.
1147 All APs should execute the Procedure when called by StartupAllAPs.
1149 @param[in] Context Context pointer for this test.
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.
1157 TestStartupAllAPs1 (
1158 IN UNIT_TEST_CONTEXT Context
1162 UINTN ProcessorIndex
;
1163 MP_SERVICE_UT_CONTEXT
*LocalContext
;
1165 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
1167 SetMem (LocalContext
->CommonBuffer
, LocalContext
->NumberOfProcessors
* sizeof (*LocalContext
->CommonBuffer
), 0xFF);
1168 Status
= MpServicesUnitTestStartupAllAPs (
1169 LocalContext
->MpServices
,
1170 (EFI_AP_PROCEDURE
)StoreCpuNumbers
,
1173 (VOID
*)LocalContext
1175 UT_ASSERT_NOT_EFI_ERROR (Status
);
1177 for (ProcessorIndex
= 0; ProcessorIndex
< LocalContext
->NumberOfProcessors
; ProcessorIndex
++) {
1179 ((ProcessorIndex
== LocalContext
->BspNumber
) && (LocalContext
->CommonBuffer
[ProcessorIndex
] == (UINTN
) ~0)) ||
1180 ((ProcessorIndex
!= LocalContext
->BspNumber
) && (LocalContext
->CommonBuffer
[ProcessorIndex
] == ProcessorIndex
))
1184 return UNIT_TEST_PASSED
;
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.
1192 @param[in] Context Context pointer for this test.
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.
1200 TestStartupAllAPs2 (
1201 IN UNIT_TEST_CONTEXT Context
1205 UINTN ProcessorIndex
;
1206 MP_SERVICE_UT_CONTEXT
*LocalContext
;
1208 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
1210 ZeroMem (LocalContext
->CommonBuffer
, LocalContext
->NumberOfProcessors
* sizeof (*LocalContext
->CommonBuffer
));
1211 Status
= MpServicesUnitTestStartupAllAPs (
1212 LocalContext
->MpServices
,
1213 (EFI_AP_PROCEDURE
)StoreAPsExecutionOrder
,
1216 (VOID
*)LocalContext
1218 UT_ASSERT_NOT_EFI_ERROR (Status
);
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)
1225 for (ProcessorIndex
= 0; ProcessorIndex
< LocalContext
->NumberOfProcessors
- 2; ProcessorIndex
++) {
1226 UT_ASSERT_TRUE (LocalContext
->CommonBuffer
[ProcessorIndex
] < LocalContext
->CommonBuffer
[ProcessorIndex
+ 1]);
1229 UT_ASSERT_EQUAL (LocalContext
->CommonBuffer
[LocalContext
->NumberOfProcessors
- 1], LocalContext
->NumberOfProcessors
- 1);
1231 return UNIT_TEST_PASSED
;
1235 Unit test of MP service StartupAllAPs.
1236 When this service is called from an AP, the return status should be EFI_DEVICE_ERROR.
1238 @param[in] Context Context pointer for this test.
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.
1246 TestStartupAllAPs3 (
1247 IN UNIT_TEST_CONTEXT Context
1252 MP_SERVICE_UT_CONTEXT
*LocalContext
;
1254 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
1256 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
1257 LocalContext
->ApNumber
= ApNumber
;
1258 Status
= MpServicesUnitTestStartupThisAP (
1259 LocalContext
->MpServices
,
1260 (EFI_AP_PROCEDURE
)RunMpServiceStartupAllAPsOnAp
,
1263 (VOID
*)LocalContext
1266 if (ApNumber
== LocalContext
->BspNumber
) {
1267 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
1269 UT_ASSERT_NOT_EFI_ERROR (Status
);
1270 UT_ASSERT_STATUS_EQUAL (LocalContext
->ApProcedureReturnStatus
, EFI_DEVICE_ERROR
);
1274 return UNIT_TEST_PASSED
;
1278 Unit test of MP service StartupAllAPs.
1279 When called with all AP timeout, the return status should be EFI_TIMEOUT.
1281 @param[in] Context Context pointer for this test.
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.
1289 TestStartupAllAPs4 (
1290 IN UNIT_TEST_CONTEXT Context
1294 MP_SERVICE_UT_CONTEXT
*LocalContext
;
1296 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
1298 Status
= MpServicesUnitTestStartupAllAPs (
1299 LocalContext
->MpServices
,
1300 (EFI_AP_PROCEDURE
)InfiniteLoopProcedure
,
1302 RUN_PROCEDURE_TIMEOUT_VALUE
,
1305 UT_ASSERT_STATUS_EQUAL (Status
, EFI_TIMEOUT
);
1307 Status
= MpServicesUnitTestStartupAllAPs (
1308 LocalContext
->MpServices
,
1309 (EFI_AP_PROCEDURE
)InfiniteLoopProcedure
,
1311 RUN_PROCEDURE_TIMEOUT_VALUE
,
1314 UT_ASSERT_STATUS_EQUAL (Status
, EFI_TIMEOUT
);
1316 return UNIT_TEST_PASSED
;
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.
1323 @param[in] Context Context pointer for this test.
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.
1331 TestStartupAllAPs5 (
1332 IN UNIT_TEST_CONTEXT Context
1337 MP_SERVICE_UT_CONTEXT
*LocalContext
;
1339 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
1341 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
1342 Status
= MpServicesUnitTestEnableDisableAP (
1343 LocalContext
->MpServices
,
1349 if (ApNumber
== LocalContext
->BspNumber
) {
1350 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
1352 UT_ASSERT_NOT_EFI_ERROR (Status
);
1356 Status
= MpServicesUnitTestStartupAllAPs (
1357 LocalContext
->MpServices
,
1358 (EFI_AP_PROCEDURE
)EmptyProcedure
,
1363 UT_ASSERT_STATUS_EQUAL (Status
, EFI_NOT_STARTED
);
1365 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
1366 Status
= MpServicesUnitTestEnableDisableAP (
1367 LocalContext
->MpServices
,
1373 if (ApNumber
== LocalContext
->BspNumber
) {
1374 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
1376 UT_ASSERT_NOT_EFI_ERROR (Status
);
1380 return UNIT_TEST_PASSED
;
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.
1389 @param[in] Context Context pointer for this test.
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.
1398 IN UNIT_TEST_CONTEXT Context
1403 UINTN ProcessorIndex
;
1404 MP_SERVICE_UT_CONTEXT
*LocalContext
;
1406 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
1408 for (NewBspNumber
= 0; NewBspNumber
<= LocalContext
->NumberOfProcessors
; NewBspNumber
++) {
1409 Status
= MpServicesUnitTestSwitchBSP (
1410 LocalContext
->MpServices
,
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
);
1420 UT_ASSERT_NOT_EFI_ERROR (Status
);
1422 SetMem (LocalContext
->CommonBuffer
, LocalContext
->NumberOfProcessors
* sizeof (*LocalContext
->CommonBuffer
), 0xFF);
1423 Status
= MpServicesUnitTestStartupAllAPs (
1424 LocalContext
->MpServices
,
1425 (EFI_AP_PROCEDURE
)StoreCpuNumbers
,
1428 (VOID
*)LocalContext
1430 UT_ASSERT_NOT_EFI_ERROR (Status
);
1432 for (ProcessorIndex
= 0; ProcessorIndex
< LocalContext
->NumberOfProcessors
; ProcessorIndex
++) {
1434 ((ProcessorIndex
== NewBspNumber
) && (LocalContext
->CommonBuffer
[ProcessorIndex
] == (UINTN
) ~0)) ||
1435 ((ProcessorIndex
!= NewBspNumber
) && (LocalContext
->CommonBuffer
[ProcessorIndex
] == ProcessorIndex
))
1439 Status
= MpServicesUnitTestSwitchBSP (
1440 LocalContext
->MpServices
,
1441 LocalContext
->BspNumber
,
1444 UT_ASSERT_NOT_EFI_ERROR (Status
);
1448 return UNIT_TEST_PASSED
;
1452 Unit test of MP service SwitchBSP.
1453 When run this procedure on AP, the return status should be EFI_DEVICE_ERROR.
1455 @param[in] Context Context pointer for this test.
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.
1464 IN UNIT_TEST_CONTEXT Context
1469 MP_SERVICE_UT_CONTEXT
*LocalContext
;
1471 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
1473 for (ApNumber
= 0; ApNumber
< LocalContext
->NumberOfProcessors
; ApNumber
++) {
1474 LocalContext
->ApNumber
= ApNumber
;
1475 Status
= MpServicesUnitTestStartupThisAP (
1476 LocalContext
->MpServices
,
1477 (EFI_AP_PROCEDURE
)RunMpServiceSwitchBSPOnAp
,
1480 (VOID
*)LocalContext
1483 if (ApNumber
== LocalContext
->BspNumber
) {
1484 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
1486 UT_ASSERT_NOT_EFI_ERROR (Status
);
1487 UT_ASSERT_STATUS_EQUAL (LocalContext
->ApProcedureReturnStatus
, EFI_DEVICE_ERROR
);
1491 return UNIT_TEST_PASSED
;
1495 Unit test of MP service SwitchBSP.
1496 When switch a disabled AP to be BSP, the return status should be EFI_INVALID_PARAMETER.
1498 @param[in] Context Context pointer for this test.
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.
1507 IN UNIT_TEST_CONTEXT Context
1512 MP_SERVICE_UT_CONTEXT
*LocalContext
;
1514 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
1516 for (NewBspNumber
= 0; NewBspNumber
< LocalContext
->NumberOfProcessors
; NewBspNumber
++) {
1517 Status
= MpServicesUnitTestEnableDisableAP (
1518 LocalContext
->MpServices
,
1524 if (NewBspNumber
== LocalContext
->BspNumber
) {
1525 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
1527 UT_ASSERT_NOT_EFI_ERROR (Status
);
1529 Status
= MpServicesUnitTestSwitchBSP (
1530 LocalContext
->MpServices
,
1534 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
1536 Status
= MpServicesUnitTestEnableDisableAP (
1537 LocalContext
->MpServices
,
1542 UT_ASSERT_NOT_EFI_ERROR (Status
);
1546 return UNIT_TEST_PASSED
;
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.
1556 @param[in] Context Context pointer for this test.
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.
1565 IN UNIT_TEST_CONTEXT Context
1570 EFI_PROCESSOR_INFORMATION ProcessorInfoBuffer
;
1571 MP_SERVICE_UT_CONTEXT
*LocalContext
;
1573 LocalContext
= (MP_SERVICE_UT_CONTEXT
*)Context
;
1575 for (NewBspNumber
= 0; NewBspNumber
< LocalContext
->NumberOfProcessors
; NewBspNumber
++) {
1576 Status
= MpServicesUnitTestSwitchBSP (
1577 LocalContext
->MpServices
,
1582 if (NewBspNumber
== LocalContext
->BspNumber
) {
1583 UT_ASSERT_STATUS_EQUAL (Status
, EFI_INVALID_PARAMETER
);
1585 UT_ASSERT_NOT_EFI_ERROR (Status
);
1587 Status
= MpServicesUnitTestGetProcessorInfo (
1588 LocalContext
->MpServices
,
1590 &ProcessorInfoBuffer
1592 UT_ASSERT_NOT_EFI_ERROR (Status
);
1594 (ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) &&
1595 (ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_ENABLED_BIT
)
1598 Status
= MpServicesUnitTestGetProcessorInfo (
1599 LocalContext
->MpServices
,
1600 LocalContext
->BspNumber
,
1601 &ProcessorInfoBuffer
1603 UT_ASSERT_NOT_EFI_ERROR (Status
);
1605 !(ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) &&
1606 !(ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_ENABLED_BIT
)
1609 Status
= MpServicesUnitTestEnableDisableAP (
1610 LocalContext
->MpServices
,
1611 LocalContext
->BspNumber
,
1615 UT_ASSERT_NOT_EFI_ERROR (Status
);
1617 Status
= MpServicesUnitTestSwitchBSP (
1618 LocalContext
->MpServices
,
1619 LocalContext
->BspNumber
,
1622 UT_ASSERT_NOT_EFI_ERROR (Status
);
1624 Status
= MpServicesUnitTestGetProcessorInfo (
1625 LocalContext
->MpServices
,
1626 LocalContext
->BspNumber
,
1627 &ProcessorInfoBuffer
1629 UT_ASSERT_NOT_EFI_ERROR (Status
);
1631 (ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) &&
1632 (ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_ENABLED_BIT
)
1635 Status
= MpServicesUnitTestGetProcessorInfo (
1636 LocalContext
->MpServices
,
1638 &ProcessorInfoBuffer
1640 UT_ASSERT_NOT_EFI_ERROR (Status
);
1642 !(ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_AS_BSP_BIT
) &&
1643 (ProcessorInfoBuffer
.StatusFlag
& PROCESSOR_ENABLED_BIT
)
1648 return UNIT_TEST_PASSED
;
1652 Create test suite and unit tests for both EdkiiPeiMpServices2Ppi and EfiMpServiceProtocol.
1654 @param[in] Framework A pointer to the framework that is being persisted.
1655 @param[in] Context A pointer to the private data buffer.
1657 @retval EFI_SUCCESS Create test suite and unit tests successfully.
1658 @retval Others Create test suite and unit tests unsuccessfully.
1662 IN UNIT_TEST_FRAMEWORK_HANDLE Framework
,
1663 IN MP_SERVICE_UT_CONTEXT
*Context
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
;
1675 MpServiceWhoAmITestSuite
= NULL
;
1676 MpServiceGetNumberOfProcessorsTestSuite
= NULL
;
1677 MpServiceGetProcessorInfoTestSuite
= NULL
;
1678 MpServiceEnableDisableAPTestSuite
= NULL
;
1679 MpServiceStartupThisAPTestSuite
= NULL
;
1680 MpServiceStartupAllAPsTestSuite
= NULL
;
1681 MpServiceSwitchBSPTestSuite
= NULL
;
1684 // Test WhoAmI function
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"));
1692 AddTestCase (MpServiceWhoAmITestSuite
, "Test WhoAmI 1", "TestWhoAmI1", TestWhoAmI1
, InitUTContext
, CheckUTContext
, Context
);
1695 // Test GetNumberOfProcessors function
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"));
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
);
1708 // Test GetProcessorInfo function
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"));
1716 AddTestCase (MpServiceGetProcessorInfoTestSuite
, "Test GetProcessorInfo 1", "TestGetProcessorInfo1", TestGetProcessorInfo1
, InitUTContext
, CheckUTContext
, Context
);
1717 AddTestCase (MpServiceGetProcessorInfoTestSuite
, "Test GetProcessorInfo 2", "TestGetProcessorInfo2", TestGetProcessorInfo2
, InitUTContext
, CheckUTContext
, Context
);
1720 // Test EnableDisableAP function
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"));
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
);
1733 // Test StartupThisAP function
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"));
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
);
1747 // Test StartupAllAPs function
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"));
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
);
1762 // Test SwitchBSP function
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"));
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
);