TianoCore EDK2 master
Loading...
Searching...
No Matches
MtrrLibUnitTest.c File Reference
#include "MtrrLibUnitTest.h"

Go to the source code of this file.

Data Structures

struct  MTRR_LIB_TEST_CONTEXT
 
struct  MTRR_LIB_GET_FIRMWARE_VARIABLE_MTRR_COUNT_CONTEXT
 

Functions

 STATIC_ASSERT ((ARRAY_SIZE(mFixedMtrrsIndex)==MTRR_NUMBER_OF_FIXED_MTRR), "gFixedMtrrIndex does NOT contain all the fixed MTRRs!")
 
UNIT_TEST_STATUS VerifyMemoryRanges (IN MTRR_MEMORY_RANGE *ExpectedMemoryRanges, IN UINTN ExpectedMemoryRangeCount, IN MTRR_MEMORY_RANGE *ActualRanges, IN UINTN ActualRangeCount)
 
VOID DumpMemoryRanges (MTRR_MEMORY_RANGE *Ranges, UINTN RangeCount)
 
VOID GenerateRandomMemoryTypeCombination (IN UINT32 TotalCount, OUT UINT32 *UcCount, OUT UINT32 *WtCount, OUT UINT32 *WbCount, OUT UINT32 *WpCount, OUT UINT32 *WcCount)
 
