Skip to content

Commit 59d9d0d

Browse files
Changed all tests using random to use a seed in JIT/Methodical (#50767)
* Changed all tests using random to use a seed in JIT/Methodical * Cleaned up code from suggestion * Added seeds to the tests using unseeded random in JIT * Update Span indexer to not rely on the order of random data * Change circle in convex to not rely on specific random values * Undo changes to tests with seed specified
1 parent 14c0350 commit 59d9d0d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+461
-54
lines changed

src/tests/JIT/Directed/CheckedCtor/Generic_Test_CSharp_Base_4.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ public class BaseClass
3131

3232
public class DerivedClass<T> : BaseClass
3333
{
34-
private static readonly Random Generator = new Random();
34+
public const int DefaultSeed = 20010415;
35+
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
36+
{
37+
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
38+
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
39+
_ => DefaultSeed
40+
};
41+
42+
private static readonly Random Generator = new Random(Seed);
3543
private static string GetString() { return "Text"; }
3644
public int Field1 = ((Generator.Next(5, 8) == 10) ? 10 : 20);
3745
public string Field2 = (GetString() ?? "NeededToFallBack");

src/tests/JIT/Directed/CheckedCtor/Generic_Test_CSharp_Peer_4.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ public class BaseClass
3131

3232
public class DerivedClass<T> : BaseClass
3333
{
34-
private static readonly Random Generator = new Random();
34+
public const int DefaultSeed = 20010415;
35+
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
36+
{
37+
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
38+
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
39+
_ => DefaultSeed
40+
};
41+
42+
private static readonly Random Generator = new Random(Seed);
3543
private static string GetString() { return "Text"; }
3644
public int Field1 = ((Generator.Next(5, 8) == 10) ? 10 : 20);
3745
public string Field2 = (GetString() ?? "NeededToFallBack");

src/tests/JIT/Directed/CheckedCtor/Test_CSharp_Base_4.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ public class BaseClass
3131

3232
public class DerivedClass : BaseClass
3333
{
34-
private static readonly Random Generator = new Random();
34+
public const int DefaultSeed = 20010415;
35+
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
36+
{
37+
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
38+
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
39+
_ => DefaultSeed
40+
};
41+
42+
private static readonly Random Generator = new Random(Seed);
3543
private static string GetString() { return "Text"; }
3644
public int Field1 = ((Generator.Next(5, 8) == 10) ? 10 : 20);
3745
public string Field2 = (GetString() ?? "NeededToFallBack");

src/tests/JIT/Directed/CheckedCtor/Test_CSharp_Peer_4.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@ public class BaseClass
3131

3232
public class DerivedClass : BaseClass
3333
{
34-
private static readonly Random Generator = new Random();
34+
public const int DefaultSeed = 20010415;
35+
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
36+
{
37+
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
38+
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
39+
_ => DefaultSeed
40+
};
41+
42+
private static readonly Random Generator = new Random(Seed);
3543
private static string GetString() { return "Text"; }
3644
public int Field1 = ((Generator.Next(5, 8) == 10) ? 10 : 20);
3745
public string Field2 = (GetString() ?? "NeededToFallBack");

src/tests/JIT/Directed/PREFIX/PrimitiveVT/callconv1.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ namespace PrimitiveVT
77

88
unsafe class CallConv1
99
{
10-
static Random rand = new Random();
10+
public const int DefaultSeed = 20010415;
11+
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
12+
{
13+
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
14+
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
15+
_ => DefaultSeed
16+
};
17+
18+
static Random rand = new Random(Seed);
1119
VT1A vt1a;
1220
static VT1A x;
1321

src/tests/JIT/Directed/PREFIX/PrimitiveVT/callconv2.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,15 @@ namespace PrimitiveVT
77

88
unsafe class CallConv2
99
{
10-
static Random rand = new Random();
10+
public const int DefaultSeed = 20010415;
11+
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
12+
{
13+
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
14+
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
15+
_ => DefaultSeed
16+
};
17+
18+
static Random rand = new Random(Seed);
1119
VT2A vt1a;
1220
static VT2A x;
1321

src/tests/JIT/Directed/StrAccess/straccess1.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,16 @@ public static String f(ref String arg)
2525
{
2626
return arg;
2727
}
28-
public static Random rand = new Random();
28+
29+
public const int DefaultSeed = 20010415;
30+
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
31+
{
32+
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
33+
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
34+
_ => DefaultSeed
35+
};
36+
37+
public static Random rand = new Random(Seed);
2938
public static int Main()
3039
{
3140
bool passed = true;

src/tests/JIT/Directed/StrAccess/straccess2.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,16 @@ public static int f1(ref int arg)
3737
{
3838
return arg;
3939
}
40-
public static Random rand = new Random();
40+
41+
public const int DefaultSeed = 20010415;
42+
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
43+
{
44+
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
45+
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
46+
_ => DefaultSeed
47+
};
48+
49+
public static Random rand = new Random(Seed);
4150
public static int Main()
4251
{
4352
bool passed = true;

src/tests/JIT/Directed/StrAccess/straccess3.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ internal class CL
2020
internal class StrAccess1
2121
{
2222
public static String str1;
23-
public static Random rand = new Random(12345); //this version is deterministic
23+
public const int DefaultSeed = 20010415;
24+
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
25+
{
26+
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
27+
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
28+
_ => DefaultSeed
29+
};
30+
31+
public static Random rand = new Random(Seed);
2432

2533
private static int randomUnicodeLetterOrDigit()
2634
{

src/tests/JIT/Directed/StrAccess/straccess4.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,15 @@ internal class CL
2020
internal class StrAccess1
2121
{
2222
public static String str1;
23-
public static Random rand = new Random();
23+
public const int DefaultSeed = 20010415;
24+
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
25+
{
26+
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
27+
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
28+
_ => DefaultSeed
29+
};
30+
31+
public static Random rand = new Random(Seed);
2432

2533
private static int randomUnicodeLetterOrDigit()
2634
{

0 commit comments

Comments
 (0)