TianoCore EDK2 master
Loading...
Searching...
No Matches
MtrrLibUnitTest.h File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdarg.h>
#include <stddef.h>
#include <setjmp.h>
#include <cmocka.h>
#include <time.h>
#include <Uefi.h>
#include <Library/BaseLib.h>
#include <Library/BaseMemoryLib.h>
#include <Library/DebugLib.h>
#include <Library/UnitTestLib.h>
#include <Library/MtrrLib.h>
#include <Library/UnitTestHostBaseLib.h>
#include <Register/ArchitecturalMsr.h>
#include <Register/Cpuid.h>
#include <Register/Msr.h>

Go to the source code of this file.

Data Structures

struct  MTRR_LIB_SYSTEM_PARAMETER
 

Macros

#define UNIT_TEST_APP_NAME   "MtrrLib Unit Tests"
 
#define UNIT_TEST_APP_VERSION   "1.0"
 
#define SCRATCH_BUFFER_SIZE   SIZE_16KB
 

Functions

UNIT_TEST_STATUS EFIAPI InitializeMtrrRegs (IN MTRR_LIB_SYSTEM_PARAMETER *SystemParameter)
 
UNIT_TEST_STATUS EFIAPI InitializeSystem (IN UNIT_TEST_CONTEXT Context)
 
MTRR_MEMORY_CACHE_TYPE GenerateRandomCacheType (VOID)
 
VOID GenerateValidAndConfigurableMtrrPairs (IN UINT32 PhysicalAddressBits, IN OUT MTRR_MEMORY_RANGE *RawMemoryRanges, IN UINT32 UcCount, IN UINT32 WtCount, IN UINT32 WbCount, IN UINT32 WpCount, IN UINT32 WcCount)
 
VOID GetEffectiveMemoryRanges (IN MTRR_MEMORY_CACHE_TYPE DefaultType, IN UINT32 PhysicalAddressBits, IN MTRR_MEMORY_RANGE *RawMemoryRanges, IN UINT32 RawMemoryRangeCount, OUT MTRR_MEMORY_RANGE *MemoryRanges, OUT UINTN *MemoryRangeCount)
 
VOID GenerateRandomMtrrPair (IN UINT32 PhysicalAddressBits, IN MTRR_MEMORY_CACHE_TYPE CacheType, OUT MTRR_VARIABLE_SETTING *MtrrPair OPTIONAL, OUT MTRR_MEMORY_RANGE *MtrrMemoryRange OPTIONAL)
 
VOID CollectTestResult (IN MTRR_MEMORY_CACHE_TYPE DefaultType, IN UINT32 PhysicalAddressBits, IN UINT32 VariableMtrrCount, IN MTRR_SETTINGS *Mtrrs, OUT MTRR_MEMORY_RANGE *Ranges, IN OUT UINTN *RangeCount, OUT UINT32 *MtrrCount)
 
UINT64 Random64 (UINT64 Start, UINT64 Limit)
 
UINT32 Random32 (UINT32 Start, UINT32 Limit)
 
VOID GenerateRandomNumbers (CHAR8 *FilePath, UINTN Count)
 

Variables

UINT32 mFixedMtrrsIndex []
 
BOOLEAN mRandomInput
 

Detailed Description

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

Definition in file MtrrLibUnitTest.h.

Macro Definition Documentation

◆ SCRATCH_BUFFER_SIZE

#define SCRATCH_BUFFER_SIZE   SIZE_16KB

Definition at line 35 of file MtrrLibUnitTest.h.

◆ UNIT_TEST_APP_NAME

#define UNIT_TEST_APP_NAME   "MtrrLib Unit Tests"

Definition at line 32 of file MtrrLibUnitTest.h.

◆ UNIT_TEST_APP_VERSION

#define UNIT_TEST_APP_VERSION   "1.0"

Definition at line 33 of file MtrrLibUnitTest.h.

Function Documentation

◆ CollectTestResult()

VOID CollectTestResult ( IN MTRR_MEMORY_CACHE_TYPE  DefaultType,
IN UINT32  PhysicalAddressBits,
IN UINT32  VariableMtrrCount,
IN MTRR_SETTINGS Mtrrs,
OUT MTRR_MEMORY_RANGE Ranges,
IN OUT UINTN RangeCount,
OUT UINT32 *  MtrrCount 
)

Collect the test result.

Parameters
DefaultTypeDefault memory type.
PhysicalAddressBitsPhysical address bits.
VariableMtrrCountCount of variable MTRRs.
MtrrsMTRR settings to collect from.
RangesReturn the memory ranges.
RangeCountReturn the count of memory ranges.
MtrrCountReturn the count of variable MTRRs being used.

Definition at line 437 of file Support.c.

◆ GenerateRandomCacheType()

MTRR_MEMORY_CACHE_TYPE GenerateRandomCacheType ( VOID  )

Return a random memory cache type.

Definition at line 658 of file Support.c.

