Skip to content

Commit

Permalink
fixup: write_module and check module function
Browse files Browse the repository at this point in the history
  • Loading branch information
spellfish committed Dec 18, 2024
1 parent 168af31 commit 13163d8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
19 changes: 19 additions & 0 deletions test/fuzz/fuzzer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ let timeout_count = ref 0

let global_count = ref 0

let write_module filename m =
let oc = open_out filename in
Fmt.pf (Format.formatter_of_out_channel oc) "%a@." Owi.Text.pp_modul m;
close_out oc

let compare (module I1 : Interprets.INTERPRET)
(module I2 : Interprets.INTERPRET) m =
if Param.debug then begin
Expand Down Expand Up @@ -69,6 +74,20 @@ let compare (module I1 : Interprets.INTERPRET)

let check (module I1 : Interprets.INTERPRET) (module I2 : Interprets.INTERPRET)
m =
(* Save the generated module *)
if Param.save_modules then (
(* Create output directory if it doesn't exist *)
if not (Sys.file_exists Param.output_dir) then
Unix.mkdir Param.output_dir 0o755;

let filename = Printf.sprintf "%s/gen_do_module_%d.wat"
Param.output_dir !global_count in
write_module filename m;

if Param.debug then
Fmt.epr "Saved module to %s@\n" filename;
);

compare (module I1) (module I2) m

let add_test name gen (module I1 : Interprets.INTERPRET)
Expand Down
4 changes: 4 additions & 0 deletions test/fuzz/param.ml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,7 @@ let initial_fuel = 100
let allow_partial_timeout = true

let max_time_execution = 0.01 (* seconds *)

let save_modules = true (* Set to false to disable saving modules *)

let output_dir = "generated_modules" (* Directory to save modules *)

0 comments on commit 13163d8

Please sign in to comment.