-
Notifications
You must be signed in to change notification settings - Fork 19
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
base: main
Are you sure you want to change the base?
Conversation
Hi @spellfish. Thanks for the PR, I think this is an addition we're willing to accept. Do you plan to re-open the PR ? If yes, I'll have some minor comments about code style but nothing too complicated. On another topic, I'm a little bit curious about how/why do you use Owi and our fuzzer, if you're willing to tell me more, you can drop me an e-mail or join our zulip at https://chat.ocaml.pro (ping me there and I'll add you to the Wasm discussion). |
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 |
There was a problem hiding this comment.
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...).
@@ -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 ( |
There was a problem hiding this comment.
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 ( ... )
.
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; |
There was a problem hiding this comment.
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).
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" |
There was a problem hiding this comment.
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.
|
||
let save_modules = true (* Set to false to disable saving modules *) | ||
|
||
let output_dir = "generated_modules" (* Directory to save modules *) |
There was a problem hiding this comment.
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)
@@ -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 *) |
There was a problem hiding this comment.
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
Generated modules will be saved in WebAssembly text format (.wat) in the output directory
generated_modules
.save_modules
that should be set to 'true' (or 'false' to disable saving)owi run
Modules contain random, but valid :
The generated modules are random but valid WebAssembly programs, so their behavior will vary. We can add additional parameters in param.ml to control aspects of generation like module complexity, instruction types, etc.