Skip to content

Commit

Permalink
UefiCpuPkg: Add shell UnitTest module for DxeCpuExceptionHandlerLib
Browse files Browse the repository at this point in the history
Add a new shell UnitTest module for DxeCpuExceptionHandlerLib.

Signed-off-by: Dun Tan <[email protected]>
Cc: Eric Dong <[email protected]>
Cc: Ray Ni <[email protected]>
Cc: Rahul Kumar <[email protected]>
  • Loading branch information
td36 committed Nov 18, 2022
1 parent b0d560c commit 8ca4504
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#ifndef CPU_EXCEPTION_HANDLER_TEST_H_
#define CPU_EXCEPTION_HANDLER_TEST_H_

#include <PiPei.h>
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
Expand All @@ -49,7 +50,6 @@
#include <Library/CpuPageTableLib.h>
#include <Guid/MemoryAllocationHob.h>
#include <Protocol/MpService.h>
#include <PiPei.h>
#include <Ppi/MpServices2.h>

#define UNIT_TEST_APP_NAME "Cpu Exception Handler Lib Unit Tests"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -484,18 +484,6 @@ TestRegisterHandlerForGPAndPF (

UT_ASSERT_EQUAL (Status, EFI_SUCCESS);

//
// GP exception.
//
DEBUG ((DEBUG_INFO, "TestCase2: ExceptionType is %d\n", EXCEPT_IA32_GP_FAULT));
Status = RegisterCpuInterruptHandler (EXCEPT_IA32_GP_FAULT, AdjustRipForFaultHandler);
UT_ASSERT_EQUAL (Status, EFI_SUCCESS);

TriggerGPException (CR4_RESERVED_BIT);
UT_ASSERT_EQUAL (mExceptionType, EXCEPT_IA32_GP_FAULT);
Status = RegisterCpuInterruptHandler (EXCEPT_IA32_GP_FAULT, NULL);
UT_ASSERT_EQUAL (Status, EFI_SUCCESS);

//
// PF exception.
//
Expand Down Expand Up @@ -556,6 +544,7 @@ TestCpuContextConsistency (
}
} else if (Index == EXCEPT_IA32_GP_FAULT) {
FaultParameter = CR4_RESERVED_BIT;
continue;
} else {
if ((mErrorCodeExceptionFlag & (1 << Index)) != 0) {
continue;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
## @file
# Unit tests of the DxeCpuExceptionHandlerLib instance.
#
# Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>
# SPDX-License-Identifier: BSD-2-Clause-Patent
##

[Defines]
INF_VERSION = 0x00010005
BASE_NAME = ShellCpuExceptionHandlerLibUnitTest
FILE_GUID = 2630B4E5-4B20-4EA0-A8FA-C5C3179E6A75
MODULE_TYPE = UEFI_APPLICATION
VERSION_STRING = 1.0
ENTRY_POINT = CpuExceptionHandlerTestEntry

#
# The following information is for reference only and not required by the build tools.
#
# VALID_ARCHITECTURES = X64
#

[Sources.common]
CpuExceptionHandlerTest.h
CpuExceptionHandlerTestCommon.c
DxeCpuExceptionHandlerUnitTest.c
X64/ArchExceptionHandlerTestAsm.nasm
X64/ArchExceptionHandlerTest.c

[Packages]
MdePkg/MdePkg.dec
MdeModulePkg/MdeModulePkg.dec
UefiCpuPkg/UefiCpuPkg.dec

[LibraryClasses]
BaseLib
BaseMemoryLib
DebugLib
UnitTestLib
MemoryAllocationLib
CpuExceptionHandlerLib
UefiApplicationEntryPoint
HobLib
UefiBootServicesTableLib
CpuPageTableLib

[Guids]
gEfiHobMemoryAllocStackGuid

[Pcd]
gEfiMdeModulePkgTokenSpaceGuid.PcdCpuStackGuard ## CONSUMES
gUefiCpuPkgTokenSpaceGuid.PcdCpuApStackSize ## CONSUMES

[Protocols]
gEfiMpServiceProtocolGuid
gEfiTimerArchProtocolGuid
6 changes: 6 additions & 0 deletions UefiCpuPkg/UefiCpuPkg.dsc
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,12 @@

[Components.X64]
UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/DxeCpuExceptionHandlerLibUnitTest.inf
UefiCpuPkg/Library/CpuExceptionHandlerLib/UnitTest/ShellCpuExceptionHandlerLibUnitTest.inf {
<LibraryClasses>
CpuExceptionHandlerLib|UefiCpuPkg/Library/CpuExceptionHandlerLib/DxeCpuExceptionHandlerLib.inf
HobLib|MdePkg/Library/DxeHobLib/DxeHobLib.inf
UnitTestResultReportLib|UnitTestFrameworkPkg/Library/UnitTestResultReportLib/UnitTestResultReportLibConOut.inf
}

[BuildOptions]
*_*_*_CC_FLAGS = -D DISABLE_NEW_DEPRECATED_INTERFACES

0 comments on commit 8ca4504

Please sign in to comment.