From d41ba975d0d694d354480cd421ceff24c6934c07 Mon Sep 17 00:00:00 2001 From: Richard Zak Date: Tue, 17 May 2022 21:51:15 -0400 Subject: [PATCH 1/8] feat: support for target `wasm32-wasi` Signed-off-by: Richard Zak Co-authored-by: Harald Hoyer --- .github/workflows/ci.yml | 20 ++- tokio-macros/src/entry.rs | 9 ++ tokio-util/src/lib.rs | 1 + tokio/Cargo.toml | 7 +- tokio/src/io/driver/mod.rs | 5 + tokio/src/macros/cfg.rs | 18 ++- tokio/src/net/mod.rs | 14 +- tokio/src/net/tcp/listener.rs | 152 ++++++++++++-------- tokio/src/net/tcp/mod.rs | 4 +- tokio/src/net/tcp/stream.rs | 264 +++++++++++++++++++--------------- tokio/src/runtime/builder.rs | 18 +-- tokio/src/runtime/mod.rs | 68 ++++----- tokio/src/task/mod.rs | 6 +- tokio/src/util/linked_list.rs | 1 + 14 files changed, 351 insertions(+), 236 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c90c6357996..a8fcafafaca 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -489,9 +489,23 @@ jobs: - name: Install cargo-wasi run: cargo install cargo-wasi - # TODO: Expand this when full WASI support lands. - # Currently, this is a bare bones regression test - # for features that work today with wasi. + - name: WASI test tokio full + run: cargo test -p tokio --target wasm32-wasi --features full + env: + CARGO_TARGET_WASM32_WASI_RUNNER: "wasmtime run --" + RUSTFLAGS: --cfg tokio_unstable -Dwarnings + + - name: WASI test tokio-util full + run: cargo test -p tokio-util --target wasm32-wasi --features full + env: + CARGO_TARGET_WASM32_WASI_RUNNER: "wasmtime run --" + RUSTFLAGS: --cfg tokio_unstable -Dwarnings + + - name: WASI test tokio-stream + run: cargo test -p tokio-stream --target wasm32-wasi --features time,net,io-util,sync + env: + CARGO_TARGET_WASM32_WASI_RUNNER: "wasmtime run --" + RUSTFLAGS: --cfg tokio_unstable -Dwarnings - name: test tests-integration --features wasi-rt # TODO: this should become: `cargo hack wasi test --each-feature` diff --git a/tokio-macros/src/entry.rs b/tokio-macros/src/entry.rs index 68eb829176b..77bbbb9a376 100644 --- a/tokio-macros/src/entry.rs +++ b/tokio-macros/src/entry.rs @@ -53,10 +53,16 @@ struct Configuration { impl Configuration { fn new(is_test: bool, rt_multi_thread: bool) -> Self { Configuration { + #[cfg(not(target_os = "wasi"))] rt_multi_thread_available: rt_multi_thread, + #[cfg(target_os = "wasi")] + rt_multi_thread_available: false, default_flavor: match is_test { true => RuntimeFlavor::CurrentThread, + #[cfg(not(target_os = "wasi"))] false => RuntimeFlavor::Threaded, + #[cfg(target_os = "wasi")] + false => RuntimeFlavor::CurrentThread, }, flavor: None, worker_threads: None, @@ -142,6 +148,9 @@ impl Configuration { worker_threads.map(|(val, _span)| val) } (Threaded, _) => { + #[cfg(target_os = "wasi")] + let msg = "The runtime flavor `multi_thread` is not available for the target `wasm32-wasi`, please use `current_thread`."; + #[cfg(not(target_os = "wasi"))] let msg = if self.flavor.is_none() { "The default runtime flavor is `multi_thread`, but the `rt-multi-thread` feature is disabled." } else { diff --git a/tokio-util/src/lib.rs b/tokio-util/src/lib.rs index e4876a58a80..524fc4705dd 100644 --- a/tokio-util/src/lib.rs +++ b/tokio-util/src/lib.rs @@ -29,6 +29,7 @@ cfg_codec! { } cfg_net! { + #[cfg(not(target_arch = "wasm32"))] pub mod udp; pub mod net; } diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 9228b3c6449..ca6f8d78f14 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -51,7 +51,6 @@ net = [ "mio/os-poll", "mio/os-ext", "mio/net", - "socket2", "winapi/fileapi", "winapi/handleapi", "winapi/namedpipeapi", @@ -112,11 +111,13 @@ pin-project-lite = "0.2.0" bytes = { version = "1.0.0", optional = true } once_cell = { version = "1.5.2", optional = true } memchr = { version = "2.2", optional = true } -mio = { version = "0.8.1", optional = true } -socket2 = { version = "0.4.4", optional = true, features = [ "all" ] } +mio = { version = "0.8.4", optional = true } num_cpus = { version = "1.8.0", optional = true } parking_lot = { version = "0.12.0", optional = true } +[target.'cfg(not(target_arch = "wasm32"))'.dependencies] +socket2 = { version = "0.4.4", features = [ "all" ] } + # Currently unstable. The API exposed by these features may be broken at any time. # Requires `--cfg tokio_unstable` to enable. [target.'cfg(tokio_unstable)'.dependencies] diff --git a/tokio/src/io/driver/mod.rs b/tokio/src/io/driver/mod.rs index 4b420e1c8a2..265396bd24f 100644 --- a/tokio/src/io/driver/mod.rs +++ b/tokio/src/io/driver/mod.rs @@ -72,6 +72,8 @@ pub(super) struct Inner { io_dispatch: RwLock, /// Used to wake up the reactor from a call to `turn`. + /// Not supported on Wasi due to lack of threading support. + #[cfg(not(target_os = "wasi"))] waker: mio::Waker, metrics: IoDriverMetrics, @@ -115,6 +117,7 @@ impl Driver { /// creation. pub(crate) fn new() -> io::Result { let poll = mio::Poll::new()?; + #[cfg(not(target_os = "wasi"))] let waker = mio::Waker::new(poll.registry(), TOKEN_WAKEUP)?; let registry = poll.registry().try_clone()?; @@ -129,6 +132,7 @@ impl Driver { inner: Arc::new(Inner { registry, io_dispatch: RwLock::new(IoDispatcher::new(allocator)), + #[cfg(not(target_os = "wasi"))] waker, metrics: IoDriverMetrics::default(), }), @@ -300,6 +304,7 @@ impl Handle { /// blocked in `turn`, then the next call to `turn` will not block and /// return immediately. fn wakeup(&self) { + #[cfg(not(target_os = "wasi"))] self.inner.waker.wake().expect("failed to wake I/O driver"); } } diff --git a/tokio/src/macros/cfg.rs b/tokio/src/macros/cfg.rs index 45ae5f9913a..45b31c80025 100644 --- a/tokio/src/macros/cfg.rs +++ b/tokio/src/macros/cfg.rs @@ -61,6 +61,7 @@ macro_rules! cfg_fs { ($($item:item)*) => { $( #[cfg(feature = "fs")] + #[cfg(not(target_os = "wasi"))] #[cfg_attr(docsrs, doc(cfg(feature = "fs")))] $item )* @@ -247,6 +248,7 @@ macro_rules! cfg_process { #[cfg(feature = "process")] #[cfg_attr(docsrs, doc(cfg(feature = "process")))] #[cfg(not(loom))] + #[cfg(not(target_os = "wasi"))] $item )* } @@ -275,6 +277,7 @@ macro_rules! cfg_signal { #[cfg(feature = "signal")] #[cfg_attr(docsrs, doc(cfg(feature = "signal")))] #[cfg(not(loom))] + #[cfg(not(target_os = "wasi"))] $item )* } @@ -451,7 +454,8 @@ macro_rules! cfg_has_atomic_u64 { target_arch = "arm", target_arch = "mips", target_arch = "powerpc", - target_arch = "riscv32" + target_arch = "riscv32", + target_arch = "wasm32" )))] $item )* @@ -465,9 +469,19 @@ macro_rules! cfg_not_has_atomic_u64 { target_arch = "arm", target_arch = "mips", target_arch = "powerpc", - target_arch = "riscv32" + target_arch = "riscv32", + target_arch = "wasm32" ))] $item )* } } + +macro_rules! cfg_not_wasi { + ($($item:item)*) => { + $( + #[cfg(not(target_os = "wasi"))] + $item + )* + } +} diff --git a/tokio/src/net/mod.rs b/tokio/src/net/mod.rs index 0b8c1ecd194..2d317a8a219 100644 --- a/tokio/src/net/mod.rs +++ b/tokio/src/net/mod.rs @@ -23,8 +23,10 @@ //! [`UnixDatagram`]: UnixDatagram mod addr; -#[cfg(feature = "net")] -pub(crate) use addr::to_socket_addrs; +cfg_not_wasi! { + #[cfg(feature = "net")] + pub(crate) use addr::to_socket_addrs; +} pub use addr::ToSocketAddrs; cfg_net! { @@ -33,11 +35,13 @@ cfg_net! { pub mod tcp; pub use tcp::listener::TcpListener; - pub use tcp::socket::TcpSocket; pub use tcp::stream::TcpStream; + cfg_not_wasi! { + pub use tcp::socket::TcpSocket; - mod udp; - pub use udp::UdpSocket; + mod udp; + pub use udp::UdpSocket; + } } cfg_net_unix! { diff --git a/tokio/src/net/tcp/listener.rs b/tokio/src/net/tcp/listener.rs index 8aecb21aaa9..d14667a9386 100644 --- a/tokio/src/net/tcp/listener.rs +++ b/tokio/src/net/tcp/listener.rs @@ -1,6 +1,9 @@ use crate::io::{Interest, PollEvented}; use crate::net::tcp::TcpStream; -use crate::net::{to_socket_addrs, ToSocketAddrs}; + +cfg_not_wasi! { + use crate::net::{to_socket_addrs, ToSocketAddrs}; +} use std::convert::TryFrom; use std::fmt; @@ -55,68 +58,70 @@ cfg_net! { } impl TcpListener { - /// Creates a new TcpListener, which will be bound to the specified address. - /// - /// The returned listener is ready for accepting connections. - /// - /// Binding with a port number of 0 will request that the OS assigns a port - /// to this listener. The port allocated can be queried via the `local_addr` - /// method. - /// - /// The address type can be any implementor of the [`ToSocketAddrs`] trait. - /// If `addr` yields multiple addresses, bind will be attempted with each of - /// the addresses until one succeeds and returns the listener. If none of - /// the addresses succeed in creating a listener, the error returned from - /// the last attempt (the last address) is returned. - /// - /// This function sets the `SO_REUSEADDR` option on the socket. - /// - /// To configure the socket before binding, you can use the [`TcpSocket`] - /// type. - /// - /// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs - /// [`TcpSocket`]: struct@crate::net::TcpSocket - /// - /// # Examples - /// - /// ```no_run - /// use tokio::net::TcpListener; - /// - /// use std::io; - /// - /// #[tokio::main] - /// async fn main() -> io::Result<()> { - /// let listener = TcpListener::bind("127.0.0.1:2345").await?; - /// - /// // use the listener - /// - /// # let _ = listener; - /// Ok(()) - /// } - /// ``` - pub async fn bind(addr: A) -> io::Result { - let addrs = to_socket_addrs(addr).await?; + cfg_not_wasi! { + /// Creates a new TcpListener, which will be bound to the specified address. + /// + /// The returned listener is ready for accepting connections. + /// + /// Binding with a port number of 0 will request that the OS assigns a port + /// to this listener. The port allocated can be queried via the `local_addr` + /// method. + /// + /// The address type can be any implementor of the [`ToSocketAddrs`] trait. + /// If `addr` yields multiple addresses, bind will be attempted with each of + /// the addresses until one succeeds and returns the listener. If none of + /// the addresses succeed in creating a listener, the error returned from + /// the last attempt (the last address) is returned. + /// + /// This function sets the `SO_REUSEADDR` option on the socket. + /// + /// To configure the socket before binding, you can use the [`TcpSocket`] + /// type. + /// + /// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs + /// [`TcpSocket`]: struct@crate::net::TcpSocket + /// + /// # Examples + /// + /// ```no_run + /// use tokio::net::TcpListener; + /// + /// use std::io; + /// + /// #[tokio::main] + /// async fn main() -> io::Result<()> { + /// let listener = TcpListener::bind("127.0.0.1:2345").await?; + /// + /// // use the listener + /// + /// # let _ = listener; + /// Ok(()) + /// } + /// ``` + pub async fn bind(addr: A) -> io::Result { + let addrs = to_socket_addrs(addr).await?; - let mut last_err = None; + let mut last_err = None; - for addr in addrs { - match TcpListener::bind_addr(addr) { - Ok(listener) => return Ok(listener), - Err(e) => last_err = Some(e), + for addr in addrs { + match TcpListener::bind_addr(addr) { + Ok(listener) => return Ok(listener), + Err(e) => last_err = Some(e), + } } - } - Err(last_err.unwrap_or_else(|| { - io::Error::new( - io::ErrorKind::InvalidInput, - "could not resolve to any address", - ) - })) - } + Err(last_err.unwrap_or_else(|| { + io::Error::new( + io::ErrorKind::InvalidInput, + "could not resolve to any address", + ) + })) + } - fn bind_addr(addr: SocketAddr) -> io::Result { - let listener = mio::net::TcpListener::bind(addr)?; - TcpListener::new(listener) + fn bind_addr(addr: SocketAddr) -> io::Result { + let listener = mio::net::TcpListener::bind(addr)?; + TcpListener::new(listener) + } } /// Accepts a new incoming connection from this listener. @@ -267,11 +272,22 @@ impl TcpListener { .map(|io| io.into_raw_socket()) .map(|raw_socket| unsafe { std::net::TcpListener::from_raw_socket(raw_socket) }) } + + #[cfg(target_os = "wasi")] + { + use std::os::wasi::io::{FromRawFd, IntoRawFd}; + self.io + .into_inner() + .map(|io| io.into_raw_fd()) + .map(|raw_fd| unsafe { std::net::TcpListener::from_raw_fd(raw_fd) }) + } } - pub(crate) fn new(listener: mio::net::TcpListener) -> io::Result { - let io = PollEvented::new(listener)?; - Ok(TcpListener { io }) + cfg_not_wasi! { + pub(crate) fn new(listener: mio::net::TcpListener) -> io::Result { + let io = PollEvented::new(listener)?; + Ok(TcpListener { io }) + } } /// Returns the local address that this listener is bound to. @@ -384,6 +400,20 @@ mod sys { } } +cfg_unstable! { + #[cfg(target_os = "wasi")] + mod sys { + use super::TcpListener; + use std::os::wasi::prelude::*; + + impl AsRawFd for TcpListener { + fn as_raw_fd(&self) -> RawFd { + self.io.as_raw_fd() + } + } + } +} + #[cfg(windows)] mod sys { use super::TcpListener; diff --git a/tokio/src/net/tcp/mod.rs b/tokio/src/net/tcp/mod.rs index cb8a8b238be..734eabe6dda 100644 --- a/tokio/src/net/tcp/mod.rs +++ b/tokio/src/net/tcp/mod.rs @@ -2,7 +2,9 @@ pub(crate) mod listener; -pub(crate) mod socket; +cfg_not_wasi! { + pub(crate) mod socket; +} mod split; pub use split::{ReadHalf, WriteHalf}; diff --git a/tokio/src/net/tcp/stream.rs b/tokio/src/net/tcp/stream.rs index 204d9ca256c..199ac58185c 100644 --- a/tokio/src/net/tcp/stream.rs +++ b/tokio/src/net/tcp/stream.rs @@ -1,8 +1,12 @@ -use crate::future::poll_fn; +cfg_not_wasi! { + use crate::future::poll_fn; + use crate::net::{to_socket_addrs, ToSocketAddrs}; + use std::time::Duration; +} + use crate::io::{AsyncRead, AsyncWrite, Interest, PollEvented, ReadBuf, Ready}; use crate::net::tcp::split::{split, ReadHalf, WriteHalf}; use crate::net::tcp::split_owned::{split_owned, OwnedReadHalf, OwnedWriteHalf}; -use crate::net::{to_socket_addrs, ToSocketAddrs}; use std::convert::TryFrom; use std::fmt; @@ -10,7 +14,6 @@ use std::io; use std::net::{Shutdown, SocketAddr}; use std::pin::Pin; use std::task::{Context, Poll}; -use std::time::Duration; cfg_io_util! { use bytes::BufMut; @@ -70,86 +73,88 @@ cfg_net! { } impl TcpStream { - /// Opens a TCP connection to a remote host. - /// - /// `addr` is an address of the remote host. Anything which implements the - /// [`ToSocketAddrs`] trait can be supplied as the address. If `addr` - /// yields multiple addresses, connect will be attempted with each of the - /// addresses until a connection is successful. If none of the addresses - /// result in a successful connection, the error returned from the last - /// connection attempt (the last address) is returned. - /// - /// To configure the socket before connecting, you can use the [`TcpSocket`] - /// type. - /// - /// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs - /// [`TcpSocket`]: struct@crate::net::TcpSocket - /// - /// # Examples - /// - /// ```no_run - /// use tokio::net::TcpStream; - /// use tokio::io::AsyncWriteExt; - /// use std::error::Error; - /// - /// #[tokio::main] - /// async fn main() -> Result<(), Box> { - /// // Connect to a peer - /// let mut stream = TcpStream::connect("127.0.0.1:8080").await?; - /// - /// // Write some data. - /// stream.write_all(b"hello world!").await?; - /// - /// Ok(()) - /// } - /// ``` - /// - /// The [`write_all`] method is defined on the [`AsyncWriteExt`] trait. - /// - /// [`write_all`]: fn@crate::io::AsyncWriteExt::write_all - /// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt - pub async fn connect(addr: A) -> io::Result { - let addrs = to_socket_addrs(addr).await?; + cfg_not_wasi! { + /// Opens a TCP connection to a remote host. + /// + /// `addr` is an address of the remote host. Anything which implements the + /// [`ToSocketAddrs`] trait can be supplied as the address. If `addr` + /// yields multiple addresses, connect will be attempted with each of the + /// addresses until a connection is successful. If none of the addresses + /// result in a successful connection, the error returned from the last + /// connection attempt (the last address) is returned. + /// + /// To configure the socket before connecting, you can use the [`TcpSocket`] + /// type. + /// + /// [`ToSocketAddrs`]: trait@crate::net::ToSocketAddrs + /// [`TcpSocket`]: struct@crate::net::TcpSocket + /// + /// # Examples + /// + /// ```no_run + /// use tokio::net::TcpStream; + /// use tokio::io::AsyncWriteExt; + /// use std::error::Error; + /// + /// #[tokio::main] + /// async fn main() -> Result<(), Box> { + /// // Connect to a peer + /// let mut stream = TcpStream::connect("127.0.0.1:8080").await?; + /// + /// // Write some data. + /// stream.write_all(b"hello world!").await?; + /// + /// Ok(()) + /// } + /// ``` + /// + /// The [`write_all`] method is defined on the [`AsyncWriteExt`] trait. + /// + /// [`write_all`]: fn@crate::io::AsyncWriteExt::write_all + /// [`AsyncWriteExt`]: trait@crate::io::AsyncWriteExt + pub async fn connect(addr: A) -> io::Result { + let addrs = to_socket_addrs(addr).await?; - let mut last_err = None; + let mut last_err = None; - for addr in addrs { - match TcpStream::connect_addr(addr).await { - Ok(stream) => return Ok(stream), - Err(e) => last_err = Some(e), + for addr in addrs { + match TcpStream::connect_addr(addr).await { + Ok(stream) => return Ok(stream), + Err(e) => last_err = Some(e), + } } + + Err(last_err.unwrap_or_else(|| { + io::Error::new( + io::ErrorKind::InvalidInput, + "could not resolve to any address", + ) + })) } - Err(last_err.unwrap_or_else(|| { - io::Error::new( - io::ErrorKind::InvalidInput, - "could not resolve to any address", - ) - })) - } + /// Establishes a connection to the specified `addr`. + async fn connect_addr(addr: SocketAddr) -> io::Result { + let sys = mio::net::TcpStream::connect(addr)?; + TcpStream::connect_mio(sys).await + } - /// Establishes a connection to the specified `addr`. - async fn connect_addr(addr: SocketAddr) -> io::Result { - let sys = mio::net::TcpStream::connect(addr)?; - TcpStream::connect_mio(sys).await - } + pub(crate) async fn connect_mio(sys: mio::net::TcpStream) -> io::Result { + let stream = TcpStream::new(sys)?; - pub(crate) async fn connect_mio(sys: mio::net::TcpStream) -> io::Result { - let stream = TcpStream::new(sys)?; + // Once we've connected, wait for the stream to be writable as + // that's when the actual connection has been initiated. Once we're + // writable we check for `take_socket_error` to see if the connect + // actually hit an error or not. + // + // If all that succeeded then we ship everything on up. + poll_fn(|cx| stream.io.registration().poll_write_ready(cx)).await?; - // Once we've connected, wait for the stream to be writable as - // that's when the actual connection has been initiated. Once we're - // writable we check for `take_socket_error` to see if the connect - // actually hit an error or not. - // - // If all that succeeded then we ship everything on up. - poll_fn(|cx| stream.io.registration().poll_write_ready(cx)).await?; + if let Some(e) = stream.io.take_error()? { + return Err(e); + } - if let Some(e) = stream.io.take_error()? { - return Err(e); + Ok(stream) } - - Ok(stream) } pub(crate) fn new(connected: mio::net::TcpStream) -> io::Result { @@ -244,6 +249,15 @@ impl TcpStream { .map(|io| io.into_raw_socket()) .map(|raw_socket| unsafe { std::net::TcpStream::from_raw_socket(raw_socket) }) } + + #[cfg(target_os = "wasi")] + { + use std::os::wasi::io::{FromRawFd, IntoRawFd}; + self.io + .into_inner() + .map(|io| io.into_raw_fd()) + .map(|raw_fd| unsafe { std::net::TcpStream::from_raw_fd(raw_fd) }) + } } /// Returns the local address that this stream is bound to. @@ -1077,52 +1091,54 @@ impl TcpStream { self.io.set_nodelay(nodelay) } - /// Reads the linger duration for this socket by getting the `SO_LINGER` - /// option. - /// - /// For more information about this option, see [`set_linger`]. - /// - /// [`set_linger`]: TcpStream::set_linger - /// - /// # Examples - /// - /// ```no_run - /// use tokio::net::TcpStream; - /// - /// # async fn dox() -> Result<(), Box> { - /// let stream = TcpStream::connect("127.0.0.1:8080").await?; - /// - /// println!("{:?}", stream.linger()?); - /// # Ok(()) - /// # } - /// ``` - pub fn linger(&self) -> io::Result> { - socket2::SockRef::from(self).linger() - } + cfg_not_wasi! { + /// Reads the linger duration for this socket by getting the `SO_LINGER` + /// option. + /// + /// For more information about this option, see [`set_linger`]. + /// + /// [`set_linger`]: TcpStream::set_linger + /// + /// # Examples + /// + /// ```no_run + /// use tokio::net::TcpStream; + /// + /// # async fn dox() -> Result<(), Box> { + /// let stream = TcpStream::connect("127.0.0.1:8080").await?; + /// + /// println!("{:?}", stream.linger()?); + /// # Ok(()) + /// # } + /// ``` + pub fn linger(&self) -> io::Result> { + socket2::SockRef::from(self).linger() + } - /// Sets the linger duration of this socket by setting the SO_LINGER option. - /// - /// This option controls the action taken when a stream has unsent messages and the stream is - /// closed. If SO_LINGER is set, the system shall block the process until it can transmit the - /// data or until the time expires. - /// - /// If SO_LINGER is not specified, and the stream is closed, the system handles the call in a - /// way that allows the process to continue as quickly as possible. - /// - /// # Examples - /// - /// ```no_run - /// use tokio::net::TcpStream; - /// - /// # async fn dox() -> Result<(), Box> { - /// let stream = TcpStream::connect("127.0.0.1:8080").await?; - /// - /// stream.set_linger(None)?; - /// # Ok(()) - /// # } - /// ``` - pub fn set_linger(&self, dur: Option) -> io::Result<()> { - socket2::SockRef::from(self).set_linger(dur) + /// Sets the linger duration of this socket by setting the SO_LINGER option. + /// + /// This option controls the action taken when a stream has unsent messages and the stream is + /// closed. If SO_LINGER is set, the system shall block the process until it can transmit the + /// data or until the time expires. + /// + /// If SO_LINGER is not specified, and the stream is closed, the system handles the call in a + /// way that allows the process to continue as quickly as possible. + /// + /// # Examples + /// + /// ```no_run + /// use tokio::net::TcpStream; + /// + /// # async fn dox() -> Result<(), Box> { + /// let stream = TcpStream::connect("127.0.0.1:8080").await?; + /// + /// stream.set_linger(None)?; + /// # Ok(()) + /// # } + /// ``` + pub fn set_linger(&self, dur: Option) -> io::Result<()> { + socket2::SockRef::from(self).set_linger(dur) + } } /// Gets the value of the `IP_TTL` option for this socket. @@ -1315,3 +1331,15 @@ mod sys { } } } + +#[cfg(all(tokio_unstable, target_os = "wasi"))] +mod sys { + use super::TcpStream; + use std::os::wasi::prelude::*; + + impl AsRawFd for TcpStream { + fn as_raw_fd(&self) -> RawFd { + self.io.as_raw_fd() + } + } +} diff --git a/tokio/src/runtime/builder.rs b/tokio/src/runtime/builder.rs index 490bc96d5a9..646c64e1ee9 100644 --- a/tokio/src/runtime/builder.rs +++ b/tokio/src/runtime/builder.rs @@ -197,14 +197,16 @@ impl Builder { Builder::new(Kind::CurrentThread, 31, EVENT_INTERVAL) } - /// Returns a new builder with the multi thread scheduler selected. - /// - /// Configuration methods can be chained on the return value. - #[cfg(feature = "rt-multi-thread")] - #[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))] - pub fn new_multi_thread() -> Builder { - // The number `61` is fairly arbitrary. I believe this value was copied from golang. - Builder::new(Kind::MultiThread, 61, 61) + cfg_not_wasi! { + /// Returns a new builder with the multi thread scheduler selected. + /// + /// Configuration methods can be chained on the return value. + #[cfg(feature = "rt-multi-thread")] + #[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))] + pub fn new_multi_thread() -> Builder { + // The number `61` is fairly arbitrary. I believe this value was copied from golang. + Builder::new(Kind::MultiThread, 61, 61) + } } /// Returns a new runtime builder initialized with default configuration diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs index b9e7e2de958..7f8dbe13efd 100644 --- a/tokio/src/runtime/mod.rs +++ b/tokio/src/runtime/mod.rs @@ -311,39 +311,41 @@ cfg_rt! { type Callback = std::sync::Arc; impl Runtime { - /// Creates a new runtime instance with default configuration values. - /// - /// This results in the multi threaded scheduler, I/O driver, and time driver being - /// initialized. - /// - /// Most applications will not need to call this function directly. Instead, - /// they will use the [`#[tokio::main]` attribute][main]. When a more complex - /// configuration is necessary, the [runtime builder] may be used. - /// - /// See [module level][mod] documentation for more details. - /// - /// # Examples - /// - /// Creating a new `Runtime` with default configuration values. - /// - /// ``` - /// use tokio::runtime::Runtime; - /// - /// let rt = Runtime::new() - /// .unwrap(); - /// - /// // Use the runtime... - /// ``` - /// - /// [mod]: index.html - /// [main]: ../attr.main.html - /// [threaded scheduler]: index.html#threaded-scheduler - /// [basic scheduler]: index.html#basic-scheduler - /// [runtime builder]: crate::runtime::Builder - #[cfg(feature = "rt-multi-thread")] - #[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))] - pub fn new() -> std::io::Result { - Builder::new_multi_thread().enable_all().build() + cfg_not_wasi! { + /// Creates a new runtime instance with default configuration values. + /// + /// This results in the multi threaded scheduler, I/O driver, and time driver being + /// initialized. + /// + /// Most applications will not need to call this function directly. Instead, + /// they will use the [`#[tokio::main]` attribute][main]. When a more complex + /// configuration is necessary, the [runtime builder] may be used. + /// + /// See [module level][mod] documentation for more details. + /// + /// # Examples + /// + /// Creating a new `Runtime` with default configuration values. + /// + /// ``` + /// use tokio::runtime::Runtime; + /// + /// let rt = Runtime::new() + /// .unwrap(); + /// + /// // Use the runtime... + /// ``` + /// + /// [mod]: index.html + /// [main]: ../attr.main.html + /// [threaded scheduler]: index.html#threaded-scheduler + /// [basic scheduler]: index.html#basic-scheduler + /// [runtime builder]: crate::runtime::Builder + #[cfg(feature = "rt-multi-thread")] + #[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))] + pub fn new() -> std::io::Result { + Builder::new_multi_thread().enable_all().build() + } } /// Returns a handle to the runtime's spawner. diff --git a/tokio/src/task/mod.rs b/tokio/src/task/mod.rs index 8ea73fb48de..37a68b6e3bf 100644 --- a/tokio/src/task/mod.rs +++ b/tokio/src/task/mod.rs @@ -278,8 +278,10 @@ cfg_rt! { pub use crate::runtime::task::{JoinError, JoinHandle}; - mod blocking; - pub use blocking::spawn_blocking; + cfg_not_wasi! { + mod blocking; + pub use blocking::spawn_blocking; + } mod spawn; pub use spawn::spawn; diff --git a/tokio/src/util/linked_list.rs b/tokio/src/util/linked_list.rs index e6bdde68c7a..af963204467 100644 --- a/tokio/src/util/linked_list.rs +++ b/tokio/src/util/linked_list.rs @@ -631,6 +631,7 @@ mod tests { } } + #[cfg(not(target_arch = "wasm32"))] fn run_fuzz(ops: Vec) { use std::collections::VecDeque; From 4acce7fb2ae5f490f85faee63a8f6cb01aea8ce6 Mon Sep 17 00:00:00 2001 From: Richard Zak Date: Wed, 29 Jun 2022 11:43:56 -0400 Subject: [PATCH 2/8] fixup: polling issue on Wasi Signed-off-by: Richard Zak --- tokio/src/io/driver/mod.rs | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tokio/src/io/driver/mod.rs b/tokio/src/io/driver/mod.rs index 265396bd24f..745c73bafd1 100644 --- a/tokio/src/io/driver/mod.rs +++ b/tokio/src/io/driver/mod.rs @@ -168,6 +168,11 @@ impl Driver { match self.poll.poll(&mut events, max_wait) { Ok(_) => {} Err(ref e) if e.kind() == io::ErrorKind::Interrupted => {} + #[cfg(target_os = "wasi")] + Err(e) if e.kind() == io::ErrorKind::InvalidInput => { + // In case of wasm32_wasi this error happens, when trying to poll without subscriptions + // just return from the park, as there would be nothing, which wakes us up. + } Err(e) => return Err(e), } From 6ade965343afa1227e9bf783c36f632eb59488be Mon Sep 17 00:00:00 2001 From: Richard Zak Date: Tue, 5 Jul 2022 15:10:48 -0400 Subject: [PATCH 3/8] fix: wasi park with sleep Signed-off-by: Richard Zak --- tokio/src/park/thread.rs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tokio/src/park/thread.rs b/tokio/src/park/thread.rs index 27ce2024396..b42b73fe0fe 100644 --- a/tokio/src/park/thread.rs +++ b/tokio/src/park/thread.rs @@ -64,7 +64,11 @@ impl Park for ParkThread { } fn park_timeout(&mut self, duration: Duration) -> Result<(), Self::Error> { + // Wasi doesn't have threads, so just sleep. + #[cfg(not(target_os = "wasi"))] self.inner.park_timeout(duration); + #[cfg(target_os = "wasi")] + std::thread::sleep(duration); Ok(()) } From 3b6cf098115533d1931a4efb5f1923d53c32a4cb Mon Sep 17 00:00:00 2001 From: Richard Zak Date: Fri, 10 Jun 2022 23:35:57 -0400 Subject: [PATCH 4/8] feat: wasi unit tests Co-authored-by: Harald Hoyer Signed-off-by: Richard Zak --- tests-integration/tests/macros_select.rs | 1 + tests-integration/tests/process_stdio.rs | 2 +- tokio-macros/src/entry.rs | 9 -- tokio-stream/Cargo.toml | 1 + tokio-stream/tests/stream_panic.rs | 1 + tokio-stream/tests/stream_stream_map.rs | 1 + tokio-stream/tests/watch.rs | 1 + tokio-util/src/task/mod.rs | 2 + tokio-util/tests/context.rs | 1 + tokio-util/tests/io_sync_bridge.rs | 1 + tokio-util/tests/panic.rs | 2 +- tokio-util/tests/spawn_pinned.rs | 1 + tokio-util/tests/time_delay_queue.rs | 2 + tokio-util/tests/udp.rs | 1 + tokio/Cargo.toml | 2 +- tokio/src/coop.rs | 2 +- tokio/src/macros/cfg.rs | 11 +- tokio/src/runtime/builder.rs | 6 +- tokio/src/runtime/mod.rs | 6 +- tokio/src/runtime/spawner.rs | 18 +-- tokio/src/sync/tests/atomic_waker.rs | 2 +- tokio/src/sync/tests/notify.rs | 2 +- tokio/src/sync/tests/semaphore_batch.rs | 2 +- tokio/src/time/driver/tests/mod.rs | 2 + tokio/tests/async_send_sync.rs | 151 ++++++++++++++--------- tokio/tests/buffered.rs | 2 +- tokio/tests/fs.rs | 2 +- tokio/tests/fs_copy.rs | 2 +- tokio/tests/fs_dir.rs | 2 +- tokio/tests/fs_file.rs | 2 +- tokio/tests/fs_link.rs | 2 +- tokio/tests/io_buf_reader.rs | 4 + tokio/tests/io_buf_writer.rs | 4 + tokio/tests/io_copy.rs | 2 + tokio/tests/io_copy_bidirectional.rs | 2 +- tokio/tests/io_driver.rs | 2 +- tokio/tests/io_driver_drop.rs | 2 +- tokio/tests/io_fill_buf.rs | 2 +- tokio/tests/io_mem_stream.rs | 6 + tokio/tests/io_util_empty.rs | 3 + tokio/tests/join_handle_panic.rs | 2 +- tokio/tests/macros_join.rs | 10 +- tokio/tests/macros_pin.rs | 4 +- tokio/tests/macros_rename_test.rs | 2 +- tokio/tests/macros_select.rs | 6 +- tokio/tests/macros_test.rs | 2 +- tokio/tests/macros_try_join.rs | 6 +- tokio/tests/net_lookup_host.rs | 2 +- tokio/tests/no_rt.rs | 2 +- tokio/tests/process_smoke.rs | 2 +- tokio/tests/rt_basic.rs | 6 + tokio/tests/rt_common.rs | 56 ++++++++- tokio/tests/rt_handle_block_on.rs | 15 ++- tokio/tests/rt_panic.rs | 1 + tokio/tests/rt_threaded.rs | 48 ++++++- tokio/tests/sync_barrier.rs | 2 +- tokio/tests/sync_broadcast.rs | 2 +- tokio/tests/sync_errors.rs | 2 +- tokio/tests/sync_mpsc.rs | 17 +-- tokio/tests/sync_mutex.rs | 6 +- tokio/tests/sync_mutex_owned.rs | 6 +- tokio/tests/sync_notify.rs | 2 +- tokio/tests/sync_oneshot.rs | 8 +- tokio/tests/sync_panic.rs | 2 +- tokio/tests/sync_rwlock.rs | 8 +- tokio/tests/sync_semaphore.rs | 6 +- tokio/tests/sync_semaphore_owned.rs | 7 +- tokio/tests/sync_watch.rs | 2 +- tokio/tests/task_abort.rs | 2 +- tokio/tests/task_blocking.rs | 2 +- tokio/tests/task_local.rs | 2 +- tokio/tests/task_local_set.rs | 22 +++- tokio/tests/tcp_accept.rs | 2 +- tokio/tests/tcp_connect.rs | 2 +- tokio/tests/tcp_echo.rs | 2 +- tokio/tests/tcp_into_split.rs | 2 +- tokio/tests/tcp_into_std.rs | 2 +- tokio/tests/tcp_peek.rs | 2 +- tokio/tests/tcp_shutdown.rs | 2 +- tokio/tests/tcp_socket.rs | 2 +- tokio/tests/tcp_split.rs | 2 +- tokio/tests/tcp_stream.rs | 2 +- tokio/tests/test_clock.rs | 3 + tokio/tests/time_interval.rs | 5 + tokio/tests/time_panic.rs | 2 +- tokio/tests/time_pause.rs | 2 +- tokio/tests/time_rt.rs | 1 + tokio/tests/time_timeout.rs | 3 + tokio/tests/udp.rs | 2 +- tokio/tests/unwindsafe.rs | 2 +- 90 files changed, 398 insertions(+), 173 deletions(-) diff --git a/tests-integration/tests/macros_select.rs b/tests-integration/tests/macros_select.rs index 4c4fef7ce77..a1a242c0f4e 100644 --- a/tests-integration/tests/macros_select.rs +++ b/tests-integration/tests/macros_select.rs @@ -4,6 +4,7 @@ use futures::channel::oneshot; use futures::executor::block_on; use std::thread; +#[cfg_attr(target_os = "wasi", ignore = "WASI: std::thread::spawn not supported")] #[test] fn join_with_select() { block_on(async { diff --git a/tests-integration/tests/process_stdio.rs b/tests-integration/tests/process_stdio.rs index 94861635b6d..1ce41013ced 100644 --- a/tests-integration/tests/process_stdio.rs +++ b/tests-integration/tests/process_stdio.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::io::{AsyncBufReadExt, AsyncReadExt, AsyncWriteExt, BufReader}; use tokio::join; diff --git a/tokio-macros/src/entry.rs b/tokio-macros/src/entry.rs index 77bbbb9a376..68eb829176b 100644 --- a/tokio-macros/src/entry.rs +++ b/tokio-macros/src/entry.rs @@ -53,16 +53,10 @@ struct Configuration { impl Configuration { fn new(is_test: bool, rt_multi_thread: bool) -> Self { Configuration { - #[cfg(not(target_os = "wasi"))] rt_multi_thread_available: rt_multi_thread, - #[cfg(target_os = "wasi")] - rt_multi_thread_available: false, default_flavor: match is_test { true => RuntimeFlavor::CurrentThread, - #[cfg(not(target_os = "wasi"))] false => RuntimeFlavor::Threaded, - #[cfg(target_os = "wasi")] - false => RuntimeFlavor::CurrentThread, }, flavor: None, worker_threads: None, @@ -148,9 +142,6 @@ impl Configuration { worker_threads.map(|(val, _span)| val) } (Threaded, _) => { - #[cfg(target_os = "wasi")] - let msg = "The runtime flavor `multi_thread` is not available for the target `wasm32-wasi`, please use `current_thread`."; - #[cfg(not(target_os = "wasi"))] let msg = if self.flavor.is_none() { "The default runtime flavor is `multi_thread`, but the `rt-multi-thread` feature is disabled." } else { diff --git a/tokio-stream/Cargo.toml b/tokio-stream/Cargo.toml index a84c924bfd9..2d693f86000 100644 --- a/tokio-stream/Cargo.toml +++ b/tokio-stream/Cargo.toml @@ -38,6 +38,7 @@ parking_lot = "0.12.0" tokio-test = { path = "../tokio-test" } futures = { version = "0.3", default-features = false } +[target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] proptest = "1" [package.metadata.docs.rs] diff --git a/tokio-stream/tests/stream_panic.rs b/tokio-stream/tests/stream_panic.rs index c0a3a45a476..a8d7b961537 100644 --- a/tokio-stream/tests/stream_panic.rs +++ b/tokio-stream/tests/stream_panic.rs @@ -1,5 +1,6 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "time")] +#![cfg(not(target_os = "wasi"))] use parking_lot::{const_mutex, Mutex}; use std::error::Error; diff --git a/tokio-stream/tests/stream_stream_map.rs b/tokio-stream/tests/stream_stream_map.rs index 53f3d86c768..ffc489b32ef 100644 --- a/tokio-stream/tests/stream_stream_map.rs +++ b/tokio-stream/tests/stream_stream_map.rs @@ -325,6 +325,7 @@ fn one_ready_many_none() { } } +#[cfg(not(target_os = "wasi"))] proptest::proptest! { #[test] fn fuzz_pending_complete_mix(kinds: Vec) { diff --git a/tokio-stream/tests/watch.rs b/tokio-stream/tests/watch.rs index a56254edefd..55e1792341a 100644 --- a/tokio-stream/tests/watch.rs +++ b/tokio-stream/tests/watch.rs @@ -5,6 +5,7 @@ use tokio_stream::wrappers::WatchStream; use tokio_stream::StreamExt; #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn message_not_twice() { let (tx, rx) = watch::channel("hello"); diff --git a/tokio-util/src/task/mod.rs b/tokio-util/src/task/mod.rs index 7ba8ad9a218..de41dd5dbe8 100644 --- a/tokio-util/src/task/mod.rs +++ b/tokio-util/src/task/mod.rs @@ -2,7 +2,9 @@ #[cfg(tokio_unstable)] mod join_map; +#[cfg(not(target_os = "wasi"))] mod spawn_pinned; +#[cfg(not(target_os = "wasi"))] pub use spawn_pinned::LocalPoolHandle; #[cfg(tokio_unstable)] diff --git a/tokio-util/tests/context.rs b/tokio-util/tests/context.rs index 7510f36fd17..dfe26047990 100644 --- a/tokio-util/tests/context.rs +++ b/tokio-util/tests/context.rs @@ -1,4 +1,5 @@ #![cfg(feature = "rt")] +#![cfg(not(target_os = "wasi"))] #![warn(rust_2018_idioms)] use tokio::runtime::Builder; diff --git a/tokio-util/tests/io_sync_bridge.rs b/tokio-util/tests/io_sync_bridge.rs index 0d420857b50..6a2acecb7ac 100644 --- a/tokio-util/tests/io_sync_bridge.rs +++ b/tokio-util/tests/io_sync_bridge.rs @@ -1,4 +1,5 @@ #![cfg(feature = "io-util")] +#![cfg(not(target_os = "wasi"))] use std::error::Error; use std::io::{Cursor, Read, Result as IoResult}; diff --git a/tokio-util/tests/panic.rs b/tokio-util/tests/panic.rs index fbaab5f22c7..76b8f64d4ea 100644 --- a/tokio-util/tests/panic.rs +++ b/tokio-util/tests/panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use parking_lot::{const_mutex, Mutex}; use std::error::Error; diff --git a/tokio-util/tests/spawn_pinned.rs b/tokio-util/tests/spawn_pinned.rs index ac68b7f34dc..9ed7157715c 100644 --- a/tokio-util/tests/spawn_pinned.rs +++ b/tokio-util/tests/spawn_pinned.rs @@ -1,4 +1,5 @@ #![warn(rust_2018_idioms)] +#![cfg(not(target_os = "wasi"))] use std::rc::Rc; use std::sync::Arc; diff --git a/tokio-util/tests/time_delay_queue.rs b/tokio-util/tests/time_delay_queue.rs index cb163adf3a6..0fcdbf4a073 100644 --- a/tokio-util/tests/time_delay_queue.rs +++ b/tokio-util/tests/time_delay_queue.rs @@ -778,6 +778,7 @@ async fn compact_change_deadline() { assert!(entry.is_none()); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test(start_paused = true)] async fn remove_after_compact() { let now = Instant::now(); @@ -794,6 +795,7 @@ async fn remove_after_compact() { assert!(panic.is_err()); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test(start_paused = true)] async fn remove_after_compact_poll() { let now = Instant::now(); diff --git a/tokio-util/tests/udp.rs b/tokio-util/tests/udp.rs index b9436a30aa6..996d073067b 100644 --- a/tokio-util/tests/udp.rs +++ b/tokio-util/tests/udp.rs @@ -1,4 +1,5 @@ #![warn(rust_2018_idioms)] +#![cfg(not(target_os = "wasi"))] use tokio::net::UdpSocket; use tokio_stream::StreamExt; diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index ca6f8d78f14..5edd9a2f645 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -153,7 +153,7 @@ proptest = "1" rand = "0.8.0" socket2 = "0.4" -[target.'cfg(target_arch = "wasm32")'.dev-dependencies] +[target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dev-dependencies] wasm-bindgen-test = "0.3.0" [target.'cfg(target_os = "freebsd")'.dev-dependencies] diff --git a/tokio/src/coop.rs b/tokio/src/coop.rs index bde1888a367..eaedae9b1b2 100644 --- a/tokio/src/coop.rs +++ b/tokio/src/coop.rs @@ -207,7 +207,7 @@ cfg_coop! { mod test { use super::*; - #[cfg(target_arch = "wasm32")] + #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; fn get() -> Budget { diff --git a/tokio/src/macros/cfg.rs b/tokio/src/macros/cfg.rs index 45b31c80025..fd3556c302e 100644 --- a/tokio/src/macros/cfg.rs +++ b/tokio/src/macros/cfg.rs @@ -337,7 +337,7 @@ macro_rules! cfg_not_rt { macro_rules! cfg_rt_multi_thread { ($($item:item)*) => { $( - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] #[cfg_attr(docsrs, doc(cfg(feature = "rt-multi-thread")))] $item )* @@ -485,3 +485,12 @@ macro_rules! cfg_not_wasi { )* } } + +macro_rules! cfg_is_wasm_not_wasi { + ($($item:item)*) => { + $( + #[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] + $item + )* + } +} diff --git a/tokio/src/runtime/builder.rs b/tokio/src/runtime/builder.rs index 646c64e1ee9..8f477a94004 100644 --- a/tokio/src/runtime/builder.rs +++ b/tokio/src/runtime/builder.rs @@ -174,7 +174,7 @@ pub(crate) type ThreadNameFn = std::sync::Arc String + Send + Sync + pub(crate) enum Kind { CurrentThread, - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] MultiThread, } @@ -619,7 +619,7 @@ impl Builder { pub fn build(&mut self) -> io::Result { match &self.kind { Kind::CurrentThread => self.build_basic_runtime(), - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Kind::MultiThread => self.build_threaded_runtime(), } } @@ -628,7 +628,7 @@ impl Builder { driver::Cfg { enable_pause_time: match self.kind { Kind::CurrentThread => true, - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Kind::MultiThread => false, }, enable_io: self.enable_io, diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs index 7f8dbe13efd..dad285d1fbd 100644 --- a/tokio/src/runtime/mod.rs +++ b/tokio/src/runtime/mod.rs @@ -303,7 +303,7 @@ cfg_rt! { CurrentThread(BasicScheduler), /// Execute tasks across multiple threads. - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] ThreadPool(ThreadPool), } @@ -482,7 +482,7 @@ cfg_rt! { match &self.kind { Kind::CurrentThread(exec) => exec.block_on(future), - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Kind::ThreadPool(exec) => exec.block_on(future), } } @@ -612,7 +612,7 @@ cfg_rt! { }, } }, - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Kind::ThreadPool(_) => { // The threaded scheduler drops its tasks on its worker threads, which is // already in the runtime's context. diff --git a/tokio/src/runtime/spawner.rs b/tokio/src/runtime/spawner.rs index fb4d7f91845..dd1f6da24ae 100644 --- a/tokio/src/runtime/spawner.rs +++ b/tokio/src/runtime/spawner.rs @@ -10,13 +10,13 @@ cfg_rt_multi_thread! { #[derive(Debug, Clone)] pub(crate) enum Spawner { Basic(basic_scheduler::Spawner), - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] ThreadPool(thread_pool::Spawner), } impl Spawner { pub(crate) fn shutdown(&mut self) { - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] { if let Spawner::ThreadPool(spawner) = self { spawner.shutdown(); @@ -31,7 +31,7 @@ impl Spawner { { match self { Spawner::Basic(spawner) => spawner.spawn(future, id), - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Spawner::ThreadPool(spawner) => spawner.spawn(future, id), } } @@ -39,7 +39,7 @@ impl Spawner { pub(crate) fn as_handle_inner(&self) -> &HandleInner { match self { Spawner::Basic(spawner) => spawner.as_handle_inner(), - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Spawner::ThreadPool(spawner) => spawner.as_handle_inner(), } } @@ -52,7 +52,7 @@ cfg_metrics! { pub(crate) fn num_workers(&self) -> usize { match self { Spawner::Basic(_) => 1, - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Spawner::ThreadPool(spawner) => spawner.num_workers(), } } @@ -60,7 +60,7 @@ cfg_metrics! { pub(crate) fn scheduler_metrics(&self) -> &SchedulerMetrics { match self { Spawner::Basic(spawner) => spawner.scheduler_metrics(), - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Spawner::ThreadPool(spawner) => spawner.scheduler_metrics(), } } @@ -68,7 +68,7 @@ cfg_metrics! { pub(crate) fn worker_metrics(&self, worker: usize) -> &WorkerMetrics { match self { Spawner::Basic(spawner) => spawner.worker_metrics(worker), - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Spawner::ThreadPool(spawner) => spawner.worker_metrics(worker), } } @@ -76,7 +76,7 @@ cfg_metrics! { pub(crate) fn injection_queue_depth(&self) -> usize { match self { Spawner::Basic(spawner) => spawner.injection_queue_depth(), - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Spawner::ThreadPool(spawner) => spawner.injection_queue_depth(), } } @@ -84,7 +84,7 @@ cfg_metrics! { pub(crate) fn worker_local_queue_depth(&self, worker: usize) -> usize { match self { Spawner::Basic(spawner) => spawner.worker_metrics(worker).queue_depth(), - #[cfg(feature = "rt-multi-thread")] + #[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] Spawner::ThreadPool(spawner) => spawner.worker_local_queue_depth(worker), } } diff --git a/tokio/src/sync/tests/atomic_waker.rs b/tokio/src/sync/tests/atomic_waker.rs index ec13cbd6585..34bb9fbe782 100644 --- a/tokio/src/sync/tests/atomic_waker.rs +++ b/tokio/src/sync/tests/atomic_waker.rs @@ -12,7 +12,7 @@ impl AssertSync for AtomicWaker {} impl AssertSend for Waker {} impl AssertSync for Waker {} -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; #[test] diff --git a/tokio/src/sync/tests/notify.rs b/tokio/src/sync/tests/notify.rs index 20153b7a5a8..858752b6fe5 100644 --- a/tokio/src/sync/tests/notify.rs +++ b/tokio/src/sync/tests/notify.rs @@ -4,7 +4,7 @@ use std::mem::ManuallyDrop; use std::sync::Arc; use std::task::{Context, RawWaker, RawWakerVTable, Waker}; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; #[test] diff --git a/tokio/src/sync/tests/semaphore_batch.rs b/tokio/src/sync/tests/semaphore_batch.rs index d529a9e8869..103e09dea4f 100644 --- a/tokio/src/sync/tests/semaphore_batch.rs +++ b/tokio/src/sync/tests/semaphore_batch.rs @@ -1,7 +1,7 @@ use crate::sync::batch_semaphore::Semaphore; use tokio_test::*; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; #[test] diff --git a/tokio/src/time/driver/tests/mod.rs b/tokio/src/time/driver/tests/mod.rs index 3ac8c756437..005a2386ae3 100644 --- a/tokio/src/time/driver/tests/mod.rs +++ b/tokio/src/time/driver/tests/mod.rs @@ -1,3 +1,5 @@ +#![cfg(not(target_os = "wasi"))] + use std::{task::Context, time::Duration}; #[cfg(not(loom))] diff --git a/tokio/tests/async_send_sync.rs b/tokio/tests/async_send_sync.rs index 1f53d0db960..a6b963d90be 100644 --- a/tokio/tests/async_send_sync.rs +++ b/tokio/tests/async_send_sync.rs @@ -127,70 +127,95 @@ macro_rules! assert_value { }; } -assert_value!(tokio::fs::DirBuilder: Send & Sync & Unpin); -assert_value!(tokio::fs::DirEntry: Send & Sync & Unpin); -assert_value!(tokio::fs::File: Send & Sync & Unpin); -assert_value!(tokio::fs::OpenOptions: Send & Sync & Unpin); -assert_value!(tokio::fs::ReadDir: Send & Sync & Unpin); - -async_assert_fn!(tokio::fs::canonicalize(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::copy(&str, &str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::create_dir(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::create_dir_all(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::hard_link(&str, &str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::metadata(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::read(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::read_dir(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::read_link(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::read_to_string(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::remove_dir(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::remove_dir_all(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::remove_file(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::rename(&str, &str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::set_permissions(&str, std::fs::Permissions): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::symlink_metadata(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::write(&str, Vec): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::ReadDir::next_entry(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::OpenOptions::open(_, &str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::DirBuilder::create(_, &str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::DirEntry::metadata(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::DirEntry::file_type(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::File::open(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::File::create(&str): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::File::sync_all(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::File::sync_data(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::File::set_len(_, u64): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::File::metadata(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::File::try_clone(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::File::into_std(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::fs::File::set_permissions(_, std::fs::Permissions): Send & Sync & !Unpin); +macro_rules! cfg_not_wasi { + ($($item:item)*) => { + $( + #[cfg(not(target_os = "wasi"))] + $item + )* + } +} + +cfg_not_wasi! { + mod fs { + use super::*; + assert_value!(tokio::fs::DirBuilder: Send & Sync & Unpin); + assert_value!(tokio::fs::DirEntry: Send & Sync & Unpin); + assert_value!(tokio::fs::File: Send & Sync & Unpin); + assert_value!(tokio::fs::OpenOptions: Send & Sync & Unpin); + assert_value!(tokio::fs::ReadDir: Send & Sync & Unpin); + + async_assert_fn!(tokio::fs::canonicalize(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::copy(&str, &str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::create_dir(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::create_dir_all(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::hard_link(&str, &str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::metadata(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::read(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::read_dir(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::read_link(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::read_to_string(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::remove_dir(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::remove_dir_all(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::remove_file(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::rename(&str, &str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::set_permissions(&str, std::fs::Permissions): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::symlink_metadata(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::write(&str, Vec): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::ReadDir::next_entry(_): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::OpenOptions::open(_, &str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::DirBuilder::create(_, &str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::DirEntry::metadata(_): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::DirEntry::file_type(_): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::File::open(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::File::create(&str): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::File::sync_all(_): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::File::sync_data(_): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::File::set_len(_, u64): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::File::metadata(_): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::File::try_clone(_): Send & Sync & !Unpin); + async_assert_fn!(tokio::fs::File::into_std(_): Send & Sync & !Unpin); + async_assert_fn!( + tokio::fs::File::set_permissions(_, std::fs::Permissions): Send & Sync & !Unpin + ); + } +} + +cfg_not_wasi! { + assert_value!(tokio::net::TcpSocket: Send & Sync & Unpin); + async_assert_fn!(tokio::net::TcpListener::bind(SocketAddr): Send & Sync & !Unpin); + async_assert_fn!(tokio::net::TcpStream::connect(SocketAddr): Send & Sync & !Unpin); +} assert_value!(tokio::net::TcpListener: Send & Sync & Unpin); -assert_value!(tokio::net::TcpSocket: Send & Sync & Unpin); assert_value!(tokio::net::TcpStream: Send & Sync & Unpin); -assert_value!(tokio::net::UdpSocket: Send & Sync & Unpin); assert_value!(tokio::net::tcp::OwnedReadHalf: Send & Sync & Unpin); assert_value!(tokio::net::tcp::OwnedWriteHalf: Send & Sync & Unpin); assert_value!(tokio::net::tcp::ReadHalf<'_>: Send & Sync & Unpin); assert_value!(tokio::net::tcp::ReuniteError: Send & Sync & Unpin); assert_value!(tokio::net::tcp::WriteHalf<'_>: Send & Sync & Unpin); async_assert_fn!(tokio::net::TcpListener::accept(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::net::TcpListener::bind(SocketAddr): Send & Sync & !Unpin); -async_assert_fn!(tokio::net::TcpStream::connect(SocketAddr): Send & Sync & !Unpin); async_assert_fn!(tokio::net::TcpStream::peek(_, &mut [u8]): Send & Sync & !Unpin); async_assert_fn!(tokio::net::TcpStream::readable(_): Send & Sync & !Unpin); async_assert_fn!(tokio::net::TcpStream::ready(_, tokio::io::Interest): Send & Sync & !Unpin); async_assert_fn!(tokio::net::TcpStream::writable(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::net::UdpSocket::bind(SocketAddr): Send & Sync & !Unpin); -async_assert_fn!(tokio::net::UdpSocket::connect(_, SocketAddr): Send & Sync & !Unpin); -async_assert_fn!(tokio::net::UdpSocket::peek_from(_, &mut [u8]): Send & Sync & !Unpin); -async_assert_fn!(tokio::net::UdpSocket::readable(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::net::UdpSocket::ready(_, tokio::io::Interest): Send & Sync & !Unpin); -async_assert_fn!(tokio::net::UdpSocket::recv(_, &mut [u8]): Send & Sync & !Unpin); -async_assert_fn!(tokio::net::UdpSocket::recv_from(_, &mut [u8]): Send & Sync & !Unpin); -async_assert_fn!(tokio::net::UdpSocket::send(_, &[u8]): Send & Sync & !Unpin); -async_assert_fn!(tokio::net::UdpSocket::send_to(_, &[u8], SocketAddr): Send & Sync & !Unpin); -async_assert_fn!(tokio::net::UdpSocket::writable(_): Send & Sync & !Unpin); + +cfg_not_wasi! { + mod udp_socket { + use super::*; + assert_value!(tokio::net::UdpSocket: Send & Sync & Unpin); + async_assert_fn!(tokio::net::UdpSocket::bind(SocketAddr): Send & Sync & !Unpin); + async_assert_fn!(tokio::net::UdpSocket::connect(_, SocketAddr): Send & Sync & !Unpin); + async_assert_fn!(tokio::net::UdpSocket::peek_from(_, &mut [u8]): Send & Sync & !Unpin); + async_assert_fn!(tokio::net::UdpSocket::readable(_): Send & Sync & !Unpin); + async_assert_fn!(tokio::net::UdpSocket::ready(_, tokio::io::Interest): Send & Sync & !Unpin); + async_assert_fn!(tokio::net::UdpSocket::recv(_, &mut [u8]): Send & Sync & !Unpin); + async_assert_fn!(tokio::net::UdpSocket::recv_from(_, &mut [u8]): Send & Sync & !Unpin); + async_assert_fn!(tokio::net::UdpSocket::send(_, &[u8]): Send & Sync & !Unpin); + async_assert_fn!(tokio::net::UdpSocket::send_to(_, &[u8], SocketAddr): Send & Sync & !Unpin); + async_assert_fn!(tokio::net::UdpSocket::writable(_): Send & Sync & !Unpin); + } +} async_assert_fn!(tokio::net::lookup_host(SocketAddr): Send & Sync & !Unpin); async_assert_fn!(tokio::net::tcp::ReadHalf::peek(_, &mut [u8]): Send & Sync & !Unpin); @@ -242,16 +267,22 @@ mod windows_named_pipe { async_assert_fn!(NamedPipeServer::writable(_): Send & Sync & !Unpin); } -assert_value!(tokio::process::Child: Send & Sync & Unpin); -assert_value!(tokio::process::ChildStderr: Send & Sync & Unpin); -assert_value!(tokio::process::ChildStdin: Send & Sync & Unpin); -assert_value!(tokio::process::ChildStdout: Send & Sync & Unpin); -assert_value!(tokio::process::Command: Send & Sync & Unpin); -async_assert_fn!(tokio::process::Child::kill(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::process::Child::wait(_): Send & Sync & !Unpin); -async_assert_fn!(tokio::process::Child::wait_with_output(_): Send & Sync & !Unpin); +cfg_not_wasi! { + mod test_process { + use super::*; + assert_value!(tokio::process::Child: Send & Sync & Unpin); + assert_value!(tokio::process::ChildStderr: Send & Sync & Unpin); + assert_value!(tokio::process::ChildStdin: Send & Sync & Unpin); + assert_value!(tokio::process::ChildStdout: Send & Sync & Unpin); + assert_value!(tokio::process::Command: Send & Sync & Unpin); + async_assert_fn!(tokio::process::Child::kill(_): Send & Sync & !Unpin); + async_assert_fn!(tokio::process::Child::wait(_): Send & Sync & !Unpin); + async_assert_fn!(tokio::process::Child::wait_with_output(_): Send & Sync & !Unpin); + } + + async_assert_fn!(tokio::signal::ctrl_c(): Send & Sync & !Unpin); +} -async_assert_fn!(tokio::signal::ctrl_c(): Send & Sync & !Unpin); #[cfg(unix)] mod unix_signal { use super::*; diff --git a/tokio/tests/buffered.rs b/tokio/tests/buffered.rs index 98b6d5f3121..45d9016de08 100644 --- a/tokio/tests/buffered.rs +++ b/tokio/tests/buffered.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::net::TcpListener; use tokio_test::assert_ok; diff --git a/tokio/tests/fs.rs b/tokio/tests/fs.rs index 13c44c08d6a..0a15a081c88 100644 --- a/tokio/tests/fs.rs +++ b/tokio/tests/fs.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::fs; use tokio_test::assert_ok; diff --git a/tokio/tests/fs_copy.rs b/tokio/tests/fs_copy.rs index 8d1632013ea..813b344232c 100644 --- a/tokio/tests/fs_copy.rs +++ b/tokio/tests/fs_copy.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tempfile::tempdir; use tokio::fs; diff --git a/tokio/tests/fs_dir.rs b/tokio/tests/fs_dir.rs index 21efe8c0eeb..1f3c217633e 100644 --- a/tokio/tests/fs_dir.rs +++ b/tokio/tests/fs_dir.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::fs; use tokio_test::{assert_err, assert_ok}; diff --git a/tokio/tests/fs_file.rs b/tokio/tests/fs_file.rs index f645e61aeda..7fb107aea19 100644 --- a/tokio/tests/fs_file.rs +++ b/tokio/tests/fs_file.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::io::prelude::*; use tempfile::NamedTempFile; diff --git a/tokio/tests/fs_link.rs b/tokio/tests/fs_link.rs index 2ef666fb2f6..be7e3ca8863 100644 --- a/tokio/tests/fs_link.rs +++ b/tokio/tests/fs_link.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::fs; diff --git a/tokio/tests/io_buf_reader.rs b/tokio/tests/io_buf_reader.rs index 0d3f6bafc20..0a02ad49118 100644 --- a/tokio/tests/io_buf_reader.rs +++ b/tokio/tests/io_buf_reader.rs @@ -222,6 +222,8 @@ async fn test_short_reads() { assert_eq!(reader.read(&mut buf).await.unwrap(), 0); } +// https://github.com/tokio-rs/mio/pull/1580 +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn maybe_pending() { let inner: &[u8] = &[5, 6, 7, 0, 1, 2, 3, 4]; @@ -259,6 +261,7 @@ async fn maybe_pending() { assert_eq!(reader.read(&mut buf).await.unwrap(), 0); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn maybe_pending_buf_read() { let inner = MaybePending::new(&[0, 1, 2, 3, 1, 0]); @@ -278,6 +281,7 @@ async fn maybe_pending_buf_read() { } // https://github.com/rust-lang/futures-rs/pull/1573#discussion_r281162309 +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn maybe_pending_seek() { struct MaybePendingSeek<'a> { diff --git a/tokio/tests/io_buf_writer.rs b/tokio/tests/io_buf_writer.rs index 47a0d466f49..3bb82c10afd 100644 --- a/tokio/tests/io_buf_writer.rs +++ b/tokio/tests/io_buf_writer.rs @@ -131,6 +131,8 @@ async fn buf_writer_seek() { assert_eq!(&w.into_inner().into_inner()[..], &[0, 1, 8, 9, 4, 5, 6, 7]); } +// https://github.com/tokio-rs/mio/pull/1580 +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn maybe_pending_buf_writer() { let mut writer = BufWriter::with_capacity(2, MaybePending::new(Vec::new())); @@ -179,6 +181,7 @@ async fn maybe_pending_buf_writer() { ); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn maybe_pending_buf_writer_inner_flushes() { let mut w = BufWriter::with_capacity(3, MaybePending::new(Vec::new())); @@ -189,6 +192,7 @@ async fn maybe_pending_buf_writer_inner_flushes() { assert_eq!(w, [0, 1]); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn maybe_pending_buf_writer_seek() { struct MaybePendingSeek { diff --git a/tokio/tests/io_copy.rs b/tokio/tests/io_copy.rs index 005e1701191..ed28b256e0f 100644 --- a/tokio/tests/io_copy.rs +++ b/tokio/tests/io_copy.rs @@ -37,6 +37,8 @@ async fn copy() { assert_eq!(wr, b"hello world"); } +// https://github.com/tokio-rs/mio/pull/1580 +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn proxy() { struct BufferedWd { diff --git a/tokio/tests/io_copy_bidirectional.rs b/tokio/tests/io_copy_bidirectional.rs index 0e82b29ea69..160e523e16a 100644 --- a/tokio/tests/io_copy_bidirectional.rs +++ b/tokio/tests/io_copy_bidirectional.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::time::Duration; use tokio::io::{self, copy_bidirectional, AsyncReadExt, AsyncWriteExt}; diff --git a/tokio/tests/io_driver.rs b/tokio/tests/io_driver.rs index 6fb566de582..f9efd0d8d79 100644 --- a/tokio/tests/io_driver.rs +++ b/tokio/tests/io_driver.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::net::TcpListener; use tokio::runtime; diff --git a/tokio/tests/io_driver_drop.rs b/tokio/tests/io_driver_drop.rs index 631e66e9fbe..d5891e59ec1 100644 --- a/tokio/tests/io_driver_drop.rs +++ b/tokio/tests/io_driver_drop.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::net::TcpListener; use tokio::runtime; diff --git a/tokio/tests/io_fill_buf.rs b/tokio/tests/io_fill_buf.rs index 0b2ebd78fc7..e7b3bdcf96f 100644 --- a/tokio/tests/io_fill_buf.rs +++ b/tokio/tests/io_fill_buf.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tempfile::NamedTempFile; use tokio::fs::File; diff --git a/tokio/tests/io_mem_stream.rs b/tokio/tests/io_mem_stream.rs index a2c2dadfc90..df756268213 100644 --- a/tokio/tests/io_mem_stream.rs +++ b/tokio/tests/io_mem_stream.rs @@ -18,6 +18,8 @@ async fn ping_pong() { assert_eq!(&buf, b"pong"); } +// https://github.com/tokio-rs/mio/pull/1580 +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn across_tasks() { let (mut a, mut b) = duplex(32); @@ -40,6 +42,7 @@ async fn across_tasks() { t2.await.unwrap(); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn disconnect() { let (mut a, mut b) = duplex(32); @@ -62,6 +65,7 @@ async fn disconnect() { t2.await.unwrap(); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn disconnect_reader() { let (a, mut b) = duplex(2); @@ -81,6 +85,7 @@ async fn disconnect_reader() { t1.await.unwrap(); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn max_write_size() { let (mut a, mut b) = duplex(32); @@ -101,6 +106,7 @@ async fn max_write_size() { drop(b); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn duplex_is_cooperative() { let (mut tx, mut rx) = tokio::io::duplex(1024 * 8); diff --git a/tokio/tests/io_util_empty.rs b/tokio/tests/io_util_empty.rs index e49cd17fcd5..8a1bea093b4 100644 --- a/tokio/tests/io_util_empty.rs +++ b/tokio/tests/io_util_empty.rs @@ -1,6 +1,8 @@ #![cfg(feature = "full")] use tokio::io::{AsyncBufReadExt, AsyncReadExt}; +// https://github.com/tokio-rs/mio/pull/1580 +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn empty_read_is_cooperative() { tokio::select! { @@ -16,6 +18,7 @@ async fn empty_read_is_cooperative() { } } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn empty_buf_reads_are_cooperative() { tokio::select! { diff --git a/tokio/tests/join_handle_panic.rs b/tokio/tests/join_handle_panic.rs index f7de92d4178..0e0375c6781 100644 --- a/tokio/tests/join_handle_panic.rs +++ b/tokio/tests/join_handle_panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] struct PanicsOnDrop; diff --git a/tokio/tests/macros_join.rs b/tokio/tests/macros_join.rs index 56bd9c58f3c..03a3f8877a6 100644 --- a/tokio/tests/macros_join.rs +++ b/tokio/tests/macros_join.rs @@ -2,12 +2,12 @@ #![allow(clippy::blacklisted_name)] use std::sync::Arc; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use tokio::sync::{oneshot, Semaphore}; @@ -82,6 +82,7 @@ fn join_size() { assert_eq!(mem::size_of_val(&fut), 32); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] async fn non_cooperative_task(permits: Arc) -> usize { let mut exceeded_budget = 0; @@ -97,6 +98,7 @@ async fn non_cooperative_task(permits: Arc) -> usize { exceeded_budget } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] async fn poor_little_task(permits: Arc) -> usize { let mut how_many_times_i_got_to_run = 0; @@ -108,6 +110,7 @@ async fn poor_little_task(permits: Arc) -> usize { how_many_times_i_got_to_run } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test] async fn join_does_not_allow_tasks_to_starve() { let permits = Arc::new(Semaphore::new(1)); @@ -122,6 +125,7 @@ async fn join_does_not_allow_tasks_to_starve() { assert_eq!(5, little_task_result); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test] async fn a_different_future_is_polled_first_every_time_poll_fn_is_polled() { let poll_order = Arc::new(std::sync::Mutex::new(vec![])); diff --git a/tokio/tests/macros_pin.rs b/tokio/tests/macros_pin.rs index 70c95a1c823..001528ddeb0 100644 --- a/tokio/tests/macros_pin.rs +++ b/tokio/tests/macros_pin.rs @@ -1,9 +1,9 @@ #![cfg(feature = "macros")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; async fn one() {} diff --git a/tokio/tests/macros_rename_test.rs b/tokio/tests/macros_rename_test.rs index fd5554ced1f..cccaa85d346 100644 --- a/tokio/tests/macros_rename_test.rs +++ b/tokio/tests/macros_rename_test.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] #[allow(unused_imports)] use std as tokio; diff --git a/tokio/tests/macros_select.rs b/tokio/tests/macros_select.rs index c60a4a9506f..c2dfc345e1a 100644 --- a/tokio/tests/macros_select.rs +++ b/tokio/tests/macros_select.rs @@ -1,10 +1,10 @@ #![cfg(feature = "macros")] #![allow(clippy::blacklisted_name)] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use tokio::sync::oneshot; @@ -125,7 +125,9 @@ async fn one_ready() { assert_eq!(1, v); } +// https://github.com/tokio-rs/mio/pull/1580 #[maybe_tokio_test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn select_streams() { use tokio::sync::mpsc; diff --git a/tokio/tests/macros_test.rs b/tokio/tests/macros_test.rs index c5d9d9f9b01..164c06413a0 100644 --- a/tokio/tests/macros_test.rs +++ b/tokio/tests/macros_test.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::test; diff --git a/tokio/tests/macros_try_join.rs b/tokio/tests/macros_try_join.rs index 556436d2207..7a755360f8c 100644 --- a/tokio/tests/macros_try_join.rs +++ b/tokio/tests/macros_try_join.rs @@ -6,10 +6,10 @@ use std::sync::Arc; use tokio::sync::{oneshot, Semaphore}; use tokio_test::{assert_pending, assert_ready, task}; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; #[maybe_tokio_test] @@ -137,6 +137,7 @@ async fn poor_little_task(permits: Arc) -> Result { Ok(how_many_times_i_got_to_run) } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test] async fn try_join_does_not_allow_tasks_to_starve() { let permits = Arc::new(Semaphore::new(10)); @@ -153,6 +154,7 @@ async fn try_join_does_not_allow_tasks_to_starve() { assert_eq!(5, little_task_result); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test] async fn a_different_future_is_polled_first_every_time_poll_fn_is_polled() { let poll_order = Arc::new(std::sync::Mutex::new(vec![])); diff --git a/tokio/tests/net_lookup_host.rs b/tokio/tests/net_lookup_host.rs index 44c8e19e0d8..8a85bb8d326 100644 --- a/tokio/tests/net_lookup_host.rs +++ b/tokio/tests/net_lookup_host.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::net; use tokio_test::assert_ok; diff --git a/tokio/tests/no_rt.rs b/tokio/tests/no_rt.rs index 64e56f4d43b..2bd304eea77 100644 --- a/tokio/tests/no_rt.rs +++ b/tokio/tests/no_rt.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::net::TcpStream; use tokio::sync::oneshot; diff --git a/tokio/tests/process_smoke.rs b/tokio/tests/process_smoke.rs index fae5793fab7..5662308077d 100644 --- a/tokio/tests/process_smoke.rs +++ b/tokio/tests/process_smoke.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::process::Command; use tokio_test::assert_ok; diff --git a/tokio/tests/rt_basic.rs b/tokio/tests/rt_basic.rs index 50b7e9732a5..026c63a7ae5 100644 --- a/tokio/tests/rt_basic.rs +++ b/tokio/tests/rt_basic.rs @@ -25,6 +25,8 @@ macro_rules! cfg_metrics { } } +// https://github.com/tokio-rs/mio/pull/1580 +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawned_task_does_not_progress_without_block_on() { let (tx, mut rx) = oneshot::channel(); @@ -44,6 +46,7 @@ fn spawned_task_does_not_progress_without_block_on() { assert_eq!(out, "hello"); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn no_extra_poll() { use pin_project_lite::pin_project; @@ -112,6 +115,7 @@ fn no_extra_poll() { assert_eq!(npolls.load(SeqCst), 1 + 2 + 1); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn acquire_mutex_in_drop() { use futures::future::pending; @@ -206,6 +210,7 @@ fn wake_in_drop_after_panic() { }); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawn_two() { let rt = rt(); @@ -238,6 +243,7 @@ fn spawn_two() { } } +#[cfg_attr(target_os = "wasi", ignore = "WASI: std::thread::spawn not supported")] #[test] fn spawn_remote() { let rt = rt(); diff --git a/tokio/tests/rt_common.rs b/tokio/tests/rt_common.rs index 14e19095933..14ee7d2fcd6 100644 --- a/tokio/tests/rt_common.rs +++ b/tokio/tests/rt_common.rs @@ -18,6 +18,7 @@ macro_rules! rt_test { } } + #[cfg(not(target_os = "wasi"))] mod threaded_scheduler_4_threads { $($t)* @@ -31,6 +32,7 @@ macro_rules! rt_test { } } + #[cfg(not(target_os = "wasi"))] mod threaded_scheduler_1_thread { $($t)* @@ -55,18 +57,30 @@ fn send_sync_bound() { } rt_test! { - use tokio::net::{TcpListener, TcpStream, UdpSocket}; + #[cfg(not(target_os="wasi"))] + use tokio::net::{TcpListener, TcpStream}; + #[cfg(not(target_os="wasi"))] use tokio::io::{AsyncReadExt, AsyncWriteExt}; + use tokio::runtime::Runtime; use tokio::sync::oneshot; use tokio::{task, time}; - use tokio_test::{assert_err, assert_ok}; + + #[cfg(not(target_os="wasi"))] + use tokio_test::assert_err; + use tokio_test::assert_ok; use futures::future::poll_fn; use std::future::Future; use std::pin::Pin; - use std::sync::{mpsc, Arc}; + + #[cfg(not(target_os="wasi"))] + use std::sync::mpsc; + + use std::sync::Arc; use std::task::{Context, Poll}; + + #[cfg(not(target_os="wasi"))] use std::thread; use std::time::{Duration, Instant}; @@ -83,6 +97,7 @@ rt_test! { } + #[cfg(not(target_os="wasi"))] #[test] fn block_on_async() { let rt = rt(); @@ -101,6 +116,8 @@ rt_test! { assert_eq!(out, "ZOMG"); } + // https://github.com/tokio-rs/mio/pull/1580 + #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawn_one_bg() { let rt = rt(); @@ -118,6 +135,7 @@ rt_test! { assert_eq!(out, "ZOMG"); } + #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawn_one_join() { let rt = rt(); @@ -141,6 +159,7 @@ rt_test! { assert_eq!(out, "ZOMG"); } + #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawn_two() { let rt = rt(); @@ -164,6 +183,7 @@ rt_test! { assert_eq!(out, "ZOMG"); } + #[cfg(not(target_os="wasi"))] #[test] fn spawn_many_from_block_on() { use tokio::sync::mpsc; @@ -214,6 +234,7 @@ rt_test! { } } + #[cfg(not(target_os="wasi"))] #[test] fn spawn_many_from_task() { use tokio::sync::mpsc; @@ -274,6 +295,7 @@ rt_test! { } } + #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawn_await_chain() { let rt = rt(); @@ -329,6 +351,7 @@ rt_test! { assert_eq!(out, "ZOMG"); } + #[cfg(not(target_os="wasi"))] #[test] fn complete_block_on_under_load() { let rt = rt(); @@ -352,6 +375,7 @@ rt_test! { }); } + #[cfg(not(target_os="wasi"))] #[test] fn complete_task_under_load() { let rt = rt(); @@ -381,6 +405,7 @@ rt_test! { }); } + #[cfg(not(target_os="wasi"))] #[test] fn spawn_from_other_thread_idle() { let rt = rt(); @@ -401,6 +426,7 @@ rt_test! { }); } + #[cfg(not(target_os="wasi"))] #[test] fn spawn_from_other_thread_under_load() { let rt = rt(); @@ -440,6 +466,7 @@ rt_test! { assert!(now.elapsed() >= dur); } + #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn sleep_in_spawn() { let rt = rt(); @@ -461,6 +488,7 @@ rt_test! { assert!(now.elapsed() >= dur); } + #[cfg(not(target_os="wasi"))] #[test] fn block_on_socket() { let rt = rt(); @@ -481,6 +509,7 @@ rt_test! { }); } + #[cfg(not(target_os="wasi"))] #[test] fn spawn_from_blocking() { let rt = rt(); @@ -496,6 +525,7 @@ rt_test! { assert_eq!(out, "hello") } + #[cfg(not(target_os="wasi"))] #[test] fn spawn_blocking_from_blocking() { let rt = rt(); @@ -511,6 +541,7 @@ rt_test! { assert_eq!(out, "hello") } + #[cfg(not(target_os="wasi"))] #[test] fn sleep_from_blocking() { let rt = rt(); @@ -531,6 +562,7 @@ rt_test! { }); } + #[cfg(not(target_os="wasi"))] #[test] fn socket_from_blocking() { let rt = rt(); @@ -554,6 +586,7 @@ rt_test! { }); } + #[cfg(not(target_os="wasi"))] #[test] fn always_active_parker() { // This test it to show that we will always have @@ -600,6 +633,7 @@ rt_test! { // concern. There also isn't a great/obvious solution to take. For now, the // test is disabled. #[cfg(not(windows))] + #[cfg(not(target_os="wasi"))] fn io_driver_called_when_under_load() { let rt = rt(); @@ -635,6 +669,7 @@ rt_test! { }); } + #[cfg(not(target_os="wasi"))] #[test] fn client_server_block_on() { let rt = rt(); @@ -646,6 +681,7 @@ rt_test! { assert_err!(rx.try_recv()); } + #[cfg(not(target_os="wasi"))] #[test] fn panic_in_task() { let rt = rt(); @@ -679,6 +715,7 @@ rt_test! { rt.block_on(async { panic!() }); } + #[cfg(not(target_os = "wasi"))] async fn yield_once() { let mut yielded = false; poll_fn(|cx| { @@ -693,6 +730,7 @@ rt_test! { .await } + #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn enter_and_spawn() { let rt = rt(); @@ -704,6 +742,7 @@ rt_test! { assert_ok!(rt.block_on(handle)); } + #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn eagerly_drops_futures_on_shutdown() { use std::sync::mpsc; @@ -746,6 +785,7 @@ rt_test! { assert_ok!(drop_rx.recv()); } + #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn wake_while_rt_is_dropping() { use tokio::sync::Barrier; @@ -816,8 +856,10 @@ rt_test! { assert!(drop_triggered.load(Ordering::Relaxed)); } + #[cfg(not(target_os="wasi"))] #[test] fn io_notify_while_shutting_down() { + use tokio::net::UdpSocket; use std::net::Ipv6Addr; use std::sync::Arc; @@ -851,6 +893,7 @@ rt_test! { } } + #[cfg(not(target_os="wasi"))] #[test] fn shutdown_timeout() { let (tx, rx) = oneshot::channel(); @@ -868,6 +911,7 @@ rt_test! { Arc::try_unwrap(runtime).unwrap().shutdown_timeout(Duration::from_millis(100)); } + #[cfg(not(target_os="wasi"))] #[test] fn shutdown_timeout_0() { let runtime = rt(); @@ -899,6 +943,7 @@ rt_test! { // See https://github.com/rust-lang/rust/issues/74875 #[test] #[cfg(not(windows))] + #[cfg(not(target_os="wasi"))] fn runtime_in_thread_local() { use std::cell::RefCell; use std::thread; @@ -918,6 +963,7 @@ rt_test! { }).join().unwrap(); } + #[cfg(not(target_os="wasi"))] async fn client_server(tx: mpsc::Sender<()>) { let server = assert_ok!(TcpListener::bind("127.0.0.1:0").await); @@ -942,6 +988,7 @@ rt_test! { tx.send(()).unwrap(); } + #[cfg(not(target_os="wasi"))] #[test] fn local_set_block_on_socket() { let rt = rt(); @@ -963,6 +1010,7 @@ rt_test! { }); } + #[cfg(not(target_os="wasi"))] #[test] fn local_set_client_server_block_on() { let rt = rt(); @@ -976,6 +1024,7 @@ rt_test! { assert_err!(rx.try_recv()); } + #[cfg(not(target_os="wasi"))] async fn client_server_local(tx: mpsc::Sender<()>) { let server = assert_ok!(TcpListener::bind("127.0.0.1:0").await); @@ -1081,6 +1130,7 @@ rt_test! { // Tests that the "next task" scheduler optimization is not able to starve // other tasks. + #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn ping_pong_saturation() { use std::sync::atomic::{Ordering, AtomicBool}; diff --git a/tokio/tests/rt_handle_block_on.rs b/tokio/tests/rt_handle_block_on.rs index 5c1d533a010..a43c637e76a 100644 --- a/tokio/tests/rt_handle_block_on.rs +++ b/tokio/tests/rt_handle_block_on.rs @@ -10,9 +10,10 @@ use std::time::Duration; use tokio::runtime::{Handle, Runtime}; use tokio::sync::mpsc; -use tokio::task::spawn_blocking; -use tokio::{fs, net, time}; +#[cfg(not(target_os = "wasi"))] +use tokio::{net, time}; +#[cfg(not(target_os = "wasi"))] macro_rules! multi_threaded_rt_test { ($($t:tt)*) => { mod threaded_scheduler_4_threads_only { @@ -45,6 +46,7 @@ macro_rules! multi_threaded_rt_test { } } +#[cfg(not(target_os = "wasi"))] macro_rules! rt_test { ($($t:tt)*) => { mod current_thread_scheduler { @@ -124,7 +126,9 @@ fn unbounded_mpsc_channel() { }) } +#[cfg(not(target_os = "wasi"))] rt_test! { + use tokio::fs; // ==== spawn blocking futures ====== #[test] @@ -156,6 +160,7 @@ rt_test! { #[test] fn basic_spawn_blocking() { + use tokio::task::spawn_blocking; let rt = rt(); let _enter = rt.enter(); @@ -171,6 +176,7 @@ rt_test! { #[test] fn spawn_blocking_after_shutdown_fails() { + use tokio::task::spawn_blocking; let rt = rt(); let _enter = rt.enter(); rt.shutdown_timeout(Duration::from_secs(1000)); @@ -187,6 +193,7 @@ rt_test! { #[test] fn spawn_blocking_started_before_shutdown_continues() { + use tokio::task::spawn_blocking; let rt = rt(); let _enter = rt.enter(); @@ -412,6 +419,7 @@ rt_test! { } } +#[cfg(not(target_os = "wasi"))] multi_threaded_rt_test! { #[cfg(unix)] #[test] @@ -474,6 +482,7 @@ multi_threaded_rt_test! { // ==== utils ====== /// Create a new multi threaded runtime +#[cfg(not(target_os = "wasi"))] fn new_multi_thread(n: usize) -> Runtime { tokio::runtime::Builder::new_multi_thread() .worker_threads(n) @@ -507,6 +516,7 @@ where f(); } + #[cfg(not(target_os = "wasi"))] { println!("multi thread (1 thread) runtime"); @@ -519,6 +529,7 @@ where f(); } + #[cfg(not(target_os = "wasi"))] { println!("multi thread (4 threads) runtime"); diff --git a/tokio/tests/rt_panic.rs b/tokio/tests/rt_panic.rs index 90014736211..112a7336881 100644 --- a/tokio/tests/rt_panic.rs +++ b/tokio/tests/rt_panic.rs @@ -1,5 +1,6 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "full")] +#![cfg(not(target_os = "wasi"))] use futures::future; use std::error::Error; diff --git a/tokio/tests/rt_threaded.rs b/tokio/tests/rt_threaded.rs index b2f84fd33ff..413024201ff 100644 --- a/tokio/tests/rt_threaded.rs +++ b/tokio/tests/rt_threaded.rs @@ -1,12 +1,17 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "full")] +#[cfg(not(target_os = "wasi"))] use tokio::io::{AsyncReadExt, AsyncWriteExt}; +#[cfg(not(target_os = "wasi"))] use tokio::net::{TcpListener, TcpStream}; -use tokio::runtime::{self, Runtime}; +use tokio::runtime; use tokio::sync::oneshot; -use tokio_test::{assert_err, assert_ok}; +#[cfg(not(target_os = "wasi"))] +use tokio_test::assert_err; +use tokio_test::assert_ok; +#[cfg(not(target_os = "wasi"))] use futures::future::poll_fn; use std::future::Future; use std::pin::Pin; @@ -24,6 +29,7 @@ macro_rules! cfg_metrics { } } +#[cfg(not(target_os = "wasi"))] #[test] fn single_thread() { // No panic when starting a runtime w/ a single thread @@ -33,6 +39,10 @@ fn single_thread() { .build(); } +#[cfg_attr( + target_os = "wasi", + ignore = "WASI: std::mpsc without thread parking not working" +)] #[test] fn many_oneshot_futures() { // used for notifying the main thread @@ -64,6 +74,8 @@ fn many_oneshot_futures() { } } +// https://github.com/tokio-rs/mio/pull/1580 +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawn_two() { let rt = rt(); @@ -160,6 +172,7 @@ fn many_multishot_futures() { } } +#[cfg(not(target_os = "wasi"))] #[test] fn spawn_shutdown() { let rt = rt(); @@ -179,6 +192,7 @@ fn spawn_shutdown() { assert_err!(rx.try_recv()); } +#[cfg(not(target_os = "wasi"))] async fn client_server(tx: mpsc::Sender<()>) { let server = assert_ok!(TcpListener::bind("127.0.0.1:0").await); @@ -203,6 +217,7 @@ async fn client_server(tx: mpsc::Sender<()>) { tx.send(()).unwrap(); } +#[cfg(not(target_os = "wasi"))] #[test] fn drop_threadpool_drops_futures() { for _ in 0..1_000 { @@ -259,6 +274,7 @@ fn drop_threadpool_drops_futures() { } } +#[cfg(not(target_os = "wasi"))] #[test] fn start_stop_callbacks_called() { use std::sync::atomic::{AtomicUsize, Ordering}; @@ -293,6 +309,7 @@ fn start_stop_callbacks_called() { assert!(before_stop.load(Ordering::Relaxed) > 0); } +#[cfg(not(target_os = "wasi"))] #[test] fn blocking() { // used for notifying the main thread @@ -338,6 +355,7 @@ fn blocking() { } } +#[cfg(not(target_os = "wasi"))] #[test] fn multi_threadpool() { use tokio::sync::oneshot; @@ -366,6 +384,7 @@ fn multi_threadpool() { // // The test ensures that, when this happens, attempting to consume from a // channel yields occasionally even if there are values ready to receive. +#[cfg(not(target_os = "wasi"))] #[test] fn coop_and_block_in_place() { let rt = tokio::runtime::Builder::new_multi_thread() @@ -416,6 +435,7 @@ fn coop_and_block_in_place() { } // Testing this does not panic +#[cfg(not(target_os = "wasi"))] #[test] fn max_blocking_threads() { let _rt = tokio::runtime::Builder::new_multi_thread() @@ -424,6 +444,7 @@ fn max_blocking_threads() { .unwrap(); } +#[cfg(not(target_os = "wasi"))] #[test] #[should_panic] fn max_blocking_threads_set_to_zero() { @@ -433,6 +454,7 @@ fn max_blocking_threads_set_to_zero() { .unwrap(); } +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn hang_on_shutdown() { let (sync_tx, sync_rx) = std::sync::mpsc::channel::<()>(); @@ -501,12 +523,19 @@ fn wake_during_shutdown() { } } + #[cfg(not(target_os = "wasi"))] let rt = tokio::runtime::Builder::new_multi_thread() .worker_threads(1) .enable_all() .build() .unwrap(); + #[cfg(target_os = "wasi")] + let rt = tokio::runtime::Builder::new_current_thread() + .enable_all() + .build() + .unwrap(); + let (f1, f2) = MyFuture::new(); rt.spawn(f1); @@ -515,17 +544,20 @@ fn wake_during_shutdown() { rt.block_on(async { tokio::time::sleep(tokio::time::Duration::from_millis(20)).await }); } +#[cfg(not(target_os = "wasi"))] #[should_panic] #[tokio::test] async fn test_block_in_place1() { tokio::task::block_in_place(|| {}); } +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn test_block_in_place2() { tokio::task::block_in_place(|| {}); } +#[cfg(not(target_os = "wasi"))] #[should_panic] #[tokio::main(flavor = "current_thread")] #[test] @@ -533,12 +565,20 @@ async fn test_block_in_place3() { tokio::task::block_in_place(|| {}); } +#[cfg(not(target_os = "wasi"))] #[tokio::main] #[test] async fn test_block_in_place4() { tokio::task::block_in_place(|| {}); } -fn rt() -> Runtime { - Runtime::new().unwrap() +#[cfg(not(target_os = "wasi"))] +fn rt() -> runtime::Runtime { + runtime::Runtime::new().unwrap() +} + +#[cfg(target_os = "wasi")] +fn rt() -> runtime::Runtime { + use runtime::Builder; + Builder::new_current_thread().enable_all().build().unwrap() } diff --git a/tokio/tests/sync_barrier.rs b/tokio/tests/sync_barrier.rs index 5fe7ba98c8b..afd3ef16b5f 100644 --- a/tokio/tests/sync_barrier.rs +++ b/tokio/tests/sync_barrier.rs @@ -2,7 +2,7 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use tokio::sync::Barrier; diff --git a/tokio/tests/sync_broadcast.rs b/tokio/tests/sync_broadcast.rs index b38b6380023..7ca8281ce3e 100644 --- a/tokio/tests/sync_broadcast.rs +++ b/tokio/tests/sync_broadcast.rs @@ -2,7 +2,7 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use tokio::sync::broadcast; diff --git a/tokio/tests/sync_errors.rs b/tokio/tests/sync_errors.rs index 2eac585d40c..3dd42fad2f6 100644 --- a/tokio/tests/sync_errors.rs +++ b/tokio/tests/sync_errors.rs @@ -1,7 +1,7 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; fn is_error() {} diff --git a/tokio/tests/sync_mpsc.rs b/tokio/tests/sync_mpsc.rs index abbfa9d7f46..e170e1b1ada 100644 --- a/tokio/tests/sync_mpsc.rs +++ b/tokio/tests/sync_mpsc.rs @@ -2,12 +2,12 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use tokio::sync::mpsc; @@ -88,7 +88,7 @@ async fn reserve_disarm() { } #[tokio::test] -#[cfg(feature = "full")] +#[cfg(all(feature = "full", not(target_os = "wasi")))] async fn send_recv_stream_with_buffer() { use tokio_stream::StreamExt; @@ -105,7 +105,9 @@ async fn send_recv_stream_with_buffer() { assert_eq!(None, rx.next().await); } +// https://github.com/tokio-rs/mio/pull/1580 #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn async_send_recv_with_buffer() { let (tx, mut rx) = mpsc::channel(16); @@ -177,6 +179,7 @@ async fn send_recv_unbounded() { } #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn async_send_recv_unbounded() { let (tx, mut rx) = mpsc::unbounded_channel(); @@ -192,7 +195,7 @@ async fn async_send_recv_unbounded() { } #[tokio::test] -#[cfg(feature = "full")] +#[cfg(all(feature = "full", not(target_os = "wasi")))] async fn send_recv_stream_unbounded() { use tokio_stream::StreamExt; @@ -453,7 +456,7 @@ fn unconsumed_messages_are_dropped() { } #[test] -#[cfg(feature = "full")] +#[cfg(all(feature = "full", not(target_os = "wasi")))] fn blocking_recv() { let (tx, mut rx) = mpsc::channel::(1); @@ -478,7 +481,7 @@ async fn blocking_recv_async() { } #[test] -#[cfg(feature = "full")] +#[cfg(all(feature = "full", not(target_os = "wasi")))] fn blocking_send() { let (tx, mut rx) = mpsc::channel::(1); diff --git a/tokio/tests/sync_mutex.rs b/tokio/tests/sync_mutex.rs index bcd9b1ebac6..ef60a348f93 100644 --- a/tokio/tests/sync_mutex.rs +++ b/tokio/tests/sync_mutex.rs @@ -1,12 +1,12 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use tokio::sync::Mutex; diff --git a/tokio/tests/sync_mutex_owned.rs b/tokio/tests/sync_mutex_owned.rs index 98ced158390..5fb48ec8a0a 100644 --- a/tokio/tests/sync_mutex_owned.rs +++ b/tokio/tests/sync_mutex_owned.rs @@ -1,12 +1,12 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use tokio::sync::Mutex; diff --git a/tokio/tests/sync_notify.rs b/tokio/tests/sync_notify.rs index 4236a91d1a9..4bbc71c5054 100644 --- a/tokio/tests/sync_notify.rs +++ b/tokio/tests/sync_notify.rs @@ -1,7 +1,7 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use tokio::sync::Notify; diff --git a/tokio/tests/sync_oneshot.rs b/tokio/tests/sync_oneshot.rs index 7714f80be93..130deee36e5 100644 --- a/tokio/tests/sync_oneshot.rs +++ b/tokio/tests/sync_oneshot.rs @@ -1,12 +1,12 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use tokio::sync::oneshot; @@ -93,7 +93,9 @@ fn close_rx() { assert_err!(tx.into_inner().send(1)); } +// https://github.com/tokio-rs/mio/pull/1580 #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn async_rx_closed() { let (mut tx, rx) = oneshot::channel::<()>(); diff --git a/tokio/tests/sync_panic.rs b/tokio/tests/sync_panic.rs index 9aea9a89e08..fb81ad8b4dd 100644 --- a/tokio/tests/sync_panic.rs +++ b/tokio/tests/sync_panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::error::Error; use tokio::{ diff --git a/tokio/tests/sync_rwlock.rs b/tokio/tests/sync_rwlock.rs index 01bbdbb5a58..dc51727096f 100644 --- a/tokio/tests/sync_rwlock.rs +++ b/tokio/tests/sync_rwlock.rs @@ -1,12 +1,12 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as maybe_tokio_test; -#[cfg(not(target_arch = "wasm32"))] +#[cfg(not(all(target_arch = "wasm32", not(target_os = "wasi"))))] use tokio::test as maybe_tokio_test; use std::task::Poll; @@ -172,7 +172,7 @@ async fn write_order() { } // A single RwLock is contested by tasks in multiple threads -#[cfg(feature = "full")] +#[cfg(all(feature = "full", not(target_os = "wasi")))] #[tokio::test(flavor = "multi_thread", worker_threads = 8)] async fn multithreaded() { use futures::stream::{self, StreamExt}; diff --git a/tokio/tests/sync_semaphore.rs b/tokio/tests/sync_semaphore.rs index d9266650085..7e6e362333f 100644 --- a/tokio/tests/sync_semaphore.rs +++ b/tokio/tests/sync_semaphore.rs @@ -1,6 +1,6 @@ #![cfg(feature = "sync")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use std::sync::Arc; @@ -25,7 +25,9 @@ fn try_acquire() { assert!(p3.is_ok()); } +// https://github.com/tokio-rs/mio/pull/1580 #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn acquire() { let sem = Arc::new(Semaphore::new(1)); @@ -39,6 +41,7 @@ async fn acquire() { } #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn add_permits() { let sem = Arc::new(Semaphore::new(0)); @@ -64,6 +67,7 @@ fn forget() { } #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn stresstest() { let sem = Arc::new(Semaphore::new(5)); diff --git a/tokio/tests/sync_semaphore_owned.rs b/tokio/tests/sync_semaphore_owned.rs index 98c20d7b035..22e93c2ee01 100644 --- a/tokio/tests/sync_semaphore_owned.rs +++ b/tokio/tests/sync_semaphore_owned.rs @@ -1,6 +1,6 @@ #![cfg(feature = "sync")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use std::sync::Arc; @@ -35,7 +35,9 @@ fn try_acquire_many() { assert!(sem.try_acquire_owned().is_err()); } +// https://github.com/tokio-rs/mio/pull/1580 #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn acquire() { let sem = Arc::new(Semaphore::new(1)); @@ -49,6 +51,7 @@ async fn acquire() { } #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn acquire_many() { let semaphore = Arc::new(Semaphore::new(42)); @@ -65,6 +68,7 @@ async fn acquire_many() { } #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn add_permits() { let sem = Arc::new(Semaphore::new(0)); @@ -90,6 +94,7 @@ fn forget() { } #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn stresstest() { let sem = Arc::new(Semaphore::new(5)); diff --git a/tokio/tests/sync_watch.rs b/tokio/tests/sync_watch.rs index d47f0df7326..13aecc25971 100644 --- a/tokio/tests/sync_watch.rs +++ b/tokio/tests/sync_watch.rs @@ -2,7 +2,7 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "sync")] -#[cfg(target_arch = "wasm32")] +#[cfg(all(target_arch = "wasm32", not(target_os = "wasi")))] use wasm_bindgen_test::wasm_bindgen_test as test; use tokio::sync::watch; diff --git a/tokio/tests/task_abort.rs b/tokio/tests/task_abort.rs index fe6b50cd46e..7f31e659127 100644 --- a/tokio/tests/task_abort.rs +++ b/tokio/tests/task_abort.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::sync::Arc; use std::thread::sleep; diff --git a/tokio/tests/task_blocking.rs b/tokio/tests/task_blocking.rs index ee7e78ad482..42c0d38c8ab 100644 --- a/tokio/tests/task_blocking.rs +++ b/tokio/tests/task_blocking.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::{runtime, task}; use tokio_test::assert_ok; diff --git a/tokio/tests/task_local.rs b/tokio/tests/task_local.rs index 4e33f29be43..75bb60dc4ad 100644 --- a/tokio/tests/task_local.rs +++ b/tokio/tests/task_local.rs @@ -1,4 +1,4 @@ -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; diff --git a/tokio/tests/task_local_set.rs b/tokio/tests/task_local_set.rs index 2bd5b17b84d..2b2bcdc924c 100644 --- a/tokio/tests/task_local_set.rs +++ b/tokio/tests/task_local_set.rs @@ -6,16 +6,19 @@ use futures::{ FutureExt, }; -use tokio::runtime::{self, Runtime}; +use tokio::runtime; use tokio::sync::{mpsc, oneshot}; use tokio::task::{self, LocalSet}; use tokio::time; +#[cfg(not(target_os = "wasi"))] use std::cell::Cell; use std::sync::atomic::Ordering::{self, SeqCst}; use std::sync::atomic::{AtomicBool, AtomicUsize}; use std::time::Duration; +// https://github.com/tokio-rs/mio/pull/1580 +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test(flavor = "current_thread")] async fn local_basic_scheduler() { LocalSet::new() @@ -25,6 +28,7 @@ async fn local_basic_scheduler() { .await; } +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn local_threadpool() { thread_local! { @@ -45,6 +49,7 @@ async fn local_threadpool() { .await; } +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn localset_future_threadpool() { thread_local! { @@ -60,6 +65,7 @@ async fn localset_future_threadpool() { local.await; } +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn localset_future_timers() { static RAN1: AtomicBool = AtomicBool::new(false); @@ -104,6 +110,7 @@ async fn localset_future_drives_all_local_futs() { assert!(RAN3.load(Ordering::SeqCst)); } +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn local_threadpool_timer() { // This test ensures that runtime services like the timer are properly @@ -127,6 +134,7 @@ async fn local_threadpool_timer() { .await; } +#[cfg(not(target_os = "wasi"))] #[test] // This will panic, since the thread that calls `block_on` cannot use // in-place blocking inside of `block_on`. @@ -153,6 +161,7 @@ fn local_threadpool_blocking_in_place() { }); } +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn local_threadpool_blocking_run() { thread_local! { @@ -181,6 +190,7 @@ async fn local_threadpool_blocking_run() { .await; } +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn all_spawns_are_local() { use futures::future; @@ -207,6 +217,7 @@ async fn all_spawns_are_local() { .await; } +#[cfg(not(target_os = "wasi"))] #[tokio::test(flavor = "multi_thread")] async fn nested_spawn_is_local() { thread_local! { @@ -242,6 +253,7 @@ async fn nested_spawn_is_local() { .await; } +#[cfg(not(target_os = "wasi"))] #[test] fn join_local_future_elsewhere() { thread_local! { @@ -282,6 +294,7 @@ fn join_local_future_elsewhere() { }); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[test] fn drop_cancels_tasks() { use std::rc::Rc; @@ -355,6 +368,7 @@ fn with_timeout(timeout: Duration, f: impl FnOnce() + Send + 'static) { thread.join().expect("test thread should not panic!") } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[test] fn drop_cancels_remote_tasks() { // This test reproduces issue #1885. @@ -377,6 +391,7 @@ fn drop_cancels_remote_tasks() { }); } +#[cfg(not(target_os = "wasi"))] #[test] fn local_tasks_wake_join_all() { // This test reproduces issue #2460. @@ -398,6 +413,7 @@ fn local_tasks_wake_join_all() { }); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[test] fn local_tasks_are_polled_after_tick() { // This test depends on timing, so we run it up to five times. @@ -472,6 +488,7 @@ async fn local_tasks_are_polled_after_tick_inner() { .await; } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test] async fn acquire_mutex_in_drop() { use futures::future::pending; @@ -509,6 +526,7 @@ async fn acquire_mutex_in_drop() { } #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn spawn_wakes_localset() { let local = LocalSet::new(); futures::select! { @@ -540,7 +558,7 @@ mod unstable { } } -fn rt() -> Runtime { +fn rt() -> runtime::Runtime { tokio::runtime::Builder::new_current_thread() .enable_all() .build() diff --git a/tokio/tests/tcp_accept.rs b/tokio/tests/tcp_accept.rs index 5ffb946f345..3107e5de223 100644 --- a/tokio/tests/tcp_accept.rs +++ b/tokio/tests/tcp_accept.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::net::{TcpListener, TcpStream}; use tokio::sync::{mpsc, oneshot}; diff --git a/tokio/tests/tcp_connect.rs b/tokio/tests/tcp_connect.rs index cbe68fa2764..10cb6b1d44c 100644 --- a/tokio/tests/tcp_connect.rs +++ b/tokio/tests/tcp_connect.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::net::{TcpListener, TcpStream}; use tokio::sync::oneshot; diff --git a/tokio/tests/tcp_echo.rs b/tokio/tests/tcp_echo.rs index 5bb7ff0acc2..d5144f63841 100644 --- a/tokio/tests/tcp_echo.rs +++ b/tokio/tests/tcp_echo.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::io::{self, AsyncReadExt, AsyncWriteExt}; use tokio::net::{TcpListener, TcpStream}; diff --git a/tokio/tests/tcp_into_split.rs b/tokio/tests/tcp_into_split.rs index 2e06643a028..8ee91bbf399 100644 --- a/tokio/tests/tcp_into_split.rs +++ b/tokio/tests/tcp_into_split.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::io::{Error, ErrorKind, Result}; use std::io::{Read, Write}; diff --git a/tokio/tests/tcp_into_std.rs b/tokio/tests/tcp_into_std.rs index 4bf24c14dd7..e0769d2eff9 100644 --- a/tokio/tests/tcp_into_std.rs +++ b/tokio/tests/tcp_into_std.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::io::Read; use std::io::Result; diff --git a/tokio/tests/tcp_peek.rs b/tokio/tests/tcp_peek.rs index aecc0ac19cd..4d763666a51 100644 --- a/tokio/tests/tcp_peek.rs +++ b/tokio/tests/tcp_peek.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::io::AsyncReadExt; use tokio::net::TcpStream; diff --git a/tokio/tests/tcp_shutdown.rs b/tokio/tests/tcp_shutdown.rs index 536a16130ab..2a5704360c3 100644 --- a/tokio/tests/tcp_shutdown.rs +++ b/tokio/tests/tcp_shutdown.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::io::{self, AsyncReadExt, AsyncWriteExt}; use tokio::net::{TcpListener, TcpStream}; diff --git a/tokio/tests/tcp_socket.rs b/tokio/tests/tcp_socket.rs index 3030416502a..c5129f15230 100644 --- a/tokio/tests/tcp_socket.rs +++ b/tokio/tests/tcp_socket.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::time::Duration; use tokio::net::TcpSocket; diff --git a/tokio/tests/tcp_split.rs b/tokio/tests/tcp_split.rs index 7171dac4635..8174ab67e51 100644 --- a/tokio/tests/tcp_split.rs +++ b/tokio/tests/tcp_split.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::io::Result; use std::io::{Read, Write}; diff --git a/tokio/tests/tcp_stream.rs b/tokio/tests/tcp_stream.rs index 0b5d12ae8e2..422e69b9cbb 100644 --- a/tokio/tests/tcp_stream.rs +++ b/tokio/tests/tcp_stream.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::io::{AsyncReadExt, AsyncWriteExt, Interest}; use tokio::net::{TcpListener, TcpStream}; diff --git a/tokio/tests/test_clock.rs b/tokio/tests/test_clock.rs index 891636fdb28..f129e6700c9 100644 --- a/tokio/tests/test_clock.rs +++ b/tokio/tests/test_clock.rs @@ -3,7 +3,9 @@ use tokio::time::{self, Duration, Instant}; +// https://github.com/tokio-rs/mio/pull/1580 #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn resume_lets_time_move_forward_instead_of_resetting_it() { let start = Instant::now(); time::pause(); @@ -17,6 +19,7 @@ async fn resume_lets_time_move_forward_instead_of_resetting_it() { } #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn can_pause_after_resume() { let start = Instant::now(); time::pause(); diff --git a/tokio/tests/time_interval.rs b/tokio/tests/time_interval.rs index 186582e2e52..2a696fa4c1a 100644 --- a/tokio/tests/time_interval.rs +++ b/tokio/tests/time_interval.rs @@ -38,6 +38,8 @@ async fn interval_zero_duration() { // Ready(s + 5p) | // Ready(s + 6p) #[tokio::test(start_paused = true)] +// https://github.com/tokio-rs/mio/pull/1580 +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn burst() { let start = Instant::now(); @@ -82,6 +84,7 @@ async fn burst() { // Ready(s + 3p + d) | // Ready(s + 4p + d) #[tokio::test(start_paused = true)] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn delay() { let start = Instant::now(); @@ -134,6 +137,7 @@ async fn delay() { // Ready(s + p) Ready(s + 5p) | // Ready(s + 6p) #[tokio::test(start_paused = true)] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn skip() { let start = Instant::now(); @@ -167,6 +171,7 @@ async fn skip() { } #[tokio::test(start_paused = true)] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn reset() { let start = Instant::now(); diff --git a/tokio/tests/time_panic.rs b/tokio/tests/time_panic.rs index 3ed936f52a8..94a595f2949 100644 --- a/tokio/tests/time_panic.rs +++ b/tokio/tests/time_panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use futures::future; use std::error::Error; diff --git a/tokio/tests/time_pause.rs b/tokio/tests/time_pause.rs index 02e050a2dc4..49ee45f9ada 100644 --- a/tokio/tests/time_pause.rs +++ b/tokio/tests/time_pause.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use rand::SeedableRng; use rand::{rngs::StdRng, Rng}; diff --git a/tokio/tests/time_rt.rs b/tokio/tests/time_rt.rs index 23367be4188..6ac44322adb 100644 --- a/tokio/tests/time_rt.rs +++ b/tokio/tests/time_rt.rs @@ -5,6 +5,7 @@ use tokio::time::*; use std::sync::mpsc; +#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] #[test] fn timer_with_threaded_runtime() { use tokio::runtime::Runtime; diff --git a/tokio/tests/time_timeout.rs b/tokio/tests/time_timeout.rs index a1ff51e7d27..abccea80da1 100644 --- a/tokio/tests/time_timeout.rs +++ b/tokio/tests/time_timeout.rs @@ -17,6 +17,7 @@ async fn simultaneous_deadline_future_completion() { assert_ready_ok!(fut.poll()); } +#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test] async fn completed_future_past_deadline() { // Wrap it with a deadline @@ -101,7 +102,9 @@ async fn very_large_timeout() { assert_ready_ok!(fut.poll()).unwrap(); } +// https://github.com/tokio-rs/mio/pull/1580 #[tokio::test] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn deadline_now_elapses() { use futures::future::pending; diff --git a/tokio/tests/udp.rs b/tokio/tests/udp.rs index ec2a1e96104..1355ed2c4a2 100644 --- a/tokio/tests/udp.rs +++ b/tokio/tests/udp.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use futures::future::poll_fn; use std::io; diff --git a/tokio/tests/unwindsafe.rs b/tokio/tests/unwindsafe.rs index 09fe8394565..919d3bd442c 100644 --- a/tokio/tests/unwindsafe.rs +++ b/tokio/tests/unwindsafe.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::panic::{RefUnwindSafe, UnwindSafe}; From af6a351a6fb52dc7a280b20b31b004dd2663a543 Mon Sep 17 00:00:00 2001 From: Richard Zak Date: Tue, 28 Jun 2022 17:04:01 -0400 Subject: [PATCH 5/8] fixup: rebase, io_panic fix Signed-off-by: Richard Zak --- tokio/tests/io_panic.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tokio/tests/io_panic.rs b/tokio/tests/io_panic.rs index 07d824d1660..dacc4c11b53 100644 --- a/tokio/tests/io_panic.rs +++ b/tokio/tests/io_panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] use std::task::{Context, Poll}; use std::{error::Error, pin::Pin}; From aeedf1233645a16e303a2bb081be9bf15ef2f6c5 Mon Sep 17 00:00:00 2001 From: Richard Zak Date: Wed, 29 Jun 2022 21:01:47 -0400 Subject: [PATCH 6/8] fixup: enable more tests for Wasi Also adding comments when a test is disabled. Signed-off-by: Richard Zak --- tokio-stream/tests/stream_panic.rs | 2 +- tokio-stream/tests/watch.rs | 1 - tokio-util/tests/context.rs | 2 +- tokio-util/tests/io_sync_bridge.rs | 2 +- tokio-util/tests/panic.rs | 2 +- tokio-util/tests/spawn_pinned.rs | 2 +- tokio-util/tests/udp.rs | 2 +- tokio/tests/async_send_sync.rs | 1 + tokio/tests/buffered.rs | 2 +- tokio/tests/fs.rs | 2 +- tokio/tests/fs_copy.rs | 2 +- tokio/tests/fs_dir.rs | 2 +- tokio/tests/fs_file.rs | 2 +- tokio/tests/fs_link.rs | 2 +- tokio/tests/io_buf_reader.rs | 5 --- tokio/tests/io_buf_writer.rs | 4 -- tokio/tests/io_copy.rs | 2 - tokio/tests/io_copy_bidirectional.rs | 2 +- tokio/tests/io_driver.rs | 1 + tokio/tests/io_driver_drop.rs | 2 +- tokio/tests/io_fill_buf.rs | 2 +- tokio/tests/io_mem_stream.rs | 6 --- tokio/tests/io_panic.rs | 2 +- tokio/tests/io_read.rs | 2 +- tokio/tests/io_split.rs | 2 +- tokio/tests/io_take.rs | 2 +- tokio/tests/io_util_empty.rs | 3 -- tokio/tests/join_handle_panic.rs | 2 +- tokio/tests/macros_join.rs | 4 -- tokio/tests/macros_rename_test.rs | 2 +- tokio/tests/macros_select.rs | 2 - tokio/tests/macros_test.rs | 2 +- tokio/tests/macros_try_join.rs | 2 - tokio/tests/net_bind_resource.rs | 2 +- tokio/tests/net_lookup_host.rs | 2 +- tokio/tests/no_rt.rs | 2 +- tokio/tests/process_smoke.rs | 2 +- tokio/tests/rt_basic.rs | 7 +--- tokio/tests/rt_common.rs | 63 ++++++++++++---------------- tokio/tests/rt_handle_block_on.rs | 4 +- tokio/tests/rt_panic.rs | 2 +- tokio/tests/rt_threaded.rs | 32 +++++++------- tokio/tests/signal_no_rt.rs | 1 + tokio/tests/sync_mpsc.rs | 3 -- tokio/tests/sync_oneshot.rs | 2 - tokio/tests/sync_rwlock.rs | 2 +- tokio/tests/sync_semaphore.rs | 4 -- tokio/tests/sync_semaphore_owned.rs | 5 --- tokio/tests/task_abort.rs | 2 +- tokio/tests/task_blocking.rs | 2 +- tokio/tests/task_local.rs | 2 +- tokio/tests/task_local_set.rs | 34 +++++++-------- tokio/tests/tcp_accept.rs | 2 +- tokio/tests/tcp_connect.rs | 2 +- tokio/tests/tcp_echo.rs | 2 +- tokio/tests/tcp_into_split.rs | 2 +- tokio/tests/tcp_into_std.rs | 2 +- tokio/tests/tcp_peek.rs | 2 +- tokio/tests/tcp_shutdown.rs | 2 +- tokio/tests/tcp_socket.rs | 2 +- tokio/tests/tcp_split.rs | 2 +- tokio/tests/tcp_stream.rs | 2 +- tokio/tests/test_clock.rs | 6 +-- tokio/tests/time_interval.rs | 5 --- tokio/tests/time_panic.rs | 2 +- tokio/tests/time_pause.rs | 2 +- tokio/tests/time_rt.rs | 2 +- tokio/tests/time_sleep.rs | 1 + tokio/tests/time_timeout.rs | 4 +- tokio/tests/udp.rs | 2 +- tokio/tests/unwindsafe.rs | 2 +- 71 files changed, 117 insertions(+), 177 deletions(-) diff --git a/tokio-stream/tests/stream_panic.rs b/tokio-stream/tests/stream_panic.rs index a8d7b961537..8ff9ff59b5f 100644 --- a/tokio-stream/tests/stream_panic.rs +++ b/tokio-stream/tests/stream_panic.rs @@ -1,6 +1,6 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "time")] -#![cfg(not(target_os = "wasi"))] +#![cfg(not(target_os = "wasi"))] // Wasi does not support panic recovery use parking_lot::{const_mutex, Mutex}; use std::error::Error; diff --git a/tokio-stream/tests/watch.rs b/tokio-stream/tests/watch.rs index 55e1792341a..a56254edefd 100644 --- a/tokio-stream/tests/watch.rs +++ b/tokio-stream/tests/watch.rs @@ -5,7 +5,6 @@ use tokio_stream::wrappers::WatchStream; use tokio_stream::StreamExt; #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn message_not_twice() { let (tx, rx) = watch::channel("hello"); diff --git a/tokio-util/tests/context.rs b/tokio-util/tests/context.rs index dfe26047990..c2c05d25c7b 100644 --- a/tokio-util/tests/context.rs +++ b/tokio-util/tests/context.rs @@ -1,5 +1,5 @@ #![cfg(feature = "rt")] -#![cfg(not(target_os = "wasi"))] +#![cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #![warn(rust_2018_idioms)] use tokio::runtime::Builder; diff --git a/tokio-util/tests/io_sync_bridge.rs b/tokio-util/tests/io_sync_bridge.rs index 6a2acecb7ac..e22631e48c9 100644 --- a/tokio-util/tests/io_sync_bridge.rs +++ b/tokio-util/tests/io_sync_bridge.rs @@ -1,5 +1,5 @@ #![cfg(feature = "io-util")] -#![cfg(not(target_os = "wasi"))] +#![cfg(not(target_os = "wasi"))] // Wasi doesn't support threads use std::error::Error; use std::io::{Cursor, Read, Result as IoResult}; diff --git a/tokio-util/tests/panic.rs b/tokio-util/tests/panic.rs index 76b8f64d4ea..e4fcb47ef69 100644 --- a/tokio-util/tests/panic.rs +++ b/tokio-util/tests/panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery use parking_lot::{const_mutex, Mutex}; use std::error::Error; diff --git a/tokio-util/tests/spawn_pinned.rs b/tokio-util/tests/spawn_pinned.rs index 9ed7157715c..b620cce048c 100644 --- a/tokio-util/tests/spawn_pinned.rs +++ b/tokio-util/tests/spawn_pinned.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(not(target_os = "wasi"))] +#![cfg(not(target_os = "wasi"))] // Wasi doesn't support threads use std::rc::Rc; use std::sync::Arc; diff --git a/tokio-util/tests/udp.rs b/tokio-util/tests/udp.rs index 996d073067b..1b99806364c 100644 --- a/tokio-util/tests/udp.rs +++ b/tokio-util/tests/udp.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(not(target_os = "wasi"))] +#![cfg(not(target_os = "wasi"))] // Wasi doesn't support UDP use tokio::net::UdpSocket; use tokio_stream::StreamExt; diff --git a/tokio/tests/async_send_sync.rs b/tokio/tests/async_send_sync.rs index a6b963d90be..397e55fa55f 100644 --- a/tokio/tests/async_send_sync.rs +++ b/tokio/tests/async_send_sync.rs @@ -200,6 +200,7 @@ async_assert_fn!(tokio::net::TcpStream::readable(_): Send & Sync & !Unpin); async_assert_fn!(tokio::net::TcpStream::ready(_, tokio::io::Interest): Send & Sync & !Unpin); async_assert_fn!(tokio::net::TcpStream::writable(_): Send & Sync & !Unpin); +// Wasi does not support UDP cfg_not_wasi! { mod udp_socket { use super::*; diff --git a/tokio/tests/buffered.rs b/tokio/tests/buffered.rs index 45d9016de08..2ae1100448f 100644 --- a/tokio/tests/buffered.rs +++ b/tokio/tests/buffered.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support bind() use tokio::net::TcpListener; use tokio_test::assert_ok; diff --git a/tokio/tests/fs.rs b/tokio/tests/fs.rs index 0a15a081c88..9f739f60c44 100644 --- a/tokio/tests/fs.rs +++ b/tokio/tests/fs.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations use tokio::fs; use tokio_test::assert_ok; diff --git a/tokio/tests/fs_copy.rs b/tokio/tests/fs_copy.rs index 813b344232c..e32aebd939b 100644 --- a/tokio/tests/fs_copy.rs +++ b/tokio/tests/fs_copy.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations use tempfile::tempdir; use tokio::fs; diff --git a/tokio/tests/fs_dir.rs b/tokio/tests/fs_dir.rs index 1f3c217633e..21391e27b56 100644 --- a/tokio/tests/fs_dir.rs +++ b/tokio/tests/fs_dir.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support directory operations use tokio::fs; use tokio_test::{assert_err, assert_ok}; diff --git a/tokio/tests/fs_file.rs b/tokio/tests/fs_file.rs index 7fb107aea19..55ff24183c6 100644 --- a/tokio/tests/fs_file.rs +++ b/tokio/tests/fs_file.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations use std::io::prelude::*; use tempfile::NamedTempFile; diff --git a/tokio/tests/fs_link.rs b/tokio/tests/fs_link.rs index be7e3ca8863..9a83df523b9 100644 --- a/tokio/tests/fs_link.rs +++ b/tokio/tests/fs_link.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations use tokio::fs; diff --git a/tokio/tests/io_buf_reader.rs b/tokio/tests/io_buf_reader.rs index 0a02ad49118..864bc023ab5 100644 --- a/tokio/tests/io_buf_reader.rs +++ b/tokio/tests/io_buf_reader.rs @@ -222,8 +222,6 @@ async fn test_short_reads() { assert_eq!(reader.read(&mut buf).await.unwrap(), 0); } -// https://github.com/tokio-rs/mio/pull/1580 -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn maybe_pending() { let inner: &[u8] = &[5, 6, 7, 0, 1, 2, 3, 4]; @@ -261,7 +259,6 @@ async fn maybe_pending() { assert_eq!(reader.read(&mut buf).await.unwrap(), 0); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn maybe_pending_buf_read() { let inner = MaybePending::new(&[0, 1, 2, 3, 1, 0]); @@ -280,8 +277,6 @@ async fn maybe_pending_buf_read() { assert_eq!(v, []); } -// https://github.com/rust-lang/futures-rs/pull/1573#discussion_r281162309 -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn maybe_pending_seek() { struct MaybePendingSeek<'a> { diff --git a/tokio/tests/io_buf_writer.rs b/tokio/tests/io_buf_writer.rs index 3bb82c10afd..47a0d466f49 100644 --- a/tokio/tests/io_buf_writer.rs +++ b/tokio/tests/io_buf_writer.rs @@ -131,8 +131,6 @@ async fn buf_writer_seek() { assert_eq!(&w.into_inner().into_inner()[..], &[0, 1, 8, 9, 4, 5, 6, 7]); } -// https://github.com/tokio-rs/mio/pull/1580 -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn maybe_pending_buf_writer() { let mut writer = BufWriter::with_capacity(2, MaybePending::new(Vec::new())); @@ -181,7 +179,6 @@ async fn maybe_pending_buf_writer() { ); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn maybe_pending_buf_writer_inner_flushes() { let mut w = BufWriter::with_capacity(3, MaybePending::new(Vec::new())); @@ -192,7 +189,6 @@ async fn maybe_pending_buf_writer_inner_flushes() { assert_eq!(w, [0, 1]); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn maybe_pending_buf_writer_seek() { struct MaybePendingSeek { diff --git a/tokio/tests/io_copy.rs b/tokio/tests/io_copy.rs index ed28b256e0f..005e1701191 100644 --- a/tokio/tests/io_copy.rs +++ b/tokio/tests/io_copy.rs @@ -37,8 +37,6 @@ async fn copy() { assert_eq!(wr, b"hello world"); } -// https://github.com/tokio-rs/mio/pull/1580 -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn proxy() { struct BufferedWd { diff --git a/tokio/tests/io_copy_bidirectional.rs b/tokio/tests/io_copy_bidirectional.rs index 160e523e16a..679d78dc1a7 100644 --- a/tokio/tests/io_copy_bidirectional.rs +++ b/tokio/tests/io_copy_bidirectional.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support bind() use std::time::Duration; use tokio::io::{self, copy_bidirectional, AsyncReadExt, AsyncWriteExt}; diff --git a/tokio/tests/io_driver.rs b/tokio/tests/io_driver.rs index f9efd0d8d79..650e66c8b2a 100644 --- a/tokio/tests/io_driver.rs +++ b/tokio/tests/io_driver.rs @@ -1,4 +1,5 @@ #![warn(rust_2018_idioms)] +// Wasi does not support panic recovery or threading #![cfg(all(feature = "full", not(target_os = "wasi")))] use tokio::net::TcpListener; diff --git a/tokio/tests/io_driver_drop.rs b/tokio/tests/io_driver_drop.rs index d5891e59ec1..c3182637916 100644 --- a/tokio/tests/io_driver_drop.rs +++ b/tokio/tests/io_driver_drop.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support bind use tokio::net::TcpListener; use tokio::runtime; diff --git a/tokio/tests/io_fill_buf.rs b/tokio/tests/io_fill_buf.rs index e7b3bdcf96f..534417c855d 100644 --- a/tokio/tests/io_fill_buf.rs +++ b/tokio/tests/io_fill_buf.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support file operations use tempfile::NamedTempFile; use tokio::fs::File; diff --git a/tokio/tests/io_mem_stream.rs b/tokio/tests/io_mem_stream.rs index df756268213..a2c2dadfc90 100644 --- a/tokio/tests/io_mem_stream.rs +++ b/tokio/tests/io_mem_stream.rs @@ -18,8 +18,6 @@ async fn ping_pong() { assert_eq!(&buf, b"pong"); } -// https://github.com/tokio-rs/mio/pull/1580 -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn across_tasks() { let (mut a, mut b) = duplex(32); @@ -42,7 +40,6 @@ async fn across_tasks() { t2.await.unwrap(); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn disconnect() { let (mut a, mut b) = duplex(32); @@ -65,7 +62,6 @@ async fn disconnect() { t2.await.unwrap(); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn disconnect_reader() { let (a, mut b) = duplex(2); @@ -85,7 +81,6 @@ async fn disconnect_reader() { t1.await.unwrap(); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn max_write_size() { let (mut a, mut b) = duplex(32); @@ -106,7 +101,6 @@ async fn max_write_size() { drop(b); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn duplex_is_cooperative() { let (mut tx, mut rx) = tokio::io::duplex(1024 * 8); diff --git a/tokio/tests/io_panic.rs b/tokio/tests/io_panic.rs index dacc4c11b53..9b2bf6a3bd8 100644 --- a/tokio/tests/io_panic.rs +++ b/tokio/tests/io_panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery use std::task::{Context, Poll}; use std::{error::Error, pin::Pin}; diff --git a/tokio/tests/io_read.rs b/tokio/tests/io_read.rs index 11da5a14825..6bea0ac865e 100644 --- a/tokio/tests/io_read.rs +++ b/tokio/tests/io_read.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery use tokio::io::{AsyncRead, AsyncReadExt, ReadBuf}; use tokio_test::assert_ok; diff --git a/tokio/tests/io_split.rs b/tokio/tests/io_split.rs index a0121667f75..77b77a3a04c 100644 --- a/tokio/tests/io_split.rs +++ b/tokio/tests/io_split.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery use tokio::io::{split, AsyncRead, AsyncWrite, ReadBuf, ReadHalf, WriteHalf}; diff --git a/tokio/tests/io_take.rs b/tokio/tests/io_take.rs index d623de1d190..539f17f3a2d 100644 --- a/tokio/tests/io_take.rs +++ b/tokio/tests/io_take.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery use std::pin::Pin; use std::task::{Context, Poll}; diff --git a/tokio/tests/io_util_empty.rs b/tokio/tests/io_util_empty.rs index 8a1bea093b4..e49cd17fcd5 100644 --- a/tokio/tests/io_util_empty.rs +++ b/tokio/tests/io_util_empty.rs @@ -1,8 +1,6 @@ #![cfg(feature = "full")] use tokio::io::{AsyncBufReadExt, AsyncReadExt}; -// https://github.com/tokio-rs/mio/pull/1580 -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn empty_read_is_cooperative() { tokio::select! { @@ -18,7 +16,6 @@ async fn empty_read_is_cooperative() { } } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test] async fn empty_buf_reads_are_cooperative() { tokio::select! { diff --git a/tokio/tests/join_handle_panic.rs b/tokio/tests/join_handle_panic.rs index 0e0375c6781..055b1f6b69c 100644 --- a/tokio/tests/join_handle_panic.rs +++ b/tokio/tests/join_handle_panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery struct PanicsOnDrop; diff --git a/tokio/tests/macros_join.rs b/tokio/tests/macros_join.rs index 03a3f8877a6..17eba20efd9 100644 --- a/tokio/tests/macros_join.rs +++ b/tokio/tests/macros_join.rs @@ -82,7 +82,6 @@ fn join_size() { assert_eq!(mem::size_of_val(&fut), 32); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] async fn non_cooperative_task(permits: Arc) -> usize { let mut exceeded_budget = 0; @@ -98,7 +97,6 @@ async fn non_cooperative_task(permits: Arc) -> usize { exceeded_budget } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] async fn poor_little_task(permits: Arc) -> usize { let mut how_many_times_i_got_to_run = 0; @@ -110,7 +108,6 @@ async fn poor_little_task(permits: Arc) -> usize { how_many_times_i_got_to_run } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test] async fn join_does_not_allow_tasks_to_starve() { let permits = Arc::new(Semaphore::new(1)); @@ -125,7 +122,6 @@ async fn join_does_not_allow_tasks_to_starve() { assert_eq!(5, little_task_result); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test] async fn a_different_future_is_polled_first_every_time_poll_fn_is_polled() { let poll_order = Arc::new(std::sync::Mutex::new(vec![])); diff --git a/tokio/tests/macros_rename_test.rs b/tokio/tests/macros_rename_test.rs index cccaa85d346..a99c921e11d 100644 --- a/tokio/tests/macros_rename_test.rs +++ b/tokio/tests/macros_rename_test.rs @@ -1,4 +1,4 @@ -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threading #[allow(unused_imports)] use std as tokio; diff --git a/tokio/tests/macros_select.rs b/tokio/tests/macros_select.rs index c2dfc345e1a..c7297b52884 100644 --- a/tokio/tests/macros_select.rs +++ b/tokio/tests/macros_select.rs @@ -125,9 +125,7 @@ async fn one_ready() { assert_eq!(1, v); } -// https://github.com/tokio-rs/mio/pull/1580 #[maybe_tokio_test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn select_streams() { use tokio::sync::mpsc; diff --git a/tokio/tests/macros_test.rs b/tokio/tests/macros_test.rs index 164c06413a0..311067ecdfd 100644 --- a/tokio/tests/macros_test.rs +++ b/tokio/tests/macros_test.rs @@ -1,4 +1,4 @@ -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threading use tokio::test; diff --git a/tokio/tests/macros_try_join.rs b/tokio/tests/macros_try_join.rs index 7a755360f8c..c1bf6d3f16a 100644 --- a/tokio/tests/macros_try_join.rs +++ b/tokio/tests/macros_try_join.rs @@ -137,7 +137,6 @@ async fn poor_little_task(permits: Arc) -> Result { Ok(how_many_times_i_got_to_run) } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test] async fn try_join_does_not_allow_tasks_to_starve() { let permits = Arc::new(Semaphore::new(10)); @@ -154,7 +153,6 @@ async fn try_join_does_not_allow_tasks_to_starve() { assert_eq!(5, little_task_result); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test] async fn a_different_future_is_polled_first_every_time_poll_fn_is_polled() { let poll_order = Arc::new(std::sync::Mutex::new(vec![])); diff --git a/tokio/tests/net_bind_resource.rs b/tokio/tests/net_bind_resource.rs index d4a0b8dab08..d279fe4a15e 100644 --- a/tokio/tests/net_bind_resource.rs +++ b/tokio/tests/net_bind_resource.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery or bind use tokio::net::TcpListener; diff --git a/tokio/tests/net_lookup_host.rs b/tokio/tests/net_lookup_host.rs index 8a85bb8d326..667030c7e02 100644 --- a/tokio/tests/net_lookup_host.rs +++ b/tokio/tests/net_lookup_host.rs @@ -1,4 +1,4 @@ -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support direct socket operations use tokio::net; use tokio_test::assert_ok; diff --git a/tokio/tests/no_rt.rs b/tokio/tests/no_rt.rs index 2bd304eea77..89c7ce0aa57 100644 --- a/tokio/tests/no_rt.rs +++ b/tokio/tests/no_rt.rs @@ -1,4 +1,4 @@ -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery use tokio::net::TcpStream; use tokio::sync::oneshot; diff --git a/tokio/tests/process_smoke.rs b/tokio/tests/process_smoke.rs index 5662308077d..635b951a065 100644 --- a/tokio/tests/process_smoke.rs +++ b/tokio/tests/process_smoke.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi cannot run system commands use tokio::process::Command; use tokio_test::assert_ok; diff --git a/tokio/tests/rt_basic.rs b/tokio/tests/rt_basic.rs index 026c63a7ae5..c3df1c1a859 100644 --- a/tokio/tests/rt_basic.rs +++ b/tokio/tests/rt_basic.rs @@ -25,8 +25,6 @@ macro_rules! cfg_metrics { } } -// https://github.com/tokio-rs/mio/pull/1580 -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawned_task_does_not_progress_without_block_on() { let (tx, mut rx) = oneshot::channel(); @@ -46,7 +44,6 @@ fn spawned_task_does_not_progress_without_block_on() { assert_eq!(out, "hello"); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn no_extra_poll() { use pin_project_lite::pin_project; @@ -115,7 +112,6 @@ fn no_extra_poll() { assert_eq!(npolls.load(SeqCst), 1 + 2 + 1); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn acquire_mutex_in_drop() { use futures::future::pending; @@ -182,6 +178,7 @@ fn drop_tasks_in_context() { } #[test] +#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] #[should_panic(expected = "boom")] fn wake_in_drop_after_panic() { let (tx, rx) = oneshot::channel::<()>(); @@ -210,7 +207,6 @@ fn wake_in_drop_after_panic() { }); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawn_two() { let rt = rt(); @@ -280,6 +276,7 @@ fn spawn_remote() { } #[test] +#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] #[should_panic( expected = "A Tokio 1.x context was found, but timers are disabled. Call `enable_time` on the runtime builder to enable timers." )] diff --git a/tokio/tests/rt_common.rs b/tokio/tests/rt_common.rs index 14ee7d2fcd6..da8dc6e3a09 100644 --- a/tokio/tests/rt_common.rs +++ b/tokio/tests/rt_common.rs @@ -18,7 +18,7 @@ macro_rules! rt_test { } } - #[cfg(not(target_os = "wasi"))] + #[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads mod threaded_scheduler_4_threads { $($t)* @@ -32,7 +32,7 @@ macro_rules! rt_test { } } - #[cfg(not(target_os = "wasi"))] + #[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads mod threaded_scheduler_1_thread { $($t)* @@ -116,8 +116,6 @@ rt_test! { assert_eq!(out, "ZOMG"); } - // https://github.com/tokio-rs/mio/pull/1580 - #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawn_one_bg() { let rt = rt(); @@ -135,7 +133,6 @@ rt_test! { assert_eq!(out, "ZOMG"); } - #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawn_one_join() { let rt = rt(); @@ -159,7 +156,6 @@ rt_test! { assert_eq!(out, "ZOMG"); } - #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawn_two() { let rt = rt(); @@ -183,7 +179,7 @@ rt_test! { assert_eq!(out, "ZOMG"); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn spawn_many_from_block_on() { use tokio::sync::mpsc; @@ -234,7 +230,7 @@ rt_test! { } } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn spawn_many_from_task() { use tokio::sync::mpsc; @@ -295,7 +291,6 @@ rt_test! { } } - #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawn_await_chain() { let rt = rt(); @@ -351,7 +346,7 @@ rt_test! { assert_eq!(out, "ZOMG"); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn complete_block_on_under_load() { let rt = rt(); @@ -375,7 +370,7 @@ rt_test! { }); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn complete_task_under_load() { let rt = rt(); @@ -405,7 +400,7 @@ rt_test! { }); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn spawn_from_other_thread_idle() { let rt = rt(); @@ -426,7 +421,7 @@ rt_test! { }); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn spawn_from_other_thread_under_load() { let rt = rt(); @@ -466,7 +461,6 @@ rt_test! { assert!(now.elapsed() >= dur); } - #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn sleep_in_spawn() { let rt = rt(); @@ -488,7 +482,7 @@ rt_test! { assert!(now.elapsed() >= dur); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support bind #[test] fn block_on_socket() { let rt = rt(); @@ -509,7 +503,7 @@ rt_test! { }); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn spawn_from_blocking() { let rt = rt(); @@ -525,7 +519,7 @@ rt_test! { assert_eq!(out, "hello") } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn spawn_blocking_from_blocking() { let rt = rt(); @@ -541,7 +535,7 @@ rt_test! { assert_eq!(out, "hello") } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn sleep_from_blocking() { let rt = rt(); @@ -562,7 +556,7 @@ rt_test! { }); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support bind #[test] fn socket_from_blocking() { let rt = rt(); @@ -586,7 +580,7 @@ rt_test! { }); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn always_active_parker() { // This test it to show that we will always have @@ -633,7 +627,7 @@ rt_test! { // concern. There also isn't a great/obvious solution to take. For now, the // test is disabled. #[cfg(not(windows))] - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support bind or threads fn io_driver_called_when_under_load() { let rt = rt(); @@ -669,7 +663,7 @@ rt_test! { }); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn client_server_block_on() { let rt = rt(); @@ -681,7 +675,7 @@ rt_test! { assert_err!(rx.try_recv()); } - #[cfg(not(target_os="wasi"))] + #[cfg_attr(target_os = "wasi", ignore = "Wasi does not support threads or panic recovery")] #[test] fn panic_in_task() { let rt = rt(); @@ -710,12 +704,13 @@ rt_test! { #[test] #[should_panic] + #[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] fn panic_in_block_on() { let rt = rt(); rt.block_on(async { panic!() }); } - #[cfg(not(target_os = "wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads async fn yield_once() { let mut yielded = false; poll_fn(|cx| { @@ -730,7 +725,6 @@ rt_test! { .await } - #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn enter_and_spawn() { let rt = rt(); @@ -742,7 +736,6 @@ rt_test! { assert_ok!(rt.block_on(handle)); } - #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn eagerly_drops_futures_on_shutdown() { use std::sync::mpsc; @@ -785,7 +778,6 @@ rt_test! { assert_ok!(drop_rx.recv()); } - #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn wake_while_rt_is_dropping() { use tokio::sync::Barrier; @@ -856,7 +848,7 @@ rt_test! { assert!(drop_triggered.load(Ordering::Relaxed)); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi doesn't support UDP or bind() #[test] fn io_notify_while_shutting_down() { use tokio::net::UdpSocket; @@ -893,7 +885,7 @@ rt_test! { } } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn shutdown_timeout() { let (tx, rx) = oneshot::channel(); @@ -911,7 +903,7 @@ rt_test! { Arc::try_unwrap(runtime).unwrap().shutdown_timeout(Duration::from_millis(100)); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support threads #[test] fn shutdown_timeout_0() { let runtime = rt(); @@ -943,7 +935,7 @@ rt_test! { // See https://github.com/rust-lang/rust/issues/74875 #[test] #[cfg(not(windows))] - #[cfg(not(target_os="wasi"))] + #[cfg_attr(target_os = "wasi", ignore = "Wasi does not support threads")] fn runtime_in_thread_local() { use std::cell::RefCell; use std::thread; @@ -963,7 +955,7 @@ rt_test! { }).join().unwrap(); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os="wasi"))] // Wasi does not support bind async fn client_server(tx: mpsc::Sender<()>) { let server = assert_ok!(TcpListener::bind("127.0.0.1:0").await); @@ -988,7 +980,7 @@ rt_test! { tx.send(()).unwrap(); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os = "wasi"))] // Wasi does not support bind #[test] fn local_set_block_on_socket() { let rt = rt(); @@ -1010,7 +1002,7 @@ rt_test! { }); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os = "wasi"))] // Wasi does not support bind #[test] fn local_set_client_server_block_on() { let rt = rt(); @@ -1024,7 +1016,7 @@ rt_test! { assert_err!(rx.try_recv()); } - #[cfg(not(target_os="wasi"))] + #[cfg(not(target_os = "wasi"))] // Wasi does not support bind async fn client_server_local(tx: mpsc::Sender<()>) { let server = assert_ok!(TcpListener::bind("127.0.0.1:0").await); @@ -1130,7 +1122,6 @@ rt_test! { // Tests that the "next task" scheduler optimization is not able to starve // other tasks. - #[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn ping_pong_saturation() { use std::sync::atomic::{Ordering, AtomicBool}; diff --git a/tokio/tests/rt_handle_block_on.rs b/tokio/tests/rt_handle_block_on.rs index a43c637e76a..e8f3993aa03 100644 --- a/tokio/tests/rt_handle_block_on.rs +++ b/tokio/tests/rt_handle_block_on.rs @@ -13,7 +13,7 @@ use tokio::sync::mpsc; #[cfg(not(target_os = "wasi"))] use tokio::{net, time}; -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads macro_rules! multi_threaded_rt_test { ($($t:tt)*) => { mod threaded_scheduler_4_threads_only { @@ -126,7 +126,7 @@ fn unbounded_mpsc_channel() { }) } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support file operations or bind rt_test! { use tokio::fs; // ==== spawn blocking futures ====== diff --git a/tokio/tests/rt_panic.rs b/tokio/tests/rt_panic.rs index 112a7336881..1488c9dcd22 100644 --- a/tokio/tests/rt_panic.rs +++ b/tokio/tests/rt_panic.rs @@ -1,6 +1,6 @@ #![warn(rust_2018_idioms)] #![cfg(feature = "full")] -#![cfg(not(target_os = "wasi"))] +#![cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery use futures::future; use std::error::Error; diff --git a/tokio/tests/rt_threaded.rs b/tokio/tests/rt_threaded.rs index 413024201ff..a79007d48bc 100644 --- a/tokio/tests/rt_threaded.rs +++ b/tokio/tests/rt_threaded.rs @@ -29,7 +29,7 @@ macro_rules! cfg_metrics { } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn single_thread() { // No panic when starting a runtime w/ a single thread @@ -74,8 +74,6 @@ fn many_oneshot_futures() { } } -// https://github.com/tokio-rs/mio/pull/1580 -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[test] fn spawn_two() { let rt = rt(); @@ -172,7 +170,7 @@ fn many_multishot_futures() { } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn spawn_shutdown() { let rt = rt(); @@ -192,7 +190,7 @@ fn spawn_shutdown() { assert_err!(rx.try_recv()); } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support bind async fn client_server(tx: mpsc::Sender<()>) { let server = assert_ok!(TcpListener::bind("127.0.0.1:0").await); @@ -217,7 +215,7 @@ async fn client_server(tx: mpsc::Sender<()>) { tx.send(()).unwrap(); } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn drop_threadpool_drops_futures() { for _ in 0..1_000 { @@ -274,7 +272,7 @@ fn drop_threadpool_drops_futures() { } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn start_stop_callbacks_called() { use std::sync::atomic::{AtomicUsize, Ordering}; @@ -309,7 +307,7 @@ fn start_stop_callbacks_called() { assert!(before_stop.load(Ordering::Relaxed) > 0); } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn blocking() { // used for notifying the main thread @@ -355,7 +353,7 @@ fn blocking() { } } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn multi_threadpool() { use tokio::sync::oneshot; @@ -384,7 +382,7 @@ fn multi_threadpool() { // // The test ensures that, when this happens, attempting to consume from a // channel yields occasionally even if there are values ready to receive. -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn coop_and_block_in_place() { let rt = tokio::runtime::Builder::new_multi_thread() @@ -435,7 +433,7 @@ fn coop_and_block_in_place() { } // Testing this does not panic -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi does not support threads #[test] fn max_blocking_threads() { let _rt = tokio::runtime::Builder::new_multi_thread() @@ -444,7 +442,7 @@ fn max_blocking_threads() { .unwrap(); } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi does not support threads #[test] #[should_panic] fn max_blocking_threads_set_to_zero() { @@ -454,7 +452,7 @@ fn max_blocking_threads_set_to_zero() { .unwrap(); } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi does not support threads #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn hang_on_shutdown() { let (sync_tx, sync_rx) = std::sync::mpsc::channel::<()>(); @@ -544,20 +542,20 @@ fn wake_during_shutdown() { rt.block_on(async { tokio::time::sleep(tokio::time::Duration::from_millis(20)).await }); } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[should_panic] #[tokio::test] async fn test_block_in_place1() { tokio::task::block_in_place(|| {}); } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[tokio::test(flavor = "multi_thread")] async fn test_block_in_place2() { tokio::task::block_in_place(|| {}); } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[should_panic] #[tokio::main(flavor = "current_thread")] #[test] @@ -565,7 +563,7 @@ async fn test_block_in_place3() { tokio::task::block_in_place(|| {}); } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[tokio::main] #[test] async fn test_block_in_place4() { diff --git a/tokio/tests/signal_no_rt.rs b/tokio/tests/signal_no_rt.rs index b0f32b2d10f..db284e16513 100644 --- a/tokio/tests/signal_no_rt.rs +++ b/tokio/tests/signal_no_rt.rs @@ -4,6 +4,7 @@ use tokio::signal::unix::{signal, SignalKind}; +#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] #[test] #[should_panic] fn no_runtime_panics_creating_signals() { diff --git a/tokio/tests/sync_mpsc.rs b/tokio/tests/sync_mpsc.rs index e170e1b1ada..f598db0889a 100644 --- a/tokio/tests/sync_mpsc.rs +++ b/tokio/tests/sync_mpsc.rs @@ -105,9 +105,7 @@ async fn send_recv_stream_with_buffer() { assert_eq!(None, rx.next().await); } -// https://github.com/tokio-rs/mio/pull/1580 #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn async_send_recv_with_buffer() { let (tx, mut rx) = mpsc::channel(16); @@ -179,7 +177,6 @@ async fn send_recv_unbounded() { } #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn async_send_recv_unbounded() { let (tx, mut rx) = mpsc::unbounded_channel(); diff --git a/tokio/tests/sync_oneshot.rs b/tokio/tests/sync_oneshot.rs index 130deee36e5..76194abae1f 100644 --- a/tokio/tests/sync_oneshot.rs +++ b/tokio/tests/sync_oneshot.rs @@ -93,9 +93,7 @@ fn close_rx() { assert_err!(tx.into_inner().send(1)); } -// https://github.com/tokio-rs/mio/pull/1580 #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn async_rx_closed() { let (mut tx, rx) = oneshot::channel::<()>(); diff --git a/tokio/tests/sync_rwlock.rs b/tokio/tests/sync_rwlock.rs index dc51727096f..ff10fa324db 100644 --- a/tokio/tests/sync_rwlock.rs +++ b/tokio/tests/sync_rwlock.rs @@ -172,7 +172,7 @@ async fn write_order() { } // A single RwLock is contested by tasks in multiple threads -#[cfg(all(feature = "full", not(target_os = "wasi")))] +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread", worker_threads = 8)] async fn multithreaded() { use futures::stream::{self, StreamExt}; diff --git a/tokio/tests/sync_semaphore.rs b/tokio/tests/sync_semaphore.rs index 7e6e362333f..72b646539e3 100644 --- a/tokio/tests/sync_semaphore.rs +++ b/tokio/tests/sync_semaphore.rs @@ -25,9 +25,7 @@ fn try_acquire() { assert!(p3.is_ok()); } -// https://github.com/tokio-rs/mio/pull/1580 #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn acquire() { let sem = Arc::new(Semaphore::new(1)); @@ -41,7 +39,6 @@ async fn acquire() { } #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn add_permits() { let sem = Arc::new(Semaphore::new(0)); @@ -67,7 +64,6 @@ fn forget() { } #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn stresstest() { let sem = Arc::new(Semaphore::new(5)); diff --git a/tokio/tests/sync_semaphore_owned.rs b/tokio/tests/sync_semaphore_owned.rs index 22e93c2ee01..5780c0e10eb 100644 --- a/tokio/tests/sync_semaphore_owned.rs +++ b/tokio/tests/sync_semaphore_owned.rs @@ -35,9 +35,7 @@ fn try_acquire_many() { assert!(sem.try_acquire_owned().is_err()); } -// https://github.com/tokio-rs/mio/pull/1580 #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn acquire() { let sem = Arc::new(Semaphore::new(1)); @@ -51,7 +49,6 @@ async fn acquire() { } #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn acquire_many() { let semaphore = Arc::new(Semaphore::new(42)); @@ -68,7 +65,6 @@ async fn acquire_many() { } #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn add_permits() { let sem = Arc::new(Semaphore::new(0)); @@ -94,7 +90,6 @@ fn forget() { } #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[cfg(feature = "full")] async fn stresstest() { let sem = Arc::new(Semaphore::new(5)); diff --git a/tokio/tests/task_abort.rs b/tokio/tests/task_abort.rs index 7f31e659127..2c165d00383 100644 --- a/tokio/tests/task_abort.rs +++ b/tokio/tests/task_abort.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery use std::sync::Arc; use std::thread::sleep; diff --git a/tokio/tests/task_blocking.rs b/tokio/tests/task_blocking.rs index 42c0d38c8ab..46307b03fef 100644 --- a/tokio/tests/task_blocking.rs +++ b/tokio/tests/task_blocking.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads use tokio::{runtime, task}; use tokio_test::assert_ok; diff --git a/tokio/tests/task_local.rs b/tokio/tests/task_local.rs index 75bb60dc4ad..f0da060b1a4 100644 --- a/tokio/tests/task_local.rs +++ b/tokio/tests/task_local.rs @@ -1,4 +1,4 @@ -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads use std::future::Future; use std::pin::Pin; use std::task::{Context, Poll}; diff --git a/tokio/tests/task_local_set.rs b/tokio/tests/task_local_set.rs index 2b2bcdc924c..91dd998d09c 100644 --- a/tokio/tests/task_local_set.rs +++ b/tokio/tests/task_local_set.rs @@ -13,12 +13,14 @@ use tokio::time; #[cfg(not(target_os = "wasi"))] use std::cell::Cell; -use std::sync::atomic::Ordering::{self, SeqCst}; -use std::sync::atomic::{AtomicBool, AtomicUsize}; +use std::sync::atomic::AtomicBool; +#[cfg(not(target_os = "wasi"))] +use std::sync::atomic::AtomicUsize; +use std::sync::atomic::Ordering; +#[cfg(not(target_os = "wasi"))] +use std::sync::atomic::Ordering::SeqCst; use std::time::Duration; -// https://github.com/tokio-rs/mio/pull/1580 -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] #[tokio::test(flavor = "current_thread")] async fn local_basic_scheduler() { LocalSet::new() @@ -28,7 +30,7 @@ async fn local_basic_scheduler() { .await; } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn local_threadpool() { thread_local! { @@ -49,7 +51,7 @@ async fn local_threadpool() { .await; } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn localset_future_threadpool() { thread_local! { @@ -65,7 +67,7 @@ async fn localset_future_threadpool() { local.await; } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn localset_future_timers() { static RAN1: AtomicBool = AtomicBool::new(false); @@ -110,7 +112,7 @@ async fn localset_future_drives_all_local_futs() { assert!(RAN3.load(Ordering::SeqCst)); } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn local_threadpool_timer() { // This test ensures that runtime services like the timer are properly @@ -134,7 +136,7 @@ async fn local_threadpool_timer() { .await; } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[test] // This will panic, since the thread that calls `block_on` cannot use // in-place blocking inside of `block_on`. @@ -161,7 +163,7 @@ fn local_threadpool_blocking_in_place() { }); } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn local_threadpool_blocking_run() { thread_local! { @@ -190,7 +192,7 @@ async fn local_threadpool_blocking_run() { .await; } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn all_spawns_are_local() { use futures::future; @@ -217,7 +219,7 @@ async fn all_spawns_are_local() { .await; } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread")] async fn nested_spawn_is_local() { thread_local! { @@ -253,7 +255,7 @@ async fn nested_spawn_is_local() { .await; } -#[cfg(not(target_os = "wasi"))] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn join_local_future_elsewhere() { thread_local! { @@ -294,7 +296,6 @@ fn join_local_future_elsewhere() { }); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[test] fn drop_cancels_tasks() { use std::rc::Rc; @@ -413,7 +414,7 @@ fn local_tasks_wake_join_all() { }); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[test] fn local_tasks_are_polled_after_tick() { // This test depends on timing, so we run it up to five times. @@ -430,6 +431,7 @@ fn local_tasks_are_polled_after_tick() { local_tasks_are_polled_after_tick_inner(); } +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[tokio::main(flavor = "current_thread")] async fn local_tasks_are_polled_after_tick_inner() { // Reproduces issues #1899 and #1900 @@ -488,7 +490,6 @@ async fn local_tasks_are_polled_after_tick_inner() { .await; } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] #[tokio::test] async fn acquire_mutex_in_drop() { use futures::future::pending; @@ -526,7 +527,6 @@ async fn acquire_mutex_in_drop() { } #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn spawn_wakes_localset() { let local = LocalSet::new(); futures::select! { diff --git a/tokio/tests/tcp_accept.rs b/tokio/tests/tcp_accept.rs index 3107e5de223..d547c48daa3 100644 --- a/tokio/tests/tcp_accept.rs +++ b/tokio/tests/tcp_accept.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use tokio::net::{TcpListener, TcpStream}; use tokio::sync::{mpsc, oneshot}; diff --git a/tokio/tests/tcp_connect.rs b/tokio/tests/tcp_connect.rs index 10cb6b1d44c..269ba8ef695 100644 --- a/tokio/tests/tcp_connect.rs +++ b/tokio/tests/tcp_connect.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use tokio::net::{TcpListener, TcpStream}; use tokio::sync::oneshot; diff --git a/tokio/tests/tcp_echo.rs b/tokio/tests/tcp_echo.rs index d5144f63841..dfd4dd7b9f4 100644 --- a/tokio/tests/tcp_echo.rs +++ b/tokio/tests/tcp_echo.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use tokio::io::{self, AsyncReadExt, AsyncWriteExt}; use tokio::net::{TcpListener, TcpStream}; diff --git a/tokio/tests/tcp_into_split.rs b/tokio/tests/tcp_into_split.rs index 8ee91bbf399..2a030691f64 100644 --- a/tokio/tests/tcp_into_split.rs +++ b/tokio/tests/tcp_into_split.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use std::io::{Error, ErrorKind, Result}; use std::io::{Read, Write}; diff --git a/tokio/tests/tcp_into_std.rs b/tokio/tests/tcp_into_std.rs index e0769d2eff9..58996f75c90 100644 --- a/tokio/tests/tcp_into_std.rs +++ b/tokio/tests/tcp_into_std.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use std::io::Read; use std::io::Result; diff --git a/tokio/tests/tcp_peek.rs b/tokio/tests/tcp_peek.rs index 4d763666a51..606e23e7c16 100644 --- a/tokio/tests/tcp_peek.rs +++ b/tokio/tests/tcp_peek.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use tokio::io::AsyncReadExt; use tokio::net::TcpStream; diff --git a/tokio/tests/tcp_shutdown.rs b/tokio/tests/tcp_shutdown.rs index 2a5704360c3..86c1485a4a4 100644 --- a/tokio/tests/tcp_shutdown.rs +++ b/tokio/tests/tcp_shutdown.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use tokio::io::{self, AsyncReadExt, AsyncWriteExt}; use tokio::net::{TcpListener, TcpStream}; diff --git a/tokio/tests/tcp_socket.rs b/tokio/tests/tcp_socket.rs index c5129f15230..faead95c0bb 100644 --- a/tokio/tests/tcp_socket.rs +++ b/tokio/tests/tcp_socket.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use std::time::Duration; use tokio::net::TcpSocket; diff --git a/tokio/tests/tcp_split.rs b/tokio/tests/tcp_split.rs index 8174ab67e51..a1fc39af25c 100644 --- a/tokio/tests/tcp_split.rs +++ b/tokio/tests/tcp_split.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use std::io::Result; use std::io::{Read, Write}; diff --git a/tokio/tests/tcp_stream.rs b/tokio/tests/tcp_stream.rs index 422e69b9cbb..f1048f93898 100644 --- a/tokio/tests/tcp_stream.rs +++ b/tokio/tests/tcp_stream.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support bind use tokio::io::{AsyncReadExt, AsyncWriteExt, Interest}; use tokio::net::{TcpListener, TcpStream}; diff --git a/tokio/tests/test_clock.rs b/tokio/tests/test_clock.rs index f129e6700c9..6141c11b534 100644 --- a/tokio/tests/test_clock.rs +++ b/tokio/tests/test_clock.rs @@ -3,9 +3,7 @@ use tokio::time::{self, Duration, Instant}; -// https://github.com/tokio-rs/mio/pull/1580 #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn resume_lets_time_move_forward_instead_of_resetting_it() { let start = Instant::now(); time::pause(); @@ -19,7 +17,6 @@ async fn resume_lets_time_move_forward_instead_of_resetting_it() { } #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn can_pause_after_resume() { let start = Instant::now(); time::pause(); @@ -31,6 +28,7 @@ async fn can_pause_after_resume() { assert!(Instant::now() - start < Duration::from_secs(21)); } +#[cfg(not(target_os = "wasi"))] // Wasi does not support panic recovery #[tokio::test] #[should_panic] async fn freezing_time_while_frozen_panics() { @@ -38,12 +36,14 @@ async fn freezing_time_while_frozen_panics() { time::pause(); } +#[cfg(not(target_os = "wasi"))] // Wasi does not support panic recovery #[tokio::test] #[should_panic] async fn advancing_time_when_time_is_not_frozen_panics() { time::advance(Duration::from_secs(1)).await; } +#[cfg(not(target_os = "wasi"))] // Wasi does not support panic recovery #[tokio::test] #[should_panic] async fn resuming_time_when_not_frozen_panics() { diff --git a/tokio/tests/time_interval.rs b/tokio/tests/time_interval.rs index 2a696fa4c1a..186582e2e52 100644 --- a/tokio/tests/time_interval.rs +++ b/tokio/tests/time_interval.rs @@ -38,8 +38,6 @@ async fn interval_zero_duration() { // Ready(s + 5p) | // Ready(s + 6p) #[tokio::test(start_paused = true)] -// https://github.com/tokio-rs/mio/pull/1580 -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn burst() { let start = Instant::now(); @@ -84,7 +82,6 @@ async fn burst() { // Ready(s + 3p + d) | // Ready(s + 4p + d) #[tokio::test(start_paused = true)] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn delay() { let start = Instant::now(); @@ -137,7 +134,6 @@ async fn delay() { // Ready(s + p) Ready(s + 5p) | // Ready(s + 6p) #[tokio::test(start_paused = true)] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn skip() { let start = Instant::now(); @@ -171,7 +167,6 @@ async fn skip() { } #[tokio::test(start_paused = true)] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn reset() { let start = Instant::now(); diff --git a/tokio/tests/time_panic.rs b/tokio/tests/time_panic.rs index 94a595f2949..cb06f44522a 100644 --- a/tokio/tests/time_panic.rs +++ b/tokio/tests/time_panic.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support panic recovery use futures::future; use std::error::Error; diff --git a/tokio/tests/time_pause.rs b/tokio/tests/time_pause.rs index 49ee45f9ada..30b752335b8 100644 --- a/tokio/tests/time_pause.rs +++ b/tokio/tests/time_pause.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads use rand::SeedableRng; use rand::{rngs::StdRng, Rng}; diff --git a/tokio/tests/time_rt.rs b/tokio/tests/time_rt.rs index 6ac44322adb..3652b0bc448 100644 --- a/tokio/tests/time_rt.rs +++ b/tokio/tests/time_rt.rs @@ -5,7 +5,7 @@ use tokio::time::*; use std::sync::mpsc; -#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] +#[cfg(all(feature = "rt-multi-thread", not(target_os = "wasi")))] // Wasi doesn't support threads #[test] fn timer_with_threaded_runtime() { use tokio::runtime::Runtime; diff --git a/tokio/tests/time_sleep.rs b/tokio/tests/time_sleep.rs index 97cadecb0a5..787f6329a16 100644 --- a/tokio/tests/time_sleep.rs +++ b/tokio/tests/time_sleep.rs @@ -168,6 +168,7 @@ async fn reset_sleep_to_past() { assert_ready!(sleep.poll()); } +#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[test] #[should_panic] fn creating_sleep_outside_of_context() { diff --git a/tokio/tests/time_timeout.rs b/tokio/tests/time_timeout.rs index abccea80da1..63ea5c90487 100644 --- a/tokio/tests/time_timeout.rs +++ b/tokio/tests/time_timeout.rs @@ -17,7 +17,7 @@ async fn simultaneous_deadline_future_completion() { assert_ready_ok!(fut.poll()); } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] +#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support threads")] #[tokio::test] async fn completed_future_past_deadline() { // Wrap it with a deadline @@ -102,9 +102,7 @@ async fn very_large_timeout() { assert_ready_ok!(fut.poll()).unwrap(); } -// https://github.com/tokio-rs/mio/pull/1580 #[tokio::test] -#[cfg_attr(target_os = "wasi", ignore = "FIXME: empty poll in park")] async fn deadline_now_elapses() { use futures::future::pending; diff --git a/tokio/tests/udp.rs b/tokio/tests/udp.rs index 1355ed2c4a2..5a29525d421 100644 --- a/tokio/tests/udp.rs +++ b/tokio/tests/udp.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support bind or UDP use futures::future::poll_fn; use std::io; diff --git a/tokio/tests/unwindsafe.rs b/tokio/tests/unwindsafe.rs index 919d3bd442c..23fc1b2a4ac 100644 --- a/tokio/tests/unwindsafe.rs +++ b/tokio/tests/unwindsafe.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] +#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi does not support panic recovery use std::panic::{RefUnwindSafe, UnwindSafe}; From 4c0cf30c40709d824844804fd2e6b1452cc8474b Mon Sep 17 00:00:00 2001 From: Richard Zak Date: Tue, 5 Jul 2022 14:46:16 -0400 Subject: [PATCH 7/8] fixup Signed-off-by: Richard Zak --- tests-integration/tests/macros_main.rs | 6 +++- tokio-stream/tests/stream_panic.rs | 3 +- tokio/Cargo.toml | 4 ++- tokio/src/io/mod.rs | 2 ++ tokio/src/runtime/blocking/pool.rs | 1 + tokio/src/runtime/mod.rs | 1 + tokio/tests/io_buf_reader.rs | 1 + tokio/tests/rt_basic.rs | 2 ++ tokio/tests/rt_metrics.rs | 2 +- tokio/tests/rt_threaded.rs | 42 ++------------------------ tokio/tests/sync_mpsc.rs | 8 ++--- tokio/tests/task_local_set.rs | 10 ++++-- tokio/tests/test_clock.rs | 3 -- tokio/tests/time_pause.rs | 9 ++++-- tokio/tests/time_timeout.rs | 2 +- 15 files changed, 39 insertions(+), 57 deletions(-) diff --git a/tests-integration/tests/macros_main.rs b/tests-integration/tests/macros_main.rs index 31442805141..e34387e5ec1 100644 --- a/tests-integration/tests/macros_main.rs +++ b/tests-integration/tests/macros_main.rs @@ -1,4 +1,8 @@ -#![cfg(all(feature = "macros", feature = "rt-multi-thread"))] +#![cfg(all( + feature = "macros", + feature = "rt-multi-thread", + not(target_os = "wasi") +))] #[tokio::main] async fn basic_main() -> usize { diff --git a/tokio-stream/tests/stream_panic.rs b/tokio-stream/tests/stream_panic.rs index 8ff9ff59b5f..22c1c208001 100644 --- a/tokio-stream/tests/stream_panic.rs +++ b/tokio-stream/tests/stream_panic.rs @@ -1,6 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "time")] -#![cfg(not(target_os = "wasi"))] // Wasi does not support panic recovery +#![cfg(all(feature = "time", not(target_os = "wasi")))] // Wasi does not support panic recovery use parking_lot::{const_mutex, Mutex}; use std::error::Error; diff --git a/tokio/Cargo.toml b/tokio/Cargo.toml index 5edd9a2f645..b9aa68c8f94 100644 --- a/tokio/Cargo.toml +++ b/tokio/Cargo.toml @@ -150,9 +150,11 @@ async-stream = "0.3" [target.'cfg(not(target_arch = "wasm32"))'.dev-dependencies] proptest = "1" -rand = "0.8.0" socket2 = "0.4" +[target.'cfg(not(all(target_arch = "wasm32", target_os = "unknown")))'.dev-dependencies] +rand = "0.8.0" + [target.'cfg(all(target_arch = "wasm32", not(target_os = "wasi")))'.dev-dependencies] wasm-bindgen-test = "0.3.0" diff --git a/tokio/src/io/mod.rs b/tokio/src/io/mod.rs index cfdda61f694..7113af0c363 100644 --- a/tokio/src/io/mod.rs +++ b/tokio/src/io/mod.rs @@ -211,9 +211,11 @@ cfg_io_driver_impl! { pub use driver::{Interest, Ready}; } + #[cfg_attr(target_os = "wasi", allow(unused_imports))] mod poll_evented; #[cfg(not(loom))] + #[cfg_attr(target_os = "wasi", allow(unused_imports))] pub(crate) use poll_evented::PollEvented; } diff --git a/tokio/src/runtime/blocking/pool.rs b/tokio/src/runtime/blocking/pool.rs index f73868ee9e7..7dadacc07cf 100644 --- a/tokio/src/runtime/blocking/pool.rs +++ b/tokio/src/runtime/blocking/pool.rs @@ -105,6 +105,7 @@ const KEEP_ALIVE: Duration = Duration::from_secs(10); /// Tasks will be scheduled as non-mandatory, meaning they may not get executed /// in case of runtime shutdown. #[track_caller] +#[cfg_attr(target_os = "wasi", allow(dead_code))] pub(crate) fn spawn_blocking(func: F) -> JoinHandle where F: FnOnce() -> R + Send + 'static, diff --git a/tokio/src/runtime/mod.rs b/tokio/src/runtime/mod.rs index dad285d1fbd..46a63614e54 100644 --- a/tokio/src/runtime/mod.rs +++ b/tokio/src/runtime/mod.rs @@ -204,6 +204,7 @@ cfg_rt! { mod blocking; use blocking::BlockingPool; + #[cfg_attr(target_os = "wasi", allow(unused_imports))] pub(crate) use blocking::spawn_blocking; cfg_trace! { diff --git a/tokio/tests/io_buf_reader.rs b/tokio/tests/io_buf_reader.rs index 864bc023ab5..0d3f6bafc20 100644 --- a/tokio/tests/io_buf_reader.rs +++ b/tokio/tests/io_buf_reader.rs @@ -277,6 +277,7 @@ async fn maybe_pending_buf_read() { assert_eq!(v, []); } +// https://github.com/rust-lang/futures-rs/pull/1573#discussion_r281162309 #[tokio::test] async fn maybe_pending_seek() { struct MaybePendingSeek<'a> { diff --git a/tokio/tests/rt_basic.rs b/tokio/tests/rt_basic.rs index c3df1c1a859..73bafdc4d5c 100644 --- a/tokio/tests/rt_basic.rs +++ b/tokio/tests/rt_basic.rs @@ -315,6 +315,7 @@ mod unstable { } #[test] + #[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] fn spawns_do_nothing() { use std::sync::Arc; @@ -343,6 +344,7 @@ mod unstable { } #[test] + #[cfg_attr(target_os = "wasi", ignore = "Wasi does not support panic recovery")] fn shutdown_all_concurrent_block_on() { const N: usize = 2; use std::sync::{mpsc, Arc}; diff --git a/tokio/tests/rt_metrics.rs b/tokio/tests/rt_metrics.rs index e86beb91421..3b8070533cf 100644 --- a/tokio/tests/rt_metrics.rs +++ b/tokio/tests/rt_metrics.rs @@ -1,5 +1,5 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", tokio_unstable))] +#![cfg(all(feature = "full", tokio_unstable, not(target_os = "wasi")))] use tokio::runtime::Runtime; use tokio::time::{self, Duration}; diff --git a/tokio/tests/rt_threaded.rs b/tokio/tests/rt_threaded.rs index a79007d48bc..187cd557b37 100644 --- a/tokio/tests/rt_threaded.rs +++ b/tokio/tests/rt_threaded.rs @@ -1,17 +1,12 @@ #![warn(rust_2018_idioms)] -#![cfg(feature = "full")] +#![cfg(all(feature = "full", not(target_os = "wasi")))] -#[cfg(not(target_os = "wasi"))] use tokio::io::{AsyncReadExt, AsyncWriteExt}; -#[cfg(not(target_os = "wasi"))] use tokio::net::{TcpListener, TcpStream}; use tokio::runtime; use tokio::sync::oneshot; -#[cfg(not(target_os = "wasi"))] -use tokio_test::assert_err; -use tokio_test::assert_ok; +use tokio_test::{assert_err, assert_ok}; -#[cfg(not(target_os = "wasi"))] use futures::future::poll_fn; use std::future::Future; use std::pin::Pin; @@ -29,7 +24,6 @@ macro_rules! cfg_metrics { } } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn single_thread() { // No panic when starting a runtime w/ a single thread @@ -39,10 +33,6 @@ fn single_thread() { .build(); } -#[cfg_attr( - target_os = "wasi", - ignore = "WASI: std::mpsc without thread parking not working" -)] #[test] fn many_oneshot_futures() { // used for notifying the main thread @@ -170,7 +160,6 @@ fn many_multishot_futures() { } } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn spawn_shutdown() { let rt = rt(); @@ -190,7 +179,6 @@ fn spawn_shutdown() { assert_err!(rx.try_recv()); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support bind async fn client_server(tx: mpsc::Sender<()>) { let server = assert_ok!(TcpListener::bind("127.0.0.1:0").await); @@ -215,7 +203,6 @@ async fn client_server(tx: mpsc::Sender<()>) { tx.send(()).unwrap(); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn drop_threadpool_drops_futures() { for _ in 0..1_000 { @@ -272,7 +259,6 @@ fn drop_threadpool_drops_futures() { } } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn start_stop_callbacks_called() { use std::sync::atomic::{AtomicUsize, Ordering}; @@ -307,7 +293,6 @@ fn start_stop_callbacks_called() { assert!(before_stop.load(Ordering::Relaxed) > 0); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn blocking() { // used for notifying the main thread @@ -353,7 +338,6 @@ fn blocking() { } } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn multi_threadpool() { use tokio::sync::oneshot; @@ -382,7 +366,6 @@ fn multi_threadpool() { // // The test ensures that, when this happens, attempting to consume from a // channel yields occasionally even if there are values ready to receive. -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support threads #[test] fn coop_and_block_in_place() { let rt = tokio::runtime::Builder::new_multi_thread() @@ -433,7 +416,6 @@ fn coop_and_block_in_place() { } // Testing this does not panic -#[cfg(not(target_os = "wasi"))] // Wasi does not support threads #[test] fn max_blocking_threads() { let _rt = tokio::runtime::Builder::new_multi_thread() @@ -442,7 +424,6 @@ fn max_blocking_threads() { .unwrap(); } -#[cfg(not(target_os = "wasi"))] // Wasi does not support threads #[test] #[should_panic] fn max_blocking_threads_set_to_zero() { @@ -452,7 +433,6 @@ fn max_blocking_threads_set_to_zero() { .unwrap(); } -#[cfg(not(target_os = "wasi"))] // Wasi does not support threads #[tokio::test(flavor = "multi_thread", worker_threads = 2)] async fn hang_on_shutdown() { let (sync_tx, sync_rx) = std::sync::mpsc::channel::<()>(); @@ -521,19 +501,12 @@ fn wake_during_shutdown() { } } - #[cfg(not(target_os = "wasi"))] let rt = tokio::runtime::Builder::new_multi_thread() .worker_threads(1) .enable_all() .build() .unwrap(); - #[cfg(target_os = "wasi")] - let rt = tokio::runtime::Builder::new_current_thread() - .enable_all() - .build() - .unwrap(); - let (f1, f2) = MyFuture::new(); rt.spawn(f1); @@ -542,20 +515,17 @@ fn wake_during_shutdown() { rt.block_on(async { tokio::time::sleep(tokio::time::Duration::from_millis(20)).await }); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[should_panic] #[tokio::test] async fn test_block_in_place1() { tokio::task::block_in_place(|| {}); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[tokio::test(flavor = "multi_thread")] async fn test_block_in_place2() { tokio::task::block_in_place(|| {}); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[should_panic] #[tokio::main(flavor = "current_thread")] #[test] @@ -563,20 +533,12 @@ async fn test_block_in_place3() { tokio::task::block_in_place(|| {}); } -#[cfg(not(target_os = "wasi"))] // Wasi doesn't support panic recovery #[tokio::main] #[test] async fn test_block_in_place4() { tokio::task::block_in_place(|| {}); } -#[cfg(not(target_os = "wasi"))] fn rt() -> runtime::Runtime { runtime::Runtime::new().unwrap() } - -#[cfg(target_os = "wasi")] -fn rt() -> runtime::Runtime { - use runtime::Builder; - Builder::new_current_thread().enable_all().build().unwrap() -} diff --git a/tokio/tests/sync_mpsc.rs b/tokio/tests/sync_mpsc.rs index f598db0889a..a1510f57d09 100644 --- a/tokio/tests/sync_mpsc.rs +++ b/tokio/tests/sync_mpsc.rs @@ -88,7 +88,7 @@ async fn reserve_disarm() { } #[tokio::test] -#[cfg(all(feature = "full", not(target_os = "wasi")))] +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads async fn send_recv_stream_with_buffer() { use tokio_stream::StreamExt; @@ -192,7 +192,7 @@ async fn async_send_recv_unbounded() { } #[tokio::test] -#[cfg(all(feature = "full", not(target_os = "wasi")))] +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads async fn send_recv_stream_unbounded() { use tokio_stream::StreamExt; @@ -453,7 +453,7 @@ fn unconsumed_messages_are_dropped() { } #[test] -#[cfg(all(feature = "full", not(target_os = "wasi")))] +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads fn blocking_recv() { let (tx, mut rx) = mpsc::channel::(1); @@ -478,7 +478,7 @@ async fn blocking_recv_async() { } #[test] -#[cfg(all(feature = "full", not(target_os = "wasi")))] +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads fn blocking_send() { let (tx, mut rx) = mpsc::channel::(1); diff --git a/tokio/tests/task_local_set.rs b/tokio/tests/task_local_set.rs index 91dd998d09c..c2bb4848c56 100644 --- a/tokio/tests/task_local_set.rs +++ b/tokio/tests/task_local_set.rs @@ -369,7 +369,10 @@ fn with_timeout(timeout: Duration, f: impl FnOnce() + Send + 'static) { thread.join().expect("test thread should not panic!") } -#[cfg_attr(target_os = "wasi", ignore = "FIXME: Does not seem to work with WASI")] +#[cfg_attr( + target_os = "wasi", + ignore = "`unwrap()` in `with_timeout()` panics on Wasi" +)] #[test] fn drop_cancels_remote_tasks() { // This test reproduces issue #1885. @@ -392,7 +395,10 @@ fn drop_cancels_remote_tasks() { }); } -#[cfg(not(target_os = "wasi"))] +#[cfg_attr( + target_os = "wasi", + ignore = "FIXME: `task::spawn_local().await.unwrap()` panics on Wasi" +)] #[test] fn local_tasks_wake_join_all() { // This test reproduces issue #2460. diff --git a/tokio/tests/test_clock.rs b/tokio/tests/test_clock.rs index 6141c11b534..891636fdb28 100644 --- a/tokio/tests/test_clock.rs +++ b/tokio/tests/test_clock.rs @@ -28,7 +28,6 @@ async fn can_pause_after_resume() { assert!(Instant::now() - start < Duration::from_secs(21)); } -#[cfg(not(target_os = "wasi"))] // Wasi does not support panic recovery #[tokio::test] #[should_panic] async fn freezing_time_while_frozen_panics() { @@ -36,14 +35,12 @@ async fn freezing_time_while_frozen_panics() { time::pause(); } -#[cfg(not(target_os = "wasi"))] // Wasi does not support panic recovery #[tokio::test] #[should_panic] async fn advancing_time_when_time_is_not_frozen_panics() { time::advance(Duration::from_secs(1)).await; } -#[cfg(not(target_os = "wasi"))] // Wasi does not support panic recovery #[tokio::test] #[should_panic] async fn resuming_time_when_not_frozen_panics() { diff --git a/tokio/tests/time_pause.rs b/tokio/tests/time_pause.rs index 30b752335b8..6251b4b829f 100644 --- a/tokio/tests/time_pause.rs +++ b/tokio/tests/time_pause.rs @@ -1,10 +1,13 @@ #![warn(rust_2018_idioms)] -#![cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads +#![cfg(feature = "full")] use rand::SeedableRng; use rand::{rngs::StdRng, Rng}; use tokio::time::{self, Duration, Instant, Sleep}; -use tokio_test::{assert_elapsed, assert_err, assert_pending, assert_ready, assert_ready_eq, task}; +use tokio_test::{assert_elapsed, assert_pending, assert_ready, assert_ready_eq, task}; + +#[cfg(not(target_os = "wasi"))] +use tokio_test::assert_err; use std::{ future::Future, @@ -26,12 +29,14 @@ async fn pause_time_in_task() { t.await.unwrap(); } +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread", worker_threads = 1)] #[should_panic] async fn pause_time_in_main_threads() { tokio::time::pause(); } +#[cfg(all(feature = "full", not(target_os = "wasi")))] // Wasi doesn't support threads #[tokio::test(flavor = "multi_thread", worker_threads = 1)] async fn pause_time_in_spawn_threads() { let t = tokio::spawn(async { diff --git a/tokio/tests/time_timeout.rs b/tokio/tests/time_timeout.rs index 63ea5c90487..ec871cf62fe 100644 --- a/tokio/tests/time_timeout.rs +++ b/tokio/tests/time_timeout.rs @@ -17,7 +17,7 @@ async fn simultaneous_deadline_future_completion() { assert_ready_ok!(fut.poll()); } -#[cfg_attr(target_os = "wasi", ignore = "Wasi does not support threads")] +#[cfg_attr(target_os = "wasi", ignore = "FIXME: `fut.poll()` panics on Wasi")] #[tokio::test] async fn completed_future_past_deadline() { // Wrap it with a deadline From eb926689ef07e89c04d82b2fb5416bcbe70da68a Mon Sep 17 00:00:00 2001 From: Richard Zak Date: Tue, 12 Jul 2022 10:54:50 -0400 Subject: [PATCH 8/8] gate most Wasm32 features on unstable Signed-off-by: Richard Zak --- tokio/src/lib.rs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/tokio/src/lib.rs b/tokio/src/lib.rs index c0d7e6252e4..4d9678c5df0 100644 --- a/tokio/src/lib.rs +++ b/tokio/src/lib.rs @@ -393,6 +393,20 @@ compile_error! { "Tokio requires the platform pointer width to be 32, 64, or 128 bits" } +#[cfg(all( + not(tokio_unstable), + target_arch = "wasm32", + any( + feature = "fs", + feature = "io-std", + feature = "net", + feature = "process", + feature = "rt-multi-thread", + feature = "signal" + ) +))] +compile_error!("Only features sync,macros,io-util,rt are supported on wasm."); + // Includes re-exports used by macros. // // This module is not intended to be part of the public API. In general, any