◆ GenerateRandomMtrrPair()

VOID GenerateRandomMtrrPair ( IN UINT32  PhysicalAddressBits,
IN MTRR_MEMORY_CACHE_TYPE  CacheType,
OUT MTRR_VARIABLE_SETTING *MtrrPair  OPTIONAL,
OUT MTRR_MEMORY_RANGE *MtrrMemoryRange  OPTIONAL 
)

Generate random MTRR BASE/MASK for a specified type.

Parameters
PhysicalAddressBitsPhysical address bits.
CacheTypeCache type.
MtrrPairReturn the random MTRR.
MtrrMemoryRangeReturn the random memory range.

Definition at line 514 of file Support.c.

◆ GenerateRandomNumbers()

VOID GenerateRandomNumbers ( CHAR8 *  FilePath,
UINTN  Count 
)

Generate Count random numbers in FilePath.

Parameters
FilePathThe file path to put the generated random numbers.
CountCount of random numbers.

Definition at line 68 of file Support.c.

◆ GenerateValidAndConfigurableMtrrPairs()

VOID GenerateValidAndConfigurableMtrrPairs ( IN UINT32  PhysicalAddressBits,
IN OUT MTRR_MEMORY_RANGE RawMemoryRanges,
IN UINT32  UcCount,
IN UINT32  WtCount,
IN UINT32  WbCount,
IN UINT32  WpCount,
IN UINT32  WcCount 
)

Generate random MTRRs.

Parameters
PhysicalAddressBitsPhysical address bits.
RawMemoryRangesReturn the randomly generated MTRRs.
UcCountCount of Uncacheable MTRRs.
WtCountCount of Write Through MTRRs.
WbCountCount of Write Back MTRRs.
WpCountCount of Write Protected MTRRs.
WcCountCount of Write Combining MTRRs.

Generate random MTRRs.

Parameters
PhysicalAddressBitsPhysical address bits.
RawMemoryRangesReturn the randomly generated MTRRs.
UcCountCount of Uncacheable MTRRs.
WtCountCount of Write Through MTRRs.
WbCountCount of Write Back MTRRs.
WpCountCount of Write Protected MTRRs.
WcCountCount of Write Combine MTRRs.

Definition at line 606 of file Support.c.

◆ GetEffectiveMemoryRanges()

VOID GetEffectiveMemoryRanges ( IN MTRR_MEMORY_CACHE_TYPE  DefaultType,
IN UINT32  PhysicalAddressBits,
IN MTRR_MEMORY_RANGE RawMemoryRanges,
IN UINT32  RawMemoryRangeCount,
OUT MTRR_MEMORY_RANGE MemoryRanges,
OUT UINTN MemoryRangeCount 
)

Convert the MTRR BASE/MASK array to memory ranges.

Parameters
DefaultTypeDefault memory type.
PhysicalAddressBitsPhysical address bits.
RawMemoryRangesRaw memory ranges.
RawMemoryRangeCountCount of raw memory ranges.
MemoryRangesMemory ranges.
MemoryRangeCountCount of memory ranges.

Definition at line 1009 of file Support.c.

◆ InitializeMtrrRegs()

UNIT_TEST_STATUS EFIAPI InitializeMtrrRegs ( IN MTRR_LIB_SYSTEM_PARAMETER SystemParameter)

Initialize the MTRR registers.

Parameters
SystemParameterSystem parameter that controls the MTRR registers initialization.

Definition at line 358 of file Support.c.

◆ InitializeSystem()

UNIT_TEST_STATUS EFIAPI InitializeSystem ( IN UNIT_TEST_CONTEXT  Context)

Initialize the MTRR registers.

Parameters
ContextSystem parameter that controls the MTRR registers initialization.

Definition at line 418 of file Support.c.

◆ Random32()

UINT32 Random32 ( UINT32  Start,
UINT32  Limit 
)

Return a 32bit random number.

Parameters
StartStart of the random number range.
LimitLimit of the random number range.
Returns
32bit random number

Return a 32bit random number.

Parameters
StartStart of the random number range.
LimitLimit of the random number range, and return value can be Limit.
Returns
32bit random number

Definition at line 92 of file RandomTest.c.

◆ Random64()

UINT64 Random64 ( UINT64  Start,
UINT64  Limit 
)

Return a 64bit random number.

Parameters
StartStart of the random number range.
LimitLimit of the random number range.
Returns
64bit random number

Return a 64bit random number.

Parameters
StartStart of the random number range.
LimitLimit of the random number range, and return value can be Limit.
Returns
64bit random number

Definition at line 111 of file RandomTest.c.

Variable Documentation

◆ mFixedMtrrsIndex

UINT32 mFixedMtrrsIndex[]
extern

Definition at line 42 of file MtrrLibUnitTest.c.

◆ mRandomInput

BOOLEAN mRandomInput
extern

Definition at line 25 of file Support.c.