Skip to content

Commit

Permalink
Add instrumentation to investigate flakiness in ConstantFolding_01
Browse files Browse the repository at this point in the history
  • Loading branch information
jcouv committed Sep 30, 2022
1 parent fd8185d commit 4ceed89
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/Compilers/CSharp/Test/Emit2/Emit/NumericIntPtrTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9006,7 +9006,8 @@ static void Main()
var refA = comp.EmitToImageReference();
comp = CreateEmptyCompilation(sourceB, references: new[] { refA, mscorlibRefWithoutSharing }, options: TestOptions.ReleaseExe, parseOptions: TestOptions.Regular9);

CompileAndVerify(comp, expectedOutput: expectedResult);
// Investigating flaky IL verification issue. Tracked by https://github.com/dotnet/roslyn/issues/63782
CompileAndVerify(comp, expectedOutput: expectedResult, verify: Verification.PassesOrFailFast);
Assert.NotNull(expectedResult);
}

Expand Down Expand Up @@ -9040,7 +9041,8 @@ static void Main()
return;
}

CompileAndVerify(comp, expectedOutput: expectedResult).VerifyDiagnostics(expectedDiagnostics);
// Investigating flaky IL verification issue. Tracked by https://github.com/dotnet/roslyn/issues/63782
CompileAndVerify(comp, expectedOutput: expectedResult, verify: Verification.PassesOrFailFast).VerifyDiagnostics(expectedDiagnostics);
Assert.NotNull(expectedResult);
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/Compilers/Test/Core/CommonTestBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public enum Verification
FailsPEVerify = 1 << 2,
FailsILVerify = 1 << 3,
Fails = FailsPEVerify | FailsILVerify,

PassesOrFailFast = 1 << 4,
}

/// <summary>
Expand Down
27 changes: 25 additions & 2 deletions src/Compilers/Test/Core/CompilationVerifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,18 @@ void listMethodsInType(ICSharpCode.Decompiler.TypeSystem.ITypeDefinition type, D
}
}

public string DumpIL()
{
var output = new ICSharpCode.Decompiler.PlainTextOutput();
using var testEnvironment = RuntimeEnvironmentFactory.Create(_dependencies);
string mainModuleFullName = Emit(testEnvironment, manifestResources: null, EmitOptions.Default);
using var moduleMetadata = ModuleMetadata.CreateFromImage(testEnvironment.GetMainImage());
var peFile = new PEFile(mainModuleFullName, moduleMetadata.Module.PEReaderOpt);
var disassembler = new ICSharpCode.Decompiler.Disassembler.ReflectionDisassembler(output, default);
disassembler.WriteModuleContents(peFile);
return output.ToString();
}

/// <summary>
/// Asserts that the emitted IL for a type is the same as the expected IL.
/// Many core library types are in different assemblies on .Net Framework, and .Net Core.
Expand Down Expand Up @@ -214,10 +226,21 @@ public void Emit(

string mainModuleName = Emit(testEnvironment, manifestResources, emitOptions);
_allModuleData = testEnvironment.GetAllModuleData();
testEnvironment.Verify(peVerify);

try
{
testEnvironment.Verify(peVerify);
#if NETCOREAPP
ILVerify(peVerify);
ILVerify(peVerify);
#endif
}
catch (Exception)when(peVerify is Verification.PassesOrFailFast)
{
var il = DumpIL();
Console.WriteLine(il);

Environment.FailFast("Investigating flaky IL verification issue. Tracked by https://github.com/dotnet/roslyn/issues/63782");
}

if (expectedSignatures != null)
{
Expand Down

0 comments on commit 4ceed89

Please sign in to comment.