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

Conversation

spellfish
Copy link

Generated modules will be saved in WebAssembly text format (.wat) in the output directory generated_modules.

  • fuzz/param.ml contains a flag save_modules that should be set to 'true' (or 'false' to disable saving)
  • Each module will be named gen_do_module_N.wat where N is the incremental counter from global_count.
  • Generated modules are valid WebAssembly modules since they're generated using the type-aware generators in gen.ml
  • Modules can be converted to binary format using wat2wasm and run directly using owi run

Modules contain random, but valid :

  • Functions
  • Instructions
  • Memory operations
  • Global variables
  • Type definitions

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.

@spellfish spellfish closed this Dec 18, 2024
@zapashcanon
Copy link
Member

zapashcanon commented Dec 18, 2024

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

@spellfish spellfish reopened this Dec 18, 2024
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...).

@@ -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 ( ... ).

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

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"
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.


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

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)

@@ -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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants