wazero
wazero copied to clipboard
fuzz: implement random function body generator
This is the left TODO in #481. https://github.com/tetratelabs/wazero/blob/043f67ab8419d639a7911a3dbf4d57520de383d8/internal/modgen/modgen.go#L409
Generating the function body randomly is a bit trickier than others in the sense that function body is stateful -- this means that the set of usable opcodes at any point of generation vary depending on what's generated so far (the contents of value stacks, control blocks, existing functions, signatures, globals, etc), and only a subset of opcodes can be chosen to make the generated function valid.
Not only that, we should have an option like ensureTermination bool
which makes it possible for
functions to terminate execution in finite time so that we can fuzz not only the compiler but also
the compiled machine code by actually running it (maybe exposing it in the start section)
luckily we have function validation already implemented in Go https://github.com/tetratelabs/wazero/blob/main/internal/wasm/func_validation.go
so the impl would look like similar to the validation code so that the generated opcode should pass the validation :D
superseded by https://github.com/tetratelabs/wazero-fuzz -- revive this issue once we prioritize the pure-Go fuzzing infra in wazero. Closing for now!