-
Notifications
You must be signed in to change notification settings - Fork 264
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Run integration tests in single process #3715
Changes from 168 commits
6ab36d7
7ccf451
2833156
ccaaa49
65cdf8d
ee34a06
eb87fae
a3afb04
e8a1db8
fa3e1fc
69b66b6
180fc63
1742fa1
5653e00
a63b1e5
92077bc
0dffe00
445e414
10491b5
0637aaf
565506d
8e1491d
5ebc7bd
ba69454
8b551ca
d9d0770
4f2d775
7909705
7c57753
7603f80
5609e7e
66dcc83
802c8ba
61f3e22
db7d458
5971403
8d4a007
ac02112
1287adc
6ca5fe0
5162183
307cbfa
f55a83f
3ebcbab
9c931d8
dff76d3
5873f81
84154bd
fa8fea4
b02245e
d08a5ba
25b50e9
4773fae
d235384
50a7043
8bcf45a
ff3fce3
60cc947
b874a87
f577bec
5283366
cc03c41
44d72ef
0f15a16
fd48bee
e89d0eb
d886039
9add5ae
0a0fca3
a17f323
e336e93
16f41d9
d0228e5
706e677
c80fcf6
e53b0b9
42f4e6a
9013d76
553812f
0c8e7b0
4002bc1
d69a74d
82e5e01
96978ad
f730b8d
2782fe0
684d018
df1a020
cbb5bdd
866be4e
5e2f2e5
8e6479c
9e526cc
b1d3e10
e1c0847
bb5e9cd
cd5c5d8
8ea20a5
b7cdc6c
2492683
9ff2c68
bd1b180
57bb88a
ba286ab
9b2f493
1d9a8cf
687ff00
25afde7
d0b5846
5ec91ca
e467696
fa40552
16a46eb
71a544e
28e1a08
9b3db67
7185abf
64ed99b
dd2b82d
8ce63f7
c683d6a
9bab7d0
714861b
d0fc2cf
4a16b5c
c0c29b1
becad02
f62941d
8f05f36
1a790e2
697607e
47f95ec
539d6c9
57a463f
625a6f0
1221526
b5c9e48
fc8eb97
591ba60
3dc4e8a
35ce43f
bcb33cd
744587f
0b1e844
89f98ef
7fe9e59
55d37fc
d2957ac
09fe703
78f9259
21e2ffd
513f374
289a6df
324564d
6fff097
2355a05
fde4b5e
61dd21d
e4632c2
bb66297
8448af8
514cd02
e4d39e7
bb50259
79f4d68
20a84e3
9cf986d
1948a8d
31591ac
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
using System.Linq; | ||
using System.Reflection; | ||
using System.Runtime.Loader; | ||
using System.Text; | ||
using System.Text.Json; | ||
using Microsoft.CodeAnalysis; | ||
using Microsoft.CodeAnalysis.CSharp; | ||
|
@@ -44,7 +45,6 @@ public override bool CompileTargetProgram(string dafnyProgramName, string target | |
MetadataReference.CreateFromFile(typeof(object).GetTypeInfo().Assembly.Location), | ||
MetadataReference.CreateFromFile(Assembly.Load("mscorlib").Location)); | ||
|
||
var inMemory = runAfterCompile; | ||
compilation = compilation.WithOptions(compilation.Options.WithOutputKind(callToMain != null ? OutputKind.ConsoleApplication : OutputKind.DynamicallyLinkedLibrary)); | ||
|
||
var tempCompilationResult = new CSharpCompilationResult(); | ||
|
@@ -93,54 +93,40 @@ public override bool CompileTargetProgram(string dafnyProgramName, string target | |
var outputDir = targetFilename == null ? Directory.GetCurrentDirectory() : Path.GetDirectoryName(Path.GetFullPath(targetFilename)); | ||
var outputPath = Path.Join(outputDir, Path.GetFileNameWithoutExtension(Path.GetFileName(dafnyProgramName)) + ".dll"); | ||
var outputJson = Path.Join(outputDir, Path.GetFileNameWithoutExtension(Path.GetFileName(dafnyProgramName)) + ".runtimeconfig.json"); | ||
if (inMemory) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Might be worth mentioning this change of behavior in a release note (that C# always emits source code now). I can't find any note of it in documentation, and I do like making this more consistent with the other backends, but it could be surprising to some customers that have been using Dafny for a long time. |
||
using var stream = new MemoryStream(); | ||
var emitResult = compilation.Emit(stream); | ||
if (emitResult.Success) { | ||
tempCompilationResult.CompiledAssembly = Assembly.Load(stream.GetBuffer()); | ||
} else { | ||
outputWriter.WriteLine("Errors compiling program:"); | ||
var errors = emitResult.Diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error).ToList(); | ||
foreach (var ce in errors) { | ||
outputWriter.WriteLine(ce.ToString()); | ||
outputWriter.WriteLine(); | ||
} | ||
return false; | ||
var emitResult = compilation.Emit(outputPath); | ||
|
||
if (emitResult.Success) { | ||
tempCompilationResult.CompiledAssembly = Assembly.LoadFile(outputPath); | ||
if (Options.CompileVerbose) { | ||
outputWriter.WriteLine("Compiled assembly into {0}.dll", compilation.AssemblyName); | ||
} | ||
} else { | ||
var emitResult = compilation.Emit(outputPath); | ||
|
||
if (emitResult.Success) { | ||
tempCompilationResult.CompiledAssembly = Assembly.LoadFile(outputPath); | ||
if (Options.CompileVerbose) { | ||
outputWriter.WriteLine("Compiled assembly into {0}.dll", compilation.AssemblyName); | ||
} | ||
try { | ||
var configuration = JsonSerializer.Serialize( | ||
new { | ||
runtimeOptions = new { | ||
tfm = "net6.0", | ||
framework = new { | ||
name = "Microsoft.NETCore.App", | ||
version = "6.0.0", | ||
rollForward = "LatestMinor" | ||
} | ||
try { | ||
var configuration = JsonSerializer.Serialize( | ||
new { | ||
runtimeOptions = new { | ||
tfm = "net6.0", | ||
framework = new { | ||
name = "Microsoft.NETCore.App", | ||
version = "6.0.0", | ||
rollForward = "LatestMinor" | ||
} | ||
}, new JsonSerializerOptions() { WriteIndented = true }); | ||
File.WriteAllText(outputJson, configuration + Environment.NewLine); | ||
} catch (Exception e) { | ||
outputWriter.WriteLine($"Error trying to write '{outputJson}': {e.Message}"); | ||
return false; | ||
} | ||
} else { | ||
outputWriter.WriteLine("Errors compiling program into {0}", compilation.AssemblyName); | ||
var errors = emitResult.Diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error).ToList(); | ||
foreach (var ce in errors) { | ||
outputWriter.WriteLine(ce.ToString()); | ||
outputWriter.WriteLine(); | ||
} | ||
} | ||
}, new JsonSerializerOptions() { WriteIndented = true }); | ||
File.WriteAllText(outputJson, configuration + Environment.NewLine); | ||
} catch (Exception e) { | ||
outputWriter.WriteLine($"Error trying to write '{outputJson}': {e.Message}"); | ||
return false; | ||
} | ||
} else { | ||
outputWriter.WriteLine("Errors compiling program into {0}", compilation.AssemblyName); | ||
var errors = emitResult.Diagnostics.Where(d => d.Severity == DiagnosticSeverity.Error).ToList(); | ||
foreach (var ce in errors) { | ||
outputWriter.WriteLine(ce.ToString()); | ||
outputWriter.WriteLine(); | ||
} | ||
|
||
return false; | ||
} | ||
|
||
compilationResult = tempCompilationResult; | ||
|
@@ -151,37 +137,24 @@ private class CSharpCompilationResult { | |
public Assembly CompiledAssembly; | ||
} | ||
|
||
public override bool RunTargetProgram(string dafnyProgramName, string targetProgramText, string callToMain, string/*?*/ targetFilename, ReadOnlyCollection<string> otherFileNames, | ||
object compilationResult, TextWriter outputWriter) { | ||
public override bool RunTargetProgram(string dafnyProgramName, string targetProgramText, string callToMain, | ||
string targetFilename /*?*/, ReadOnlyCollection<string> otherFileNames, | ||
object compilationResult, TextWriter outputWriter, TextWriter errorWriter) { | ||
|
||
var crx = (CSharpCompilationResult)compilationResult; | ||
|
||
foreach (var otherFileName in otherFileNames) { | ||
if (Path.GetExtension(otherFileName) == ".dll") { | ||
AssemblyLoadContext.Default.LoadFromAssemblyPath(Path.GetFullPath(otherFileName)); | ||
var targetDirectory = Path.GetDirectoryName(crx.CompiledAssembly.Location); | ||
File.Copy(otherFileName, Path.Combine(targetDirectory!, Path.GetFileName(otherFileName)), true); | ||
} | ||
} | ||
|
||
if (crx.CompiledAssembly == null) { | ||
throw new Exception("Cannot call run target program on a compilation that failed"); | ||
} | ||
var entry = crx.CompiledAssembly.EntryPoint; | ||
if (entry == null) { | ||
throw new Exception("Cannot call run target on a compilation whose assembly has no entry."); | ||
} | ||
try { | ||
Console.OutputEncoding = System.Text.Encoding.UTF8; // Force UTF-8 output in dafny run (#2999) | ||
object[] parameters = entry.GetParameters().Length == 0 ? new object[] { } : new object[] { Options.MainArgs.ToArray() }; | ||
entry.Invoke(null, parameters); | ||
return true; | ||
} catch (System.Reflection.TargetInvocationException e) { | ||
outputWriter.WriteLine("Error: Execution resulted in exception: {0}", e.Message); | ||
outputWriter.WriteLine(e.InnerException.ToString()); | ||
} catch (System.Exception e) { | ||
outputWriter.WriteLine("Error: Execution resulted in exception: {0}", e.Message); | ||
outputWriter.WriteLine(e.ToString()); | ||
} | ||
return false; | ||
var psi = PrepareProcessStartInfo("dotnet", new[] { crx.CompiledAssembly.Location }.Concat(Options.MainArgs)); | ||
return RunProcess(psi, outputWriter, errorWriter) == 0; | ||
} | ||
|
||
public CsharpBackend(DafnyOptions options) : base(options) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AFAICT a lot of the test failures are due to not using a recent commit from the libraries repo, if you update that pointer it should fix them (because we updated that code to work with Dafny 4)