2 Unit tests of the CpuExceptionHandlerLib.
4 Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
5 SPDX-License-Identifier: BSD-2-Clause-Patent
9 #include "CpuExceptionHandlerTest.h"
10 #include <Library/UefiBootServicesTableLib.h>
13 Initialize Bsp Idt with a new Idt table and return the IA32_DESCRIPTOR buffer.
14 In PEIM, store original PeiServicePointer before new Idt table.
16 @return Pointer to the allocated IA32_DESCRIPTOR buffer.
24 IA32_DESCRIPTOR
*Idtr
;
26 Idtr
= AllocateZeroPool (sizeof (IA32_DESCRIPTOR
));
27 ASSERT (Idtr
!= NULL
);
28 NewIdtTable
= AllocateZeroPool (sizeof (IA32_IDT_GATE_DESCRIPTOR
) * CPU_INTERRUPT_NUM
);
29 ASSERT (NewIdtTable
!= NULL
);
30 Idtr
->Base
= (UINTN
)NewIdtTable
;
31 Idtr
->Limit
= (UINT16
)(sizeof (IA32_IDT_GATE_DESCRIPTOR
) * CPU_INTERRUPT_NUM
- 1);
38 Retrieve the number of logical processor in the platform and the number of those logical processors that
39 are enabled on this boot.
41 @param[in] MpServices MP_SERVICES structure.
42 @param[out] NumberOfProcessors Pointer to the total number of logical processors in the system, including
43 the BSP and disabled APs.
44 @param[out] NumberOfEnabledProcessors Pointer to the number of processors in the system that are enabled.
46 @retval EFI_SUCCESS Retrieve the number of logical processor successfully
47 @retval Others Retrieve the number of logical processor unsuccessfully
50 MpServicesUnitTestGetNumberOfProcessors (
51 IN MP_SERVICES MpServices
,
52 OUT UINTN
*NumberOfProcessors
,
53 OUT UINTN
*NumberOfEnabledProcessors
56 return MpServices
.Protocol
->GetNumberOfProcessors (MpServices
.Protocol
, NumberOfProcessors
, NumberOfEnabledProcessors
);
60 Get the handle number for the calling processor.
62 @param[in] MpServices MP_SERVICES structure.
63 @param[out] ProcessorNumber The handle number for the calling processor.
65 @retval EFI_SUCCESS Get the handle number for the calling processor successfully.
66 @retval Others Get the handle number for the calling processor unsuccessfully.
69 MpServicesUnitTestWhoAmI (
70 IN MP_SERVICES MpServices
,
71 OUT UINTN
*ProcessorNumber
74 return MpServices
.Protocol
->WhoAmI (MpServices
.Protocol
, ProcessorNumber
);
78 Caller gets one enabled AP to execute a caller-provided function.
80 @param[in] MpServices MP_SERVICES structure.
81 @param[in] Procedure Pointer to the function to be run on enabled APs of the system.
82 @param[in] ProcessorNumber The handle number of the AP.
83 @param[in] TimeoutInMicroSeconds Indicates the time limit in microseconds for APs to return from Procedure,
84 for blocking mode only. Zero means infinity.
85 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
88 @retval EFI_SUCCESS Caller gets one enabled AP to execute a caller-provided function successfully
89 @retval Others Caller gets one enabled AP to execute a caller-provided function unsuccessfully
92 MpServicesUnitTestStartupThisAP (
93 IN MP_SERVICES MpServices
,
94 IN EFI_AP_PROCEDURE Procedure
,
95 IN UINTN ProcessorNumber
,
96 IN UINTN TimeoutInMicroSeconds
,
97 IN VOID
*ProcedureArgument
100 return MpServices
.Protocol
->StartupThisAP (MpServices
.Protocol
, Procedure
, ProcessorNumber
, NULL
, TimeoutInMicroSeconds
, ProcedureArgument
, NULL
);
104 Execute a caller provided function on all enabled APs.
106 @param[in] MpServices MP_SERVICES structure.
107 @param[in] Procedure Pointer to the function to be run on enabled APs of the system.
108 @param[in] SingleThread If TRUE, then all the enabled APs execute the function specified by Procedure
109 one by one, in ascending order of processor handle number.
110 If FALSE, then all the enabled APs execute the function specified by Procedure
112 @param[in] TimeoutInMicroSeconds Indicates the time limit in microseconds for APs to return from Procedure,
113 for blocking mode only. Zero means infinity.
114 @param[in] ProcedureArgument The parameter passed into Procedure for all APs.
116 @retval EFI_SUCCESS Execute a caller provided function on all enabled APs successfully
117 @retval Others Execute a caller provided function on all enabled APs unsuccessfully
120 MpServicesUnitTestStartupAllAPs (
121 IN MP_SERVICES MpServices
,
122 IN EFI_AP_PROCEDURE Procedure
,
123 IN BOOLEAN SingleThread
,
124 IN UINTN TimeoutInMicroSeconds
,
125 IN VOID
*ProcedureArgument
128 return MpServices
.Protocol
->StartupAllAPs (MpServices
.Protocol
, Procedure
, SingleThread
, NULL
, TimeoutInMicroSeconds
, ProcedureArgument
, NULL
);
132 Get EFI_MP_SERVICES_PROTOCOL pointer.
134 @param[out] MpServices Pointer to the buffer where EFI_MP_SERVICES_PROTOCOL is stored
136 @retval EFI_SUCCESS EFI_MP_SERVICES_PROTOCOL interface is returned
137 @retval EFI_NOT_FOUND EFI_MP_SERVICES_PROTOCOL interface is not found
141 OUT MP_SERVICES
*MpServices
144 return gBS
->LocateProtocol (&gEfiMpServiceProtocolGuid
, NULL
, (VOID
**)&MpServices
->Protocol
);
148 Entry for CpuExceptionHandlerDxeTest driver.
150 @param ImageHandle Image handle this driver.
151 @param SystemTable Pointer to the System Table.
153 @retval EFI_SUCCESS The driver executed normally.
158 CpuExceptionHandlerTestEntry (
159 IN EFI_HANDLE ImageHandle
,
160 IN EFI_SYSTEM_TABLE
*SystemTable
164 UNIT_TEST_FRAMEWORK_HANDLE Framework
;
168 DEBUG ((DEBUG_INFO
, "%a v%a\n", UNIT_TEST_APP_NAME
, UNIT_TEST_APP_VERSION
));
171 // Start setting up the test framework for running the tests.
173 Status
= InitUnitTestFramework (&Framework
, UNIT_TEST_APP_NAME
, gEfiCallerBaseName
, UNIT_TEST_APP_VERSION
);
174 if (EFI_ERROR (Status
)) {
175 DEBUG ((DEBUG_ERROR
, "Failed in InitUnitTestFramework. Status = %r\n", Status
));
179 Status
= AddCommonTestCase (Framework
);
180 if (EFI_ERROR (Status
)) {
181 DEBUG ((DEBUG_ERROR
, "Failed in AddCommonTestCase. Status = %r\n", Status
));
186 // Execute the tests.
188 Status
= RunAllTestSuites (Framework
);
192 FreeUnitTestFramework (Framework
);