From 3cd93403d66f8100956fbb8f9332d3acb5fadf62 Mon Sep 17 00:00:00 2001 From: Roman Volosatovs Date: Wed, 22 Jan 2025 13:44:31 +0100 Subject: [PATCH] feat(wasi): add support for `wasi:clocks@0.3.0` Signed-off-by: Roman Volosatovs --- Cargo.lock | 2 + ci/vendor-wit.sh | 1 + crates/test-programs/Cargo.toml | 3 + .../test-programs/src/bin/preview2_sleep.rs | 2 +- .../test-programs/src/bin/preview3_sleep.rs | 62 ++++++++++++++++ crates/test-programs/src/lib.rs | 11 ++- crates/test-programs/src/sockets.rs | 2 +- crates/wasi/src/p2/host/clocks.rs | 2 +- crates/wasi/src/p3/bindings.rs | 11 ++- crates/wasi/src/p3/host/clocks.rs | 73 +++++++++++++++++++ crates/wasi/src/p3/host/clocks/sync.rs | 28 +++++++ crates/wasi/src/p3/host/mod.rs | 1 + crates/wasi/src/p3/mod.rs | 4 + .../monotonic-clock.wit | 45 ++++++++++++ .../timezone.wit | 55 ++++++++++++++ .../wall-clock.wit | 46 ++++++++++++ .../clocks@3850f9d@wit-0.3.0-draft/world.wit | 11 +++ crates/wasi/src/p3/wit/world.wit | 1 + crates/wasi/tests/all/api.rs | 3 +- crates/wasi/tests/all/async_.rs | 5 ++ crates/wasi/tests/all/sync.rs | 5 ++ 21 files changed, 364 insertions(+), 9 deletions(-) create mode 100644 crates/test-programs/src/bin/preview3_sleep.rs create mode 100644 crates/wasi/src/p3/host/clocks.rs create mode 100644 crates/wasi/src/p3/host/clocks/sync.rs create mode 100644 crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/monotonic-clock.wit create mode 100644 crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/timezone.wit create mode 100644 crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/wall-clock.wit create mode 100644 crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/world.wit diff --git a/Cargo.lock b/Cargo.lock index 81b69a03056d..c012caff304d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3383,11 +3383,13 @@ dependencies = [ "getrandom", "libc", "sha2", + "tokio", "url", "wasi 0.11.0+wasi-snapshot-preview1", "wasi 0.14.0+wasi-0.2.3", "wasi-nn", "wit-bindgen", + "wit-bindgen-rt", ] [[package]] diff --git a/ci/vendor-wit.sh b/ci/vendor-wit.sh index 36857710ddcf..7c6db6e95551 100755 --- a/ci/vendor-wit.sh +++ b/ci/vendor-wit.sh @@ -46,6 +46,7 @@ make_vendor "wasi/src/p2" " " make_vendor "wasi/src/p3" " + clocks@3850f9d@wit-0.3.0-draft random@3e99124@wit-0.3.0-draft " diff --git a/crates/test-programs/Cargo.toml b/crates/test-programs/Cargo.toml index ec734b766b03..ee75288c79ae 100644 --- a/crates/test-programs/Cargo.toml +++ b/crates/test-programs/Cargo.toml @@ -15,6 +15,8 @@ anyhow = { workspace = true, features = ['std'] } wasi = "0.11.0" wasi-nn = "0.6.0" wit-bindgen = { workspace = true, features = ['default'] } +# TODO: Remove once https://github.com/bytecodealliance/wit-bindgen/pull/1136 lands +wit-bindgen-rt = "0.37" libc = { workspace = true } getrandom = "0.2.9" futures = { workspace = true, default-features = false, features = ['alloc'] } @@ -22,3 +24,4 @@ url = { workspace = true } sha2 = "0.10.2" base64 = "0.21.0" wasip2 = { version = "0.14.0", package = 'wasi' } +tokio = { workspace = true, features = ["macros"] } diff --git a/crates/test-programs/src/bin/preview2_sleep.rs b/crates/test-programs/src/bin/preview2_sleep.rs index a6c8dae39840..a3ea8ec5f8f2 100644 --- a/crates/test-programs/src/bin/preview2_sleep.rs +++ b/crates/test-programs/src/bin/preview2_sleep.rs @@ -1,4 +1,4 @@ -use test_programs::wasi::clocks::monotonic_clock; +use test_programs::wasi::clocks0_2_3::monotonic_clock; fn main() { sleep_10ms(); diff --git a/crates/test-programs/src/bin/preview3_sleep.rs b/crates/test-programs/src/bin/preview3_sleep.rs new file mode 100644 index 000000000000..b205b2e530b8 --- /dev/null +++ b/crates/test-programs/src/bin/preview3_sleep.rs @@ -0,0 +1,62 @@ +use core::future::Future as _; +use core::pin::pin; +use core::ptr; +use core::task::{Context, Poll, RawWaker, RawWakerVTable, Waker}; + +use test_programs::wasi::clocks0_3_0::monotonic_clock; + +// Adapted from https://github.com/rust-lang/rust/blob/cd805f09ffbfa3896c8f50a619de9b67e1d9f3c3/library/core/src/task/wake.rs#L63-L77 +// TODO: Replace by `Waker::noop` once MSRV is raised to 1.85 +const NOOP_RAW_WAKER: RawWaker = { + const VTABLE: RawWakerVTable = RawWakerVTable::new( + // Cloning just returns a new no-op raw waker + |_| NOOP_RAW_WAKER, + // `wake` does nothing + |_| {}, + // `wake_by_ref` does nothing + |_| {}, + // Dropping does nothing as we don't allocate anything + |_| {}, + ); + RawWaker::new(ptr::null(), &VTABLE) +}; + +const NOOP_WAKER: &'static Waker = &unsafe { Waker::from_raw(NOOP_RAW_WAKER) }; + +#[tokio::main(flavor = "current_thread")] +async fn main() { + sleep_10ms().await; + sleep_0ms(); + sleep_backwards_in_time(); +} + +async fn sleep_10ms() { + let dur = 10_000_000; + monotonic_clock::wait_until(monotonic_clock::now() + dur).await; + monotonic_clock::wait_for(dur).await; +} + +fn sleep_0ms() { + let mut cx = Context::from_waker(NOOP_WAKER); + + assert_eq!( + pin!(monotonic_clock::wait_until(monotonic_clock::now())).poll(&mut cx), + Poll::Ready(()), + "waiting until now() is ready immediately", + ); + assert_eq!( + pin!(monotonic_clock::wait_for(0)).poll(&mut cx), + Poll::Ready(()), + "waiting for 0 is ready immediately", + ); +} + +fn sleep_backwards_in_time() { + let mut cx = Context::from_waker(NOOP_WAKER); + + assert_eq!( + pin!(monotonic_clock::wait_until(monotonic_clock::now() - 1)).poll(&mut cx), + Poll::Ready(()), + "waiting until instant which has passed is ready immediately", + ); +} diff --git a/crates/test-programs/src/lib.rs b/crates/test-programs/src/lib.rs index 1575f1633cdf..f86e35c7a246 100644 --- a/crates/test-programs/src/lib.rs +++ b/crates/test-programs/src/lib.rs @@ -13,6 +13,7 @@ wit_bindgen::generate!({ include wasi:config/imports@0.2.0-draft; include wasi:keyvalue/imports@0.2.0-draft; + include wasi:clocks/imports@0.3.0; include wasi:random/imports@0.3.0; } ", @@ -24,6 +25,12 @@ wit_bindgen::generate!({ ], world: "wasmtime:test/test", features: ["cli-exit-with-code"], + async: { + imports: [ + "wasi:clocks/monotonic-clock@0.3.0#wait-for", + "wasi:clocks/monotonic-clock@0.3.0#wait-until", + ], + }, generate_all, }); @@ -43,8 +50,8 @@ pub mod proxy { "wasi:cli/stdout@0.2.3": crate::wasi::cli::stdout, "wasi:cli/stderr@0.2.3": crate::wasi::cli::stderr, "wasi:cli/stdin@0.2.3": crate::wasi::cli::stdin, - "wasi:clocks/monotonic-clock@0.2.3": crate::wasi::clocks::monotonic_clock, - "wasi:clocks/wall-clock@0.2.3": crate::wasi::clocks::wall_clock, + "wasi:clocks/monotonic-clock@0.2.3": crate::wasi::clocks0_2_3::monotonic_clock, + "wasi:clocks/wall-clock@0.2.3": crate::wasi::clocks0_2_3::wall_clock, }, }); } diff --git a/crates/test-programs/src/sockets.rs b/crates/test-programs/src/sockets.rs index e5bf79e0fa39..0c41031a10fc 100644 --- a/crates/test-programs/src/sockets.rs +++ b/crates/test-programs/src/sockets.rs @@ -1,4 +1,4 @@ -use crate::wasi::clocks::monotonic_clock; +use crate::wasi::clocks0_2_3::monotonic_clock; use crate::wasi::io::poll::{self, Pollable}; use crate::wasi::io::streams::{InputStream, OutputStream, StreamError}; use crate::wasi::random0_2_3 as random; diff --git a/crates/wasi/src/p2/host/clocks.rs b/crates/wasi/src/p2/host/clocks.rs index 11ea695a40b7..6a516ea01289 100644 --- a/crates/wasi/src/p2/host/clocks.rs +++ b/crates/wasi/src/p2/host/clocks.rs @@ -17,7 +17,7 @@ impl TryFrom for Datetime { let duration = time.duration_since(SystemTime::from_std(std::time::SystemTime::UNIX_EPOCH))?; - Ok(Datetime { + Ok(Self { seconds: duration.as_secs(), nanoseconds: duration.subsec_nanos(), }) diff --git a/crates/wasi/src/p3/bindings.rs b/crates/wasi/src/p3/bindings.rs index 43399bf9e495..a19243e6aa2a 100644 --- a/crates/wasi/src/p3/bindings.rs +++ b/crates/wasi/src/p3/bindings.rs @@ -24,9 +24,10 @@ //! inline: " //! package example:wasi; //! -//! // An example of extending the `wasi:random/imports` world with a +//! // An example of extending the `wasi:cli/command` world with a //! // custom host interface. //! world my-world { +//! include wasi:clocks/imports@0.3.0; //! include wasi:random/imports@0.3.0; //! //! import custom-host; @@ -96,9 +97,10 @@ /// inline: " /// package example:wasi; /// -/// // An example of extending the `wasi:random/imports` world with a +/// // An example of extending the `wasi:cli/command` world with a /// // custom host interface. /// world my-world { +/// include wasi:clocks/imports@0.3.0; /// include wasi:random/imports@0.3.0; /// /// import custom-host; @@ -157,6 +159,7 @@ pub mod sync { package inline:wasi; world command { + include wasi:clocks/imports@0.3.0; include wasi:random/imports@0.3.0; } ", @@ -166,6 +169,7 @@ pub mod sync { // These interfaces come from the outer module, as it's // sync/async agnostic. "wasi:random": crate::p3::bindings::random, + "wasi:clocks/wall-clock": crate::p3::bindings::clocks::wall_clock, }, require_store_data_send: true, }); @@ -324,6 +328,7 @@ mod async_io { package inline:wasi; world command { + include wasi:clocks/imports@0.3.0; include wasi:random/imports@0.3.0; } ", @@ -338,6 +343,8 @@ mod async_io { // which in theory can be shared across interfaces, so this may // need fancier syntax in the future. only_imports: [ + "wait-for", + "wait-until", ], }, }); diff --git a/crates/wasi/src/p3/host/clocks.rs b/crates/wasi/src/p3/host/clocks.rs new file mode 100644 index 000000000000..4e6f7e3d66ec --- /dev/null +++ b/crates/wasi/src/p3/host/clocks.rs @@ -0,0 +1,73 @@ +use crate::p3::bindings::{ + clocks::monotonic_clock::{self, Duration as WasiDuration, Instant}, + clocks::wall_clock::{self, Datetime}, +}; +use crate::{WasiImpl, WasiView}; +use cap_std::time::SystemTime; +use std::time::Duration; +use tokio::time::sleep; + +mod sync; + +impl TryFrom for Datetime { + type Error = anyhow::Error; + + fn try_from(time: SystemTime) -> Result { + let duration = + time.duration_since(SystemTime::from_std(std::time::SystemTime::UNIX_EPOCH))?; + + Ok(Self { + seconds: duration.as_secs(), + nanoseconds: duration.subsec_nanos(), + }) + } +} + +impl wall_clock::Host for WasiImpl +where + T: WasiView, +{ + fn now(&mut self) -> anyhow::Result { + let now = self.ctx().wall_clock.now(); + Ok(Datetime { + seconds: now.as_secs(), + nanoseconds: now.subsec_nanos(), + }) + } + + fn resolution(&mut self) -> anyhow::Result { + let res = self.ctx().wall_clock.resolution(); + Ok(Datetime { + seconds: res.as_secs(), + nanoseconds: res.subsec_nanos(), + }) + } +} + +impl monotonic_clock::Host for WasiImpl +where + T: WasiView, +{ + fn now(&mut self) -> anyhow::Result { + Ok(self.ctx().monotonic_clock.now()) + } + + fn resolution(&mut self) -> anyhow::Result { + Ok(self.ctx().monotonic_clock.resolution()) + } + + async fn wait_until(&mut self, when: Instant) -> anyhow::Result<()> { + let clock_now = self.ctx().monotonic_clock.now(); + if when > clock_now { + sleep(Duration::from_nanos(when - clock_now)).await; + }; + Ok(()) + } + + async fn wait_for(&mut self, duration: WasiDuration) -> anyhow::Result<()> { + if duration > 0 { + sleep(Duration::from_nanos(duration)).await; + } + Ok(()) + } +} diff --git a/crates/wasi/src/p3/host/clocks/sync.rs b/crates/wasi/src/p3/host/clocks/sync.rs new file mode 100644 index 000000000000..44fb7cacf1bc --- /dev/null +++ b/crates/wasi/src/p3/host/clocks/sync.rs @@ -0,0 +1,28 @@ +use crate::p3::bindings::clocks as async_clocks; +use crate::p3::bindings::sync::clocks as sync_clocks; +use crate::p3::bindings::sync::clocks::monotonic_clock::{Duration, Instant}; +use crate::runtime::in_tokio; +use crate::{WasiImpl, WasiView}; + +impl sync_clocks::monotonic_clock::Host for WasiImpl +where + T: WasiView, +{ + fn now(&mut self) -> anyhow::Result { + async_clocks::monotonic_clock::Host::now(self) + } + + fn resolution(&mut self) -> anyhow::Result { + async_clocks::monotonic_clock::Host::resolution(self) + } + + fn wait_until(&mut self, when: Instant) -> anyhow::Result<()> { + in_tokio(async_clocks::monotonic_clock::Host::wait_until(self, when)) + } + + fn wait_for(&mut self, duration: Duration) -> anyhow::Result<()> { + in_tokio(async_clocks::monotonic_clock::Host::wait_for( + self, duration, + )) + } +} diff --git a/crates/wasi/src/p3/host/mod.rs b/crates/wasi/src/p3/host/mod.rs index ed42dbde6c00..ffe1dca5bfeb 100644 --- a/crates/wasi/src/p3/host/mod.rs +++ b/crates/wasi/src/p3/host/mod.rs @@ -1 +1,2 @@ +mod clocks; mod random; diff --git a/crates/wasi/src/p3/mod.rs b/crates/wasi/src/p3/mod.rs index 8d5b4329131a..60bb9766ad69 100644 --- a/crates/wasi/src/p3/mod.rs +++ b/crates/wasi/src/p3/mod.rs @@ -78,6 +78,8 @@ pub fn add_to_linker_async(linker: &mut Linker) -> anyhow::Resul let l = linker; let closure = type_annotate::(|t| WasiImpl(IoImpl(t))); + crate::p3::bindings::clocks::wall_clock::add_to_linker_get_host(l, closure)?; + crate::p3::bindings::clocks::monotonic_clock::add_to_linker_get_host(l, closure)?; crate::p3::bindings::random::random::add_to_linker_get_host(l, closure)?; crate::p3::bindings::random::insecure::add_to_linker_get_host(l, closure)?; crate::p3::bindings::random::insecure_seed::add_to_linker_get_host(l, closure)?; @@ -145,6 +147,8 @@ pub fn add_to_linker_sync( let l = linker; let closure = type_annotate::(|t| WasiImpl(IoImpl(t))); + crate::p3::bindings::clocks::wall_clock::add_to_linker_get_host(l, closure)?; + crate::p3::bindings::sync::clocks::monotonic_clock::add_to_linker_get_host(l, closure)?; crate::p3::bindings::random::random::add_to_linker_get_host(l, closure)?; crate::p3::bindings::random::insecure::add_to_linker_get_host(l, closure)?; crate::p3::bindings::random::insecure_seed::add_to_linker_get_host(l, closure)?; diff --git a/crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/monotonic-clock.wit b/crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/monotonic-clock.wit new file mode 100644 index 000000000000..87ebdaac510a --- /dev/null +++ b/crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/monotonic-clock.wit @@ -0,0 +1,45 @@ +package wasi:clocks@0.3.0; +/// WASI Monotonic Clock is a clock API intended to let users measure elapsed +/// time. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +/// +/// A monotonic clock is a clock which has an unspecified initial value, and +/// successive reads of the clock will produce non-decreasing values. +@since(version = 0.3.0) +interface monotonic-clock { + /// An instant in time, in nanoseconds. An instant is relative to an + /// unspecified initial value, and can only be compared to instances from + /// the same monotonic-clock. + @since(version = 0.3.0) + type instant = u64; + + /// A duration of time, in nanoseconds. + @since(version = 0.3.0) + type duration = u64; + + /// Read the current value of the clock. + /// + /// The clock is monotonic, therefore calling this function repeatedly will + /// produce a sequence of non-decreasing values. + @since(version = 0.3.0) + now: func() -> instant; + + /// Query the resolution of the clock. Returns the duration of time + /// corresponding to a clock tick. + @since(version = 0.3.0) + resolution: func() -> duration; + + /// Wait until the specified instant has occurred. + @since(version = 0.3.0) + wait-until: func( + when: instant, + ); + + /// Wait for the specified duration has elapsed. + @since(version = 0.3.0) + wait-for: func( + how-long: duration, + ); +} diff --git a/crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/timezone.wit b/crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/timezone.wit new file mode 100644 index 000000000000..ac9146834f80 --- /dev/null +++ b/crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/timezone.wit @@ -0,0 +1,55 @@ +package wasi:clocks@0.3.0; + +@unstable(feature = clocks-timezone) +interface timezone { + @unstable(feature = clocks-timezone) + use wall-clock.{datetime}; + + /// Return information needed to display the given `datetime`. This includes + /// the UTC offset, the time zone name, and a flag indicating whether + /// daylight saving time is active. + /// + /// If the timezone cannot be determined for the given `datetime`, return a + /// `timezone-display` for `UTC` with a `utc-offset` of 0 and no daylight + /// saving time. + @unstable(feature = clocks-timezone) + display: func(when: datetime) -> timezone-display; + + /// The same as `display`, but only return the UTC offset. + @unstable(feature = clocks-timezone) + utc-offset: func(when: datetime) -> s32; + + /// Information useful for displaying the timezone of a specific `datetime`. + /// + /// This information may vary within a single `timezone` to reflect daylight + /// saving time adjustments. + @unstable(feature = clocks-timezone) + record timezone-display { + /// The number of seconds difference between UTC time and the local + /// time of the timezone. + /// + /// The returned value will always be less than 86400 which is the + /// number of seconds in a day (24*60*60). + /// + /// In implementations that do not expose an actual time zone, this + /// should return 0. + utc-offset: s32, + + /// The abbreviated name of the timezone to display to a user. The name + /// `UTC` indicates Coordinated Universal Time. Otherwise, this should + /// reference local standards for the name of the time zone. + /// + /// In implementations that do not expose an actual time zone, this + /// should be the string `UTC`. + /// + /// In time zones that do not have an applicable name, a formatted + /// representation of the UTC offset may be returned, such as `-04:00`. + name: string, + + /// Whether daylight saving time is active. + /// + /// In implementations that do not expose an actual time zone, this + /// should return false. + in-daylight-saving-time: bool, + } +} diff --git a/crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/wall-clock.wit b/crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/wall-clock.wit new file mode 100644 index 000000000000..b7a85ab35636 --- /dev/null +++ b/crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/wall-clock.wit @@ -0,0 +1,46 @@ +package wasi:clocks@0.3.0; +/// WASI Wall Clock is a clock API intended to let users query the current +/// time. The name "wall" makes an analogy to a "clock on the wall", which +/// is not necessarily monotonic as it may be reset. +/// +/// It is intended to be portable at least between Unix-family platforms and +/// Windows. +/// +/// A wall clock is a clock which measures the date and time according to +/// some external reference. +/// +/// External references may be reset, so this clock is not necessarily +/// monotonic, making it unsuitable for measuring elapsed time. +/// +/// It is intended for reporting the current date and time for humans. +@since(version = 0.3.0) +interface wall-clock { + /// A time and date in seconds plus nanoseconds. + @since(version = 0.3.0) + record datetime { + seconds: u64, + nanoseconds: u32, + } + + /// Read the current value of the clock. + /// + /// This clock is not monotonic, therefore calling this function repeatedly + /// will not necessarily produce a sequence of non-decreasing values. + /// + /// The returned timestamps represent the number of seconds since + /// 1970-01-01T00:00:00Z, also known as [POSIX's Seconds Since the Epoch], + /// also known as [Unix Time]. + /// + /// The nanoseconds field of the output is always less than 1000000000. + /// + /// [POSIX's Seconds Since the Epoch]: https://pubs.opengroup.org/onlinepubs/9699919799/xrat/V4_xbd_chap04.html#tag_21_04_16 + /// [Unix Time]: https://en.wikipedia.org/wiki/Unix_time + @since(version = 0.3.0) + now: func() -> datetime; + + /// Query the resolution of the clock. + /// + /// The nanoseconds field of the output is always less than 1000000000. + @since(version = 0.3.0) + resolution: func() -> datetime; +} diff --git a/crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/world.wit b/crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/world.wit new file mode 100644 index 000000000000..f97bcfef13b2 --- /dev/null +++ b/crates/wasi/src/p3/wit/deps/clocks@3850f9d@wit-0.3.0-draft/world.wit @@ -0,0 +1,11 @@ +package wasi:clocks@0.3.0; + +@since(version = 0.3.0) +world imports { + @since(version = 0.3.0) + import monotonic-clock; + @since(version = 0.3.0) + import wall-clock; + @unstable(feature = clocks-timezone) + import timezone; +} diff --git a/crates/wasi/src/p3/wit/world.wit b/crates/wasi/src/p3/wit/world.wit index 299fb30e6e0f..b1811df73379 100644 --- a/crates/wasi/src/p3/wit/world.wit +++ b/crates/wasi/src/p3/wit/world.wit @@ -6,5 +6,6 @@ world bindings { // TODO: Replace explicit includes by `wasi:cli/command@0.3.0` once released //include wasi:cli/imports@0.3.0; + include wasi:clocks/imports@0.3.0; include wasi:random/imports@0.3.0; } diff --git a/crates/wasi/tests/all/api.rs b/crates/wasi/tests/all/api.rs index 2c04daf65b00..f14dec76bd25 100644 --- a/crates/wasi/tests/all/api.rs +++ b/crates/wasi/tests/all/api.rs @@ -6,10 +6,9 @@ use std::sync::Mutex; use std::time::Duration; use wasmtime::component::{Component, Linker, ResourceTable}; use wasmtime::Store; -use wasmtime_wasi::p2::bindings::Command; use wasmtime_wasi::{ add_to_linker_async, - bindings::{clocks::wall_clock, filesystem::types as filesystem}, + p2::bindings::{Command, clocks::wall_clock, filesystem::types as filesystem}, DirPerms, FilePerms, HostMonotonicClock, HostWallClock, IoView, WasiCtx, WasiCtxBuilder, WasiView, }; diff --git a/crates/wasi/tests/all/async_.rs b/crates/wasi/tests/all/async_.rs index ab7283472000..18b971a4aa7d 100644 --- a/crates/wasi/tests/all/async_.rs +++ b/crates/wasi/tests/all/async_.rs @@ -405,6 +405,11 @@ async fn preview2_file_read_write() { .unwrap() } +#[cfg(feature = "p3")] +#[test_log::test(tokio::test(flavor = "multi_thread"))] +async fn preview3_sleep() { + run(PREVIEW3_SLEEP_COMPONENT, false).await.unwrap() +} #[cfg(feature = "p3")] #[test_log::test(tokio::test(flavor = "multi_thread"))] async fn preview3_random() { diff --git a/crates/wasi/tests/all/sync.rs b/crates/wasi/tests/all/sync.rs index 46adaddd9dc2..5e1584f15e4b 100644 --- a/crates/wasi/tests/all/sync.rs +++ b/crates/wasi/tests/all/sync.rs @@ -338,6 +338,11 @@ fn preview2_file_read_write() { run(PREVIEW2_FILE_READ_WRITE_COMPONENT, false).unwrap() } +#[cfg(feature = "p3")] +#[test_log::test] +fn preview3_sleep() { + run(PREVIEW3_SLEEP_COMPONENT, false).unwrap() +} #[cfg(feature = "p3")] #[test_log::test] fn preview3_random() {