wasm file loader and header validation
This commit is contained in:
commit
174bfd1d46
7 files changed
+269
No files matched your search
Executable
+20
@@ -0,0 +1,20 @@
|
||||
#!/bin/sh
|
||||
# Compile all .wat files to .wasm
|
||||
# Run from the test/ directory
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
||||
WAT_DIR="$SCRIPT_DIR/wat"
|
||||
WASM_DIR="$SCRIPT_DIR/wasm"
|
||||
|
||||
mkdir -p "$WASM_DIR"
|
||||
|
||||
for f in "$WAT_DIR"/*.wat; do
|
||||
base=$(basename "$f" .wat)
|
||||
wat2wasm "$f" -o "$WASM_DIR/$base.wasm"
|
||||
echo " $base.wat -> $base.wasm"
|
||||
done
|
||||
|
||||
# edge cases
|
||||
/usr/bin/printf '\x00asm\x02\x00\x00\x00' > "$WASM_DIR/badver.wasm"
|
||||
/usr/bin/printf '\x00bad\x01\x00\x00\x00' > "$WASM_DIR/badmagic.wasm"
|
||||
|
||||
Executable
+34
@@ -0,0 +1,34 @@
|
||||
#!/bin/sh
|
||||
# Run from the repo root
|
||||
|
||||
WASM=./src/wasm
|
||||
PASS=0
|
||||
FAIL=0
|
||||
TESTS=0
|
||||
|
||||
check() {
|
||||
TESTS=$((TESTS + 1))
|
||||
desc="$1"; shift
|
||||
expected="$1"; shift
|
||||
output=$("$@" 2>&1)
|
||||
if echo "$output" | grep -q "$expected"; then
|
||||
PASS=$((PASS + 1))
|
||||
echo " OK $desc"
|
||||
else
|
||||
FAIL=$((FAIL + 1))
|
||||
echo " FAIL $desc"
|
||||
echo " expected: $expected"
|
||||
echo " got: $output"
|
||||
fi
|
||||
}
|
||||
|
||||
echo "=== wasm runtime tests ==="
|
||||
|
||||
check "no arguments" "Usage:" $WASM
|
||||
check "valid wasm" "Valid wasm file" $WASM test/wasm/valid.wasm
|
||||
check "bad magic" "invalid wasm magic" $WASM test/wasm/badmagic.wasm
|
||||
check "bad version" "unsupported wasm" $WASM test/wasm/badver.wasm
|
||||
|
||||
echo ""
|
||||
echo "Results: $PASS/$TESTS passed, $FAIL failed"
|
||||
[ "$FAIL" -eq 0 ] && exit 0 || exit 1
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,5 @@
|
||||
(module
|
||||
(func (export "getSomething") (result i32)
|
||||
i32.const 42
|
||||
)
|
||||
)
|
||||
Reference in new issue
Block a user