TianoCore EDK2 master
|
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/UnitTestLib.h>
#include <Library/MemoryAllocationLib.h>
#include <Library/UnitTestHostBaseLib.h>
#include <Library/CpuExceptionHandlerLib.h>
#include <Library/UefiLib.h>
#include <Library/SerialPortLib.h>
#include <Library/HobLib.h>
#include <Library/CpuPageTableLib.h>
#include <Guid/MemoryAllocationHob.h>
#include <Protocol/MpService.h>
#include <PiPei.h>
#include <Ppi/MpServices2.h>
Go to the source code of this file.
Data Structures | |
struct | CPU_REGISTER_BUFFER |
union | MP_SERVICES |
struct | EXCEPTION_STACK_SWITCH_CONTEXT |
struct | GENERAL_REGISTER |
struct | GENERAL_REGISTER_IA32 |
Macros | |
#define | UNIT_TEST_APP_NAME "Cpu Exception Handler Lib Unit Tests" |
#define | UNIT_TEST_APP_VERSION "1.0" |
#define | CPU_INTERRUPT_NUM 256 |
#define | SPEC_MAX_EXCEPTION_NUM 22 |
#define | CR4_RESERVED_BIT BIT15 |
Variables | |
UINTN | mFaultInstructionLength |
EFI_EXCEPTION_TYPE | mExceptionType |
UINTN | mRspAddress [] |
Copyright (c) 2022, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent
Four test cases are created in this Unit Test module. a.Test if exception handler can be registered/unregistered for no error code exception In this test case, only no error code exception is triggered and tested by INTn instruction. The special hanlder for these exception will modify a global variable for check.
b.Test if exception handler can be registered/unregistered for GP and PF. In this test case, GP exception is triggered and tested by setting CR4_RESERVED_BIT to 1. PF exception is triggered and tested by writting to not-present or RO addres. The special hanlder for these exceptions will set a global vartiable for check and adjust Rip to return from fault exception.
c.Test if Cpu Context is consistent before and after exception. In this test case:
d.Test if stack overflow can be captured by CpuStackGuard in both Bsp and AP. In this test case, stack overflow is triggered by a funtion which calls itself continuously. This test case triggers stack overflow in both BSP and AP. All AP use same Idt with Bsp. The expectation is:
Definition in file CpuExceptionHandlerTest.h.
#define CPU_INTERRUPT_NUM 256 |
Definition at line 58 of file CpuExceptionHandlerTest.h.
#define CR4_RESERVED_BIT BIT15 |
Definition at line 60 of file CpuExceptionHandlerTest.h.
#define SPEC_MAX_EXCEPTION_NUM 22 |
Definition at line 59 of file CpuExceptionHandlerTest.h.
#define UNIT_TEST_APP_NAME "Cpu Exception Handler Lib Unit Tests" |
Definition at line 55 of file CpuExceptionHandlerTest.h.
#define UNIT_TEST_APP_VERSION "1.0" |
Definition at line 56 of file CpuExceptionHandlerTest.h.
EFI_STATUS AddCommonTestCase | ( | IN UNIT_TEST_FRAMEWORK_HANDLE | Framework | ) |
Create CpuExceptionLibUnitTestSuite and add test case.
[in] | FrameworkHandle | Unit test framework. |
EFI_OUT_OF_RESOURCES | There are not enough resources available to initialize the unit test suite. |
Definition at line 828 of file CpuExceptionHandlerTestCommon.c.
VOID EFIAPI AdjustCpuContextHandler | ( | IN EFI_EXCEPTION_TYPE | ExceptionType, |
IN EFI_SYSTEM_CONTEXT | SystemContext | ||
) |
Special handler for ConsistencyOfCpuContext test case. General register in SystemContext is modified to mExpectedContextInHandler in this handler.
ExceptionType | Exception type. |
SystemContext | Pointer to EFI_SYSTEM_CONTEXT. |
Special handler for ConsistencyOfCpuContext test case.
ExceptionType | Exception type. |
SystemContext | Pointer to EFI_SYSTEM_CONTEXT. |
Definition at line 49 of file ArchExceptionHandlerTest.c.
VOID EFIAPI AdjustRipForFaultHandler | ( | IN EFI_EXCEPTION_TYPE | ExceptionType, |
IN EFI_SYSTEM_CONTEXT | SystemContext | ||
) |
Special handler for fault exception. This handler sets Rip/Eip in SystemContext to the instruction address after the exception instruction.
ExceptionType | Exception type. |
SystemContext | Pointer to EFI_SYSTEM_CONTEXT. |
Special handler for fault exception. Rip/Eip in SystemContext will be modified to the instruction after the exception instruction.
ExceptionType | Exception type. |
SystemContext | Pointer to EFI_SYSTEM_CONTEXT. |
Definition at line 32 of file ArchExceptionHandlerTest.c.
VOID EFIAPI AsmTestConsistencyOfCpuContext | ( | IN EFI_EXCEPTION_TYPE | ExceptionType, |
IN UINTN FaultParameter | OPTIONAL | ||
) |
Test consistency of Cpu context. Four steps:
Rcx/Ecx in mExpectedContextInHandler is decided by different exception type runtime since Rcx/Ecx is needed in assembly code. For GP and PF, Rcx/Ecx is set to FaultParameter. For other exception triggered by INTn, Rcx/Ecx is set to ExceptionType.
[in] | ExceptionType | Exception type. |
[in] | FaultParameter | Parameter for GP and PF. OPTIONAL |
UNIT_TEST_STATUS CompareCpuContext | ( | VOID | ) |
Compare cpu context in ConsistencyOfCpuContext test case. 1.Compare mActualContextInHandler with mExpectedContextInHandler. 2.Compare mActualContextAfterException with mActualContextAfterException.
UNIT_TEST_PASSED | The Unit test has completed and it was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Compare cpu context in ConsistencyOfCpuContext test case. 1.Compare mActualContextInHandler with mExpectedContextInHandler. 2.Compare mActualContextAfterException with mExpectedContextAfterException.
UNIT_TEST_PASSED | The Unit test has completed and it was successful. |
UNIT_TEST_ERROR_TEST_FAILED | A test case assertion has failed. |
Definition at line 94 of file ArchExceptionHandlerTest.c.
VOID EFIAPI CpuStackGuardExceptionHandler | ( | IN EFI_EXCEPTION_TYPE | ExceptionType, |
IN EFI_SYSTEM_CONTEXT | SystemContext | ||
) |
Special handler for CpuStackGuard test case.
ExceptionType | Exception type. |
SystemContext | Pointer to EFI_SYSTEM_CONTEXT. |
Definition at line 123 of file ArchExceptionHandlerTest.c.
EFI_STATUS GetMpServices | ( | OUT MP_SERVICES * | MpServices | ) |
Get EFI_MP_SERVICES_PROTOCOL/EDKII_PEI_MP_SERVICES2_PPI pointer.
[out] | MpServices | Pointer to the MP_SERVICES buffer |
EFI_SUCCESS | EFI_MP_SERVICES_PROTOCOL/PPI interface is returned |
EFI_NOT_FOUND | EFI_MP_SERVICES_PROTOCOL/PPI interface is not found |
Get EFI_MP_SERVICES_PROTOCOL pointer.
[out] | MpServices | Pointer to the buffer where EFI_MP_SERVICES_PROTOCOL is stored |
EFI_SUCCESS | EFI_MP_SERVICES_PROTOCOL interface is returned |
EFI_NOT_FOUND | EFI_MP_SERVICES_PROTOCOL interface is not found |
Get EDKII_PEI_MP_SERVICES2_PPI pointer.
[out] | MpServices | Pointer to the buffer where EDKII_PEI_MP_SERVICES2_PPI is stored |
EFI_SUCCESS | EDKII_PEI_MP_SERVICES2_PPI interface is returned |
EFI_NOT_FOUND | EDKII_PEI_MP_SERVICES2_PPI interface is not found |
Definition at line 141 of file DxeCpuExceptionHandlerUnitTest.c.
VOID * InitializeBspIdt | ( | VOID | ) |
Initialize Bsp Idt with a new Idt table and return the IA32_DESCRIPTOR buffer. In PEIM, store original PeiServicePointer before new Idt table.
Definition at line 20 of file DxeCpuExceptionHandlerUnitTest.c.
EFI_STATUS MpServicesUnitTestGetNumberOfProcessors | ( | IN MP_SERVICES | MpServices, |
OUT UINTN * | NumberOfProcessors, | ||
OUT UINTN * | NumberOfEnabledProcessors | ||
) |
Retrieve the number of logical processor in the platform and the number of those logical processors that are enabled on this boot.
[in] | MpServices | MP_SERVICES structure. |
[out] | NumberOfProcessors | Pointer to the total number of logical processors in the system, including the BSP and disabled APs. |
[out] | NumberOfEnabledProcessors | Pointer to the number of processors in the system that are enabled. |
EFI_SUCCESS | Retrieve the number of logical processor successfully |
Others | Retrieve the number of logical processor unsuccessfully |
Definition at line 51 of file DxeCpuExceptionHandlerUnitTest.c.
EFI_STATUS MpServicesUnitTestStartupAllAPs | ( | IN MP_SERVICES | MpServices, |
IN EFI_AP_PROCEDURE | Procedure, | ||
IN BOOLEAN | SingleThread, | ||
IN UINTN | TimeoutInMicroSeconds, | ||
IN VOID * | ProcedureArgument | ||
) |
Execute a caller provided function on all enabled APs.
[in] | MpServices | MP_SERVICES structure. |
[in] | Procedure | Pointer to the function to be run on enabled APs of the system. |
[in] | SingleThread | If TRUE, then all the enabled APs execute the function specified by Procedure one by one, in ascending order of processor handle number. If FALSE, then all the enabled APs execute the function specified by Procedure simultaneously. |
[in] | TimeoutInMicroseconds | Indicates the time limit in microseconds for APs to return from Procedure, for blocking mode only. Zero means infinity. |
[in] | ProcedureArgument | The parameter passed into Procedure for all APs. |
EFI_SUCCESS | Execute a caller provided function on all enabled APs successfully |
Others | Execute a caller provided function on all enabled APs unsuccessfully |
Execute a caller provided function on all enabled APs.
[in] | MpServices | MP_SERVICES structure. |
[in] | Procedure | Pointer to the function to be run on enabled APs of the system. |
[in] | SingleThread | If TRUE, then all the enabled APs execute the function specified by Procedure one by one, in ascending order of processor handle number. If FALSE, then all the enabled APs execute the function specified by Procedure simultaneously. |
[in] | TimeoutInMicroSeconds | Indicates the time limit in microseconds for APs to return from Procedure, for blocking mode only. Zero means infinity. |
[in] | ProcedureArgument | The parameter passed into Procedure for all APs. |
EFI_SUCCESS | Execute a caller provided function on all enabled APs successfully |
Others | Execute a caller provided function on all enabled APs unsuccessfully |
Definition at line 121 of file DxeCpuExceptionHandlerUnitTest.c.
EFI_STATUS MpServicesUnitTestStartupThisAP | ( | IN MP_SERVICES | MpServices, |
IN EFI_AP_PROCEDURE | Procedure, | ||
IN UINTN | ProcessorNumber, | ||
IN UINTN | TimeoutInMicroSeconds, | ||
IN VOID * | ProcedureArgument | ||
) |
Caller gets one enabled AP to execute a caller-provided function.
[in] | MpServices | MP_SERVICES structure. |
[in] | Procedure | Pointer to the function to be run on enabled APs of the system. |
[in] | ProcessorNumber | The handle number of the AP. |
[in] | TimeoutInMicroseconds | Indicates the time limit in microseconds for APs to return from Procedure, for blocking mode only. Zero means infinity. |
[in] | ProcedureArgument | The parameter passed into Procedure for all APs. |
EFI_SUCCESS | Caller gets one enabled AP to execute a caller-provided function successfully |
Others | Caller gets one enabled AP to execute a caller-provided function unsuccessfully |
Caller gets one enabled AP to execute a caller-provided function.
[in] | MpServices | MP_SERVICES structure. |
[in] | Procedure | Pointer to the function to be run on enabled APs of the system. |
[in] | ProcessorNumber | The handle number of the AP. |
[in] | TimeoutInMicroSeconds | Indicates the time limit in microseconds for APs to return from Procedure, for blocking mode only. Zero means infinity. |
[in] | ProcedureArgument | The parameter passed into Procedure for all APs. |
EFI_SUCCESS | Caller gets one enabled AP to execute a caller-provided function successfully |
Others | Caller gets one enabled AP to execute a caller-provided function unsuccessfully |
Definition at line 93 of file DxeCpuExceptionHandlerUnitTest.c.
EFI_STATUS MpServicesUnitTestWhoAmI | ( | IN MP_SERVICES | MpServices, |
OUT UINTN * | ProcessorNumber | ||
) |
Get the handle number for the calling processor.
[in] | MpServices | MP_SERVICES structure. |
[out] | ProcessorNumber | The handle number for the calling processor. |
EFI_SUCCESS | Get the handle number for the calling processor successfully. |
Others | Get the handle number for the calling processor unsuccessfully. |
Definition at line 70 of file DxeCpuExceptionHandlerUnitTest.c.
VOID EFIAPI TriggerGPException | ( | UINTN | Cr4ReservedBit | ) |
Trigger GP exception by setting CR4_RESERVED_BIT to 1.
[in] | Cr4ReservedBit | Cr4 reserved bit. |
VOID EFIAPI TriggerINTnException | ( | IN EFI_EXCEPTION_TYPE | ExceptionType | ) |
Trigger no error code exception by INT n instruction.
[in] | ExceptionType | No error code exception type. |
VOID EFIAPI TriggerPFException | ( | UINTN | PFAddress | ) |
Trigger PF exception by write to not present or ReadOnly address.
[in] | PFAddress | Not present or ReadOnly address in page table. |
VOID EFIAPI TriggerStackOverflow | ( | VOID | ) |
Trigger stack overflow by calling itself continuously.
|
extern |
Definition at line 15 of file CpuExceptionHandlerTestCommon.c.
|
extern |
Definition at line 14 of file CpuExceptionHandlerTestCommon.c.
|
extern |
Definition at line 17 of file CpuExceptionHandlerTestCommon.c.