Make verification runtime aware

The ability to verify IL is presently a runtime specific operation.
Moved the logic to enforce the test conforms to the specified behavior
into the runitme layers.
上级 034c579c
......@@ -1679,7 +1679,7 @@ public class Test { }
Assert.False(diagnostics.Any());
}
[Fact, WorkItem(530585, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530585")]
[ConditionalFact(typeof(DesktopOnly)), WorkItem(530585, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/530585")]
public void Bug16465()
{
string mod =
......
......@@ -1298,7 +1298,7 @@ void L2()
1");
}
[Fact]
[ConditionalFact(typeof(DesktopOnly))]
[WorkItem(16895, "https://github.com/dotnet/roslyn/issues/16895")]
public void CaptureVarNestedLambdaSkipScope7()
{
......
......@@ -18,13 +18,6 @@ public EmitException(IEnumerable<Diagnostic> diagnostics, string directory)
}
}
public class PeVerifyException : Exception
{
public PeVerifyException(string output, string exePath)
: base(GetMessageFromResult(output, exePath)) { }
}
public class ExecutionException : Exception
{
public ExecutionException(string expectedOutput, string actualOutput, string exePath)
......
......@@ -335,8 +335,8 @@ public interface IRuntimeEnvironment : IDisposable
ImmutableArray<Diagnostic> GetDiagnostics();
SortedSet<string> GetMemberSignaturesFromMetadata(string fullyQualifiedTypeName, string memberName);
IList<ModuleData> GetAllModuleData();
void PeVerify();
string[] PeVerifyModules(string[] modulesToVerify, bool throwOnError = true);
void Verify(Verification verification);
string[] VerifyModules(string[] modulesToVerify);
void CaptureOutput(Action action, int expectedLength, out string output, out string errorOutput);
}
......
......@@ -84,15 +84,7 @@ public void Emit(string expectedOutput, int? expectedReturnCode, string[] args,
{
string mainModuleName = Emit(testEnvironment, manifestResources, emitOptions);
_allModuleData = testEnvironment.GetAllModuleData();
if (peVerify == Verification.Passes)
{
testEnvironment.PeVerify();
}
else if (peVerify == Verification.Fails)
{
Assert.Throws<PeVerifyException>(() => testEnvironment.PeVerify());
}
testEnvironment.Verify(peVerify);
if (expectedSignatures != null)
{
......@@ -118,7 +110,7 @@ public void EmitAndVerify(params string[] expectedPeVerifyOutput)
using (var testEnvironment = RuntimeEnvironmentFactory.Create(_dependencies))
{
string mainModuleName = Emit(testEnvironment, null, null);
string[] actualOutput = testEnvironment.PeVerifyModules(new[] { mainModuleName }, throwOnError: false);
string[] actualOutput = testEnvironment.VerifyModules(new[] { mainModuleName });
Assert.Equal(expectedPeVerifyOutput, actualOutput);
}
}
......
......@@ -6,6 +6,7 @@
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.CodeGen;
using Microsoft.CodeAnalysis.Emit;
using Microsoft.CodeAnalysis.Test.Utilities;
using static Roslyn.Test.Utilities.RuntimeEnvironmentUtilities;
namespace Roslyn.Test.Utilities.CoreClr
......@@ -99,14 +100,14 @@ public SortedSet<string> GetMemberSignaturesFromMetadata(string fullyQualifiedTy
throw new NotImplementedException();
}
public void PeVerify()
public void Verify(Verification verification)
{
var emitData = GetEmitData();
emitData.RuntimeData.PeverifyRequested = true;
// TODO(https://github.com/dotnet/coreclr/issues/295): Implement peverify
}
public string[] PeVerifyModules(string[] modulesToVerify, bool throwOnError = true)
public string[] VerifyModules(string[] modulesToVerify)
{
// TODO(https://github.com/dotnet/coreclr/issues/295): Implement peverify
return null;
......
......@@ -289,34 +289,40 @@ public IList<ModuleData> GetAllModuleData()
return GetEmitData().AllModuleData;
}
public void PeVerify()
public void Verify(Verification verification)
{
try
if (verification == Verification.Skipped)
{
var emitData = GetEmitData();
emitData.RuntimeData.PeverifyRequested = true;
emitData.Manager.PeVerifyModules(new[] { emitData.MainModule.FullName });
}
catch (RuntimePeVerifyException e)
{
throw new PeVerifyException(e.Output, e.ExePath);
return;
}
}
public string[] PeVerifyModules(string[] modulesToVerify, bool throwOnError = true)
{
var shouldSucceed = verification == Verification.Passes;
try
{
var emitData = GetEmitData();
emitData.RuntimeData.PeverifyRequested = true;
return emitData.Manager.PeVerifyModules(modulesToVerify, throwOnError);
emitData.Manager.PeVerifyModules(new[] { emitData.MainModule.FullName }, throwOnError: true);
if (!shouldSucceed)
{
throw new Exception("Verification succeeded unexpectedly");
}
}
catch (RuntimePeVerifyException e)
{
throw new PeVerifyException(e.Output, e.ExePath);
if (shouldSucceed)
{
throw new Exception("Verification failed");
}
}
}
public string[] VerifyModules(string[] modulesToVerify)
{
var emitData = GetEmitData();
emitData.RuntimeData.PeverifyRequested = true;
return emitData.Manager.PeVerifyModules(modulesToVerify, throwOnError: false);
}
public SortedSet<string> GetMemberSignaturesFromMetadata(string fullyQualifiedTypeName, string memberName)
{
var emitData = GetEmitData();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册