EfiMpServicesUnitTestCommom.c 61 KB

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