summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/help/wasm-interp.txt1
-rwxr-xr-xtest/run-tests.py18
-rw-r--r--test/wasi/empty.txt4
-rw-r--r--test/wasi/exit.txt15
-rw-r--r--test/wasi/oob_trap.txt29
-rw-r--r--test/wasi/write_stdout.txt38
6 files changed, 103 insertions, 2 deletions
diff --git a/test/help/wasm-interp.txt b/test/help/wasm-interp.txt
index 27c5573c..b6d246a5 100644
--- a/test/help/wasm-interp.txt
+++ b/test/help/wasm-interp.txt
@@ -40,6 +40,7 @@ options:
-V, --value-stack-size=SIZE Size in elements of the value stack
-C, --call-stack-size=SIZE Size in elements of the call stack
-t, --trace Trace execution
+ --wasi Assume input module is WASI compliant (Export WASI API the the module and invoke _start function)
--run-all-exports Run all the exported functions, in order. Useful for testing
--host-print Include an importable function named "host.print" for printing to stdout
--dummy-import-func Provide a dummy implementation of all imported functions. The function will log the call and return an appropriate zero value.
diff --git a/test/run-tests.py b/test/run-tests.py
index 1b49f4cc..9d01b564 100755
--- a/test/run-tests.py
+++ b/test/run-tests.py
@@ -88,6 +88,11 @@ TOOLS = {
('RUN', '%(wasm-interp)s %(temp_file)s.wasm --run-all-exports'),
('VERBOSE-ARGS', ['--print-cmd', '-v']),
],
+ 'run-interp-wasi': [
+ ('RUN', '%(wat2wasm)s %(in_file)s -o %(temp_file)s.wasm'),
+ ('RUN', '%(wasm-interp)s --wasi %(temp_file)s.wasm'),
+ ('VERBOSE-ARGS', ['--print-cmd', '-v']),
+ ],
'run-interp-spec': [
('RUN', '%(wast2json)s %(in_file)s -o %(temp_file)s.json'),
('RUN', '%(spectest-interp)s %(temp_file)s.json'),
@@ -673,9 +678,13 @@ class Status(object):
sys.stderr.write('\r%s\r' % (' ' * self.last_length))
-def FindTestFiles(ext, filter_pattern_re):
+def FindTestFiles(ext, filter_pattern_re, exclude_dirs):
tests = []
for root, dirs, files in os.walk(TEST_DIR):
+ for ex in exclude_dirs:
+ if ex in dirs:
+ # Filtering out dirs here causes os.walk not to descend into them
+ dirs.remove(ex)
for f in files:
path = os.path.join(root, f)
if os.path.splitext(f)[1] == ext:
@@ -908,12 +917,17 @@ def main(args):
parser.error('--stop-interactive only works with -j1')
if options.patterns:
+ exclude_dirs = []
pattern_re = '|'.join(
fnmatch.translate('*%s*' % p) for p in options.patterns)
else:
pattern_re = '.*'
+ # By default, exclude wasi tests because WASI support is not include
+ # by int the build by default.
+ # TODO(sbc): Find some way to detect the WASI support.
+ exclude_dirs = ['wasi']
- test_names = FindTestFiles('.txt', pattern_re)
+ test_names = FindTestFiles('.txt', pattern_re, exclude_dirs)
if options.list:
for test_name in test_names:
diff --git a/test/wasi/empty.txt b/test/wasi/empty.txt
new file mode 100644
index 00000000..cc5eb846
--- /dev/null
+++ b/test/wasi/empty.txt
@@ -0,0 +1,4 @@
+;;; TOOL: run-interp-wasi
+(memory (export "memory") 1)
+(func (export "_start")
+)
diff --git a/test/wasi/exit.txt b/test/wasi/exit.txt
new file mode 100644
index 00000000..5e7be912
--- /dev/null
+++ b/test/wasi/exit.txt
@@ -0,0 +1,15 @@
+;;; TOOL: run-interp-wasi
+;;; ARGS: --trace
+;;; ERROR: 42
+(import "wasi_snapshot_preview1" "proc_exit" (func $exit (param i32)))
+
+(memory (export "memory") 1)
+
+(func (export "_start")
+ (call $exit (i32.const 42))
+)
+(;; STDOUT ;;;
+#0. 0: V:0 | i32.const 42
+#0. 8: V:1 | call_import $0
+>>> running wasi function "proc_exit":
+;;; STDOUT ;;)
diff --git a/test/wasi/oob_trap.txt b/test/wasi/oob_trap.txt
new file mode 100644
index 00000000..eb191b07
--- /dev/null
+++ b/test/wasi/oob_trap.txt
@@ -0,0 +1,29 @@
+;;; TOOL: run-interp-wasi
+;;; ARGS: --trace
+;;; ERROR: 1
+;;
+;; Just like the write_stdout.txt, but with an interior point that is OOB.
+;; Specifically rather than pointing to the `hello` string at address zero,
+;; iovec[0].buf points to memsize - 1 (65536 - 1 = 65535 = 0xffff)
+;;
+
+(import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))
+(memory (export "memory") 1)
+(data (i32.const 0) "hello\n\00\00")
+(data (i32.const 8) "\08\00\00\00")
+(data (i32.const 12) "\ff\ff\00\00\06\00\00\00")
+(data (i32.const 20) "\00\00\00\00")
+
+(func (export "_start")
+ (call $fd_write (i32.const 1) (i32.const 12) (i32.const 1) (i32.const 20))
+ drop
+)
+(;; STDOUT ;;;
+#0. 0: V:0 | i32.const 1
+#0. 8: V:1 | i32.const 12
+#0. 16: V:2 | i32.const 1
+#0. 24: V:3 | i32.const 20
+#0. 32: V:4 | call_import $0
+>>> running wasi function "fd_write":
+ error: out of bounds memory access: [65535, 65541) >= max value 65536
+;;; STDOUT ;;)
diff --git a/test/wasi/write_stdout.txt b/test/wasi/write_stdout.txt
new file mode 100644
index 00000000..44afc5de
--- /dev/null
+++ b/test/wasi/write_stdout.txt
@@ -0,0 +1,38 @@
+;;; TOOL: run-interp-wasi
+;;; ARGS: --trace
+;;
+;; For details of fs_write API see:
+;; https://github.com/WebAssembly/WASI/blob/master/phases/snapshot/docs.md#fd_write
+;;
+;; It takes 4 args: fd, iovec, iovec_len, out_len
+;;
+;; Data Layout:
+;;
+;; 0-8 : "hello\n\0\0"
+;; 8-12 : iovs ptr : 8
+;; 12-20: iovs[0] : 0, 4
+;; 20-24: bytes written out param
+;;
+
+(import "wasi_snapshot_preview1" "fd_write" (func $fd_write (param i32 i32 i32 i32) (result i32)))
+(memory (export "memory") 1)
+(data (i32.const 0) "hello\n\00\00")
+(data (i32.const 8) "\08\00\00\00")
+(data (i32.const 12) "\00\00\00\00\06\00\00\00")
+(data (i32.const 20) "\00\00\00\00")
+
+(func (export "_start")
+ (call $fd_write (i32.const 1) (i32.const 12) (i32.const 1) (i32.const 20))
+ drop
+)
+(;; STDOUT ;;;
+hello
+#0. 0: V:0 | i32.const 1
+#0. 8: V:1 | i32.const 12
+#0. 16: V:2 | i32.const 1
+#0. 24: V:3 | i32.const 20
+#0. 32: V:4 | call_import $0
+>>> running wasi function "fd_write":
+#0. 40: V:1 | drop
+#0. 44: V:0 | return
+;;; STDOUT ;;)