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