waffle/fuzz/fuzz_targets/roundtrip_roundtrip.rs

20 lines
753 B
Rust
Raw Normal View History

2021-12-24 16:29:32 -06:00
#![no_main]
use libfuzzer_sys::fuzz_target;
2023-02-16 18:20:54 -06:00
use waffle::{FrontendOptions, Module};
2021-12-24 16:29:32 -06:00
fuzz_target!(|module: wasm_smith::Module| {
let _ = env_logger::try_init();
log::debug!("original module: {:?}", module);
let orig_bytes = module.to_bytes();
2023-02-16 18:20:54 -06:00
let parsed_module =
Module::from_wasm_bytes(&orig_bytes[..], &FrontendOptions::default()).unwrap();
let roundtrip_bytes = parsed_module.to_wasm_bytes().unwrap();
if let Ok(filename) = std::env::var("ROUNDTRIP_WASM_SAVE") {
std::fs::write(filename, &roundtrip_bytes[..]).unwrap();
}
2023-02-16 18:20:54 -06:00
let parsed_roundtrip_module =
Module::from_wasm_bytes(&roundtrip_bytes[..], &FrontendOptions::default()).unwrap();
2021-12-24 16:29:32 -06:00
let _ = parsed_roundtrip_module.to_wasm_bytes();
});