TianoCore EDK2 master
Loading...
Searching...
No Matches
RandomTest.c File Reference

Go to the source code of this file.

Functions

BOOLEAN EFIAPI RandomBytesUsingArray (OUT UINT8 *Output, IN UINTN Size)
 
BOOLEAN EFIAPI LocalRandomBytes (OUT UINT8 *Output, IN UINTN Size)
 
UINT32 Random32 (UINT32 Start, UINT32 Limit)
 
UINT64 Random64 (UINT64 Start, UINT64 Limit)
 
BOOLEAN RandomBoolean (UINT8 Probability)
 
VOID SetRandomStack (VOID)
 
UNIT_TEST_STATUS ValidateAndRandomeModifyPageTablePageTableEntry (IN IA32_PAGING_ENTRY *PagingEntry, IN UINTN Level, IN UINTN MaxLeafLevel, IN UINT64 Address)
 
UNIT_TEST_STATUS ValidateAndRandomeModifyPageTable (IN UINTN PageTable, IN PAGING_MODE PagingMode)
 
VOID RemoveLastMapEntry (IN OUT MAP_ENTRYS *MapEntrys)
 
VOID GenerateSingleRandomMapEntry (IN UINT64 MaxAddress, IN OUT MAP_ENTRYS *MapEntrys)
 
BOOLEAN CompareEntrysforOnePoint (IN UINT64 Address, IN MAP_ENTRYS *MapEntrys, IN IA32_MAP_ENTRY *Map, IN UINTN MapCount, IN IA32_MAP_ENTRY *InitMap, IN UINTN InitMapCount)
 
VOID AppendKeyPointToBuffer (IN OUT UINT64 *Buffer, IN OUT UINTN *Count, IN UINT64 Address)
 
VOID GetKeyPointList (IN MAP_ENTRYS *MapEntrys, IN IA32_MAP_ENTRY *Map, IN UINTN MapCount, IN OUT UINT64 *Buffer, IN OUT UINTN *Count)
 
UNIT_TEST_STATUS SingleMapEntryTest (IN OUT UINTN *PageTable, IN PAGING_MODE PagingMode, IN UINT64 MaxAddress, IN MAP_ENTRYS *MapEntrys, IN ALLOCATE_PAGE_RECORDS *PagesRecord, IN IA32_MAP_ENTRY *InitMap, IN UINTN InitMapCount)
 
VOID *EFIAPI RecordAllocatePages (IN ALLOCATE_PAGE_RECORDS *PagesRecord, IN UINTN Pages)
 
UNIT_TEST_STATUS MultipleMapEntryTest (IN UINTN ExpctedEntryNumber, IN PAGING_MODE PagingMode)
 
UNIT_TEST_STATUS EFIAPI TestCaseforRandomTest (IN UNIT_TEST_CONTEXT Context)
 

Variables

UINTN RandomNumber = 0
 
IA32_PAGING_ENTRY mValidMaskNoLeaf [6]
 
IA32_PAGING_ENTRY mValidMaskLeaf [6]
 
IA32_PAGING_ENTRY mValidMaskLeafFlag [6]
 
UINTN mRandomOption
 
IA32_MAP_ATTRIBUTE mSupportedBit
 
UINTN mNumberCount
 
UINT8 mNumbers []
 
UINTN mNumberIndex
 
UINT64 AlignedTable []
 

Detailed Description

Random test case for Unit tests of the CpuPageTableLib instance of the CpuPageTableLib class

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

Definition in file RandomTest.c.

Function Documentation

◆ AppendKeyPointToBuffer()

VOID AppendKeyPointToBuffer ( IN OUT UINT64 *  Buffer,
IN OUT UINTN Count,
IN UINT64  Address 
)

Append key point of a given address to Buffer if buffer is NULL, only count needed count

Parameters
[in,out]BufferBuffer to contains all key point.
[in,out]CountCount of the key point.
[in]Addressgiven address

Definition at line 554 of file RandomTest.c.

◆ CompareEntrysforOnePoint()

BOOLEAN CompareEntrysforOnePoint ( IN UINT64  Address,
IN MAP_ENTRYS MapEntrys,
IN IA32_MAP_ENTRY Map,
IN UINTN  MapCount,
IN IA32_MAP_ENTRY InitMap,
IN UINTN  InitMapCount 
)

