From f3a944a7f98a2e4cc7cd39a1d1d280893af0ef80 Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Thu, 26 May 2022 11:02:22 -0700 Subject: Update TEST_MAPPING Test: None Bug: 233924440 Change-Id: Ia2ac777545c16c6d90ce4613490744d796d5ee62 --- TEST_MAPPING | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/TEST_MAPPING b/TEST_MAPPING index e2df61d..ed86f4e 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -8,6 +8,20 @@ "path": "external/rust/crates/tokio" } ], + "postsubmit": [ + { + "name": "ZipFuseTest" + }, + { + "name": "authfs_device_test_src_lib" + }, + { + "name": "doh_unit_test" + }, + { + "name": "virtualizationservice_device_test" + } + ], "presubmit": [ { "name": "ZipFuseTest" -- cgit v1.2.3 From ac016dfef8a95f89bba64f2051ba182dc3c33562 Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Tue, 14 Jun 2022 16:02:36 -0700 Subject: Update TEST_MAPPING Test: None Bug: 236006683 Change-Id: I42dde37cf1b472cbde62f2b75255df881b0cacea --- TEST_MAPPING | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/TEST_MAPPING b/TEST_MAPPING index ed86f4e..e2df61d 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -8,20 +8,6 @@ "path": "external/rust/crates/tokio" } ], - "postsubmit": [ - { - "name": "ZipFuseTest" - }, - { - "name": "authfs_device_test_src_lib" - }, - { - "name": "doh_unit_test" - }, - { - "name": "virtualizationservice_device_test" - } - ], "presubmit": [ { "name": "ZipFuseTest" -- cgit v1.2.3 From a8c6c6cbd55eb94771e4f00599f5476880a50248 Mon Sep 17 00:00:00 2001 From: William Escande Date: Mon, 22 Aug 2022 11:27:55 -0700 Subject: [Bluetooth apex] Use new apex name The Bluetooth apex name is now called com.android.btservices Bug: 243054261 Test: Build Change-Id: Ie7a8e42908425bac4b8ae063c6bab24a7f0bf52c --- Android.bp | 2 +- cargo2android.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Android.bp b/Android.bp index a594b53..d519524 100644 --- a/Android.bp +++ b/Android.bp @@ -64,7 +64,7 @@ rust_library { ], apex_available: [ "//apex_available:platform", - "com.android.bluetooth", + "com.android.btservices", "com.android.resolv", "com.android.virt", ], diff --git a/cargo2android.json b/cargo2android.json index a7e2a4b..7b27fc0 100644 --- a/cargo2android.json +++ b/cargo2android.json @@ -1,7 +1,7 @@ { "apex-available": [ "//apex_available:platform", - "com.android.bluetooth", + "com.android.btservices", "com.android.resolv", "com.android.virt" ], -- cgit v1.2.3 From 098788f6ac10a52b3920bedbc46958bc008104fa Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Mon, 12 Dec 2022 08:03:43 +0100 Subject: Upgrade futures to 0.3.25 This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update rust/crates/futures For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md Test: TreeHugger Change-Id: Ib4fd808f9d6858f772faa48545b8d3556e4cd6f6 --- .cargo_vcs_info.json | 2 +- Android.bp | 2 +- Cargo.toml | 20 ++++++------ Cargo.toml.orig | 18 +++++------ METADATA | 12 ++++--- README.md | 61 ++++++++++++++++++++++++++++++++++++ src/lib.rs | 4 ++- tests/async_await_macros.rs | 10 +++--- tests/auto_traits.rs | 4 +-- tests/eventual.rs | 6 ++-- tests/future_join.rs | 32 +++++++++++++++++++ tests/future_shared.rs | 33 +++++++++++++++++++- tests/lock_mutex.rs | 50 +++++++++++++++-------------- tests/macro_comma_support.rs | 1 - tests/ready_queue.rs | 5 +-- tests/recurse.rs | 1 - tests/sink.rs | 3 +- tests/stream.rs | 42 +++++++++++++++++++++++++ tests/stream_futures_ordered.rs | 66 +++++++++++++++++++++++++++++++++++++-- tests/stream_futures_unordered.rs | 16 ++++++++-- tests/stream_try_stream.rs | 2 -- tests/task_atomic_waker.rs | 1 - tests_disabled/stream.rs | 1 - 23 files changed, 316 insertions(+), 76 deletions(-) create mode 100644 README.md create mode 100644 tests/future_join.rs diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index e483977..c68093a 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "fc1e3250219170e31cddb8857a276cba7dd08d44" + "sha1": "77d82198c5afd04af3e760a6aa50b7e875289fc3" }, "path_in_vcs": "futures" } \ No newline at end of file diff --git a/Android.bp b/Android.bp index d519524..0e41e22 100644 --- a/Android.bp +++ b/Android.bp @@ -42,7 +42,7 @@ rust_library { host_supported: true, crate_name: "futures", cargo_env_compat: true, - cargo_pkg_version: "0.3.21", + cargo_pkg_version: "0.3.25", srcs: ["src/lib.rs"], edition: "2018", features: [ diff --git a/Cargo.toml b/Cargo.toml index f740f96..4a025a8 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,13 +13,13 @@ edition = "2018" rust-version = "1.45" name = "futures" -version = "0.3.21" +version = "0.3.25" description = """ An implementation of futures and streams featuring zero allocations, composability, and iterator-like interfaces. """ homepage = "https://rust-lang.github.io/futures-rs" -readme = "../README.md" +readme = "README.md" keywords = [ "futures", "async", @@ -47,33 +47,33 @@ features = [ ] [dependencies.futures-channel] -version = "0.3.21" +version = "0.3.25" features = ["sink"] default-features = false [dependencies.futures-core] -version = "0.3.21" +version = "0.3.25" default-features = false [dependencies.futures-executor] -version = "0.3.21" +version = "0.3.25" optional = true default-features = false [dependencies.futures-io] -version = "0.3.21" +version = "0.3.25" default-features = false [dependencies.futures-sink] -version = "0.3.21" +version = "0.3.25" default-features = false [dependencies.futures-task] -version = "0.3.21" +version = "0.3.25" default-features = false [dependencies.futures-util] -version = "0.3.21" +version = "0.3.25" features = ["sink"] default-features = false @@ -81,7 +81,7 @@ default-features = false version = "1.3.0" [dev-dependencies.pin-project] -version = "1.0.1" +version = "1.0.11" [dev-dependencies.pin-utils] version = "0.1.0" diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 6871f47..544a1e3 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "futures" -version = "0.3.21" +version = "0.3.25" edition = "2018" rust-version = "1.45" license = "MIT OR Apache-2.0" @@ -15,19 +15,19 @@ composability, and iterator-like interfaces. categories = ["asynchronous"] [dependencies] -futures-core = { path = "../futures-core", version = "0.3.21", default-features = false } -futures-task = { path = "../futures-task", version = "0.3.21", default-features = false } -futures-channel = { path = "../futures-channel", version = "0.3.21", default-features = false, features = ["sink"] } -futures-executor = { path = "../futures-executor", version = "0.3.21", default-features = false, optional = true } -futures-io = { path = "../futures-io", version = "0.3.21", default-features = false } -futures-sink = { path = "../futures-sink", version = "0.3.21", default-features = false } -futures-util = { path = "../futures-util", version = "0.3.21", default-features = false, features = ["sink"] } +futures-core = { path = "../futures-core", version = "0.3.25", default-features = false } +futures-task = { path = "../futures-task", version = "0.3.25", default-features = false } +futures-channel = { path = "../futures-channel", version = "0.3.25", default-features = false, features = ["sink"] } +futures-executor = { path = "../futures-executor", version = "0.3.25", default-features = false, optional = true } +futures-io = { path = "../futures-io", version = "0.3.25", default-features = false } +futures-sink = { path = "../futures-sink", version = "0.3.25", default-features = false } +futures-util = { path = "../futures-util", version = "0.3.25", default-features = false, features = ["sink"] } [dev-dependencies] futures-executor = { path = "../futures-executor", features = ["thread-pool"] } futures-test = { path = "../futures-test" } assert_matches = "1.3.0" -pin-project = "1.0.1" +pin-project = "1.0.11" pin-utils = "0.1.0" static_assertions = "1" tokio = "0.1.11" diff --git a/METADATA b/METADATA index 554f4df..1dee576 100644 --- a/METADATA +++ b/METADATA @@ -1,3 +1,7 @@ +# This project was upgraded with external_updater. +# Usage: tools/external_updater/updater.sh update rust/crates/futures +# For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md + name: "futures" description: "An implementation of futures and streams featuring zero allocations, composability, and iterator-like interfaces." third_party { @@ -7,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/futures/futures-0.3.21.crate" + value: "https://static.crates.io/crates/futures/futures-0.3.25.crate" } - version: "0.3.21" + version: "0.3.25" license_type: NOTICE last_upgrade_date { year: 2022 - month: 3 - day: 1 + month: 12 + day: 12 } } diff --git a/README.md b/README.md new file mode 100644 index 0000000..e6127fd --- /dev/null +++ b/README.md @@ -0,0 +1,61 @@ +

+ futures-rs +

+ +

+ Zero-cost asynchronous programming in Rust +

+ +

+ + Build Status + + + + Crates.io + +

+ +

+ + Documentation + | + Website + +

+ +`futures-rs` is a library providing the foundations for asynchronous programming in Rust. +It includes key trait definitions like `Stream`, as well as utilities like `join!`, +`select!`, and various futures combinator methods which enable expressive asynchronous +control flow. + +## Usage + +Add this to your `Cargo.toml`: + +```toml +[dependencies] +futures = "0.3" +``` + +The current `futures` requires Rust 1.45 or later. + +### Feature `std` + +Futures-rs works without the standard library, such as in bare metal environments. +However, it has a significantly reduced API surface. To use futures-rs in +a `#[no_std]` environment, use: + +```toml +[dependencies] +futures = { version = "0.3", default-features = false } +``` + +## License + +Licensed under either of [Apache License, Version 2.0](LICENSE-APACHE) or +[MIT license](LICENSE-MIT) at your option. + +Unless you explicitly state otherwise, any contribution intentionally submitted +for inclusion in the work by you, as defined in the Apache-2.0 license, shall +be dual licensed as above, without any additional terms or conditions. diff --git a/src/lib.rs b/src/lib.rs index b8ebc61..b972f51 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -25,13 +25,13 @@ //! within macros and keywords such as async and await!. //! //! ```rust -//! # if cfg!(miri) { return; } // https://github.com/rust-lang/miri/issues/1038 //! # use futures::channel::mpsc; //! # use futures::executor; ///standard executors to provide a context for futures and streams //! # use futures::executor::ThreadPool; //! # use futures::StreamExt; //! # //! fn main() { +//! # { //! let pool = ThreadPool::new().expect("Failed to build pool"); //! let (tx, rx) = mpsc::unbounded::(); //! @@ -73,6 +73,8 @@ //! let values: Vec = executor::block_on(fut_values); //! //! println!("Values={:?}", values); +//! # } +//! # std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371 //! } //! ``` //! diff --git a/tests/async_await_macros.rs b/tests/async_await_macros.rs index ce1f3a3..250e345 100644 --- a/tests/async_await_macros.rs +++ b/tests/async_await_macros.rs @@ -346,36 +346,38 @@ fn stream_select() { }); } +#[cfg_attr(not(target_pointer_width = "64"), ignore)] #[test] fn join_size() { let fut = async { let ready = future::ready(0i32); join!(ready) }; - assert_eq!(mem::size_of_val(&fut), 16); + assert_eq!(mem::size_of_val(&fut), 24); let fut = async { let ready1 = future::ready(0i32); let ready2 = future::ready(0i32); join!(ready1, ready2) }; - assert_eq!(mem::size_of_val(&fut), 28); + assert_eq!(mem::size_of_val(&fut), 40); } +#[cfg_attr(not(target_pointer_width = "64"), ignore)] #[test] fn try_join_size() { let fut = async { let ready = future::ready(Ok::(0)); try_join!(ready) }; - assert_eq!(mem::size_of_val(&fut), 16); + assert_eq!(mem::size_of_val(&fut), 24); let fut = async { let ready1 = future::ready(Ok::(0)); let ready2 = future::ready(Ok::(0)); try_join!(ready1, ready2) }; - assert_eq!(mem::size_of_val(&fut), 28); + assert_eq!(mem::size_of_val(&fut), 48); } #[test] diff --git a/tests/auto_traits.rs b/tests/auto_traits.rs index b3d8b00..da00ccf 100644 --- a/tests/auto_traits.rs +++ b/tests/auto_traits.rs @@ -576,10 +576,10 @@ pub mod future { // TryJoin3, TryJoin4, TryJoin5 are the same as TryJoin - assert_impl!(TryJoinAll>: Send); + assert_impl!(TryJoinAll>: Send); assert_not_impl!(TryJoinAll: Send); assert_not_impl!(TryJoinAll: Send); - assert_impl!(TryJoinAll>: Sync); + assert_impl!(TryJoinAll>: Sync); assert_not_impl!(TryJoinAll: Sync); assert_not_impl!(TryJoinAll: Sync); assert_impl!(TryJoinAll: Unpin); diff --git a/tests/eventual.rs b/tests/eventual.rs index 3461380..951c55c 100644 --- a/tests/eventual.rs +++ b/tests/eventual.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] // https://github.com/rust-lang/miri/issues/1038 - use futures::channel::oneshot; use futures::executor::ThreadPool; use futures::future::{self, ok, Future, FutureExt, TryFutureExt}; @@ -136,6 +134,8 @@ fn select3() { #[test] fn select4() { + const N: usize = if cfg!(miri) { 100 } else { 10000 }; + let (tx, rx) = mpsc::channel::>(); let t = thread::spawn(move || { @@ -145,7 +145,7 @@ fn select4() { }); let (tx2, rx2) = mpsc::channel(); - for _ in 0..10000 { + for _ in 0..N { let (c1, p1) = oneshot::channel::(); let (c2, p2) = oneshot::channel::(); diff --git a/tests/future_join.rs b/tests/future_join.rs new file mode 100644 index 0000000..f5df9d7 --- /dev/null +++ b/tests/future_join.rs @@ -0,0 +1,32 @@ +use futures::executor::block_on; +use futures::future::Future; +use std::task::Poll; + +/// This tests verifies (through miri) that self-referencing +/// futures are not invalidated when joining them. +#[test] +fn futures_join_macro_self_referential() { + block_on(async { futures::join!(yield_now(), trouble()) }); +} + +async fn trouble() { + let lucky_number = 42; + let problematic_variable = &lucky_number; + + yield_now().await; + + // problematic dereference + let _ = { *problematic_variable }; +} + +fn yield_now() -> impl Future { + let mut yielded = false; + std::future::poll_fn(move |cx| { + if core::mem::replace(&mut yielded, true) { + Poll::Ready(()) + } else { + cx.waker().wake_by_ref(); + Poll::Pending + } + }) +} diff --git a/tests/future_shared.rs b/tests/future_shared.rs index 3ceaebb..6bf43d2 100644 --- a/tests/future_shared.rs +++ b/tests/future_shared.rs @@ -3,6 +3,7 @@ use futures::executor::{block_on, LocalPool}; use futures::future::{self, FutureExt, LocalFutureObj, TryFutureExt}; use futures::task::LocalSpawn; use std::cell::{Cell, RefCell}; +use std::panic::AssertUnwindSafe; use std::rc::Rc; use std::task::Poll; use std::thread; @@ -96,7 +97,6 @@ fn drop_in_poll() { assert_eq!(block_on(future1), 1); } -#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038 #[test] fn peek() { let mut local_pool = LocalPool::new(); @@ -194,3 +194,34 @@ fn shared_future_that_wakes_itself_until_pending_is_returned() { // has returned pending assert_eq!(block_on(futures::future::join(fut, async { proceed.set(true) })), ((), ())); } + +#[test] +#[should_panic(expected = "inner future panicked during poll")] +fn panic_while_poll() { + let fut = futures::future::poll_fn::(|_cx| panic!("test")).shared(); + + let fut_captured = fut.clone(); + std::panic::catch_unwind(AssertUnwindSafe(|| { + block_on(fut_captured); + })) + .unwrap_err(); + + block_on(fut); +} + +#[test] +#[should_panic(expected = "test_marker")] +fn poll_while_panic() { + struct S; + + impl Drop for S { + fn drop(&mut self) { + let fut = futures::future::ready(1).shared(); + assert_eq!(block_on(fut.clone()), 1); + assert_eq!(block_on(fut), 1); + } + } + + let _s = S {}; + panic!("test_marker"); +} diff --git a/tests/lock_mutex.rs b/tests/lock_mutex.rs index c92ef50..c15e76b 100644 --- a/tests/lock_mutex.rs +++ b/tests/lock_mutex.rs @@ -34,34 +34,36 @@ fn mutex_wakes_waiters() { assert!(waiter.poll_unpin(&mut panic_context()).is_ready()); } -#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038 #[test] fn mutex_contested() { - let (tx, mut rx) = mpsc::unbounded(); - let pool = ThreadPool::builder().pool_size(16).create().unwrap(); + { + let (tx, mut rx) = mpsc::unbounded(); + let pool = ThreadPool::builder().pool_size(16).create().unwrap(); - let tx = Arc::new(tx); - let mutex = Arc::new(Mutex::new(0)); + let tx = Arc::new(tx); + let mutex = Arc::new(Mutex::new(0)); - let num_tasks = 1000; - for _ in 0..num_tasks { - let tx = tx.clone(); - let mutex = mutex.clone(); - pool.spawn(async move { - let mut lock = mutex.lock().await; - ready(()).pending_once().await; - *lock += 1; - tx.unbounded_send(()).unwrap(); - drop(lock); - }) - .unwrap(); - } - - block_on(async { + let num_tasks = 1000; for _ in 0..num_tasks { - rx.next().await.unwrap(); + let tx = tx.clone(); + let mutex = mutex.clone(); + pool.spawn(async move { + let mut lock = mutex.lock().await; + ready(()).pending_once().await; + *lock += 1; + tx.unbounded_send(()).unwrap(); + drop(lock); + }) + .unwrap(); } - let lock = mutex.lock().await; - assert_eq!(num_tasks, *lock); - }) + + block_on(async { + for _ in 0..num_tasks { + rx.next().await.unwrap(); + } + let lock = mutex.lock().await; + assert_eq!(num_tasks, *lock); + }); + } + std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371 } diff --git a/tests/macro_comma_support.rs b/tests/macro_comma_support.rs index 3b082d2..85871e9 100644 --- a/tests/macro_comma_support.rs +++ b/tests/macro_comma_support.rs @@ -14,7 +14,6 @@ fn ready() { })) } -#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038 #[test] fn poll() { use futures::poll; diff --git a/tests/ready_queue.rs b/tests/ready_queue.rs index afba8f2..c19d625 100644 --- a/tests/ready_queue.rs +++ b/tests/ready_queue.rs @@ -93,10 +93,7 @@ fn dropping_ready_queue() { #[test] fn stress() { - #[cfg(miri)] - const ITER: usize = 30; - #[cfg(not(miri))] - const ITER: usize = 300; + const ITER: usize = if cfg!(miri) { 30 } else { 300 }; for i in 0..ITER { let n = (i % 10) + 1; diff --git a/tests/recurse.rs b/tests/recurse.rs index f06524f..d81753c 100644 --- a/tests/recurse.rs +++ b/tests/recurse.rs @@ -3,7 +3,6 @@ use futures::future::{self, BoxFuture, FutureExt}; use std::sync::mpsc; use std::thread; -#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038 #[test] fn lots() { #[cfg(not(futures_sanitizer))] diff --git a/tests/sink.rs b/tests/sink.rs index dc826bd..5b691e7 100644 --- a/tests/sink.rs +++ b/tests/sink.rs @@ -138,7 +138,7 @@ impl ManualFlush { for task in self.waiting_tasks.drain(..) { task.wake() } - mem::replace(&mut self.data, Vec::new()) + mem::take(&mut self.data) } } @@ -288,7 +288,6 @@ fn mpsc_blocking_start_send() { // test `flush` by using `with` to make the first insertion into a sink block // until a oneshot is completed -#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038 #[test] fn with_flush() { let (tx, rx) = oneshot::channel(); diff --git a/tests/stream.rs b/tests/stream.rs index 71ec654..5cde458 100644 --- a/tests/stream.rs +++ b/tests/stream.rs @@ -1,5 +1,9 @@ +use std::cell::Cell; use std::iter; +use std::pin::Pin; +use std::rc::Rc; use std::sync::Arc; +use std::task::Context; use futures::channel::mpsc; use futures::executor::block_on; @@ -9,6 +13,7 @@ use futures::sink::SinkExt; use futures::stream::{self, StreamExt}; use futures::task::Poll; use futures::{ready, FutureExt}; +use futures_core::Stream; use futures_test::task::noop_context; #[test] @@ -419,3 +424,40 @@ fn ready_chunks() { assert_eq!(s.next().await.unwrap(), vec![4]); }); } + +struct SlowStream { + times_should_poll: usize, + times_polled: Rc>, +} +impl Stream for SlowStream { + type Item = usize; + + fn poll_next(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll> { + self.times_polled.set(self.times_polled.get() + 1); + if self.times_polled.get() % 2 == 0 { + cx.waker().wake_by_ref(); + return Poll::Pending; + } + if self.times_polled.get() >= self.times_should_poll { + return Poll::Ready(None); + } + Poll::Ready(Some(self.times_polled.get())) + } +} + +#[test] +fn select_with_strategy_doesnt_terminate_early() { + for side in [stream::PollNext::Left, stream::PollNext::Right] { + let times_should_poll = 10; + let count = Rc::new(Cell::new(0)); + let b = stream::iter([10, 20]); + + let mut selected = stream::select_with_strategy( + SlowStream { times_should_poll, times_polled: count.clone() }, + b, + |_: &mut ()| side, + ); + block_on(async move { while selected.next().await.is_some() {} }); + assert_eq!(count.get(), times_should_poll + 1); + } +} diff --git a/tests/stream_futures_ordered.rs b/tests/stream_futures_ordered.rs index 84e0bcc..8b85a33 100644 --- a/tests/stream_futures_ordered.rs +++ b/tests/stream_futures_ordered.rs @@ -2,6 +2,7 @@ use futures::channel::oneshot; use futures::executor::{block_on, block_on_stream}; use futures::future::{self, join, Future, FutureExt, TryFutureExt}; use futures::stream::{FuturesOrdered, StreamExt}; +use futures::task::Poll; use futures_test::task::noop_context; use std::any::Any; @@ -26,7 +27,6 @@ fn works_1() { assert_eq!(None, iter.next()); } -#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038 #[test] fn works_2() { let (a_tx, a_rx) = oneshot::channel::(); @@ -46,6 +46,69 @@ fn works_2() { assert!(stream.poll_next_unpin(&mut cx).is_ready()); } +#[test] +fn test_push_front() { + let (a_tx, a_rx) = oneshot::channel::(); + let (b_tx, b_rx) = oneshot::channel::(); + let (c_tx, c_rx) = oneshot::channel::(); + let (d_tx, d_rx) = oneshot::channel::(); + + let mut stream = FuturesOrdered::new(); + + let mut cx = noop_context(); + + stream.push_back(a_rx); + stream.push_back(b_rx); + stream.push_back(c_rx); + + a_tx.send(1).unwrap(); + b_tx.send(2).unwrap(); + c_tx.send(3).unwrap(); + + // 1 and 2 should be received in order + assert_eq!(Poll::Ready(Some(Ok(1))), stream.poll_next_unpin(&mut cx)); + assert_eq!(Poll::Ready(Some(Ok(2))), stream.poll_next_unpin(&mut cx)); + + stream.push_front(d_rx); + d_tx.send(4).unwrap(); + + // we pushed `d_rx` to the front and sent 4, so we should recieve 4 next + // and then 3 after it + assert_eq!(Poll::Ready(Some(Ok(4))), stream.poll_next_unpin(&mut cx)); + assert_eq!(Poll::Ready(Some(Ok(3))), stream.poll_next_unpin(&mut cx)); +} + +#[test] +fn test_push_back() { + let (a_tx, a_rx) = oneshot::channel::(); + let (b_tx, b_rx) = oneshot::channel::(); + let (c_tx, c_rx) = oneshot::channel::(); + let (d_tx, d_rx) = oneshot::channel::(); + + let mut stream = FuturesOrdered::new(); + + let mut cx = noop_context(); + + stream.push_back(a_rx); + stream.push_back(b_rx); + stream.push_back(c_rx); + + a_tx.send(1).unwrap(); + b_tx.send(2).unwrap(); + c_tx.send(3).unwrap(); + + // All results should be received in order + + assert_eq!(Poll::Ready(Some(Ok(1))), stream.poll_next_unpin(&mut cx)); + assert_eq!(Poll::Ready(Some(Ok(2))), stream.poll_next_unpin(&mut cx)); + + stream.push_back(d_rx); + d_tx.send(4).unwrap(); + + assert_eq!(Poll::Ready(Some(Ok(3))), stream.poll_next_unpin(&mut cx)); + assert_eq!(Poll::Ready(Some(Ok(4))), stream.poll_next_unpin(&mut cx)); +} + #[test] fn from_iterator() { let stream = vec![future::ready::(1), future::ready::(2), future::ready::(3)] @@ -55,7 +118,6 @@ fn from_iterator() { assert_eq!(block_on(stream.collect::>()), vec![1, 2, 3]); } -#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038 #[test] fn queue_never_unblocked() { let (_a_tx, a_rx) = oneshot::channel::>(); diff --git a/tests/stream_futures_unordered.rs b/tests/stream_futures_unordered.rs index f62f733..b568280 100644 --- a/tests/stream_futures_unordered.rs +++ b/tests/stream_futures_unordered.rs @@ -56,7 +56,6 @@ fn works_1() { assert_eq!(None, iter.next()); } -#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038 #[test] fn works_2() { let (a_tx, a_rx) = oneshot::channel::(); @@ -86,7 +85,6 @@ fn from_iterator() { assert_eq!(block_on(stream.collect::>()), vec![1, 2, 3]); } -#[cfg_attr(miri, ignore)] // https://github.com/rust-lang/miri/issues/1038 #[test] fn finished_future() { let (_a_tx, a_rx) = oneshot::channel::(); @@ -261,6 +259,20 @@ fn into_iter_len() { assert!(into_iter.next().is_none()); } +#[test] +fn into_iter_partial() { + let stream = vec![future::ready(1), future::ready(2), future::ready(3), future::ready(4)] + .into_iter() + .collect::>(); + + let mut into_iter = stream.into_iter(); + assert!(into_iter.next().is_some()); + assert!(into_iter.next().is_some()); + assert!(into_iter.next().is_some()); + assert_eq!(into_iter.len(), 1); + // don't panic when iterator is dropped before completing +} + #[test] fn futures_not_moved_after_poll() { // Future that will be ready after being polled twice, diff --git a/tests/stream_try_stream.rs b/tests/stream_try_stream.rs index d83fc54..194e74d 100644 --- a/tests/stream_try_stream.rs +++ b/tests/stream_try_stream.rs @@ -1,5 +1,3 @@ -#![cfg(not(miri))] // https://github.com/rust-lang/miri/issues/1038 - use futures::{ stream::{self, StreamExt, TryStreamExt}, task::Poll, diff --git a/tests/task_atomic_waker.rs b/tests/task_atomic_waker.rs index 2d1612a..cec3db2 100644 --- a/tests/task_atomic_waker.rs +++ b/tests/task_atomic_waker.rs @@ -6,7 +6,6 @@ use std::sync::atomic::Ordering; use std::sync::Arc; use std::thread; -#[cfg_attr(miri, ignore)] // Miri is too slow #[test] fn basic() { let atomic_waker = Arc::new(AtomicWaker::new()); diff --git a/tests_disabled/stream.rs b/tests_disabled/stream.rs index 854dbad..a4eec2c 100644 --- a/tests_disabled/stream.rs +++ b/tests_disabled/stream.rs @@ -318,7 +318,6 @@ fn forward() { } #[test] -#[allow(deprecated)] fn concat() { let a = iter_ok::<_, ()>(vec![vec![1, 2, 3], vec![4, 5, 6], vec![7, 8, 9]]); assert_done(move || a.concat(), Ok(vec![1, 2, 3, 4, 5, 6, 7, 8, 9])); -- cgit v1.2.3 From b5588104fd5b60cb96805601529600c4ef85119d Mon Sep 17 00:00:00 2001 From: David Brazdil Date: Mon, 23 Jan 2023 13:30:28 +0000 Subject: Update TEST_MAPPING Test: None Change-Id: Icb65e8784a20481cb133474935a2f275671d3a21 --- TEST_MAPPING | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/TEST_MAPPING b/TEST_MAPPING index e2df61d..468e595 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -4,6 +4,12 @@ { "path": "external/rust/crates/anyhow" }, + { + "path": "external/rust/crates/futures-channel" + }, + { + "path": "external/rust/crates/futures-executor" + }, { "path": "external/rust/crates/tokio" } @@ -15,11 +21,26 @@ { "name": "authfs_device_test_src_lib" }, + { + "name": "bluetooth_with_facades.test" + }, { "name": "doh_unit_test" }, { - "name": "virtualizationservice_device_test" + "name": "keystore2_legacy_blobs_test" + }, + { + "name": "keystore2_test" + }, + { + "name": "legacykeystore_test" + }, + { + "name": "libpvmfw_avb.integration_test" + }, + { + "name": "virtualizationmanager_device_test" } ], "presubmit-rust": [ @@ -29,11 +50,26 @@ { "name": "authfs_device_test_src_lib" }, + { + "name": "bluetooth_with_facades.test" + }, { "name": "doh_unit_test" }, { - "name": "virtualizationservice_device_test" + "name": "keystore2_legacy_blobs_test" + }, + { + "name": "keystore2_test" + }, + { + "name": "legacykeystore_test" + }, + { + "name": "libpvmfw_avb.integration_test" + }, + { + "name": "virtualizationmanager_device_test" } ] } -- cgit v1.2.3 From a1ca914ebb7ee0530431e9ae2f577496e8e46f1a Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Mon, 30 Jan 2023 11:30:08 +0100 Subject: Update TEST_MAPPING Test: atest Change-Id: I12cf6190130e41c42a8920254b9b4f02669b0d1a --- TEST_MAPPING | 52 ++++++---------------------------------------------- 1 file changed, 6 insertions(+), 46 deletions(-) diff --git a/TEST_MAPPING b/TEST_MAPPING index 468e595..f20282b 100644 --- a/TEST_MAPPING +++ b/TEST_MAPPING @@ -12,64 +12,24 @@ }, { "path": "external/rust/crates/tokio" - } - ], - "presubmit": [ - { - "name": "ZipFuseTest" - }, - { - "name": "authfs_device_test_src_lib" - }, - { - "name": "bluetooth_with_facades.test" - }, - { - "name": "doh_unit_test" - }, - { - "name": "keystore2_legacy_blobs_test" - }, - { - "name": "keystore2_test" - }, - { - "name": "legacykeystore_test" - }, - { - "name": "libpvmfw_avb.integration_test" - }, - { - "name": "virtualizationmanager_device_test" - } - ], - "presubmit-rust": [ - { - "name": "ZipFuseTest" - }, - { - "name": "authfs_device_test_src_lib" - }, - { - "name": "bluetooth_with_facades.test" }, { - "name": "doh_unit_test" + "path": "packages/modules/DnsResolver" }, { - "name": "keystore2_legacy_blobs_test" + "path": "packages/modules/Virtualization/authfs" }, { - "name": "keystore2_test" + "path": "packages/modules/Virtualization/virtualizationmanager" }, { - "name": "legacykeystore_test" + "path": "packages/modules/Virtualization/zipfuse" }, { - "name": "libpvmfw_avb.integration_test" + "path": "system/security/keystore2" }, { - "name": "virtualizationmanager_device_test" + "path": "system/security/keystore2/legacykeystore" } ] } -- cgit v1.2.3 From 4c9fd15119c24908209b64cd3bcd195236c3831f Mon Sep 17 00:00:00 2001 From: Jeff Vander Stoep Date: Wed, 15 Feb 2023 20:19:57 +0100 Subject: Upgrade futures to 0.3.26 This project was upgraded with external_updater. Usage: tools/external_updater/updater.sh update rust/crates/futures For more info, check https://cs.android.com/android/platform/superproject/+/master:tools/external_updater/README.md Test: TreeHugger Change-Id: I20fd44e4c5add463ab97b6d0aa1be555453405e9 --- .cargo_vcs_info.json | 2 +- Android.bp | 2 +- Cargo.toml | 16 +++++++------- Cargo.toml.orig | 16 +++++++------- METADATA | 10 ++++----- README.md | 6 +++--- tests/async_await_macros.rs | 2 ++ tests/auto_traits.rs | 4 ++-- tests/eventual.rs | 18 ++++++++++++++++ tests/future_shared.rs | 46 +++++++++++++++++++++++++++++++++++++++++ tests/stream_futures_ordered.rs | 24 +++++++++++++++++++++ 11 files changed, 118 insertions(+), 28 deletions(-) diff --git a/.cargo_vcs_info.json b/.cargo_vcs_info.json index c68093a..c5e5d7e 100644 --- a/.cargo_vcs_info.json +++ b/.cargo_vcs_info.json @@ -1,6 +1,6 @@ { "git": { - "sha1": "77d82198c5afd04af3e760a6aa50b7e875289fc3" + "sha1": "5e3693a350f96244151081d2c030208cd15f9572" }, "path_in_vcs": "futures" } \ No newline at end of file diff --git a/Android.bp b/Android.bp index 0e41e22..2acdd2c 100644 --- a/Android.bp +++ b/Android.bp @@ -42,7 +42,7 @@ rust_library { host_supported: true, crate_name: "futures", cargo_env_compat: true, - cargo_pkg_version: "0.3.25", + cargo_pkg_version: "0.3.26", srcs: ["src/lib.rs"], edition: "2018", features: [ diff --git a/Cargo.toml b/Cargo.toml index 4a025a8..51e052a 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -13,7 +13,7 @@ edition = "2018" rust-version = "1.45" name = "futures" -version = "0.3.25" +version = "0.3.26" description = """ An implementation of futures and streams featuring zero allocations, composability, and iterator-like interfaces. @@ -47,33 +47,33 @@ features = [ ] [dependencies.futures-channel] -version = "0.3.25" +version = "0.3.26" features = ["sink"] default-features = false [dependencies.futures-core] -version = "0.3.25" +version = "0.3.26" default-features = false [dependencies.futures-executor] -version = "0.3.25" +version = "0.3.26" optional = true default-features = false [dependencies.futures-io] -version = "0.3.25" +version = "0.3.26" default-features = false [dependencies.futures-sink] -version = "0.3.25" +version = "0.3.26" default-features = false [dependencies.futures-task] -version = "0.3.25" +version = "0.3.26" default-features = false [dependencies.futures-util] -version = "0.3.25" +version = "0.3.26" features = ["sink"] default-features = false diff --git a/Cargo.toml.orig b/Cargo.toml.orig index 544a1e3..e7a5f38 100644 --- a/Cargo.toml.orig +++ b/Cargo.toml.orig @@ -1,6 +1,6 @@ [package] name = "futures" -version = "0.3.25" +version = "0.3.26" edition = "2018" rust-version = "1.45" license = "MIT OR Apache-2.0" @@ -15,13 +15,13 @@ composability, and iterator-like interfaces. categories = ["asynchronous"] [dependencies] -futures-core = { path = "../futures-core", version = "0.3.25", default-features = false } -futures-task = { path = "../futures-task", version = "0.3.25", default-features = false } -futures-channel = { path = "../futures-channel", version = "0.3.25", default-features = false, features = ["sink"] } -futures-executor = { path = "../futures-executor", version = "0.3.25", default-features = false, optional = true } -futures-io = { path = "../futures-io", version = "0.3.25", default-features = false } -futures-sink = { path = "../futures-sink", version = "0.3.25", default-features = false } -futures-util = { path = "../futures-util", version = "0.3.25", default-features = false, features = ["sink"] } +futures-core = { path = "../futures-core", version = "0.3.26", default-features = false } +futures-task = { path = "../futures-task", version = "0.3.26", default-features = false } +futures-channel = { path = "../futures-channel", version = "0.3.26", default-features = false, features = ["sink"] } +futures-executor = { path = "../futures-executor", version = "0.3.26", default-features = false, optional = true } +futures-io = { path = "../futures-io", version = "0.3.26", default-features = false } +futures-sink = { path = "../futures-sink", version = "0.3.26", default-features = false } +futures-util = { path = "../futures-util", version = "0.3.26", default-features = false, features = ["sink"] } [dev-dependencies] futures-executor = { path = "../futures-executor", features = ["thread-pool"] } diff --git a/METADATA b/METADATA index 1dee576..240fa20 100644 --- a/METADATA +++ b/METADATA @@ -11,13 +11,13 @@ third_party { } url { type: ARCHIVE - value: "https://static.crates.io/crates/futures/futures-0.3.25.crate" + value: "https://static.crates.io/crates/futures/futures-0.3.26.crate" } - version: "0.3.25" + version: "0.3.26" license_type: NOTICE last_upgrade_date { - year: 2022 - month: 12 - day: 12 + year: 2023 + month: 2 + day: 15 } } diff --git a/README.md b/README.md index e6127fd..45e1f5b 100644 --- a/README.md +++ b/README.md @@ -8,16 +8,16 @@

- Build Status + Build Status - Crates.io + crates.io

- + Documentation | Website diff --git a/tests/async_await_macros.rs b/tests/async_await_macros.rs index 250e345..82a617f 100644 --- a/tests/async_await_macros.rs +++ b/tests/async_await_macros.rs @@ -380,11 +380,13 @@ fn try_join_size() { assert_eq!(mem::size_of_val(&fut), 48); } +#[allow(clippy::let_underscore_future)] #[test] fn join_doesnt_require_unpin() { let _ = async { join!(async {}, async {}) }; } +#[allow(clippy::let_underscore_future)] #[test] fn try_join_doesnt_require_unpin() { let _ = async { try_join!(async { Ok::<(), ()>(()) }, async { Ok::<(), ()>(()) },) }; diff --git a/tests/auto_traits.rs b/tests/auto_traits.rs index da00ccf..5fc0f7d 100644 --- a/tests/auto_traits.rs +++ b/tests/auto_traits.rs @@ -1480,10 +1480,10 @@ pub mod stream { assert_not_impl!(PollImmediate: Unpin); assert_impl!(ReadyChunks>: Send); - assert_not_impl!(ReadyChunks: Send); + assert_impl!(ReadyChunks: Send); assert_not_impl!(ReadyChunks: Send); assert_impl!(ReadyChunks>: Sync); - assert_not_impl!(ReadyChunks: Sync); + assert_impl!(ReadyChunks: Sync); assert_not_impl!(ReadyChunks: Sync); assert_impl!(ReadyChunks: Unpin); assert_not_impl!(ReadyChunks: Unpin); diff --git a/tests/eventual.rs b/tests/eventual.rs index 951c55c..57a49b2 100644 --- a/tests/eventual.rs +++ b/tests/eventual.rs @@ -16,6 +16,8 @@ fn join1() { run(future::try_join(ok::(1), ok(2)).map_ok(move |v| tx.send(v).unwrap())); assert_eq!(rx.recv(), Ok((1, 2))); assert!(rx.recv().is_err()); + + std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371 } #[test] @@ -30,6 +32,8 @@ fn join2() { c2.send(2).unwrap(); assert_eq!(rx.recv(), Ok((1, 2))); assert!(rx.recv().is_err()); + + std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371 } #[test] @@ -43,6 +47,8 @@ fn join3() { assert_eq!(rx.recv(), Ok(1)); assert!(rx.recv().is_err()); drop(c2); + + std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371 } #[test] @@ -56,6 +62,8 @@ fn join4() { assert!(rx.recv().is_ok()); drop(c2); assert!(rx.recv().is_err()); + + std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371 } #[test] @@ -73,6 +81,8 @@ fn join5() { c3.send(3).unwrap(); assert_eq!(rx.recv(), Ok(((1, 2), 3))); assert!(rx.recv().is_err()); + + std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371 } #[test] @@ -92,6 +102,8 @@ fn select1() { c2.send(2).unwrap(); assert_eq!(rx.recv(), Ok(2)); assert!(rx.recv().is_err()); + + std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371 } #[test] @@ -111,6 +123,8 @@ fn select2() { c2.send(2).unwrap(); assert_eq!(rx.recv(), Ok(2)); assert!(rx.recv().is_err()); + + std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371 } #[test] @@ -130,6 +144,8 @@ fn select3() { drop(c2); assert_eq!(rx.recv(), Ok(2)); assert!(rx.recv().is_err()); + + std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371 } #[test] @@ -158,4 +174,6 @@ fn select4() { drop(tx); t.join().unwrap(); + + std::thread::sleep(std::time::Duration::from_millis(500)); // wait for background threads closed: https://github.com/rust-lang/miri/issues/1371 } diff --git a/tests/future_shared.rs b/tests/future_shared.rs index 6bf43d2..bd69c1d 100644 --- a/tests/future_shared.rs +++ b/tests/future_shared.rs @@ -151,6 +151,52 @@ fn downgrade() { assert!(shared2.downgrade().is_none()); } +#[test] +fn ptr_eq() { + use future::FusedFuture; + use std::collections::hash_map::DefaultHasher; + use std::hash::Hasher; + + let (tx, rx) = oneshot::channel::(); + let shared = rx.shared(); + let mut shared2 = shared.clone(); + let mut hasher = DefaultHasher::new(); + let mut hasher2 = DefaultHasher::new(); + + // Because these two futures share the same underlying future, + // `ptr_eq` should return true. + assert!(shared.ptr_eq(&shared2)); + // Equivalence relations are symmetric + assert!(shared2.ptr_eq(&shared)); + + // If `ptr_eq` returns true, they should hash to the same value. + shared.ptr_hash(&mut hasher); + shared2.ptr_hash(&mut hasher2); + assert_eq!(hasher.finish(), hasher2.finish()); + + tx.send(42).unwrap(); + assert_eq!(block_on(&mut shared2).unwrap(), 42); + + // Now that `shared2` has completed, `ptr_eq` should return false. + assert!(shared2.is_terminated()); + assert!(!shared.ptr_eq(&shared2)); + + // `ptr_eq` should continue to work for the other `Shared`. + let shared3 = shared.clone(); + let mut hasher3 = DefaultHasher::new(); + assert!(shared.ptr_eq(&shared3)); + + shared3.ptr_hash(&mut hasher3); + assert_eq!(hasher.finish(), hasher3.finish()); + + let (_tx, rx) = oneshot::channel::(); + let shared4 = rx.shared(); + + // And `ptr_eq` should return false for two futures that don't share + // the underlying future. + assert!(!shared.ptr_eq(&shared4)); +} + #[test] fn dont_clone_in_single_owner_shared_future() { let counter = CountClone(Rc::new(Cell::new(0))); diff --git a/tests/stream_futures_ordered.rs b/tests/stream_futures_ordered.rs index 8b85a33..5a4a3e2 100644 --- a/tests/stream_futures_ordered.rs +++ b/tests/stream_futures_ordered.rs @@ -146,3 +146,27 @@ fn queue_never_unblocked() { assert!(stream.poll_next_unpin(cx).is_pending()); assert!(stream.poll_next_unpin(cx).is_pending()); } + +#[test] +fn test_push_front_negative() { + let (a_tx, a_rx) = oneshot::channel::(); + let (b_tx, b_rx) = oneshot::channel::(); + let (c_tx, c_rx) = oneshot::channel::(); + + let mut stream = FuturesOrdered::new(); + + let mut cx = noop_context(); + + stream.push_front(a_rx); + stream.push_front(b_rx); + stream.push_front(c_rx); + + a_tx.send(1).unwrap(); + b_tx.send(2).unwrap(); + c_tx.send(3).unwrap(); + + // These should all be recieved in reverse order + assert_eq!(Poll::Ready(Some(Ok(3))), stream.poll_next_unpin(&mut cx)); + assert_eq!(Poll::Ready(Some(Ok(2))), stream.poll_next_unpin(&mut cx)); + assert_eq!(Poll::Ready(Some(Ok(1))), stream.poll_next_unpin(&mut cx)); +} -- cgit v1.2.3 From 78fb99c7e0057fdd480b7c1703a87d3fefb9012d Mon Sep 17 00:00:00 2001 From: Matthew Maurer Date: Tue, 7 Mar 2023 17:23:52 -0800 Subject: Make futures available to product and vendor Bug: 270690570 Test: mma in external/rust/crates Change-Id: I11c06a4d12323bc69dbd9f3634de672a377efb87 --- Android.bp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Android.bp b/Android.bp index 2acdd2c..2a41329 100644 --- a/Android.bp +++ b/Android.bp @@ -68,5 +68,7 @@ rust_library { "com.android.resolv", "com.android.virt", ], + product_available: true, + vendor_available: true, min_sdk_version: "29", } -- cgit v1.2.3