TianoCore EDK2 master
Loading...
Searching...
No Matches
EfiMpServicesUnitTestCommom.c
Go to the documentation of this file.
1
11
22EFIAPI
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);
45
46 Status = MpServicesUnitTestWhoAmI (LocalContext->MpServices, &BspNumber);
48 DEBUG ((DEBUG_INFO, "%a: BspNumber = 0x%x\n", __func__, BspNumber));
49
51 LocalContext->MpServices,
52 &NumberOfProcessors,
53 &NumberOfEnabledProcessors
54 );
56 DEBUG ((
57 DEBUG_INFO,
58 "%a: NumberOfProcessors = 0x%x, NumberOfEnabledProcessors = 0x%x\n",
59 __func__,
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++) {
79 LocalContext->MpServices,
80 ProcessorNumber,
81 &ProcessorInfoBuffer
82 );
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", __func__, ProcessorNumber));
94 LocalContext->MpServices,
95 ProcessorNumber,
96 TRUE,
97 NULL
98 );
100 }
101 }
102
103 UT_ASSERT_TRUE (IndexOfDisabledAPs == NumberOfDisabledAPs);
104 }
105
106 return UNIT_TEST_PASSED;
107}
108
115VOID
116EFIAPI
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", __func__, BspNumber));
138 }
139
140 ASSERT (BspNumber == LocalContext->BspNumber);
141
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", __func__, NumberOfProcessors));
152 }
153
154 if (NumberOfEnabledProcessors != LocalContext->NumberOfProcessors) {
155 DEBUG ((DEBUG_INFO, "%a: New NumberOfEnabledProcessors = 0x%x\n", __func__, NumberOfEnabledProcessors));
156
157 for (ProcessorNumber = 0; ProcessorNumber < LocalContext->NumberOfProcessors; ProcessorNumber++) {
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", __func__, ProcessorNumber));
168 LocalContext->MpServices,
169 ProcessorNumber,
170 TRUE,
171 NULL
172 );
173 ASSERT_EFI_ERROR (Status);
174 }
175 }
176 }
177}
178
185VOID
186EFIAPI
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 __func__,
208 LocalContext->DisabledApNumber[IndexOfDisabledAPs]
209 ));
210
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
233VOID
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
262VOID
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
292VOID
294 IN OUT VOID *Buffer
295 )
296{
297 volatile BOOLEAN InfiniteLoop;
298
299 InfiniteLoop = TRUE;
300
301 while (InfiniteLoop) {
302 }
303}
304
310VOID
312 IN OUT VOID *Buffer
313 )
314{
315}
316
322VOID
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
345VOID
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
367VOID
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
389VOID
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,
401 LocalContext->ApNumber,
402 0,
403 NULL
404 );
405}
406
412VOID
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,
424 FALSE,
425 0,
426 NULL
427 );
428}
429
435VOID
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
463EFIAPI
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 );
480 UT_ASSERT_TRUE (ProcessorNumber < LocalContext->NumberOfProcessors);
481
482 SetMem (LocalContext->CommonBuffer, LocalContext->NumberOfProcessors * sizeof (*LocalContext->CommonBuffer), 0xFF);
483 LocalContext->CommonBuffer[ProcessorNumber] = ProcessorNumber;
484
486 LocalContext->MpServices,
488 FALSE,
489 0,
490 (VOID *)LocalContext
491 );
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
517EFIAPI
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
530 LocalContext->MpServices,
531 &NumberOfProcessors,
532 &NumberOfEnabledProcessors
533 );
535 UT_ASSERT_TRUE (NumberOfProcessors > 0 && NumberOfProcessors >= NumberOfEnabledProcessors);
536
537 return UNIT_TEST_PASSED;
538}
539
551EFIAPI
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;
565 LocalContext->MpServices,
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 {
576 UT_ASSERT_STATUS_EQUAL (LocalContext->ApProcedureReturnStatus, EFI_DEVICE_ERROR);
577 }
578 }
579
580 return UNIT_TEST_PASSED;
581}
582
594EFIAPI
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++) {
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 {
619
621 LocalContext->MpServices,
622 &NumberOfProcessors,
623 &NumberOfEnabledProcessors
624 );
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++) {
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 {
648
650 LocalContext->MpServices,
651 &NumberOfProcessors,
652 &NumberOfEnabledProcessors
653 );
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
681EFIAPI
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++) {
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 {
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
728EFIAPI
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;
742 LocalContext->MpServices,
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 {
753 UT_ASSERT_STATUS_EQUAL (LocalContext->ApProcedureReturnStatus, EFI_DEVICE_ERROR);
754 }
755 }
756
757 return UNIT_TEST_PASSED;
758}
759
773EFIAPI
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++) {
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 {
798
800 LocalContext->MpServices,
802 ApNumber,
803 0,
804 NULL
805 );
806 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
807
809 LocalContext->MpServices,
810 ApNumber,
811 TRUE,
812 NULL
813 );
815
817 LocalContext->MpServices,
819 ApNumber,
820 0,
821 NULL
822 );
824 }
825 }
826
827 return UNIT_TEST_PASSED;
828}
829
841EFIAPI
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;
855 LocalContext->MpServices,
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 {
866 UT_ASSERT_STATUS_EQUAL (LocalContext->ApProcedureReturnStatus, EFI_DEVICE_ERROR);
867 }
868 }
869
870 return UNIT_TEST_PASSED;
871}
872
884EFIAPI
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++) {
900 LocalContext->MpServices,
901 ApNumber,
902 &ProcessorInfoBuffer
903 );
905
906 OldHealthFlag = ProcessorInfoBuffer.StatusFlag & PROCESSOR_HEALTH_STATUS_BIT;
907 NewHealthFlag = OldHealthFlag ^ PROCESSOR_HEALTH_STATUS_BIT;
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 {
919
921 LocalContext->MpServices,
922 ApNumber,
923 &ProcessorInfoBuffer
924 );
926 UT_ASSERT_TRUE ((ProcessorInfoBuffer.StatusFlag & PROCESSOR_HEALTH_STATUS_BIT) == NewHealthFlag);
927
929 LocalContext->MpServices,
930 ApNumber,
931 TRUE,
932 &OldHealthFlag
933 );
935 }
936 }
937
938 return UNIT_TEST_PASSED;
939}
940
954EFIAPI
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);
969 LocalContext->MpServices,
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 {
982
983 for (ProcessorIndex = 0; ProcessorIndex < LocalContext->NumberOfProcessors; ProcessorIndex++) {
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
1006EFIAPI
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;
1020 LocalContext->MpServices,
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
1049EFIAPI
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++) {
1062 LocalContext->MpServices,
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
1090EFIAPI
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++) {
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
1115 LocalContext->MpServices,
1117 ApNumber,
1118 0,
1119 NULL
1120 );
1121 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1122
1124 LocalContext->MpServices,
1125 ApNumber,
1126 TRUE,
1127 NULL
1128 );
1129 UT_ASSERT_NOT_EFI_ERROR (Status);
1130
1132 LocalContext->MpServices,
1134 ApNumber,
1135 0,
1136 NULL
1137 );
1138 UT_ASSERT_NOT_EFI_ERROR (Status);
1139 }
1140 }
1141
1142 return UNIT_TEST_PASSED;
1143}
1144
1156EFIAPI
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);
1169 LocalContext->MpServices,
1171 FALSE,
1172 0,
1173 (VOID *)LocalContext
1174 );
1175 UT_ASSERT_NOT_EFI_ERROR (Status);
1176
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))
1181 );
1182 }
1183
1184 return UNIT_TEST_PASSED;
1185}
1186
1199EFIAPI
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));
1212 LocalContext->MpServices,
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
1245EFIAPI
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;
1259 LocalContext->MpServices,
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
1288EFIAPI
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
1299 LocalContext->MpServices,
1301 TRUE,
1302 RUN_PROCEDURE_TIMEOUT_VALUE,
1303 NULL
1304 );
1305 UT_ASSERT_STATUS_EQUAL (Status, EFI_TIMEOUT);
1306
1308 LocalContext->MpServices,
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
1330EFIAPI
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++) {
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
1357 LocalContext->MpServices,
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++) {
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
1396EFIAPI
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++) {
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);
1424 LocalContext->MpServices,
1426 FALSE,
1427 0,
1428 (VOID *)LocalContext
1429 );
1430 UT_ASSERT_NOT_EFI_ERROR (Status);
1431
1432 for (ProcessorIndex = 0; ProcessorIndex < LocalContext->NumberOfProcessors; ProcessorIndex++) {
1434 ((ProcessorIndex == NewBspNumber) && (LocalContext->CommonBuffer[ProcessorIndex] == (UINTN) ~0)) ||
1435 ((ProcessorIndex != NewBspNumber) && (LocalContext->CommonBuffer[ProcessorIndex] == ProcessorIndex))
1436 );
1437 }
1438
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
1462EFIAPI
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;
1476 LocalContext->MpServices,
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
1505EFIAPI
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++) {
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
1530 LocalContext->MpServices,
1531 NewBspNumber,
1532 TRUE
1533 );
1534 UT_ASSERT_STATUS_EQUAL (Status, EFI_INVALID_PARAMETER);
1535
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
1563EFIAPI
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++) {
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
1588 LocalContext->MpServices,
1589 NewBspNumber,
1590 &ProcessorInfoBuffer
1591 );
1592 UT_ASSERT_NOT_EFI_ERROR (Status);
1594 (ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) &&
1595 (ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT)
1596 );
1597
1599 LocalContext->MpServices,
1600 LocalContext->BspNumber,
1601 &ProcessorInfoBuffer
1602 );
1603 UT_ASSERT_NOT_EFI_ERROR (Status);
1605 !(ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) &&
1606 !(ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT)
1607 );
1608
1610 LocalContext->MpServices,
1611 LocalContext->BspNumber,
1612 TRUE,
1613 NULL
1614 );
1615 UT_ASSERT_NOT_EFI_ERROR (Status);
1616
1618 LocalContext->MpServices,
1619 LocalContext->BspNumber,
1620 TRUE
1621 );
1622 UT_ASSERT_NOT_EFI_ERROR (Status);
1623
1625 LocalContext->MpServices,
1626 LocalContext->BspNumber,
1627 &ProcessorInfoBuffer
1628 );
1629 UT_ASSERT_NOT_EFI_ERROR (Status);
1631 (ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) &&
1632 (ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT)
1633 );
1634
1636 LocalContext->MpServices,
1637 NewBspNumber,
1638 &ProcessorInfoBuffer
1639 );
1640 UT_ASSERT_NOT_EFI_ERROR (Status);
1642 !(ProcessorInfoBuffer.StatusFlag & PROCESSOR_AS_BSP_BIT) &&
1643 (ProcessorInfoBuffer.StatusFlag & PROCESSOR_ENABLED_BIT)
1644 );
1645 }
1646 }
1647
1648 return UNIT_TEST_PASSED;
1649}
1650
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}
UINT64 UINTN
VOID *EFIAPI SetMem(OUT VOID *Buffer, IN UINTN Length, IN UINT8 Value)
Definition: SetMemWrapper.c:38
VOID *EFIAPI ZeroMem(OUT VOID *Buffer, IN UINTN Length)
EFI_STATUS MpServicesUnitTestWhoAmI(IN MP_SERVICES MpServices, OUT UINTN *ProcessorNumber)
EFI_STATUS MpServicesUnitTestStartupAllAPs(IN MP_SERVICES MpServices, IN EFI_AP_PROCEDURE Procedure, IN BOOLEAN SingleThread, IN UINTN TimeoutInMicroSeconds, IN VOID *ProcedureArgument)
EFI_STATUS MpServicesUnitTestGetNumberOfProcessors(IN MP_SERVICES MpServices, OUT UINTN *NumberOfProcessors, OUT UINTN *NumberOfEnabledProcessors)
EFI_STATUS MpServicesUnitTestStartupThisAP(IN MP_SERVICES MpServices, IN EFI_AP_PROCEDURE Procedure, IN UINTN ProcessorNumber, IN UINTN TimeoutInMicroSeconds, IN VOID *ProcedureArgument)
EFI_STATUS MpServicesUnitTestGetProcessorInfo(IN MP_SERVICES MpServices, IN UINTN ProcessorNumber, OUT EFI_PROCESSOR_INFORMATION *ProcessorInfoBuffer)
EFI_STATUS MpServicesUnitTestEnableDisableAP(IN MP_SERVICES MpServices, IN UINTN ProcessorNumber, IN BOOLEAN EnableAP, IN UINT32 *HealthFlag)
EFI_STATUS MpServicesUnitTestSwitchBSP(IN MP_SERVICES MpServices, IN UINTN ProcessorNumber, IN BOOLEAN EnableOldBSP)
EFI_STATUS MpServicesUnitTestGetMpServices(OUT MP_SERVICES *MpServices)
EFI_STATUS AddCommonTestCase(IN UNIT_TEST_FRAMEWORK_HANDLE Framework, IN MP_SERVICE_UT_CONTEXT *Context)
VOID EFIAPI FreeUTContext(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestStartupThisAP3(IN UNIT_TEST_CONTEXT Context)
VOID RunMpServiceStartupThisAPOnAp(IN OUT VOID *Buffer)
UNIT_TEST_STATUS EFIAPI TestStartupAllAPs5(IN UNIT_TEST_CONTEXT Context)
VOID RunMpServiceEnableDisableAPOnAp(IN OUT VOID *Buffer)
VOID StoreCpuNumbers(IN OUT VOID *Buffer)
UNIT_TEST_STATUS EFIAPI TestGetProcessorInfo2(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestStartupThisAP4(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestEnableDisableAP3(IN UNIT_TEST_CONTEXT Context)
VOID RunMpServiceSwitchBSPOnAp(IN OUT VOID *Buffer)
VOID RunMpServiceStartupAllAPsOnAp(IN OUT VOID *Buffer)
UNIT_TEST_STATUS EFIAPI TestStartupAllAPs3(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestEnableDisableAP1(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestStartupThisAP2(IN UNIT_TEST_CONTEXT Context)
VOID EFIAPI CheckUTContext(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI InitUTContext(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestStartupAllAPs1(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestGetNumberOfProcessors2(IN UNIT_TEST_CONTEXT Context)
VOID InfiniteLoopProcedure(IN OUT VOID *Buffer)
UNIT_TEST_STATUS EFIAPI TestGetNumberOfProcessors1(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestStartupAllAPs2(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestSwitchBSP4(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestSwitchBSP3(IN UNIT_TEST_CONTEXT Context)
VOID StoreAPsExecutionOrder(IN OUT VOID *Buffer)
UNIT_TEST_STATUS EFIAPI TestStartupThisAP1(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestWhoAmI1(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestGetProcessorInfo1(IN UNIT_TEST_CONTEXT Context)
VOID EmptyProcedure(IN OUT VOID *Buffer)
UNIT_TEST_STATUS EFIAPI TestEnableDisableAP2(IN UNIT_TEST_CONTEXT Context)
VOID RunMpServiceGetProcessorInfoOnAp(IN OUT VOID *Buffer)
UNIT_TEST_STATUS EFIAPI TestStartupAllAPs4(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestSwitchBSP1(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestSwitchBSP2(IN UNIT_TEST_CONTEXT Context)
UNIT_TEST_STATUS EFIAPI TestGetNumberOfProcessors3(IN UNIT_TEST_CONTEXT Context)
VOID RunMpServiceGetNumberOfProcessorsOnAp(IN OUT VOID *Buffer)
VOID EFIAPI FreePages(IN VOID *Buffer, IN UINTN Pages)
#define NULL
Definition: Base.h:319
#define TRUE
Definition: Base.h:301
#define FALSE
Definition: Base.h:307
#define IN
Definition: Base.h:279
#define OUT
Definition: Base.h:284
#define ASSERT_EFI_ERROR(StatusParameter)
Definition: DebugLib.h:462
#define DEBUG(Expression)
Definition: DebugLib.h:434
#define PROCESSOR_HEALTH_STATUS_BIT
Definition: MpService.h:84
#define PROCESSOR_AS_BSP_BIT
Definition: MpService.h:70
#define PROCESSOR_ENABLED_BIT
Definition: MpService.h:77
VOID(EFIAPI * EFI_AP_PROCEDURE)(IN OUT VOID *Buffer)
Definition: PiMultiPhase.h:198
VOID *EFIAPI AllocatePages(IN UINTN Pages)
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
#define EFI_SIZE_TO_PAGES(Size)
Definition: UefiBaseType.h:200
#define EFI_SUCCESS
Definition: UefiBaseType.h:112
#define UT_ASSERT_NOT_NULL(Pointer)
Definition: UnitTestLib.h:439
VOID * UNIT_TEST_CONTEXT
Definition: UnitTestLib.h:54
#define UT_ASSERT_TRUE(Expression)
Definition: UnitTestLib.h:350
#define UT_ASSERT_EQUAL(ValueA, ValueB)
Definition: UnitTestLib.h:375
#define UT_ASSERT_STATUS_EQUAL(Status, Expected)
Definition: UnitTestLib.h:427
EFI_STATUS EFIAPI CreateUnitTestSuite(OUT UNIT_TEST_SUITE_HANDLE *SuiteHandle, IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *Name, IN UNIT_TEST_SUITE_SETUP Setup OPTIONAL, IN UNIT_TEST_SUITE_TEARDOWN Teardown OPTIONAL)
Definition: UnitTestLib.c:326
EFI_STATUS EFIAPI AddTestCase(IN UNIT_TEST_SUITE_HANDLE SuiteHandle, IN CHAR8 *Description, IN CHAR8 *Name, IN UNIT_TEST_FUNCTION Function, IN UNIT_TEST_PREREQUISITE Prerequisite OPTIONAL, IN UNIT_TEST_CLEANUP CleanUp OPTIONAL, IN UNIT_TEST_CONTEXT Context OPTIONAL)
Definition: UnitTestLib.c:426
UINT32 UNIT_TEST_STATUS
Definition: UnitTestLib.h:16
#define UT_ASSERT_NOT_EFI_ERROR(Status)
Definition: UnitTestLib.h:414