TianoCore EDK2 master
Loading...
Searching...
No Matches
DxeCpuExceptionHandlerUnitTest.c
Go to the documentation of this file.
1
11#include <Protocol/Timer.h>
12
19VOID *
21 VOID
22 )
23{
24 UINTN *NewIdtTable;
25 IA32_DESCRIPTOR *Idtr;
26
27 Idtr = AllocateZeroPool (sizeof (IA32_DESCRIPTOR));
28 ASSERT (Idtr != NULL);
29 NewIdtTable = AllocateZeroPool (sizeof (IA32_IDT_GATE_DESCRIPTOR) * CPU_INTERRUPT_NUM);
30 ASSERT (NewIdtTable != NULL);
31 Idtr->Base = (UINTN)NewIdtTable;
32 Idtr->Limit = (UINT16)(sizeof (IA32_IDT_GATE_DESCRIPTOR) * CPU_INTERRUPT_NUM - 1);
33
34 AsmWriteIdtr (Idtr);
35 return Idtr;
36}
37
52 IN MP_SERVICES MpServices,
53 OUT UINTN *NumberOfProcessors,
54 OUT UINTN *NumberOfEnabledProcessors
55 )
56{
57 return MpServices.Protocol->GetNumberOfProcessors (MpServices.Protocol, NumberOfProcessors, NumberOfEnabledProcessors);
58}
59
71 IN MP_SERVICES MpServices,
72 OUT UINTN *ProcessorNumber
73 )
74{
75 return MpServices.Protocol->WhoAmI (MpServices.Protocol, ProcessorNumber);
76}
77
94 IN MP_SERVICES MpServices,
95 IN EFI_AP_PROCEDURE Procedure,
96 IN UINTN ProcessorNumber,
97 IN UINTN TimeoutInMicroSeconds,
98 IN VOID *ProcedureArgument
99 )
100{
101 return MpServices.Protocol->StartupThisAP (MpServices.Protocol, Procedure, ProcessorNumber, NULL, TimeoutInMicroSeconds, ProcedureArgument, NULL);
102}
103
122 IN MP_SERVICES MpServices,
123 IN EFI_AP_PROCEDURE Procedure,
124 IN BOOLEAN SingleThread,
125 IN UINTN TimeoutInMicroSeconds,
126 IN VOID *ProcedureArgument
127 )
128{
129 return MpServices.Protocol->StartupAllAPs (MpServices.Protocol, Procedure, SingleThread, NULL, TimeoutInMicroSeconds, ProcedureArgument, NULL);
130}
131
142 OUT MP_SERVICES *MpServices
143 )
144{
145 return gBS->LocateProtocol (&gEfiMpServiceProtocolGuid, NULL, (VOID **)&MpServices->Protocol);
146}
147
158EFIAPI
160 IN EFI_HANDLE ImageHandle,
161 IN EFI_SYSTEM_TABLE *SystemTable
162 )
163{
164 EFI_STATUS Status;
165 UNIT_TEST_FRAMEWORK_HANDLE Framework;
166 EFI_TIMER_ARCH_PROTOCOL *TimerArchProtocol;
167 UINT64 TimerPeriod;
168
169 Framework = NULL;
170 TimerArchProtocol = NULL;
171 TimerPeriod = 0;
172
173 DEBUG ((DEBUG_INFO, "%a v%a\n", UNIT_TEST_APP_NAME, UNIT_TEST_APP_VERSION));
174
175 //
176 // Start setting up the test framework for running the tests.
177 //
178 Status = InitUnitTestFramework (&Framework, UNIT_TEST_APP_NAME, gEfiCallerBaseName, UNIT_TEST_APP_VERSION);
179 if (EFI_ERROR (Status)) {
180 DEBUG ((DEBUG_ERROR, "Failed in InitUnitTestFramework. Status = %r\n", Status));
181 goto EXIT;
182 }
183
184 Status = AddCommonTestCase (Framework);
185 if (EFI_ERROR (Status)) {
186 DEBUG ((DEBUG_ERROR, "Failed in AddCommonTestCase. Status = %r\n", Status));
187 goto EXIT;
188 }
189
190 //
191 // If HpetTimer driver has been dispatched, disable HpetTimer before Unit Test.
192 //
193 gBS->LocateProtocol (&gEfiTimerArchProtocolGuid, NULL, (VOID **)&TimerArchProtocol);
194 if (TimerArchProtocol != NULL) {
195 Status = TimerArchProtocol->GetTimerPeriod (TimerArchProtocol, &TimerPeriod);
196 ASSERT_EFI_ERROR (Status);
197 if (TimerPeriod > 0) {
198 DEBUG ((DEBUG_INFO, "HpetTimer has been dispatched. Disable HpetTimer.\n"));
199 Status = TimerArchProtocol->SetTimerPeriod (TimerArchProtocol, 0);
200 ASSERT_EFI_ERROR (Status);
201 }
202 }
203
204 //
205 // Execute the tests.
206 //
207 Status = RunAllTestSuites (Framework);
208
209 //
210 // Restore HpetTimer after Unit Test.
211 //
212 if ((TimerArchProtocol != NULL) && (TimerPeriod > 0)) {
213 DEBUG ((DEBUG_INFO, "Restore HpetTimer after DxeCpuExceptionHandlerLib UnitTest.\n"));
214 Status = TimerArchProtocol->SetTimerPeriod (TimerArchProtocol, TimerPeriod);
215 ASSERT_EFI_ERROR (Status);
216 }
217
218EXIT:
219 if (Framework) {
220 FreeUnitTestFramework (Framework);
221 }
222
223 return Status;
224}
UINT64 UINTN
EFI_STATUS AddCommonTestCase(IN UNIT_TEST_FRAMEWORK_HANDLE Framework)
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 GetMpServices(OUT MP_SERVICES *MpServices)
EFI_STATUS MpServicesUnitTestGetNumberOfProcessors(IN MP_SERVICES MpServices, OUT UINTN *NumberOfProcessors, OUT UINTN *NumberOfEnabledProcessors)
EFI_STATUS EFIAPI CpuExceptionHandlerTestEntry(IN EFI_HANDLE ImageHandle, IN EFI_SYSTEM_TABLE *SystemTable)
EFI_STATUS MpServicesUnitTestStartupThisAP(IN MP_SERVICES MpServices, IN EFI_AP_PROCEDURE Procedure, IN UINTN ProcessorNumber, IN UINTN TimeoutInMicroSeconds, IN VOID *ProcedureArgument)
VOID * InitializeBspIdt(VOID)
VOID *EFIAPI AllocateZeroPool(IN UINTN AllocationSize)
#define NULL
Definition: Base.h:319
#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
VOID(EFIAPI * EFI_AP_PROCEDURE)(IN OUT VOID *Buffer)
Definition: PiMultiPhase.h:198
RETURN_STATUS EFI_STATUS
Definition: UefiBaseType.h:29
VOID * EFI_HANDLE
Definition: UefiBaseType.h:33
EFI_BOOT_SERVICES * gBS
EFI_STATUS EFIAPI RunAllTestSuites(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
Definition: RunTests.c:145
EFI_STATUS EFIAPI FreeUnitTestFramework(IN UNIT_TEST_FRAMEWORK_HANDLE FrameworkHandle)
Definition: UnitTestLib.c:150
EFI_STATUS EFIAPI InitUnitTestFramework(OUT UNIT_TEST_FRAMEWORK_HANDLE *FrameworkHandle, IN CHAR8 *Title, IN CHAR8 *ShortTitle, IN CHAR8 *VersionString)
Definition: UnitTestLib.c:204
VOID EFIAPI AsmWriteIdtr(IN CONST IA32_DESCRIPTOR *Idtr)