Mentions légales du service

Skip to content
Snippets Groups Projects
Commit 82201f27 authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Refactoring: isolate two auxiliary functions out of [main_random].

parent 32fafaa3
No related branches found
No related tags found
No related merge requests found
......@@ -1389,6 +1389,36 @@ let main_afl source prologue fuel =
(* -------------------------------------------------------------------------- *)
(* [tick clock fuel] ticks the clock [clock] and, once in a while,
displays an information message. *)
let[@inline] tick clock fuel =
Clock.tick clock @@ fun () ->
printf "%s tests run so far (%s/s overall, %s/s now) (fuel = %d).\n%!"
(summarize (Clock.ticks clock))
(summarize (Clock.overall_ticks_per_second clock))
(summarize (Clock.current_ticks_per_second clock))
fuel
(* [log scenario fuel] logs the failure scenario [scenario] on
[stdout] and in a file in the directory ./output/crashes.*)
let log scenario fuel =
(* Print the scenario to [stdout]. *)
output_string stdout scenario;
print_newline();
flush stdout;
(* Print the scenario into a file. *)
let temp_dir = "./output/crashes" in
mkdirp temp_dir;
let prefix = sprintf "scenario.%03d." fuel
and suffix = "" in
let _, oc = Filename.open_temp_file ~temp_dir prefix suffix in
output_string oc scenario;
close_out_noerr oc
(* -------------------------------------------------------------------------- *)
(* [main_random source prologue fuel] performs an unbounded number of test
runs in random mode. *)
......@@ -1417,32 +1447,12 @@ let rec main_random source prologue fuel =
while true do
(* Perform one run. *)
run prologue fuel;
(* Roughly every second, display statistics. *)
Clock.tick clock begin fun () ->
printf "%s tests run so far (%s/s overall, %s/s now) (fuel = %d).\n%!"
(summarize (Clock.ticks clock))
(summarize (Clock.overall_ticks_per_second clock))
(summarize (Clock.current_ticks_per_second clock))
fuel
end
(* Tick the clock and, once in a while, display statistics. *)
tick clock fuel
done
end
with Abort (scenario, fuel) ->
(* Print the scenario to [stdout]. This is necessary for the user
to be able to find out what happened. Also, log it to a file
in the directory ./output/crashes. *)
output_string stdout scenario;
print_newline();
flush stdout;
let temp_dir = "./output/crashes" in
mkdirp temp_dir;
let prefix = sprintf "scenario.%03d." fuel
and suffix = "" in
let _, oc = Filename.open_temp_file ~temp_dir prefix suffix in
output_string oc scenario;
close_out_noerr oc;
log scenario fuel;
(* 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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment