diff --git a/src/Engine.ml b/src/Engine.ml index 48a1ea24eaf59bb5ed4cbb3a2331ccd99098d8e3..c3c446a91f1ff5e44950d02b1206b841d01fc204 100644 --- a/src/Engine.ml +++ b/src/Engine.ml @@ -1410,6 +1410,10 @@ type settings = { (**This Boolean flag determines whether failure scenarios should be printed to the standard output channel. *) + save_scenario : bool; + (**This Boolean flag determines whether failure scenarios should be + saved to a file in the directory [./output/crashes]. *) + prologue : prologue; (**A prologue. *) @@ -1458,24 +1462,26 @@ let[@inline] tick clock settings = (summarize (Clock.current_ticks_per_second clock)) settings.fuel -(* [show scenario settings] logs the failure scenario [scenario] on - [stdout] and in a file in the directory ./output/crashes. *) +(* [show_and_save scenario settings] logs the failure scenario [scenario] on + [stdout] and saves it in a file in the directory ./output/crashes. *) -let[@inline] show scenario settings = +let[@inline] show_and_save scenario settings = if settings.show_scenario then begin (* Print the scenario to [stdout]. *) output_string stdout scenario; print_newline(); flush stdout end; - (* Print the scenario into a file. *) - let temp_dir = "./output/crashes" in - mkdirp temp_dir; - let prefix = sprintf "scenario.%03d." settings.fuel - and suffix = "" in - let _, oc = Filename.open_temp_file ~temp_dir prefix suffix in - output_string oc scenario; - close_out_noerr oc + if settings.save_scenario then begin + (* Write the scenario into a file. *) + let temp_dir = "./output/crashes" in + mkdirp temp_dir; + let prefix = sprintf "scenario.%03d." settings.fuel + and suffix = "" in + let _, oc = Filename.open_temp_file ~temp_dir prefix suffix in + output_string oc scenario; + close_out_noerr oc + end (* -------------------------------------------------------------------------- *) @@ -1517,7 +1523,7 @@ let rec run_random_loop settings clock (accu : failures) : failures = assert false with | Abort (scenario, fuel) -> - show scenario settings; + show_and_save scenario settings; (* We have been able to find a problem with a certain amount of fuel. Try again, with this amount. This restricts our search space, and (with luck) we might now be able to find an even @@ -1551,9 +1557,10 @@ let run_random settings : failures = let parse prologue fuel : settings = let usage = sprintf "Usage: %s <input file>" Sys.argv.(0) in - let source, timeout, fuel, show_scenario = - ref None, ref None, ref fuel, ref true + let source, timeout, fuel, save_scenario, show_scenario = + ref None, ref None, ref fuel, ref true, ref true in + let set_save_scenario b = save_scenario := b in let set_show_scenario b = show_scenario := b in let set_timeout t = timeout := Some (float_of_int t) in let spec = Arg.align [ @@ -1562,6 +1569,10 @@ let parse prologue fuel : settings = Arg.Set_int fuel, "<int> Set a fuel limit"; + "--save-scenario", + Arg.Bool set_save_scenario, + "<bool> Enable/disable saving scenarios on disk"; + "--show-scenario", Arg.Bool set_show_scenario, "<bool> Enable/disable showing scenarios on stdout"; @@ -1572,10 +1583,10 @@ let parse prologue fuel : settings = ] in Arg.parse spec (fun s -> source := Some s) usage; - let source, timeout, fuel, show_scenario = - !source, !timeout, !fuel, !show_scenario + let source, timeout, fuel, save_scenario, show_scenario = + !source, !timeout, !fuel, !save_scenario, !show_scenario in - { source; timeout; show_scenario; prologue; fuel } + { source; timeout; save_scenario; show_scenario; prologue; fuel } (* -------------------------------------------------------------------------- *) diff --git a/src/Engine.mli b/src/Engine.mli index c54357ad0b214d165a0e7e1ea1615a30f4f72bd7..8c84631516874927fa2e07428f10af5e4624f079 100644 --- a/src/Engine.mli +++ b/src/Engine.mli @@ -32,6 +32,10 @@ type settings = { (**This Boolean flag determines whether failure scenarios should be printed to the standard output channel. *) + save_scenario : bool; + (**This Boolean flag determines whether failure scenarios should be + saved to a file in the directory [./output/crashes]. *) + prologue : prologue; (**A prologue. *) diff --git a/src/Monolith.mli b/src/Monolith.mli index 982237620f3ed2b367661679530d07c28e180939..c6c7f1660b69d41e36532abd6df8aa79e47a8653 100644 --- a/src/Monolith.mli +++ b/src/Monolith.mli @@ -1160,6 +1160,10 @@ type settings = { (**This Boolean flag determines whether failure scenarios should be printed to the standard output channel. *) + save_scenario : bool; + (**This Boolean flag determines whether failure scenarios should be + saved to a file in the directory [./output/crashes]. *) + prologue : prologue; (**A prologue. *) @@ -1190,10 +1194,14 @@ val run : settings -> failures The main (optional) command line argument is a file name, which serves as the [source] field of the [settings] record. - Beyond this, the supported (optional) command line parameters are - [--fuel <int>] and [--timeout <int>]. If a fuel parameter is supplied on - the command line, then it overrides the value of [fuel] that is passed as - an argument to {!main}. *) + Beyond this, the supported optional command line parameters are + [--fuel <int>] (default: [fuel]) and + [--save-scenario <bool>] (default: [true]) and + [--show-scenario <bool>] (default: [true]) and + [--timeout <int>] (default: no time limit). + + If a fuel parameter is supplied on the command line, then it overrides the + value of [fuel] that is passed as an argument to {!main}. *) val main: ?prologue:prologue -> fuel -> unit (**{!dprintf} is analogous to [printf]. Its output is actually printed to the