Skip to content

Commit

Permalink
Fix ABI stress test coverage (dotnet#63409)
Browse files Browse the repository at this point in the history
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 dotnet#50767 and uses the environment variable in
the existing seed mechanism instead.
  • Loading branch information
jakobbotsch authored Jan 11, 2022
1 parent 917d369 commit 9b29946
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 21 deletions.
9 changes: 8 additions & 1 deletion src/tests/JIT/Stress/ABI/Config.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/tests/JIT/Stress/ABI/PInvokes.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeEx> pms = RandomParameters(s_allTypes, rand);

int calleeIndex = rand.Next(0, Config.NumCallees);
Expand Down
10 changes: 1 addition & 9 deletions src/tests/JIT/Stress/ABI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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<TypeEx> pms = RandomParameters(candidateParamTypes, rand);
var tc = new Callee(name, pms);
return tc;
Expand Down
10 changes: 1 addition & 9 deletions src/tests/JIT/Stress/ABI/Stubs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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<TypeEx> pms;
do
{
Expand Down
2 changes: 1 addition & 1 deletion src/tests/JIT/Stress/ABI/TailCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<TypeEx> callerParams;
List<Callee> callable;
do
Expand Down

0 comments on commit 9b29946

Please sign in to comment.