Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[wasmtime-wasi] fix logic error in monotonic-clock/subscribe #6993

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions crates/test-programs/tests/wasi-cap-std-sync.rs
Expand Up @@ -250,6 +250,11 @@ fn sched_yield() {
run("sched_yield", true).unwrap()
}
#[test_log::test]
#[should_panic]
fn sleep() {
run("sleep", true).unwrap()
}
#[test_log::test]
fn stdio() {
run("stdio", true).unwrap()
}
Expand Down
Expand Up @@ -294,6 +294,11 @@ async fn sched_yield() {
run("sched_yield", false).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
#[should_panic]
async fn sleep() {
run("sleep", false).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn stdio() {
run("stdio", false).await.unwrap()
}
Expand Down
4 changes: 4 additions & 0 deletions crates/test-programs/tests/wasi-preview2-components-sync.rs
Expand Up @@ -272,6 +272,10 @@ fn sched_yield() {
run("sched_yield", false).unwrap()
}
#[test_log::test]
fn sleep() {
run("sleep", false).unwrap()
}
#[test_log::test]
fn stdio() {
run("stdio", false).unwrap()
}
Expand Down
4 changes: 4 additions & 0 deletions crates/test-programs/tests/wasi-preview2-components.rs
Expand Up @@ -280,6 +280,10 @@ async fn sched_yield() {
run("sched_yield", false).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn sleep() {
run("sleep", false).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn stdio() {
run("stdio", false).await.unwrap()
}
Expand Down
5 changes: 5 additions & 0 deletions crates/test-programs/tests/wasi-tokio.rs
Expand Up @@ -256,6 +256,11 @@ async fn sched_yield() {
run("sched_yield", true).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
#[should_panic]
async fn sleep() {
run("sleep", true).await.unwrap()
}
#[test_log::test(tokio::test(flavor = "multi_thread"))]
async fn stdio() {
run("stdio", true).await.unwrap()
}
Expand Down
3 changes: 3 additions & 0 deletions crates/test-programs/wasi-tests/Cargo.toml
Expand Up @@ -9,3 +9,6 @@ publish = false
libc = "0.2.65"
wasi = "0.11.0"
once_cell = "1.12"
wit-bindgen = { workspace = true, default-features = false, features = [
"macros",
] }
16 changes: 16 additions & 0 deletions crates/test-programs/wasi-tests/src/bin/sleep.rs
@@ -0,0 +1,16 @@
use crate::wasi::{clocks::monotonic_clock, poll::poll};

wit_bindgen::generate!({
path: "../../wasi/wit",
world: "wasmtime:wasi/command-extended",
});

fn main() {
// Sleep ten milliseconds. Note that we call the relevant host functions directly rather than go through
// libstd, since we want to ensure we're calling `monotonic_clock::subscribe` with an `absolute` parameter of
// `true`, which libstd won't necessarily do (but which e.g. CPython _will_ do).
poll::poll_oneoff(&[monotonic_clock::subscribe(
monotonic_clock::now() + 10_000_000,
true,
)]);
}
2 changes: 1 addition & 1 deletion crates/wasi/src/preview2/host/clocks.rs
Expand Up @@ -64,7 +64,7 @@ impl<T: WasiView> monotonic_clock::Host for T {
})))?)
} else {
let duration = if absolute {
Duration::from_nanos(clock_now - when)
Duration::from_nanos(when - clock_now)
} else {
Duration::from_nanos(when)
};
Expand Down