forked from rustwasm/walrus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
before-after.sh
executable file
·42 lines (34 loc) · 1.07 KB
/
before-after.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env bash
# This script can be used with `creduce` to reduce the size of a WAT test case
# that has different output before vs after being round tripped through
# Walrus. I've successfully used it to reduce ~5KiB test cases down to ~100
# bytes in only a couple minutes!
#
# Usage:
#
# creduce walrus/crates/fuzz/before-after.sh path/to/fuzz.wat
set -eux
INPUT="fuzz.wat"
TEST_FILE="fuzz.wasm"
OUT_FILE="$TEST_FILE.walrus.wasm"
ORIG_OUTPUT_FILE="$TEST_FILE.output.txt"
NEW_OUTPUT_FILE="$OUT_FILE.output.txt"
function interp {
wasm-interp \
--run-all-exports \
--dummy-import-func \
--enable-threads \
--enable-bulk-memory \
--enable-reference-types \
--enable-simd \
"$1"
}
wat2wasm "$INPUT" -o "$TEST_FILE" --enable-simd --enable-bulk-memory
interp "$TEST_FILE" > "$ORIG_OUTPUT_FILE"
cargo run \
--manifest-path "$(dirname "$0")/../../Cargo.toml" \
--example round-trip \
"$TEST_FILE" \
"$OUT_FILE"
interp "$OUT_FILE" > "$NEW_OUTPUT_FILE"
! diff -U3 "$ORIG_OUTPUT_FILE" "$NEW_OUTPUT_FILE"