From 6404857361bfdd9e64bf50486390c44e455e91d0 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 5 Jan 2022 21:19:18 +0100 Subject: [PATCH] Fix ABI stress test coverage When this test was changed to use a seed from an environment variable it changed the test to repeatedly create the same Random instance, reducing coverage to only ever test one variant. This reverts the changes by #50767 and uses the environment variable in the existing seed mechanism instead. --- src/tests/JIT/Stress/ABI/Config.cs | 9 ++++++++- src/tests/JIT/Stress/ABI/PInvokes.cs | 2 +- src/tests/JIT/Stress/ABI/Program.cs | 10 +--------- src/tests/JIT/Stress/ABI/Stubs.cs | 10 +--------- src/tests/JIT/Stress/ABI/TailCalls.cs | 2 +- 5 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/tests/JIT/Stress/ABI/Config.cs b/src/tests/JIT/Stress/ABI/Config.cs index e5238763bba1e2..db4a68d77dbb54 100644 --- a/src/tests/JIT/Stress/ABI/Config.cs +++ b/src/tests/JIT/Stress/ABI/Config.cs @@ -15,10 +15,17 @@ internal class Config internal const string InstantiatingStubPrefix = "ABIStress_InstantiatingStub_"; internal static StressModes StressModes { get; set; } = StressModes.None; + + private const int DefaultSeed = 20010415; // The base seed. This value combined with the index of the // caller/pinvoker/callee will uniquely determine how it is generated // and which callee is used. - internal const int Seed = 0xeadbeef; + internal static int Seed { get; set; } = 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 + }; internal const int MinParams = 1; internal static int MaxParams { get; set; } = 25; // The number of callees to use. When stressing tailcalls, this is the number of tailcallee parameter lists to pregenerate. diff --git a/src/tests/JIT/Stress/ABI/PInvokes.cs b/src/tests/JIT/Stress/ABI/PInvokes.cs index efd1330061b44e..e790b4b809c820 100644 --- a/src/tests/JIT/Stress/ABI/PInvokes.cs +++ b/src/tests/JIT/Stress/ABI/PInvokes.cs @@ -16,7 +16,7 @@ internal partial class Program private static bool DoPInvokes(int callerIndex) { string callerName = Config.PInvokerPrefix + callerIndex; - Random rand = new Random(Seed); + Random rand = new Random(GetSeed(callerName)); List pms = RandomParameters(s_allTypes, rand); int calleeIndex = rand.Next(0, Config.NumCallees); diff --git a/src/tests/JIT/Stress/ABI/Program.cs b/src/tests/JIT/Stress/ABI/Program.cs index 3089488992504f..6fa983005e674f 100644 --- a/src/tests/JIT/Stress/ABI/Program.cs +++ b/src/tests/JIT/Stress/ABI/Program.cs @@ -17,14 +17,6 @@ namespace ABIStress { internal partial class Program { - 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 - }; - private static int Main(string[] args) { static void Usage() @@ -175,7 +167,7 @@ private static bool DoCall(int index) private static Callee CreateCallee(string name, TypeEx[] candidateParamTypes) { - Random rand = new Random(Seed); + Random rand = new Random(GetSeed(name)); List pms = RandomParameters(candidateParamTypes, rand); var tc = new Callee(name, pms); return tc; diff --git a/src/tests/JIT/Stress/ABI/Stubs.cs b/src/tests/JIT/Stress/ABI/Stubs.cs index 37078d4d0a2df4..7c4419f23b4cf0 100644 --- a/src/tests/JIT/Stress/ABI/Stubs.cs +++ b/src/tests/JIT/Stress/ABI/Stubs.cs @@ -13,14 +13,6 @@ namespace ABIStress { public class StubsTestHelpers { - 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 - }; - public static void CompareNumbers(int actual, int expected) { if (actual != expected) @@ -122,7 +114,7 @@ private static bool DoStubCall(int callerIndex, bool staticMethod, bool onValueT { string callerNameSeed = Config.InstantiatingStubPrefix + "Caller" + callerIndex; // Use a consistent seed value here so that the various various of unboxing/instantiating stubs are generated with the same arg shape string callerName = callerNameSeed + (staticMethod ? "Static" : "Instance") + (onValueType ? "Class" : "ValueType") + typeGenericShape.ToString() + methodGenericShape.ToString(); - Random rand = new Random(Seed); + Random rand = new Random(GetSeed(callerName)); List pms; do { diff --git a/src/tests/JIT/Stress/ABI/TailCalls.cs b/src/tests/JIT/Stress/ABI/TailCalls.cs index 515e17ee8c5f5e..9a3e2441d3a332 100644 --- a/src/tests/JIT/Stress/ABI/TailCalls.cs +++ b/src/tests/JIT/Stress/ABI/TailCalls.cs @@ -24,7 +24,7 @@ private static bool DoTailCall(int callerIndex) } string callerName = Config.TailCallerPrefix + callerIndex; - Random rand = new Random(Seed); + Random rand = new Random(GetSeed(callerName)); List callerParams; List callable; do