Logs a wasm file to the filesystem to make it easy to figure out what wasm was used when debugging.
(wasm: &[u8])
| 52 | /// Logs a wasm file to the filesystem to make it easy to figure out what wasm |
| 53 | /// was used when debugging. |
| 54 | pub fn log_wasm(wasm: &[u8]) { |
| 55 | super::init_fuzzing(); |
| 56 | |
| 57 | if !log::log_enabled!(log::Level::Debug) { |
| 58 | return; |
| 59 | } |
| 60 | |
| 61 | let i = CNT.fetch_add(1, SeqCst); |
| 62 | let name = format!("testcase{i}.wasm"); |
| 63 | std::fs::write(&name, wasm).expect("failed to write wasm file"); |
| 64 | log::debug!("wrote wasm file to `{name}`"); |
| 65 | let wat = format!("testcase{i}.wat"); |
| 66 | match wasmprinter::print_bytes(wasm) { |
| 67 | Ok(s) => { |
| 68 | std::fs::write(&wat, s).expect("failed to write wat file"); |
| 69 | log::debug!("wrote wat file to `{wat}`"); |
| 70 | } |
| 71 | // If wasmprinter failed remove a `*.wat` file, if any, to avoid |
| 72 | // confusing a preexisting one with this wasm which failed to get |
| 73 | // printed. |
| 74 | Err(e) => { |
| 75 | log::debug!("failed to print to wat: {e}"); |
| 76 | drop(std::fs::remove_file(&wat)); |
| 77 | } |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | /// The `T` in `Store<T>` for fuzzing stores, used to limit resource |
| 82 | /// consumption during fuzzing. |
no test coverage detected