diff --git a/test/fuzz/fuzzer.ml b/test/fuzz/fuzzer.ml index 9b38e360..043b8b46 100644 --- a/test/fuzz/fuzzer.ml +++ b/test/fuzz/fuzzer.ml @@ -4,6 +4,11 @@ let timeout_count = ref 0 let global_count = ref 0 +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 = if Param.debug then begin @@ -67,8 +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 = +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) diff --git a/test/fuzz/param.ml b/test/fuzz/param.ml index bca8295e..f173beb2 100644 --- a/test/fuzz/param.ml +++ b/test/fuzz/param.ml @@ -14,3 +14,7 @@ let initial_fuel = 100 let allow_partial_timeout = true let max_time_execution = 0.01 (* seconds *) + +let save_modules = false (* Set to 'true' enable saving modules *) + +let output_dir = Fpath.v "generated_modules" (* Directory to save modules *) \ No newline at end of file