| 1 |
// Enable dead_code / unreachable_pub here. It has been disabled in lib.rs for |
| 2 |
// other code when running loom tests. |
| 3 |
#![cfg_attr(loom, warn(dead_code, unreachable_pub))] |
| 4 |
|
| 5 |
use self::noop_scheduler::NoopSchedule; |
| 6 |
use self::unowned_wrapper::unowned; |
| 7 |
|
| 8 |
mod noop_scheduler { |
| 9 |
use crate::runtime::task::{self, Task}; |
| 10 |
|
| 11 |
/// `task::Schedule` implementation that does nothing, for testing. |
| 12 |
pub(crate) struct NoopSchedule; |
| 13 |
|
| 14 |
impl task::Schedule for NoopSchedule { |
| 15 |
fn release(&self, _task: &Task<Self>) -> Option<Task<Self>> { |
| 16 |
None |
| 17 |
} |
| 18 |
|
| 19 |
fn schedule(&self, _task: task::Notified<Self>) { |
| 20 |
unreachable!(); |
| 21 |
} |
| 22 |
} |
| 23 |
} |
| 24 |
|
| 25 |
mod unowned_wrapper { |
| 26 |
use crate::runtime::task::{Id, JoinHandle, Notified}; |
| 27 |
use crate::runtime::tests::NoopSchedule; |
| 28 |
|
| 29 |
#[cfg(all(tokio_unstable, feature = "tracing"))] |
| 30 |
pub(crate) fn unowned<T>(task: T) -> (Notified<NoopSchedule>, JoinHandle<T::Output>) |
| 31 |
where |
| 32 |
T: std::future::Future + Send + 'static, |
| 33 |
T::Output: Send + 'static, |
| 34 |
{ |
| 35 |
use tracing::Instrument; |
| 36 |
let span = tracing::trace_span!("test_span"); |
| 37 |
let task = task.instrument(span); |
| 38 |
let (task, handle) = crate::runtime::task::unowned(task, NoopSchedule, Id::next()); |
| 39 |
(task.into_notified(), handle) |
| 40 |
} |
| 41 |
|
| 42 |
#[cfg(not(all(tokio_unstable, feature = "tracing")))] |
| 43 |
pub(crate) fn unowned<T>(task: T) -> (Notified<NoopSchedule>, JoinHandle<T::Output>) |
| 44 |
where |
| 45 |
T: std::future::Future + Send + 'static, |
| 46 |
T::Output: Send + 'static, |
| 47 |
{ |
| 48 |
let (task, handle) = crate::runtime::task::unowned(task, NoopSchedule, Id::next()); |
| 49 |
(task.into_notified(), handle) |
| 50 |
} |
| 51 |
} |
| 52 |
|
| 53 |
cfg_loom! { |
| 54 |
mod loom_blocking; |
| 55 |
mod loom_current_thread; |
| 56 |
mod loom_join_set; |
| 57 |
mod loom_local; |
| 58 |
mod loom_multi_thread; |
| 59 |
mod loom_multi_thread_alt; |
| 60 |
mod loom_oneshot; |
| 61 |
|
| 62 |
// Make sure debug assertions are enabled |
| 63 |
#[cfg(not(debug_assertions))] |
| 64 |
compile_error!("these tests require debug assertions to be enabled"); |
| 65 |
} |
| 66 |
|
| 67 |
cfg_not_loom! { |
| 68 |
mod inject; |
| 69 |
mod queue; |
| 70 |
|
| 71 |
#[cfg(not(miri))] |
| 72 |
mod task_combinations; |
| 73 |
|
| 74 |
#[cfg(miri)] |
| 75 |
mod task; |
| 76 |
} |