Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature: Enable OWI fuzzer.ml to save generated WASM modules to local dir #463

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you use Bos.OS.File.writef instead ? You have an example here. It forces you to handle error properly (I just realized open_out is hidden by the prelude library in the whole code-base but not in the fuzzer...).


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 (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the case of if it is more idiomatic to use begin ... end rather than ( ... ).

(* Create output directory if it doesn't exist *)
if not (Sys.file_exists Param.output_dir) then
Unix.mkdir Param.output_dir 0o755;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use Bos.File.Dir.create instead ? Also, it is better to not tests existence before (the function is going to check it for you).


let filename = Printf.sprintf "%s/gen_do_module_%d.wat"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use Fpath.(Param.output_dir / (Fmt.str "gen_do_module_%d !global_count)) instead to have proper directory separator on every platform.

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 *)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would set this to false by default because this is quite likely to make the fuzzing much more slower


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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let output_dir = Fpath.v "generated_modules" (this is better than using strings to represents paths)

Loading