Browse Source

Add a few CLI tests for WASI. (#1281)

While here, move rs2wasm-add-func.wat into the same directory as the
other .wat tests to keep things tidy.
pull/1364/head
Dan Gohman 5 years ago
committed by GitHub
parent
commit
1c55eb1a8b
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 17
      tests/cli_tests.rs
  2. 2
      tests/instantiate.rs
  3. 25
      tests/wasm/hello_wasi_snapshot0.wat
  4. 25
      tests/wasm/hello_wasi_snapshot1.wat
  5. 0
      tests/wasm/rs2wasm-add-func.wat

17
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(())
}

2
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]

25
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")
)

25
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")
)

0
tests/wat/rs2wasm-add-func.wat → tests/wasm/rs2wasm-add-func.wat

Loading…
Cancel
Save