From 4ceed899a3d1e05b2a2afe94d9c622f08b64d8ec Mon Sep 17 00:00:00 2001 From: Julien Couvreur Date: Fri, 30 Sep 2022 13:01:31 -0700 Subject: [PATCH] Add instrumentation to investigate flakiness in ConstantFolding_01 --- .../Test/Emit2/Emit/NumericIntPtrTests.cs | 6 +++-- src/Compilers/Test/Core/CommonTestBase.cs | 2 ++ .../Test/Core/CompilationVerifier.cs | 27 +++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/Compilers/CSharp/Test/Emit2/Emit/NumericIntPtrTests.cs b/src/Compilers/CSharp/Test/Emit2/Emit/NumericIntPtrTests.cs index 05b30719ed928..2a427023d05ce 100644 --- a/src/Compilers/CSharp/Test/Emit2/Emit/NumericIntPtrTests.cs +++ b/src/Compilers/CSharp/Test/Emit2/Emit/NumericIntPtrTests.cs @@ -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); } @@ -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); } } diff --git a/src/Compilers/Test/Core/CommonTestBase.cs b/src/Compilers/Test/Core/CommonTestBase.cs index 6ebb554eb620a..df25bfa36e7a3 100644 --- a/src/Compilers/Test/Core/CommonTestBase.cs +++ b/src/Compilers/Test/Core/CommonTestBase.cs @@ -32,6 +32,8 @@ public enum Verification FailsPEVerify = 1 << 2, FailsILVerify = 1 << 3, Fails = FailsPEVerify | FailsILVerify, + + PassesOrFailFast = 1 << 4, } /// diff --git a/src/Compilers/Test/Core/CompilationVerifier.cs b/src/Compilers/Test/Core/CompilationVerifier.cs index 82a5f9c2209b5..39fa8c39f91b5 100644 --- a/src/Compilers/Test/Core/CompilationVerifier.cs +++ b/src/Compilers/Test/Core/CompilationVerifier.cs @@ -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(); + } + /// /// 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. @@ -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) {