Skip to content

Commit

Permalink
chore: send exit signal on wasi http test
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardomourar committed Aug 30, 2023
1 parent 2fb5371 commit 75f3da7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
23 changes: 15 additions & 8 deletions tests/all/cli_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -812,14 +812,21 @@ fn run_basic_component() -> Result<()> {
#[test]
fn run_wasi_http_module() -> Result<()> {
let wasm = build_wasm("tests/all/cli_tests/wasi-http.wat")?;
let stdout = run_wasmtime(&[
"--preview2",
"--wasi-modules",
"experimental-wasi-http",
"--disable-cache",
wasm.path().to_str().unwrap(),
])?;
assert_eq!(stdout, "Called _start\n");
let output = run_wasmtime_for_output(
&[
"--preview2",
"--wasi-modules",
"experimental-wasi-http",
"--disable-cache",
wasm.path().to_str().unwrap(),
],
None,
)?;
println!("{}", String::from_utf8_lossy(&output.stderr));
assert!(String::from_utf8(output.stdout)
.unwrap()
.starts_with("Called _start\n"));
assert!(!output.status.success());
Ok(())
}

Expand Down
8 changes: 6 additions & 2 deletions tests/all/cli_tests/wasi-http.wat
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
(module
(import "wasi_snapshot_preview1" "proc_exit"
(func $__wasi_proc_exit (param i32)))
(import "wasi:io/streams" "write"
(func $__wasi_io_streams_write (param i32 i32 i32 i32)))
(import "wasi:io/streams" "blocking-write"
Expand Down Expand Up @@ -60,8 +62,10 @@
(call $__wasi_http_types_drop_fields (local.get $headers_id))
(call $__wasi_http_types_drop_outgoing_request (local.get $request_id))

(call $print (i32.const 64) (i32.const 0))
(call $print (i32.const 64) (i32.const 5))
(drop (call $__wasi_io_streams_subscribe_to_output_stream (i32.const 4)))

(call $__wasi_proc_exit (i32.const 1))
)

;; A helper function for printing ptr-len strings.
Expand All @@ -83,7 +87,7 @@
(export "_start" (func $_start))
(export "cabi_realloc" (func $cabi_realloc))
(data (i32.const 32) "Called _start\0a")
(data (i32.const 64) "")
(data (i32.const 64) "Done\0a")
(data (i32.const 96) "www.example.com")
(data (i32.const 128) "body")
)

0 comments on commit 75f3da7

Please sign in to comment.