diff --git a/tests/cli_tests.rs b/tests/cli_tests.rs index 86b3a7fdaf..25be62b369 100644 --- a/tests/cli_tests.rs +++ b/tests/cli_tests.rs @@ -103,6 +103,23 @@ fn run_wasmtime_unreachable_wat() -> Result<()> { assert_eq!(code, 128 + libc::SIGABRT); #[cfg(windows)] assert_eq!(code, 3); - + Ok(()) +} + +// Run a simple WASI hello world, snapshot0 edition. +#[test] +fn hello_wasi_snapshot0() -> Result<()> { + let wasm = build_wasm("tests/wasm/hello_wasi_snapshot0.wat")?; + let stdout = run_wasmtime(&[wasm.path().to_str().unwrap(), "--disable-cache"])?; + assert_eq!(stdout, "Hello, world!\n"); + Ok(()) +} + +// Run a simple WASI hello world, snapshot1 edition. +#[test] +fn hello_wasi_snapshot1() -> Result<()> { + let wasm = build_wasm("tests/wasm/hello_wasi_snapshot1.wat")?; + let stdout = run_wasmtime(&[wasm.path().to_str().unwrap(), "--disable-cache"])?; + assert_eq!(stdout, "Hello, world!\n"); Ok(()) } diff --git a/tests/instantiate.rs b/tests/instantiate.rs index a72a2df878..961b219e8d 100644 --- a/tests/instantiate.rs +++ b/tests/instantiate.rs @@ -5,7 +5,7 @@ use wasmtime_environ::settings::Configurable; use wasmtime_environ::CacheConfig; use wasmtime_jit::{instantiate, native, CompilationStrategy, Compiler, NullResolver}; -const PATH_MODULE_RS2WASM_ADD_FUNC: &str = r"tests/wat/rs2wasm-add-func.wat"; +const PATH_MODULE_RS2WASM_ADD_FUNC: &str = r"tests/wasm/rs2wasm-add-func.wat"; /// Simple test reading a wasm-file and translating to binary representation. #[test] diff --git a/tests/wasm/hello_wasi_snapshot0.wat b/tests/wasm/hello_wasi_snapshot0.wat new file mode 100644 index 0000000000..bc69448779 --- /dev/null +++ b/tests/wasm/hello_wasi_snapshot0.wat @@ -0,0 +1,25 @@ +(module + (import "wasi_unstable" "proc_exit" + (func $__wasi_proc_exit (param i32))) + (import "wasi_unstable" "fd_write" + (func $__wasi_fd_write (param i32 i32 i32 i32) (result i32))) + (func $_start + (i32.store (i32.const 24) (i32.const 14)) + (i32.store (i32.const 20) (i32.const 0)) + (block + (br_if 0 + (call $__wasi_fd_write + (i32.const 1) + (i32.const 20) + (i32.const 1) + (i32.const 16))) + (br_if 0 (i32.ne (i32.load (i32.const 16)) (i32.const 14))) + (br 1) + ) + (call $__wasi_proc_exit (i32.const 1)) + ) + (memory 1) + (export "memory" (memory 0)) + (export "_start" (func $_start)) + (data (i32.const 0) "Hello, world!\0a") +) diff --git a/tests/wasm/hello_wasi_snapshot1.wat b/tests/wasm/hello_wasi_snapshot1.wat new file mode 100644 index 0000000000..97a0a2606b --- /dev/null +++ b/tests/wasm/hello_wasi_snapshot1.wat @@ -0,0 +1,25 @@ +(module + (import "wasi_snapshot_preview1" "proc_exit" + (func $__wasi_proc_exit (param i32))) + (import "wasi_snapshot_preview1" "fd_write" + (func $__wasi_fd_write (param i32 i32 i32 i32) (result i32))) + (func $_start + (i32.store (i32.const 24) (i32.const 14)) + (i32.store (i32.const 20) (i32.const 0)) + (block + (br_if 0 + (call $__wasi_fd_write + (i32.const 1) + (i32.const 20) + (i32.const 1) + (i32.const 16))) + (br_if 0 (i32.ne (i32.load (i32.const 16)) (i32.const 14))) + (br 1) + ) + (call $__wasi_proc_exit (i32.const 1)) + ) + (memory 1) + (export "memory" (memory 0)) + (export "_start" (func $_start)) + (data (i32.const 0) "Hello, world!\0a") +) diff --git a/tests/wat/rs2wasm-add-func.wat b/tests/wasm/rs2wasm-add-func.wat similarity index 100% rename from tests/wat/rs2wasm-add-func.wat rename to tests/wasm/rs2wasm-add-func.wat