/** @file\r
Random test case for Unit tests of the CpuPageTableLib instance of the CpuPageTableLib class\r
\r
- Copyright (c) 2022, Intel Corporation. All rights reserved.<BR>\r
+ Copyright (c) 2022 - 2023, Intel Corporation. All rights reserved.<BR>\r
SPDX-License-Identifier: BSD-2-Clause-Patent\r
\r
**/\r
}\r
}\r
\r
-/**\r
- Return a random boolean.\r
-\r
- @return boolean\r
-**/\r
-BOOLEAN\r
-RandomBoolean (\r
- VOID\r
- )\r
-{\r
- BOOLEAN Value;\r
-\r
- LocalRandomBytes ((UINT8 *)&Value, sizeof (BOOLEAN));\r
- return Value%2;\r
-}\r
-\r
/**\r
Return a 32bit random number.\r
\r
return (UINT64)(Value % (Limit - Start + 1)) + Start;\r
}\r
\r
+/**\r
+ Returns true with the percentage of input Probability.\r
+\r
+ @param[in] Probability The percentage to return true.\r
+\r
+ @return boolean\r
+**/\r
+BOOLEAN\r
+RandomBoolean (\r
+ UINT8 Probability\r
+ )\r
+{\r
+ return ((Probability > ((UINT8)Random64 (0, 100))) ? TRUE : FALSE);\r
+}\r
+\r
/**\r
Check if the Page table entry is valid\r
\r
UT_ASSERT_EQUAL ((PagingEntry->Uint64 & mValidMaskLeaf[Level].Uint64), PagingEntry->Uint64);\r
}\r
\r
- if ((RandomNumber < 100) && RandomBoolean ()) {\r
+ if ((RandomNumber < 100) && RandomBoolean (50)) {\r
RandomNumber++;\r
if (Level == 1) {\r
TempPhysicalBase = PagingEntry->Pte4K.Bits.PageTableBaseAddress;\r
UT_ASSERT_EQUAL ((PagingEntry->Uint64 & mValidMaskNoLeaf[Level].Uint64), PagingEntry->Uint64);\r
}\r
\r
- if ((RandomNumber < 100) && RandomBoolean ()) {\r
+ if ((RandomNumber < 100) && RandomBoolean (50)) {\r
RandomNumber++;\r
TempPhysicalBase = PagingEntry->Pnle.Bits.PageTableBaseAddress;\r
\r
//\r
// use AlignedTable to avoid that a random number can be very hard to be 1G or 2M aligned\r
//\r
- if ((MapsIndex != 0) && (RandomBoolean ())) {\r
+ if ((MapsIndex != 0) && (RandomBoolean (50))) {\r
FormerLinearAddress = MapEntrys->Maps[Random32 (0, (UINT32)MapsIndex-1)].LinearAddress;\r
if (FormerLinearAddress < 2 * (UINT64)SIZE_1GB) {\r
FormerLinearAddressBottom = 0;\r
//\r
MapEntrys->Maps[MapsIndex].Length = Random64 (0, MIN (MaxAddress - MapEntrys->Maps[MapsIndex].LinearAddress, 10 * (UINT64)SIZE_1GB)) & AlignedTable[Random32 (0, ARRAY_SIZE (AlignedTable) -1)];\r
\r
- if ((MapsIndex != 0) && (RandomBoolean ())) {\r
+ if ((MapsIndex != 0) && (RandomBoolean (50))) {\r
MapEntrys->Maps[MapsIndex].Attribute.Uint64 = MapEntrys->Maps[Random32 (0, (UINT32)MapsIndex-1)].Attribute.Uint64;\r
MapEntrys->Maps[MapsIndex].Mask.Uint64 = MapEntrys->Maps[Random32 (0, (UINT32)MapsIndex-1)].Mask.Uint64;\r
} else {\r
// Need to avoid such case when remove the Random option ONLY_ONE_ONE_MAPPING\r
//\r
MapEntrys->Maps[MapsIndex].Attribute.Bits.PageTableBaseAddress = (Random64 (0, (((UINT64)1)<<52) - 1) & AlignedTable[Random32 (0, ARRAY_SIZE (AlignedTable) -1)])>> 12;\r
- if (RandomBoolean ()) {\r
+ if (RandomBoolean (50)) {\r
MapEntrys->Maps[MapsIndex].Mask.Bits.PageTableBaseAddress = 0;\r
}\r
}\r