Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Changed all tests using random to use a seed in JIT/Methodical #50767

Merged
merged 9 commits into from
May 4, 2021
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ public class BaseClass

public class DerivedClass<T> : BaseClass
{
private static readonly Random Generator = new Random();
public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

private static readonly Random Generator = new Random(Seed);
private static string GetString() { return "Text"; }
public int Field1 = ((Generator.Next(5, 8) == 10) ? 10 : 20);
public string Field2 = (GetString() ?? "NeededToFallBack");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ public class BaseClass

public class DerivedClass<T> : BaseClass
{
private static readonly Random Generator = new Random();
public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

private static readonly Random Generator = new Random(Seed);
private static string GetString() { return "Text"; }
public int Field1 = ((Generator.Next(5, 8) == 10) ? 10 : 20);
public string Field2 = (GetString() ?? "NeededToFallBack");
Expand Down
10 changes: 9 additions & 1 deletion src/tests/JIT/Directed/CheckedCtor/Test_CSharp_Base_4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ public class BaseClass

public class DerivedClass : BaseClass
{
private static readonly Random Generator = new Random();
public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

private static readonly Random Generator = new Random(Seed);
private static string GetString() { return "Text"; }
public int Field1 = ((Generator.Next(5, 8) == 10) ? 10 : 20);
public string Field2 = (GetString() ?? "NeededToFallBack");
Expand Down
10 changes: 9 additions & 1 deletion src/tests/JIT/Directed/CheckedCtor/Test_CSharp_Peer_4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,15 @@ public class BaseClass

public class DerivedClass : BaseClass
{
private static readonly Random Generator = new Random();
public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

private static readonly Random Generator = new Random(Seed);
private static string GetString() { return "Text"; }
public int Field1 = ((Generator.Next(5, 8) == 10) ? 10 : 20);
public string Field2 = (GetString() ?? "NeededToFallBack");
Expand Down
10 changes: 9 additions & 1 deletion src/tests/JIT/Directed/PREFIX/PrimitiveVT/callconv1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ namespace PrimitiveVT

unsafe class CallConv1
{
static Random rand = new Random();
public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

static Random rand = new Random(Seed);
VT1A vt1a;
static VT1A x;

Expand Down
10 changes: 9 additions & 1 deletion src/tests/JIT/Directed/PREFIX/PrimitiveVT/callconv2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ namespace PrimitiveVT

unsafe class CallConv2
{
static Random rand = new Random();
public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

static Random rand = new Random(Seed);
VT2A vt1a;
static VT2A x;

Expand Down
11 changes: 10 additions & 1 deletion src/tests/JIT/Directed/StrAccess/straccess1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ public static String f(ref String arg)
{
return arg;
}
public static Random rand = new Random();

public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

public static Random rand = new Random(Seed);
public static int Main()
{
bool passed = true;
Expand Down
11 changes: 10 additions & 1 deletion src/tests/JIT/Directed/StrAccess/straccess2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,16 @@ public static int f1(ref int arg)
{
return arg;
}
public static Random rand = new Random();

public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

public static Random rand = new Random(Seed);
public static int Main()
{
bool passed = true;
Expand Down
10 changes: 9 additions & 1 deletion src/tests/JIT/Directed/StrAccess/straccess3.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ internal class CL
internal class StrAccess1
{
public static String str1;
public static Random rand = new Random(12345); //this version is deterministic
public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

public static Random rand = new Random(Seed);

private static int randomUnicodeLetterOrDigit()
{
Expand Down
10 changes: 9 additions & 1 deletion src/tests/JIT/Directed/StrAccess/straccess4.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,15 @@ internal class CL
internal class StrAccess1
{
public static String str1;
public static Random rand = new Random();
public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

public static Random rand = new Random(Seed);

private static int randomUnicodeLetterOrDigit()
{
Expand Down
10 changes: 9 additions & 1 deletion src/tests/JIT/Directed/VectorABI/VectorMgdMgd.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,15 @@ public static class VectorMgdMgd
private const int PASS = 100;
private const int FAIL = 0;

static Random random = new Random(12345);
public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

static Random random = new Random(Seed);

public static T GetValueFromInt<T>(int value)
{
Expand Down
10 changes: 9 additions & 1 deletion src/tests/JIT/Directed/VectorABI/VectorMgdMgdArray.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ public static class VectorMgdMgd
private const int PASS = 100;
private const int FAIL = 0;

static Random random = new Random(12345);
private const int DefaultSeed = 20010415;
private static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

static Random random = new Random(Seed);

public static T GetValueFromInt<T>(int value)
{
Expand Down
10 changes: 9 additions & 1 deletion src/tests/JIT/Directed/VectorABI/VectorMgdMgdStatic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,15 @@ public static class VectorMgdMgd
private const int PASS = 100;
private const int FAIL = 0;

static Random random = new Random(12345);
private const int DefaultSeed = 20010415;
private static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

static Random random = new Random(Seed);

public static T GetValueFromInt<T>(int value)
{
Expand Down
10 changes: 9 additions & 1 deletion src/tests/JIT/Directed/perffix/primitivevt/callconv1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ namespace PrimitiveVT
{
internal unsafe class CallConv1
{
private static Random s_rand = new Random();
public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

private static Random s_rand = new Random(Seed);
private VT1A _vt1a;
private static VT1A s_x;

Expand Down
10 changes: 9 additions & 1 deletion src/tests/JIT/Directed/perffix/primitivevt/callconv2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,15 @@ namespace PrimitiveVT
{
internal unsafe class CallConv2
{
private static Random s_rand = new Random();
public const int DefaultSeed = 20010415;
public static int Seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

private static Random s_rand = new Random(Seed);
private VT2A _vt1a;
private static VT2A s_x;

Expand Down
11 changes: 10 additions & 1 deletion src/tests/JIT/Methodical/MDArray/InnerProd/classarr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class intmm
{
public static int size;
public static Random rand;
public const int DefaultSeed = 20010415;
public static ArrayClass ima;
public static ArrayClass imb;
public static ArrayClass imr;
Expand Down Expand Up @@ -123,11 +124,19 @@ public static int Main()
{
bool pass = false;

rand = new Random();
int seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

rand = new Random(seed);
size = rand.Next(2, 10);

Console.WriteLine();
Console.WriteLine("2D Array");
Console.WriteLine("Random seed: {0}; set environment variable CORECLR_SEED to this value to reproduce", seed);
Console.WriteLine("Testing inner product of {0} by {0} matrices", size);
Console.WriteLine("the matrices are members of class");
Console.WriteLine("Matrix element stores random integer");
Expand Down
11 changes: 10 additions & 1 deletion src/tests/JIT/Methodical/MDArray/InnerProd/doublearr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class doublemm
{
public static Random rand;
public const int DefaultSeed = 20010415;
public static int size;

public static double GenerateDbl()
Expand Down Expand Up @@ -117,11 +118,19 @@ public static int Main()
{
bool pass = false;

rand = new Random();
int seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

rand = new Random(seed);
size = rand.Next(2, 10);

Console.WriteLine();
Console.WriteLine("2D Array");
Console.WriteLine("Random seed: {0}; set environment variable CORECLR_SEED to this value to reproduce", seed);
Console.WriteLine("Testing inner product of {0} by {0} matrices", size);
Console.WriteLine("Matrix element stores random double");
Console.WriteLine("array set/get, ref/out param are used");
Expand Down
11 changes: 10 additions & 1 deletion src/tests/JIT/Methodical/MDArray/InnerProd/intarr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public class intmm
{
public static int size;
public static Random rand;
public const int DefaultSeed = 20010415;

public static void Init2DMatrix(out int[,] m, out int[][] refm)
{
Expand Down Expand Up @@ -104,11 +105,19 @@ public static int Main()
{
bool pass = false;

rand = new Random();
int seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

rand = new Random(seed);
size = rand.Next(2, 10);

Console.WriteLine();
Console.WriteLine("2D Array");
Console.WriteLine("Random seed: {0}; set environment variable CORECLR_SEED to this value to reproduce", seed);
Console.WriteLine("Testing inner product of {0} by {0} matrices", size);
Console.WriteLine("Matrix element stores random integer");
Console.WriteLine("array set/get, ref/out param are used");
Expand Down
11 changes: 10 additions & 1 deletion src/tests/JIT/Methodical/MDArray/InnerProd/jaggedarr.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
public class doublemm
{
public static Random rand;
public const int DefaultSeed = 20010415;
public static int size;

public static double GenerateDbl()
Expand Down Expand Up @@ -117,11 +118,19 @@ public static int Main()
{
bool pass = false;

rand = new Random();
int seed = Environment.GetEnvironmentVariable("CORECLR_SEED") switch
{
string seedStr when seedStr.Equals("random", StringComparison.OrdinalIgnoreCase) => new Random().Next(),
string seedStr when int.TryParse(seedStr, out int envSeed) => envSeed,
_ => DefaultSeed
};

rand = new Random(seed);
size = rand.Next(2, 10);

Console.WriteLine();
Console.WriteLine("2D Array");
Console.WriteLine("Random seed: {0}; set environment variable CORECLR_SEED to this value to reproduce", seed);
Console.WriteLine("Testing inner product of {0} by {0} matrices", size);
Console.WriteLine("Matrix is member of a Jagged array, element stores random double");
Console.WriteLine("array set/get, ref/out param are used");
Expand Down
Loading