Skip to content

Commit

Permalink
Merge pull request #3752 from wasmerio/poll-fixes
Browse files Browse the repository at this point in the history
Added new snapshots tests that use a fixed MIO and TOKIO
  • Loading branch information
syrusakbary authored Apr 10, 2023
2 parents b01fba3 + 1221222 commit 1670917
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 2 deletions.
4 changes: 3 additions & 1 deletion lib/wasi/src/syscalls/wasi/poll_oneoff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ pub(crate) fn poll_oneoff_internal(
.filter(|a| a.2.type_ == Eventtype::Clock)
.count();
let mut clock_subs: Vec<(SubscriptionClock, u64)> = Vec::with_capacity(subs.len());
let mut time_to_sleep = Duration::ZERO;
let mut time_to_sleep = Duration::MAX;

// First we extract all the subscriptions into an array so that they
// can be processed
Expand Down Expand Up @@ -205,6 +205,8 @@ pub(crate) fn poll_oneoff_internal(
// a sleep itself
if clock_info.timeout == 0 {
time_to_sleep = Duration::MAX;
} else if clock_info.timeout == 1 {
time_to_sleep = Duration::ZERO;
} else {
time_to_sleep = Duration::from_nanos(clock_info.timeout);
clock_subs.push((clock_info, s.userdata));
Expand Down
2 changes: 1 addition & 1 deletion lib/wasi/src/syscalls/wasix/futex_wait.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ where
/// * `futex` - Memory location that holds the value that will be checked
/// * `expected` - Expected value that should be currently held at the memory location
/// * `timeout` - Timeout should the futex not be triggered in the allocated time
#[instrument(level = "trace", skip_all, fields(futex_idx = field::Empty, %expected, timeout = field::Empty, woken = field::Empty), err)]
#[instrument(level = "trace", skip_all, fields(?futex_ptr, futex_idx = field::Empty, %expected, timeout = field::Empty, woken = field::Empty), err)]
pub fn futex_wait<M: MemorySize>(
mut ctx: FunctionEnvMut<'_, WasiEnv>,
futex_ptr: WasmPtr<u32, M>,
Expand Down
18 changes: 18 additions & 0 deletions tests/integration/cli/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,24 @@ fn test_snapshot_minimodem_rx() {
ignore
)]
#[test]
fn test_snapshot_tokio() {
let snapshot = TestBuilder::new()
.with_name(function!())
.run_wasm(include_bytes!("./wasm/example-tokio.wasm"));
assert_json_snapshot!(snapshot);
}

#[cfg(not(any(target_env = "musl", target_os = "macos", target_os = "windows")))]
#[test]
fn test_snapshot_unix_pipe() {
let snapshot = TestBuilder::new()
.with_name(function!())
.run_wasm(include_bytes!("./wasm/example-unix-pipe.wasm"));
assert_json_snapshot!(snapshot);
}

#[cfg(not(any(target_env = "musl", target_os = "macos", target_os = "windows")))]
#[test]
fn test_snapshot_web_server() {
let with_inner = || {
let rt = tokio::runtime::Builder::new_multi_thread()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: tests/integration/cli/tests/snapshot.rs
assertion_line: 543
expression: snapshot
---
{
"spec": {
"name": "snapshot::test_snapshot_tokio",
"use_packages": [],
"include_webcs": [],
"cli_args": [],
"debug_output": false,
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
"stdout": "",
"stderr": "step-1\nreceived ErrorKind::WouldBlock - receiving on an empty channel\nstep-2\nstep-3\ndata match verified (len=128)\nstep-4\nreceived ErrorKind::WouldBlock - receiving on an empty channel\nstep-5\nstep-A1\nstep-B1\nstep-B2\nstep-A2\ndata match verified (len=128)\nstep-A3\nstep-B3\nstep-B4\nstep-A4\ndata match verified (len=128)\nstep-A5\nreceived ErrorKind::WouldBlock - receiving on an empty channel\nstep-A6\nstep-A7\nreceived ErrorKind::WouldBlock - receiving on an empty channel\nstep-A8\nall done\n",
"exit_code": 0
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
---
source: tests/integration/cli/tests/snapshot.rs
assertion_line: 552
expression: snapshot
---
{
"spec": {
"name": "snapshot::test_snapshot_unix_pipe",
"use_packages": [],
"include_webcs": [],
"cli_args": [],
"debug_output": false,
"enable_threads": true,
"enable_network": false
},
"result": {
"Success": {
"stdout": "all done\n",
"stderr": "received ErrorKind::WouldBlock\ndata matche verified (len=128)\nreceived ErrorKind::WouldBlock\ndata matche verified (len=128)\n",
"exit_code": 0
}
}
}
Binary file modified tests/integration/cli/tests/wasm/example-condvar.wasm
Binary file not shown.
Binary file modified tests/integration/cli/tests/wasm/example-http-ok.wasm
Binary file not shown.
Binary file modified tests/integration/cli/tests/wasm/example-multi-threading.wasm
Binary file not shown.
Binary file modified tests/integration/cli/tests/wasm/example-tcp-listener.wasm
Binary file not shown.
Binary file modified tests/integration/cli/tests/wasm/example-thread-local.wasm
Binary file not shown.
Binary file not shown.
Binary file not shown.

0 comments on commit 1670917

Please sign in to comment.