Skip to content
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

Merge functionality to filter out tests #9

Open
wants to merge 14 commits into
base: Latest
Choose a base branch
from
Prev Previous commit
Next Next commit
silence error reports during pruning
  • Loading branch information
tbean79 committed Jul 2, 2022
commit e1cca6635b9c2625d4f8c6ca1fd560d1839ae764
55 changes: 30 additions & 25 deletions Source/DafnyTestGeneration/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,33 +118,38 @@ public static class Main {
}

private static async Task<string> RetMethodIfVerified(string sourceFile, DafnyInfo dafnyInfo, string methodStr) {
string testClassPrelude = GetTestClassPrelude(sourceFile, dafnyInfo).Aggregate("", (x, y) => x = x + y + '\n');
string testClassWithSingleMethod = testClassPrelude + methodStr
+ TestMethod.EmitSynthesizeMethods() + "\n}";
Program? dafnyProgram = Utils.Parse(testClassWithSingleMethod, Path.GetFileName(sourceFile));

if (dafnyProgram != null) {
var engine = Microsoft.Boogie.ExecutionEngine.CreateWithoutSharedCache(DafnyOptions.O);
var boogiePrograms = Translator.Translate(dafnyProgram, dafnyProgram.Reporter).ToList().ConvertAll(tuple => tuple.Item2);
var boogieProgram = ProgramModifier.MergeBoogiePrograms(boogiePrograms);
var writer = new StringWriter();
var uniqueId = System.Guid.NewGuid().ToString();

Task<(Microsoft.Boogie.PipelineOutcome, Microsoft.Boogie.PipelineStatistics)>
boogieTask = Microsoft.Dafny.Main.BoogieOnce(writer, engine, "", "", boogieProgram, uniqueId);

var task = await Task.WhenAny(
boogieTask,
Task.Delay(System.TimeSpan.FromSeconds(DafnyOptions.O.TestGenOptions.Timeout)));

if (task == boogieTask) {
var (outcome, stats) = await boogieTask;

if (Microsoft.Dafny.Main.IsBoogieVerified(outcome, stats))
return methodStr;
try {
string testClassPrelude = GetTestClassPrelude(sourceFile, dafnyInfo).Aggregate("", (x, y) => x = x + y + '\n');
string testClassWithSingleMethod = testClassPrelude + methodStr
+ TestMethod.EmitSynthesizeMethods() + "\n}";
Program? dafnyProgram = Utils.Parse(testClassWithSingleMethod,
Path.GetFileName(sourceFile), new ErrorReporterSink());

if (dafnyProgram != null) {
var engine = Microsoft.Boogie.ExecutionEngine.CreateWithoutSharedCache(DafnyOptions.O);
var boogiePrograms = Translator.Translate(dafnyProgram, dafnyProgram.Reporter).ToList().ConvertAll(tuple => tuple.Item2);
var boogieProgram = ProgramModifier.MergeBoogiePrograms(boogiePrograms);
var writer = new StringWriter();
var uniqueId = System.Guid.NewGuid().ToString();

Task<(Microsoft.Boogie.PipelineOutcome, Microsoft.Boogie.PipelineStatistics)>
boogieTask = Microsoft.Dafny.Main.BoogieOnce(writer, engine, "", "", boogieProgram, uniqueId);

var task = await Task.WhenAny(
boogieTask,
Task.Delay(System.TimeSpan.FromSeconds(DafnyOptions.O.TestGenOptions.Timeout)));

if (task == boogieTask) {
var (outcome, stats) = await boogieTask;

if (Microsoft.Dafny.Main.IsBoogieVerified(outcome, stats))
return methodStr;
}
}
return "";
} catch (System.Exception) {
return "";
}
return "";
}

/// <summary>
Expand Down
5 changes: 3 additions & 2 deletions Source/DafnyTestGeneration/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ public static class Utils {
/// <summary>
/// Parse a string read (from a certain file) to a Dafny Program
/// </summary>
public static Program? Parse(string source, string fileName = "") {
public static Program? Parse(string source, string fileName = "",
ErrorReporter? customReporter = null) {
ModuleDecl module = new LiteralModuleDecl(new DefaultModuleDecl(), null);
var builtIns = new BuiltIns();
var reporter = new ConsoleErrorReporter();
var reporter = customReporter ?? new ConsoleErrorReporter();
var success = Parser.Parse(source, fileName, fileName, null, module, builtIns,
new Errors(reporter)) == 0 && Microsoft.Dafny.Main.ParseIncludesDepthFirstNotCompiledFirst(module, builtIns,
new HashSet<string>(), new Errors(reporter)) == null;
Expand Down