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

[Test Generation] Remove redundant code #4146

Merged
merged 1 commit into from
Jun 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions Source/DafnyCore/TestGenerationOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ public enum Modes { None, Block, Path };
public Modes Mode = Modes.None;
[CanBeNull] public string TargetMethod = null;
public uint SeqLengthLimit = 0;
public bool Verbose = false;
[CanBeNull] public string PrintBpl = null;
[CanBeNull] public string PrintStats = null;
public bool DisablePrune = false;
Expand Down Expand Up @@ -58,10 +57,6 @@ public bool ParseOption(string name, Bpl.CommandLineParseState ps) {
}
return true;

case "generateTestVerbose":
Verbose = true;
return true;

case "generateTestNoPrune":
DisablePrune = true;
return true;
Expand All @@ -87,8 +82,6 @@ Add an axiom that sets the length of all sequences to be no greater
If specified, only this method will be tested.
/generateTestPrintBpl:<fileName>
Print the Boogie code used during test generation.
/generateTestVerbose
Print various debugging info as comments for the generated tests.
/generateTestNoPrune
Disable axiom pruning that Dafny uses to speed up verification.";

Expand Down
4 changes: 2 additions & 2 deletions Source/DafnyTestGeneration/DafnyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -426,12 +426,12 @@ private void VisitUserDefinedTypeDeclaration(string newTypeName,
Type baseType, Expression/*?*/ witness, List<TypeParameter> typeArgs) {
if (witness != null) {
info.witnessForType[newTypeName] = witness;
if (info.Options.TestGenOptions.Verbose) {
if (info.Options.Verbose) {
info.Options.OutputWriter.WriteLine($"// Values of type {newTypeName} will be " +
$"assigned the default value of " +
$"{Printer.ExprToString(info.Options, info.witnessForType[newTypeName])}");
}
} else if (info.Options.TestGenOptions.Verbose) {
} else if (info.Options.Verbose) {
var message = $@"
*** Error: Values of type {newTypeName}
will be assigned a default value of type {baseType},
Expand Down
1 change: 0 additions & 1 deletion Source/DafnyTestGeneration/DeadCodeCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ public void PostProcess(DafnyOptions dafnyOptions, Options options, InvocationCo
dafnyOptions.Compile = true;
dafnyOptions.RunAfterCompile = false;
dafnyOptions.ForceCompile = false;
dafnyOptions.Verbose = false;
dafnyOptions.ForbidNondeterminism = true;
dafnyOptions.DefiniteAssignmentLevel = 2;

Expand Down
42 changes: 2 additions & 40 deletions Source/DafnyTestGeneration/GenerateTestsCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,40 +38,10 @@ private enum Mode {
/// parameter in everything except the value of the ProcsToCheck field that
/// determines the procedures to be verified and should be set to the value of
/// the <param name="procedureToVerify"></param> parameter.
/// Note that this cannot be refactored to use the DafnyOptions.CopyTo method
/// because we have to modify ProcsToCheck list, which does not have a setter.
/// </summary>
internal static DafnyOptions CopyForProcedure(DafnyOptions options, string procedureToVerify) {
var copy = DafnyOptions.Create(options.OutputWriter, options.Input, new[] { "/proc:" + procedureToVerify });
// Options set by the user:
copy.LoopUnrollCount = options.LoopUnrollCount;
copy.TestGenOptions.SeqLengthLimit = options.TestGenOptions.SeqLengthLimit;
copy.TestGenOptions.TargetMethod = options.TestGenOptions.TargetMethod;
copy.ProverLogFilePath = options.ProverLogFilePath;
copy.ProverLogFileAppend = options.ProverLogFileAppend;
copy.ProverOptions.Clear();
copy.ProverOptions.AddRange(options.ProverOptions);
copy.ResourceLimit = options.ResourceLimit;
copy.TimeLimit = options.TimeLimit;
copy.ProverDllName = options.ProverDllName;
copy.TheProverFactory = options.TheProverFactory;
copy.TestGenOptions.Verbose = options.TestGenOptions.Verbose;
copy.TestGenOptions.PrintBpl = options.TestGenOptions.PrintBpl;
copy.TestGenOptions.DisablePrune = options.TestGenOptions.DisablePrune;
copy.Prune = !options.TestGenOptions.DisablePrune;
// Options set by default in PostProcess:
copy.CompilerName = options.CompilerName;
copy.Compile = options.Compile;
copy.RunAfterCompile = options.RunAfterCompile;
copy.ForceCompile = options.ForceCompile;
copy.Verbose = options.Verbose;
copy.DeprecationNoise = options.DeprecationNoise;
copy.ForbidNondeterminism = options.ForbidNondeterminism;
copy.DefiniteAssignmentLevel = options.DefiniteAssignmentLevel;
copy.TestGenOptions.Mode = options.TestGenOptions.Mode;
copy.TestGenOptions.WarnDeadCode = options.TestGenOptions.WarnDeadCode;
// Options that may be modified by Test Generation itself:
copy.VerifyAllModules = options.VerifyAllModules;
var copy = new DafnyOptions(options);
copy.ProcsToCheck = new List<string>() { procedureToVerify };
return copy;
}

Expand All @@ -93,7 +63,6 @@ public void PostProcess(DafnyOptions dafnyOptions, Options options, InvocationCo
dafnyOptions.Compile = true;
dafnyOptions.RunAfterCompile = false;
dafnyOptions.ForceCompile = false;
dafnyOptions.Verbose = false;
dafnyOptions.DeprecationNoise = 0;
dafnyOptions.ForbidNondeterminism = true;
dafnyOptions.DefiniteAssignmentLevel = 2;
Expand All @@ -116,9 +85,6 @@ public void PostProcess(DafnyOptions dafnyOptions, Options options, InvocationCo
public static readonly Option<int> LoopUnroll = new("--loop-unroll",
"Higher values can improve accuracy of the analysis at the cost of taking longer to run.") {
};
public static readonly Option<bool> Verbose = new("--verbose",
"Print various debugging info as comments for the generated tests.") {
};
public static readonly Option<string> PrintBpl = new("--print-bpl",
"Print the Boogie code used during test generation.") {
ArgumentHelpName = "filename"
Expand All @@ -136,9 +102,6 @@ static GenerateTestsCommand() {
DafnyOptions.RegisterLegacyBinding(Target, (options, value) => {
options.TestGenOptions.TargetMethod = value;
});
DafnyOptions.RegisterLegacyBinding(Verbose, (options, value) => {
options.TestGenOptions.Verbose = value;
});
DafnyOptions.RegisterLegacyBinding(PrintBpl, (options, value) => {
options.TestGenOptions.PrintBpl = value;
});
Expand All @@ -150,7 +113,6 @@ static GenerateTestsCommand() {
LoopUnroll,
SequenceLengthLimit,
Target,
Verbose,
PrintBpl,
DisablePrune
);
Expand Down
11 changes: 6 additions & 5 deletions Source/DafnyTestGeneration/ProgramModification.cs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ private static void SetupForCounterexamples(DafnyOptions options) {
options.ErrorTrace = 1;
options.EnhancedErrorMessages = 1;
options.ModelViewFile = "-";
options.Prune = !options.TestGenOptions.DisablePrune;
}

/// <summary>
Expand Down Expand Up @@ -122,7 +123,7 @@ private static void SetupForCounterexamples(DafnyOptions options) {
counterexampleStatus = Status.Failure;
counterexampleLog = null;
if (result is not Task<PipelineOutcome>) {
if (Options.TestGenOptions.Verbose) {
if (Options.Verbose) {
await options.OutputWriter.WriteLineAsync(
$"// No test can be generated for {uniqueId} " +
"because the verifier timed out.");
Expand All @@ -138,13 +139,13 @@ await options.OutputWriter.WriteLineAsync(
counterexampleStatus = Status.Success;
var blockId = int.Parse(Regex.Replace(line, @"\s+", "").Split('|')[2]);
coversBlocks.Add(blockId);
if (Options.TestGenOptions.Verbose &&
if (Options.Verbose &&
Options.TestGenOptions.Mode != TestGenerationOptions.Modes.Path) {
await options.OutputWriter.WriteLineAsync($"// Test {uniqueId} covers block {blockId}");
}
}
}
if (Options.TestGenOptions.Verbose && counterexampleLog == null) {
if (Options.Verbose && counterexampleLog == null) {
if (log == "") {
await options.OutputWriter.WriteLineAsync(
$"// No test is generated for {uniqueId} " +
Expand All @@ -164,7 +165,7 @@ await options.OutputWriter.WriteLineAsync(
}

public async Task<TestMethod> GetTestMethod(Modifications cache, DafnyInfo dafnyInfo, bool returnNullIfNotUnique = true) {
if (Options.TestGenOptions.Verbose) {
if (Options.Verbose) {
await dafnyInfo.Options.OutputWriter.WriteLineAsync(
$"// Extracting the test for {uniqueId} from the counterexample...");
}
Expand All @@ -182,7 +183,7 @@ await dafnyInfo.Options.OutputWriter.WriteLineAsync(
if (duplicate == null) {
return testMethod;
}
if (Options.TestGenOptions.Verbose) {
if (Options.Verbose) {
await dafnyInfo.Options.OutputWriter.WriteLineAsync(
$"// Test for {uniqueId} matches a test previously generated " +
$"for {duplicate.uniqueId}. This happens when test generation tool " +
Expand Down
2 changes: 1 addition & 1 deletion Source/DafnyTestGeneration/ProgramModifier.cs
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ private void GetCalleesRecursively(string caller, Dictionary<string, uint> recor
continue;
}
recorded[callee] = toInline;
if (info.Options.TestGenOptions.Verbose) {
if (info.Options.Verbose) {
Console.Out.WriteLine($"// Will inline calls to {callee} with recursion unrolling depth set to {toInline}.");
}
GetCalleesRecursively(callee, recorded);
Expand Down
2 changes: 1 addition & 1 deletion Source/DafnyTestGeneration/TestMethod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -675,7 +675,7 @@ private List<string> TestMethodLines() {
List<string> lines = new();

if (errorMessages.Count != 0) {
if (DafnyInfo.Options.TestGenOptions.Verbose) {
if (DafnyInfo.Options.Verbose) {
lines.AddRange(errorMessages);
}
return lines;
Expand Down
2 changes: 0 additions & 2 deletions docs/DafnyRef/Options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -340,8 +340,6 @@ Usage: dafny [ option ... ] [ filename ... ]
If specified, only this method will be tested.
/generateTestPrintBpl:<fileName>
Print the Boogie code used during test generation.
/generateTestVerbose
Print various debugging info as comments for the generated tests.
/generateTestNoPrune
Disable axiom pruning that Dafny uses to speed up verification.
---- Compilation options ---------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions docs/dev/4146.fix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove redundant code in the test generation project