From 0db7ca27a89bf6f89f3c33e564b22ac91e0835f5 Mon Sep 17 00:00:00 2001 From: Dargones Date: Wed, 3 May 2023 11:24:04 -0400 Subject: [PATCH 1/8] Make sure options are copied in ProgramModification --- Source/DafnyTestGeneration/DeadCodeCommand.cs | 2 -- Source/DafnyTestGeneration/GenerateTestsCommand.cs | 3 +-- Source/DafnyTestGeneration/ProgramModification.cs | 8 +++++--- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/Source/DafnyTestGeneration/DeadCodeCommand.cs b/Source/DafnyTestGeneration/DeadCodeCommand.cs index 948d5f3546b..e8fe0788bfc 100644 --- a/Source/DafnyTestGeneration/DeadCodeCommand.cs +++ b/Source/DafnyTestGeneration/DeadCodeCommand.cs @@ -10,11 +10,9 @@ public class DeadCodeCommand : ICommandSpec { new Option[] { GenerateTestsCommand.LoopUnroll, GenerateTestsCommand.SequenceLengthLimit, - BoogieOptionBag.BoogieArguments, BoogieOptionBag.SolverLog, BoogieOptionBag.SolverOption, BoogieOptionBag.SolverPath, - BoogieOptionBag.SolverPlugin, BoogieOptionBag.SolverResourceLimit, BoogieOptionBag.VerificationTimeLimit }.Concat(ICommandSpec.ConsoleOutputOptions). diff --git a/Source/DafnyTestGeneration/GenerateTestsCommand.cs b/Source/DafnyTestGeneration/GenerateTestsCommand.cs index abaeacd6a27..3aa40c5cac3 100644 --- a/Source/DafnyTestGeneration/GenerateTestsCommand.cs +++ b/Source/DafnyTestGeneration/GenerateTestsCommand.cs @@ -4,6 +4,7 @@ using System.CommandLine.Invocation; using System.Linq; using DafnyCore; +using Microsoft.Boogie.SMTLib; namespace Microsoft.Dafny; @@ -14,11 +15,9 @@ public class GenerateTestsCommand : ICommandSpec { SequenceLengthLimit, Target, TestInlineDepth, - BoogieOptionBag.BoogieArguments, BoogieOptionBag.SolverLog, BoogieOptionBag.SolverOption, BoogieOptionBag.SolverPath, - BoogieOptionBag.SolverPlugin, BoogieOptionBag.SolverResourceLimit, BoogieOptionBag.VerificationTimeLimit, Verbose, diff --git a/Source/DafnyTestGeneration/ProgramModification.cs b/Source/DafnyTestGeneration/ProgramModification.cs index a8aaf4949e5..68bdf4b04f4 100644 --- a/Source/DafnyTestGeneration/ProgramModification.cs +++ b/Source/DafnyTestGeneration/ProgramModification.cs @@ -77,8 +77,8 @@ private static DafnyOptions SetupOptions(DafnyOptions original, string procedure options.ErrorTrace = 1; options.EnhancedErrorMessages = 1; options.ModelViewFile = "-"; - var proverOptions = new SMTLibSolverOptions(options); - proverOptions.Parse(options.ProverOptions); + var proverOptions = new SMTLibSolverOptions(original); + proverOptions.Parse(original.ProverOptions); var z3Version = DafnyOptions.GetZ3Version(proverOptions.ProverPath); options.ProverOptions = new List() { "O:model_evaluator.completion=true", @@ -89,7 +89,9 @@ private static DafnyOptions SetupOptions(DafnyOptions original, string procedure } else { options.ProverOptions.Insert(0, "O:model.compact=false"); } - + options.ResourceLimit = original.ResourceLimit; + options.ProverLogFilePath = original.ProverLogFilePath; + options.ProverLogFileAppend = original.ProverLogFileAppend; options.Prune = !original.TestGenOptions.DisablePrune; options.ProverOptions.AddRange(original.ProverOptions); options.LoopUnrollCount = original.LoopUnrollCount; From c78a52f9b85963514d6e98aa5435a8353f584fad Mon Sep 17 00:00:00 2001 From: Dargones Date: Thu, 4 May 2023 14:44:07 -0400 Subject: [PATCH 2/8] Fix prover lookup --- Source/DafnyTestGeneration/Main.cs | 2 ++ .../DafnyTestGeneration/ProgramModification.cs | 18 +++--------------- Source/DafnyTestGeneration/Utils.cs | 17 +++++++++++++++++ 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/Source/DafnyTestGeneration/Main.cs b/Source/DafnyTestGeneration/Main.cs index 75dbc8ce112..bb8f1746731 100644 --- a/Source/DafnyTestGeneration/Main.cs +++ b/Source/DafnyTestGeneration/Main.cs @@ -25,6 +25,7 @@ public static async IAsyncEnumerable GetDeadCodeStatistics(Program progr program.Reporter.Options.PrintMode = PrintModes.Everything; var cache = new Modifications(); + Utils.SetProverOptionsBasedOnZ3Version(program.Options); var modifications = GetModifications(cache, program).ToList(); var blocksReached = modifications.Count; HashSet allStates = new(); @@ -115,6 +116,7 @@ public static async IAsyncEnumerable GetTestMethodsForProgram(Progra // Generate tests based on counterexamples produced from modifications var cache = new Modifications(); + Utils.SetProverOptionsBasedOnZ3Version(program.Options); var programModifications = GetModifications(cache, program).ToList(); foreach (var modification in programModifications) { diff --git a/Source/DafnyTestGeneration/ProgramModification.cs b/Source/DafnyTestGeneration/ProgramModification.cs index 68bdf4b04f4..059423d50c3 100644 --- a/Source/DafnyTestGeneration/ProgramModification.cs +++ b/Source/DafnyTestGeneration/ProgramModification.cs @@ -70,30 +70,18 @@ public ProgramModification(DafnyOptions options, Program program, Implementation /// options.Parse() on a new DafnyObject. /// private static DafnyOptions SetupOptions(DafnyOptions original, string procedure) { - var options = DafnyOptions.Create(); - options.Parse(new[] { "/proc:" + procedure }); + var options = DafnyOptions.Create(new[] { "/proc:" + procedure }); + options.ProverOptions.Clear(); + options.ProverOptions.AddRange(original.ProverOptions); options.NormalizeNames = false; options.EmitDebugInformation = true; options.ErrorTrace = 1; options.EnhancedErrorMessages = 1; options.ModelViewFile = "-"; - var proverOptions = new SMTLibSolverOptions(original); - proverOptions.Parse(original.ProverOptions); - var z3Version = DafnyOptions.GetZ3Version(proverOptions.ProverPath); - options.ProverOptions = new List() { - "O:model_evaluator.completion=true", - "O:model.completion=true" - }; - if (z3Version is null || z3Version < new Version(4, 8, 6)) { - options.ProverOptions.Insert(0, "O:model.compress=false"); - } else { - options.ProverOptions.Insert(0, "O:model.compact=false"); - } options.ResourceLimit = original.ResourceLimit; options.ProverLogFilePath = original.ProverLogFilePath; options.ProverLogFileAppend = original.ProverLogFileAppend; options.Prune = !original.TestGenOptions.DisablePrune; - options.ProverOptions.AddRange(original.ProverOptions); options.LoopUnrollCount = original.LoopUnrollCount; options.DefiniteAssignmentLevel = original.DefiniteAssignmentLevel; options.WarnShadowing = original.WarnShadowing; diff --git a/Source/DafnyTestGeneration/Utils.cs b/Source/DafnyTestGeneration/Utils.cs index 7809ae8bead..e0c8e141598 100644 --- a/Source/DafnyTestGeneration/Utils.cs +++ b/Source/DafnyTestGeneration/Utils.cs @@ -1,9 +1,11 @@ #nullable disable +using System; using System.Collections.Generic; using System.IO; using System.Linq; using DafnyServer.CounterexampleGeneration; using Microsoft.Boogie; +using Microsoft.Boogie.SMTLib; using Microsoft.Dafny; using Errors = Microsoft.Dafny.Errors; using Function = Microsoft.Dafny.Function; @@ -16,6 +18,21 @@ namespace DafnyTestGeneration { public static class Utils { + public static void SetProverOptionsBasedOnZ3Version(DafnyOptions options) { + var proverOptions = new SMTLibSolverOptions(options); + proverOptions.Parse(options.ProverOptions); + var z3Version = DafnyOptions.GetZ3Version(proverOptions.ProverPath); + options.ProverOptions.AddRange(new List() { + "O:model_evaluator.completion=true", + "O:model.completion=true" + }); + if (z3Version is null || z3Version < new Version(4, 8, 6)) { + options.ProverOptions.Insert(0, "O:model_compress=false"); + } else { + options.ProverOptions.Insert(0, "O:model.compact=false"); + } + } + /// /// Call Translator with larger stack to prevent stack overflow /// From 06ee8e442de3b844dc6295ea0432584724e6336a Mon Sep 17 00:00:00 2001 From: Dargones Date: Thu, 4 May 2023 15:20:30 -0400 Subject: [PATCH 3/8] remove redundant import --- Source/DafnyTestGeneration/GenerateTestsCommand.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/Source/DafnyTestGeneration/GenerateTestsCommand.cs b/Source/DafnyTestGeneration/GenerateTestsCommand.cs index 3aa40c5cac3..e3348f929bf 100644 --- a/Source/DafnyTestGeneration/GenerateTestsCommand.cs +++ b/Source/DafnyTestGeneration/GenerateTestsCommand.cs @@ -4,7 +4,6 @@ using System.CommandLine.Invocation; using System.Linq; using DafnyCore; -using Microsoft.Boogie.SMTLib; namespace Microsoft.Dafny; From 70a479083e5f6792f0e4f96c2de5dd6239de6c09 Mon Sep 17 00:00:00 2001 From: Dargones Date: Thu, 4 May 2023 16:01:27 -0400 Subject: [PATCH 4/8] Move copy method to GenerateTestsCommand to make future changes easier --- Source/DafnyTestGeneration/DeadCodeCommand.cs | 5 ++ .../GenerateTestsCommand.cs | 46 +++++++++++++++++++ Source/DafnyTestGeneration/Main.cs | 2 - .../ProgramModification.cs | 42 +++++++++-------- Source/DafnyTestGeneration/Utils.cs | 15 ------ 5 files changed, 74 insertions(+), 36 deletions(-) diff --git a/Source/DafnyTestGeneration/DeadCodeCommand.cs b/Source/DafnyTestGeneration/DeadCodeCommand.cs index e8fe0788bfc..22a9c2c40ce 100644 --- a/Source/DafnyTestGeneration/DeadCodeCommand.cs +++ b/Source/DafnyTestGeneration/DeadCodeCommand.cs @@ -8,6 +8,8 @@ namespace Microsoft.Dafny; public class DeadCodeCommand : ICommandSpec { public IEnumerable