UNIT_TEST_STATUS EFIAPI UnitTestMtrrSetAndGetMemoryAttributesInMtrrSettings (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI UnitTestInvalidMemoryLayouts (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI UnitTestIsMtrrSupported (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI UnitTestGetVariableMtrrCount (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI UnitTestGetFirmwareVariableMtrrCount (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI UnitTestMtrrGetMemoryAttribute (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI UnitTestMtrrGetFixedMtrr (IN UNIT_TEST_CONTEXT Context)
 
VOID SetRandomlyGeneratedMtrrSettings (IN MTRR_LIB_SYSTEM_PARAMETER *SystemParameter, IN MTRR_SETTINGS *ExpectedMtrrs)
 
UNIT_TEST_STATUS EFIAPI UnitTestMtrrGetAllMtrrs (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI UnitTestMtrrSetAllMtrrs (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI UnitTestMtrrGetMemoryAttributeInVariableMtrr (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI UnitTestMtrrDebugPrintAllMtrrs (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI UnitTestMtrrGetDefaultMemoryType (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI UnitTestMtrrSetMemoryAttributeAndGetMemoryAttributesInMtrrSettings (IN UNIT_TEST_CONTEXT Context)
 
UNIT_TEST_STATUS EFIAPI SavePcdValue (UNIT_TEST_CONTEXT Context)
 
VOID EFIAPI RestorePcdValue (UNIT_TEST_CONTEXT Context)
 
STATIC EFI_STATUS EFIAPI UnitTestingEntry (UINTN Iteration)
 
INT32 main (INT32 Argc, CHAR8 *Argv[])
 

Variables

STATIC CONST MTRR_LIB_SYSTEM_PARAMETER mDefaultSystemParameter
 
STATIC MTRR_LIB_SYSTEM_PARAMETER mSystemParameters []
 
UINT32 mFixedMtrrsIndex []
 
STATIC CHAR8 * mCacheDescription [] = { "UC", "WC", "N/A", "N/A", "WT", "WP", "WB" }
 

Detailed Description

Unit tests of the MtrrLib instance of the MtrrLib class

Copyright (c) 2020 - 2023, Intel Corporation. All rights reserved.
SPDX-License-Identifier: BSD-2-Clause-Patent

Definition in file MtrrLibUnitTest.c.

Function Documentation

◆ DumpMemoryRanges()

VOID DumpMemoryRanges ( MTRR_MEMORY_RANGE Ranges,
UINTN  RangeCount 
)

Dump the memory ranges.

Parameters
RangesMemory ranges to dump.
RangeCountCount of memory ranges.

Definition at line 115 of file MtrrLibUnitTest.c.

◆ GenerateRandomMemoryTypeCombination()

VOID GenerateRandomMemoryTypeCombination ( IN UINT32  TotalCount,
OUT UINT32 *  UcCount,
OUT UINT32 *  WtCount,
OUT UINT32 *  WbCount,
OUT UINT32 *  WpCount,
OUT UINT32 *  WcCount 
)

Generate random count of MTRRs for each cache type.

Parameters
TotalCountTotal MTRR count.
UcCountReturn count of Uncacheable type.
WtCountReturn count of Write Through type.
WbCountReturn count of Write Back type.
WpCountReturn count of Write Protected type.
WcCountReturn count of Write Combining type.

Definition at line 141 of file MtrrLibUnitTest.c.

◆ main()

INT32 main ( INT32  Argc,
CHAR8 *  Argv[] 
)

Standard POSIX C entry point for host based unit test execution.

Parameters
ArgcNumber of arguments.
ArgvArray of arguments.
Returns
Test application exit code.

Definition at line 1299 of file MtrrLibUnitTest.c.

◆ RestorePcdValue()

VOID EFIAPI RestorePcdValue ( UNIT_TEST_CONTEXT  Context)

Clean up routine for UnitTestGetFirmwareVariableMtrrCount().

Parameters
ContextPoint to a UINT32 data to save the PcdCpuNumberOfReservedVariableMtrrs.

Definition at line 1195 of file MtrrLibUnitTest.c.

◆ SavePcdValue()

UNIT_TEST_STATUS EFIAPI SavePcdValue ( UNIT_TEST_CONTEXT  Context)

Prep routine for UnitTestGetFirmwareVariableMtrrCount().

Parameters
ContextPoint to a UINT32 data to save the PcdCpuNumberOfReservedVariableMtrrs.

Definition at line 1177 of file MtrrLibUnitTest.c.

◆ SetRandomlyGeneratedMtrrSettings()

VOID SetRandomlyGeneratedMtrrSettings ( IN MTRR_LIB_SYSTEM_PARAMETER SystemParameter,
IN MTRR_SETTINGS ExpectedMtrrs 
)

Set Random Variable and Fixed MTRRs Settings for unit test of UnitTestMtrrGetAllMtrrs.

Parameters
SystemParameterSystem parameter that controls the MTRR registers initialization.
ExpectedMtrrsExpected Fixed and Variable MTRRs.

Definition at line 692 of file MtrrLibUnitTest.c.

◆ UnitTestGetFirmwareVariableMtrrCount()

UNIT_TEST_STATUS EFIAPI UnitTestGetFirmwareVariableMtrrCount ( IN UNIT_TEST_CONTEXT  Context)

Unit test of MtrrLib service GetFirmwareVariableMtrrCount()

Parameters
[in]ContextIgnored
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 517 of file MtrrLibUnitTest.c.

◆ UnitTestGetVariableMtrrCount()

UNIT_TEST_STATUS EFIAPI UnitTestGetVariableMtrrCount ( IN UNIT_TEST_CONTEXT  Context)

Unit test of MtrrLib service GetVariableMtrrCount()

Parameters
[in]ContextIgnored
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 457 of file MtrrLibUnitTest.c.

◆ UnitTestingEntry()

STATIC EFI_STATUS EFIAPI UnitTestingEntry ( UINTN  Iteration)

Initialize the unit test framework, suite, and unit tests for the ResetSystemLib and run the ResetSystemLib unit test.

Parameters
IterationIteration of testing MtrrSetMemoryAttributeInMtrrSettings and MtrrSetMemoryAttributesInMtrrSettings using random inputs.
Return values
EFI_SUCCESSAll test cases were dispatched.
EFI_OUT_OF_RESOURCESThere are not enough resources available to initialize the unit tests.

Definition at line 1219 of file MtrrLibUnitTest.c.

◆ UnitTestInvalidMemoryLayouts()

UNIT_TEST_STATUS EFIAPI UnitTestInvalidMemoryLayouts ( IN UNIT_TEST_CONTEXT  Context)

Test routine to check whether invalid base/size can be rejected.

Parameters
ContextPointer to MTRR_LIB_SYSTEM_PARAMETER.
Returns
Test status.

Definition at line 333 of file MtrrLibUnitTest.c.

◆ UnitTestIsMtrrSupported()

UNIT_TEST_STATUS EFIAPI UnitTestIsMtrrSupported ( IN UNIT_TEST_CONTEXT  Context)

Unit test of MtrrLib service IsMtrrSupported()

Parameters
[in]ContextIgnored
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 389 of file MtrrLibUnitTest.c.

◆ UnitTestMtrrDebugPrintAllMtrrs()

UNIT_TEST_STATUS EFIAPI UnitTestMtrrDebugPrintAllMtrrs ( IN UNIT_TEST_CONTEXT  Context)

Unit test of MtrrLib service MtrrDebugPrintAllMtrrs()

Parameters
[in]ContextIgnored
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 957 of file MtrrLibUnitTest.c.

◆ UnitTestMtrrGetAllMtrrs()

UNIT_TEST_STATUS EFIAPI UnitTestMtrrGetAllMtrrs ( IN UNIT_TEST_CONTEXT  Context)

Unit test of MtrrLib service MtrrGetAllMtrrs()

Parameters
[in]ContextIgnored
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 742 of file MtrrLibUnitTest.c.

◆ UnitTestMtrrGetDefaultMemoryType()

UNIT_TEST_STATUS EFIAPI UnitTestMtrrGetDefaultMemoryType ( IN UNIT_TEST_CONTEXT  Context)

Unit test of MtrrLib service MtrrGetDefaultMemoryType().

Parameters
[in]ContextIgnored
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 976 of file MtrrLibUnitTest.c.

◆ UnitTestMtrrGetFixedMtrr()

UNIT_TEST_STATUS EFIAPI UnitTestMtrrGetFixedMtrr ( IN UNIT_TEST_CONTEXT  Context)

Unit test of MtrrLib service MtrrGetFixedMtrr()

Parameters
[in]ContextIgnored
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 617 of file MtrrLibUnitTest.c.

◆ UnitTestMtrrGetMemoryAttribute()

UNIT_TEST_STATUS EFIAPI UnitTestMtrrGetMemoryAttribute ( IN UNIT_TEST_CONTEXT  Context)

Unit test of MtrrLib service MtrrGetMemoryAttribute()

Parameters
[in]ContextIgnored
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 598 of file MtrrLibUnitTest.c.

◆ UnitTestMtrrGetMemoryAttributeInVariableMtrr()

UNIT_TEST_STATUS EFIAPI UnitTestMtrrGetMemoryAttributeInVariableMtrr ( IN UNIT_TEST_CONTEXT  Context)

Unit test of MtrrLib service MtrrGetMemoryAttributeInVariableMtrr()

Parameters
[in]ContextIgnored
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 883 of file MtrrLibUnitTest.c.

◆ UnitTestMtrrSetAllMtrrs()

UNIT_TEST_STATUS EFIAPI UnitTestMtrrSetAllMtrrs ( IN UNIT_TEST_CONTEXT  Context)

Unit test of MtrrLib service MtrrSetAllMtrrs()

Parameters
[in]ContextIgnored
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 824 of file MtrrLibUnitTest.c.

◆ UnitTestMtrrSetAndGetMemoryAttributesInMtrrSettings()

UNIT_TEST_STATUS EFIAPI UnitTestMtrrSetAndGetMemoryAttributesInMtrrSettings ( IN UNIT_TEST_CONTEXT  Context)

Unit test of MtrrLib service MtrrGetMemoryAttributesInMtrrSettings() and MtrrSetMemoryAttributesInMtrrSettings()

Parameters
[in]ContextIgnored
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 192 of file MtrrLibUnitTest.c.

◆ UnitTestMtrrSetMemoryAttributeAndGetMemoryAttributesInMtrrSettings()

UNIT_TEST_STATUS EFIAPI UnitTestMtrrSetMemoryAttributeAndGetMemoryAttributesInMtrrSettings ( IN UNIT_TEST_CONTEXT  Context)

Unit test of MtrrLib service MtrrSetMemoryAttributeInMtrrSettings() and MtrrGetMemoryAttributesInMtrrSettings().

Parameters
[in]ContextIgnored
Return values
UNIT_TEST_PASSEDThe Unit test has completed and the test case was successful.
UNIT_TEST_ERROR_TEST_FAILEDA test case assertion has failed.

Definition at line 1049 of file MtrrLibUnitTest.c.

◆ VerifyMemoryRanges()

UNIT_TEST_STATUS VerifyMemoryRanges ( IN MTRR_MEMORY_RANGE ExpectedMemoryRanges,
IN UINTN  ExpectedMemoryRangeCount,
IN MTRR_MEMORY_RANGE ActualRanges,
IN UINTN  ActualRangeCount 
)

Compare the actual memory ranges against expected memory ranges and return PASS when they match.

Parameters
ExpectedMemoryRangesExpected memory ranges.
ExpectedMemoryRangeCountCount of expected memory ranges.
ActualRangesActual memory ranges.
ActualRangeCountCount of actual memory ranges.
Return values
UNIT_TEST_PASSEDTest passed.
othersTest failed.

Definition at line 89 of file MtrrLibUnitTest.c.

Variable Documentation

◆ mCacheDescription

STATIC CHAR8* mCacheDescription[] = { "UC", "WC", "N/A", "N/A", "WT", "WP", "WB" }

Definition at line 75 of file MtrrLibUnitTest.c.

◆ mDefaultSystemParameter

STATIC CONST MTRR_LIB_SYSTEM_PARAMETER mDefaultSystemParameter
Initial value:
= {
42, TRUE, TRUE, CacheUncacheable, 12
}
#define TRUE
Definition: Base.h:301

Definition at line 11 of file MtrrLibUnitTest.c.

◆ mFixedMtrrsIndex

UINT32 mFixedMtrrsIndex[]
Initial value:

Definition at line 42 of file MtrrLibUnitTest.c.

◆ mSystemParameters

STATIC MTRR_LIB_SYSTEM_PARAMETER mSystemParameters[]
Initial value:
= {
{ 38, TRUE, TRUE, CacheUncacheable, 12 },
{ 38, TRUE, TRUE, CacheWriteBack, 12 },
{ 38, TRUE, TRUE, CacheWriteThrough, 12 },
{ 38, TRUE, TRUE, CacheWriteProtected, 12 },
{ 38, TRUE, TRUE, CacheWriteCombining, 12 },
{ 42, TRUE, TRUE, CacheUncacheable, 12 },
{ 42, TRUE, TRUE, CacheWriteBack, 12 },
{ 42, TRUE, TRUE, CacheWriteThrough, 12 },
{ 42, TRUE, TRUE, CacheWriteProtected, 12 },
{ 42, TRUE, TRUE, CacheWriteCombining, 12 },
{ 48, TRUE, TRUE, CacheUncacheable, 12 },
{ 48, TRUE, TRUE, CacheWriteBack, 12 },
{ 48, TRUE, TRUE, CacheWriteThrough, 12 },
{ 48, TRUE, TRUE, CacheWriteProtected, 12 },
{ 48, TRUE, TRUE, CacheWriteCombining, 12 },
{ 48, TRUE, FALSE, CacheUncacheable, 12 },
{ 48, TRUE, FALSE, CacheWriteBack, 12 },
{ 48, TRUE, FALSE, CacheWriteThrough, 12 },
{ 48, TRUE, FALSE, CacheWriteProtected, 12 },
{ 48, TRUE, FALSE, CacheWriteCombining, 12 },
{ 48, TRUE, TRUE, CacheWriteBack, 12, 7},
}
#define FALSE
Definition: Base.h:307

Definition at line 15 of file MtrrLibUnitTest.c.