Compare the attribute for one point. MapEntrys records every memory ranges that is used as input Map and MapCount are gotten from Page table Compare if this point have same attribute.

Parameters
[in]AddressAddress of one Point.
[in]MapEntrysRecord every memory ranges that is used as input
[in]MapPointer to an array that describes multiple linear address ranges.
[in]MapCountPointer to a UINTN that hold the number of entries in the Map.
[in]InitMapPointer to an array that describes init map entries.
[in]InitMapCountPointer to a UINTN that hold the number of init map entries.
Return values
TRUEAt least one byte of data is available to be read
FALSENo data is available to be read

Definition at line 418 of file RandomTest.c.

◆ GenerateSingleRandomMapEntry()

VOID GenerateSingleRandomMapEntry ( IN UINT64  MaxAddress,
IN OUT MAP_ENTRYS MapEntrys 
)

Generate single random map entry. The map entry can be the input of function PageTableMap the LinearAddress and length is aligned to aligned table.

Parameters
MaxAddressMax Address.
MapEntrysOutput MapEntrys contains all parameter as input of function PageTableMap

Definition at line 329 of file RandomTest.c.

◆ GetKeyPointList()

VOID GetKeyPointList ( IN MAP_ENTRYS MapEntrys,
IN IA32_MAP_ENTRY Map,
IN UINTN  MapCount,
IN OUT UINT64 *  Buffer,
IN OUT UINTN Count 
)

Get all key points from a buffer if buffer is NULL, only count needed count

Parameters
[in]MapEntrysRecord every memory ranges that is used as input
[in]MapPointer to an array that describes multiple linear address ranges.
[in]MapCountPointer to a UINTN that hold the actual number of entries in the Map.
[in,out]BufferBuffer to contains all key point.
[in,out]CountCount of the key point.

Definition at line 583 of file RandomTest.c.

◆ LocalRandomBytes()

BOOLEAN EFIAPI LocalRandomBytes ( OUT UINT8 *  Output,
IN UINTN  Size 
)

Generates a pseudorandom byte stream of the specified size.

Return FALSE to indicate this interface is not supported.

Parameters
[out]OutputPointer to buffer to receive random value.
[in]SizeSize of random bytes to generate.
Return values
TRUEPseudorandom byte stream generated successfully.
FALSEPseudorandom number generator fails

Definition at line 72 of file RandomTest.c.

◆ MultipleMapEntryTest()

UNIT_TEST_STATUS MultipleMapEntryTest ( IN UINTN  ExpctedEntryNumber,
IN PAGING_MODE  PagingMode 
)

The function is a whole Random test, it will call SingleMapEntryTest for ExpctedEntryNumber times

Parameters
[in]ExpctedEntryNumberThe count of random entry
[in]PagingModeThe paging mode.
Return values
UNIT_TEST_PASSEDThe test is successful.

Definition at line 916 of file RandomTest.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, 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, and return value can be Limit.
Returns
64bit random number

Definition at line 111 of file RandomTest.c.

◆ RandomBoolean()

BOOLEAN RandomBoolean ( UINT8  Probability)

Returns true with the percentage of input Probability.

Parameters
[in]ProbabilityThe percentage to return true.
Returns
boolean

Definition at line 134 of file RandomTest.c.

◆ RandomBytesUsingArray()

BOOLEAN EFIAPI RandomBytesUsingArray ( OUT UINT8 *  Output,
IN UINTN  Size 
)

Generates a pseudorandom byte stream of the specified size.

Return FALSE to indicate this interface is not supported.

Parameters
[out]OutputPointer to buffer to receive random value.
[in]SizeSize of random bytes to generate.
Return values
TRUEAlways return TRUE

Definition at line 40 of file RandomTest.c.

◆ RecordAllocatePages()

VOID *EFIAPI RecordAllocatePages ( IN ALLOCATE_PAGE_RECORDS PagesRecord,
IN UINTN  Pages 
)

Allocate page and record the information in PagesRecord

Parameters
[in]PagesRecordPoint to a struct to record memory usage
[in]PagesPage count needed to allocate
Returns
A pointer to the allocated buffer or NULL if allocation fails.

Definition at line 887 of file RandomTest.c.

◆ RemoveLastMapEntry()

VOID RemoveLastMapEntry ( IN OUT MAP_ENTRYS MapEntrys)

Remove the last MAP_ENTRY in MapEntrys.

Parameters
MapEntrysPointer to MapEntrys buffer

