Skip to content

Commit

Permalink
fixup: refactor for idiomatic ocaml, write_module Fpath.t, Bos.OS
Browse files Browse the repository at this point in the history
  • Loading branch information
spellfish authored and zapashcanon committed Jan 15, 2025
1 parent 3e8e945 commit da0cfca
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
36 changes: 16 additions & 20 deletions test/fuzz/fuzzer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ 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 write_module (fpath : Fpath.t) m =
match Bos.OS.File.writef fpath "%a@." Owi.Text.pp_modul m with
| Ok () -> Ok ()
| Error (`Msg err) -> Error (`Msg (Fmt.str "Failed to write module to %a: %s" Fpath.pp fpath err))

let compare (module I1 : Interprets.INTERPRET)
(module I2 : Interprets.INTERPRET) m =
Expand Down Expand Up @@ -72,22 +72,18 @@ let compare (module I1 : Interprets.INTERPRET)
Fmt.epr "`%s` was OK but `%s` gave error `%s`" I2.name I1.name msg;
false

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;
);

let check (module I1 : Interprets.INTERPRET) (module I2 : Interprets.INTERPRET) m =
if Param.save_modules then begin
let outdir = Fpath.v Param.output_dir in
let* () = Bos.OS.Dir.create ~mode:0o755 outdir in
let filename = Fpath.(v Param.output_dir / Fmt.str "gen_do_module_%d.wat" !global_count) in
let* () = write_module filename m in
if Param.debug then
Fmt.epr "Saved module to %a@\n" Fpath.pp filename;
Ok ()
end else
Ok ();

compare (module I1) (module I2) m

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

let max_time_execution = 0.01 (* seconds *)

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

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

0 comments on commit da0cfca

Please sign in to comment.