Definition at line 305 of file RandomTest.c.

◆ SetRandomStack()

VOID SetRandomStack ( VOID  )

Set 8K stack as random value.

Definition at line 145 of file RandomTest.c.

◆ SingleMapEntryTest()

UNIT_TEST_STATUS SingleMapEntryTest ( IN OUT UINTN PageTable,
IN PAGING_MODE  PagingMode,
IN UINT64  MaxAddress,
IN MAP_ENTRYS MapEntrys,
IN ALLOCATE_PAGE_RECORDS PagesRecord,
IN IA32_MAP_ENTRY InitMap,
IN UINTN  InitMapCount 
)

Generate random one range with randome attribute, and add it into pagetable Compare the key point has same attribute

Parameters
[in,out]PageTableThe pointer to the page table to update, or pointer to NULL if a new page table is to be created.
[in]PagingModeThe paging mode.
[in]MaxAddressMax Address.
[in]MapEntrysRecord every memory ranges that is used as input
[in]PagesRecordUsed to record memory usage for page table.
[in]InitMapPointer to an array that describes init map entries.
[in]InitMapCountPointer to a UINTN that hold the number of init map entries.
Return values
UNIT_TEST_PASSEDThe test is successful.

Definition at line 652 of file RandomTest.c.

◆ TestCaseforRandomTest()

UNIT_TEST_STATUS EFIAPI TestCaseforRandomTest ( IN UNIT_TEST_CONTEXT  Context)

Random Test

Parameters
[in]Context[Optional] An optional parameter that enables: 1) test-case reuse with varied parameters and 2) test-case re-entry for Target tests that need a reboot. This parameter is a VOID* and it is the responsibility of the test author to ensure that the contents are well understood by all test cases that may consume it.
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 1037 of file RandomTest.c.

◆ ValidateAndRandomeModifyPageTable()

UNIT_TEST_STATUS ValidateAndRandomeModifyPageTable ( IN UINTN  PageTable,
IN PAGING_MODE  PagingMode 
)

Check if the Page table is valid

Parameters
[in]PageTableThe pointer to the page table.
[in]PagingModeThe paging mode.
Return values
UNIT_TEST_PASSEDIt is a valid Page Table

Definition at line 267 of file RandomTest.c.

◆ ValidateAndRandomeModifyPageTablePageTableEntry()

UNIT_TEST_STATUS ValidateAndRandomeModifyPageTablePageTableEntry ( IN IA32_PAGING_ENTRY PagingEntry,
IN UINTN  Level,
IN UINTN  MaxLeafLevel,
IN UINT64  Address 
)

Check if the Page table entry is valid

Parameters
[in]PagingEntryThe entry in page table to verify
[in]Levelthe level of PagingEntry.
[in]MaxLeafLevelMax leaf entry level.
[in]LinearAddressThe linear address verified.
Return values
Leafentry.

Definition at line 169 of file RandomTest.c.

Variable Documentation

◆ AlignedTable

UINT64 AlignedTable[]
Initial value:
= {
~((UINT64)SIZE_4KB - 1),
~((UINT64)SIZE_2MB - 1),
~((UINT64)SIZE_1GB - 1)
}

Definition at line 21 of file RandomTest.c.

◆ mNumberCount

UINTN mNumberCount
extern

Definition at line 7 of file RandomNumber.c.

◆ mNumberIndex

UINTN mNumberIndex

Definition at line 20 of file RandomTest.c.

◆ mNumbers

UINT8 mNumbers[]
extern

Definition at line 8 of file RandomNumber.c.

◆ mRandomOption

UINTN mRandomOption

Definition at line 16 of file RandomTest.c.

◆ mSupportedBit

IA32_MAP_ATTRIBUTE mSupportedBit

Definition at line 17 of file RandomTest.c.

◆ mValidMaskLeaf

IA32_PAGING_ENTRY mValidMaskLeaf[6]
extern

Definition at line 22 of file TestHelper.c.

◆ mValidMaskLeafFlag

IA32_PAGING_ENTRY mValidMaskLeafFlag[6]
extern

Definition at line 23 of file TestHelper.c.

◆ mValidMaskNoLeaf

IA32_PAGING_ENTRY mValidMaskNoLeaf[6]
extern

Definition at line 21 of file TestHelper.c.

◆ RandomNumber

UINTN RandomNumber = 0

Definition at line 12 of file RandomTest.c.