diff options
Diffstat (limited to 'embassy-executor/tests')
| -rw-r--r-- | embassy-executor/tests/test.rs | 50 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/return_impl_future_nonsend.rs | 2 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/return_impl_future_nonsend.stderr | 6 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/return_impl_send.stderr | 2 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/spawn_nonsend.rs | 2 | ||||
| -rw-r--r-- | embassy-executor/tests/ui/spawn_nonsend.stderr | 10 |
6 files changed, 51 insertions, 21 deletions
diff --git a/embassy-executor/tests/test.rs b/embassy-executor/tests/test.rs index b84d3785a..6baf3dc21 100644 --- a/embassy-executor/tests/test.rs +++ b/embassy-executor/tests/test.rs | |||
| @@ -65,7 +65,7 @@ fn executor_task() { | |||
| 65 | } | 65 | } |
| 66 | 66 | ||
| 67 | let (executor, trace) = setup(); | 67 | let (executor, trace) = setup(); |
| 68 | executor.spawner().spawn(task1(trace.clone())).unwrap(); | 68 | executor.spawner().spawn(task1(trace.clone()).unwrap()); |
| 69 | 69 | ||
| 70 | unsafe { executor.poll() }; | 70 | unsafe { executor.poll() }; |
| 71 | unsafe { executor.poll() }; | 71 | unsafe { executor.poll() }; |
| @@ -93,7 +93,7 @@ fn executor_task_rpit() { | |||
| 93 | } | 93 | } |
| 94 | 94 | ||
| 95 | let (executor, trace) = setup(); | 95 | let (executor, trace) = setup(); |
| 96 | executor.spawner().spawn(task1(trace.clone())).unwrap(); | 96 | executor.spawner().spawn(task1(trace.clone()).unwrap()); |
| 97 | 97 | ||
| 98 | unsafe { executor.poll() }; | 98 | unsafe { executor.poll() }; |
| 99 | unsafe { executor.poll() }; | 99 | unsafe { executor.poll() }; |
| @@ -120,7 +120,7 @@ fn executor_task_self_wake() { | |||
| 120 | } | 120 | } |
| 121 | 121 | ||
| 122 | let (executor, trace) = setup(); | 122 | let (executor, trace) = setup(); |
| 123 | executor.spawner().spawn(task1(trace.clone())).unwrap(); | 123 | executor.spawner().spawn(task1(trace.clone()).unwrap()); |
| 124 | 124 | ||
| 125 | unsafe { executor.poll() }; | 125 | unsafe { executor.poll() }; |
| 126 | unsafe { executor.poll() }; | 126 | unsafe { executor.poll() }; |
| @@ -152,7 +152,7 @@ fn executor_task_self_wake_twice() { | |||
| 152 | } | 152 | } |
| 153 | 153 | ||
| 154 | let (executor, trace) = setup(); | 154 | let (executor, trace) = setup(); |
| 155 | executor.spawner().spawn(task1(trace.clone())).unwrap(); | 155 | executor.spawner().spawn(task1(trace.clone()).unwrap()); |
| 156 | 156 | ||
| 157 | unsafe { executor.poll() }; | 157 | unsafe { executor.poll() }; |
| 158 | unsafe { executor.poll() }; | 158 | unsafe { executor.poll() }; |
| @@ -188,7 +188,7 @@ fn waking_after_completion_does_not_poll() { | |||
| 188 | let waker = Box::leak(Box::new(AtomicWaker::new())); | 188 | let waker = Box::leak(Box::new(AtomicWaker::new())); |
| 189 | 189 | ||
| 190 | let (executor, trace) = setup(); | 190 | let (executor, trace) = setup(); |
| 191 | executor.spawner().spawn(task1(trace.clone(), waker)).unwrap(); | 191 | executor.spawner().spawn(task1(trace.clone(), waker).unwrap()); |
| 192 | 192 | ||
| 193 | unsafe { executor.poll() }; | 193 | unsafe { executor.poll() }; |
| 194 | waker.wake(); | 194 | waker.wake(); |
| @@ -200,7 +200,7 @@ fn waking_after_completion_does_not_poll() { | |||
| 200 | unsafe { executor.poll() }; // Clears running status | 200 | unsafe { executor.poll() }; // Clears running status |
| 201 | 201 | ||
| 202 | // Can respawn waken-but-dead task | 202 | // Can respawn waken-but-dead task |
| 203 | executor.spawner().spawn(task1(trace.clone(), waker)).unwrap(); | 203 | executor.spawner().spawn(task1(trace.clone(), waker).unwrap()); |
| 204 | 204 | ||
| 205 | unsafe { executor.poll() }; | 205 | unsafe { executor.poll() }; |
| 206 | 206 | ||
| @@ -250,7 +250,7 @@ fn waking_with_old_waker_after_respawn() { | |||
| 250 | let waker = Box::leak(Box::new(AtomicWaker::new())); | 250 | let waker = Box::leak(Box::new(AtomicWaker::new())); |
| 251 | 251 | ||
| 252 | let (executor, trace) = setup(); | 252 | let (executor, trace) = setup(); |
| 253 | executor.spawner().spawn(task1(trace.clone(), waker)).unwrap(); | 253 | executor.spawner().spawn(task1(trace.clone(), waker).unwrap()); |
| 254 | 254 | ||
| 255 | unsafe { executor.poll() }; | 255 | unsafe { executor.poll() }; |
| 256 | unsafe { executor.poll() }; // progress to registering the waker | 256 | unsafe { executor.poll() }; // progress to registering the waker |
| @@ -273,8 +273,7 @@ fn waking_with_old_waker_after_respawn() { | |||
| 273 | let (other_executor, other_trace) = setup(); | 273 | let (other_executor, other_trace) = setup(); |
| 274 | other_executor | 274 | other_executor |
| 275 | .spawner() | 275 | .spawner() |
| 276 | .spawn(task1(other_trace.clone(), waker)) | 276 | .spawn(task1(other_trace.clone(), waker).unwrap()); |
| 277 | .unwrap(); | ||
| 278 | 277 | ||
| 279 | unsafe { other_executor.poll() }; // just run to the yield_now | 278 | unsafe { other_executor.poll() }; // just run to the yield_now |
| 280 | waker.wake(); // trigger old waker registration | 279 | waker.wake(); // trigger old waker registration |
| @@ -323,6 +322,37 @@ fn recursive_task() { | |||
| 323 | #[embassy_executor::task(pool_size = 2)] | 322 | #[embassy_executor::task(pool_size = 2)] |
| 324 | async fn task1() { | 323 | async fn task1() { |
| 325 | let spawner = unsafe { Spawner::for_current_executor().await }; | 324 | let spawner = unsafe { Spawner::for_current_executor().await }; |
| 326 | spawner.spawn(task1()); | 325 | spawner.spawn(task1().unwrap()); |
| 327 | } | 326 | } |
| 328 | } | 327 | } |
| 328 | |||
| 329 | #[cfg(feature = "metadata-name")] | ||
| 330 | #[test] | ||
| 331 | fn task_metadata() { | ||
| 332 | #[task] | ||
| 333 | async fn task1(expected_name: Option<&'static str>) { | ||
| 334 | use embassy_executor::Metadata; | ||
| 335 | assert_eq!(Metadata::for_current_task().await.name(), expected_name); | ||
| 336 | } | ||
| 337 | |||
| 338 | // check no task name | ||
| 339 | let (executor, _) = setup(); | ||
| 340 | executor.spawner().spawn(task1(None).unwrap()); | ||
| 341 | unsafe { executor.poll() }; | ||
| 342 | |||
| 343 | // check setting task name | ||
| 344 | let token = task1(Some("foo")).unwrap(); | ||
| 345 | token.metadata().set_name("foo"); | ||
| 346 | executor.spawner().spawn(token); | ||
| 347 | unsafe { executor.poll() }; | ||
| 348 | |||
| 349 | let token = task1(Some("bar")).unwrap(); | ||
| 350 | token.metadata().set_name("bar"); | ||
| 351 | executor.spawner().spawn(token); | ||
| 352 | unsafe { executor.poll() }; | ||
| 353 | |||
| 354 | // check name is cleared if the task pool slot is recycled. | ||
| 355 | let (executor, _) = setup(); | ||
| 356 | executor.spawner().spawn(task1(None).unwrap()); | ||
| 357 | unsafe { executor.poll() }; | ||
| 358 | } | ||
diff --git a/embassy-executor/tests/ui/return_impl_future_nonsend.rs b/embassy-executor/tests/ui/return_impl_future_nonsend.rs index b8c184b21..77b3119d6 100644 --- a/embassy-executor/tests/ui/return_impl_future_nonsend.rs +++ b/embassy-executor/tests/ui/return_impl_future_nonsend.rs | |||
| @@ -15,7 +15,7 @@ fn task() -> impl Future<Output = ()> { | |||
| 15 | } | 15 | } |
| 16 | 16 | ||
| 17 | fn send_spawn(s: SendSpawner) { | 17 | fn send_spawn(s: SendSpawner) { |
| 18 | s.spawn(task()).unwrap(); | 18 | s.spawn(task().unwrap()); |
| 19 | } | 19 | } |
| 20 | 20 | ||
| 21 | fn main() {} | 21 | fn main() {} |
diff --git a/embassy-executor/tests/ui/return_impl_future_nonsend.stderr b/embassy-executor/tests/ui/return_impl_future_nonsend.stderr index 8aeb9738a..51944ad65 100644 --- a/embassy-executor/tests/ui/return_impl_future_nonsend.stderr +++ b/embassy-executor/tests/ui/return_impl_future_nonsend.stderr | |||
| @@ -1,8 +1,8 @@ | |||
| 1 | error: future cannot be sent between threads safely | 1 | error: future cannot be sent between threads safely |
| 2 | --> tests/ui/return_impl_future_nonsend.rs:18:13 | 2 | --> tests/ui/return_impl_future_nonsend.rs:18:13 |
| 3 | | | 3 | | |
| 4 | 18 | s.spawn(task()).unwrap(); | 4 | 18 | s.spawn(task().unwrap()); |
| 5 | | ^^^^^^ future created by async block is not `Send` | 5 | | ^^^^^^^^^^^^^^^ future created by async block is not `Send` |
| 6 | | | 6 | | |
| 7 | = help: within `impl Sized`, the trait `Send` is not implemented for `*mut ()` | 7 | = help: within `impl Sized`, the trait `Send` is not implemented for `*mut ()` |
| 8 | note: captured value is not `Send` | 8 | note: captured value is not `Send` |
| @@ -13,5 +13,5 @@ note: captured value is not `Send` | |||
| 13 | note: required by a bound in `SendSpawner::spawn` | 13 | note: required by a bound in `SendSpawner::spawn` |
| 14 | --> src/spawner.rs | 14 | --> src/spawner.rs |
| 15 | | | 15 | | |
| 16 | | pub fn spawn<S: Send>(&self, token: SpawnToken<S>) -> Result<(), SpawnError> { | 16 | | pub fn spawn<S: Send>(&self, token: SpawnToken<S>) { |
| 17 | | ^^^^ required by this bound in `SendSpawner::spawn` | 17 | | ^^^^ required by this bound in `SendSpawner::spawn` |
diff --git a/embassy-executor/tests/ui/return_impl_send.stderr b/embassy-executor/tests/ui/return_impl_send.stderr index 759be1cde..5d19465ec 100644 --- a/embassy-executor/tests/ui/return_impl_send.stderr +++ b/embassy-executor/tests/ui/return_impl_send.stderr | |||
| @@ -97,7 +97,7 @@ note: required by a bound in `TaskPool::<F, N>::spawn` | |||
| 97 | | impl<F: Future + 'static, const N: usize> TaskPool<F, N> { | 97 | | impl<F: Future + 'static, const N: usize> TaskPool<F, N> { |
| 98 | | ^^^^^^ required by this bound in `TaskPool::<F, N>::spawn` | 98 | | ^^^^^^ required by this bound in `TaskPool::<F, N>::spawn` |
| 99 | ... | 99 | ... |
| 100 | | pub fn spawn(&'static self, future: impl FnOnce() -> F) -> SpawnToken<impl Sized> { | 100 | | pub fn spawn(&'static self, future: impl FnOnce() -> F) -> Result<SpawnToken<impl Sized>, SpawnError> { |
| 101 | | ----- required by a bound in this associated function | 101 | | ----- required by a bound in this associated function |
| 102 | = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) | 102 | = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) |
| 103 | 103 | ||
diff --git a/embassy-executor/tests/ui/spawn_nonsend.rs b/embassy-executor/tests/ui/spawn_nonsend.rs index 4c4cc7697..601041941 100644 --- a/embassy-executor/tests/ui/spawn_nonsend.rs +++ b/embassy-executor/tests/ui/spawn_nonsend.rs | |||
| @@ -10,7 +10,7 @@ async fn task(non_send: *mut ()) { | |||
| 10 | } | 10 | } |
| 11 | 11 | ||
| 12 | fn send_spawn(s: SendSpawner) { | 12 | fn send_spawn(s: SendSpawner) { |
| 13 | s.spawn(task(core::ptr::null_mut())).unwrap(); | 13 | s.spawn(task(core::ptr::null_mut()).unwrap()); |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | fn main() {} | 16 | fn main() {} |
diff --git a/embassy-executor/tests/ui/spawn_nonsend.stderr b/embassy-executor/tests/ui/spawn_nonsend.stderr index 2a06c8b94..25bd7d78d 100644 --- a/embassy-executor/tests/ui/spawn_nonsend.stderr +++ b/embassy-executor/tests/ui/spawn_nonsend.stderr | |||
| @@ -12,8 +12,8 @@ error[E0277]: `*mut ()` cannot be sent between threads safely | |||
| 12 | 7 | #[embassy_executor::task] | 12 | 7 | #[embassy_executor::task] |
| 13 | | ------------------------- within this `impl Sized` | 13 | | ------------------------- within this `impl Sized` |
| 14 | ... | 14 | ... |
| 15 | 13 | s.spawn(task(core::ptr::null_mut())).unwrap(); | 15 | 13 | s.spawn(task(core::ptr::null_mut()).unwrap()); |
| 16 | | ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut ()` cannot be sent between threads safely | 16 | | ----- ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ `*mut ()` cannot be sent between threads safely |
| 17 | | | | 17 | | | |
| 18 | | required by a bound introduced by this call | 18 | | required by a bound introduced by this call |
| 19 | | | 19 | | |
| @@ -26,8 +26,8 @@ note: required because it's used within this closure | |||
| 26 | note: required because it appears within the type `impl Sized` | 26 | note: required because it appears within the type `impl Sized` |
| 27 | --> src/raw/mod.rs | 27 | --> src/raw/mod.rs |
| 28 | | | 28 | | |
| 29 | | pub unsafe fn _spawn_async_fn<FutFn>(&'static self, future: FutFn) -> SpawnToken<impl Sized> | 29 | | pub unsafe fn _spawn_async_fn<FutFn>(&'static self, future: FutFn) -> Result<SpawnToken<impl Sized>, SpawnError> |
| 30 | | ^^^^^^^^^^ | 30 | | ^^^^^^^^^^ |
| 31 | note: required because it appears within the type `impl Sized` | 31 | note: required because it appears within the type `impl Sized` |
| 32 | --> tests/ui/spawn_nonsend.rs:7:1 | 32 | --> tests/ui/spawn_nonsend.rs:7:1 |
| 33 | | | 33 | | |
| @@ -36,6 +36,6 @@ note: required because it appears within the type `impl Sized` | |||
| 36 | note: required by a bound in `SendSpawner::spawn` | 36 | note: required by a bound in `SendSpawner::spawn` |
| 37 | --> src/spawner.rs | 37 | --> src/spawner.rs |
| 38 | | | 38 | | |
| 39 | | pub fn spawn<S: Send>(&self, token: SpawnToken<S>) -> Result<(), SpawnError> { | 39 | | pub fn spawn<S: Send>(&self, token: SpawnToken<S>) { |
| 40 | | ^^^^ required by this bound in `SendSpawner::spawn` | 40 | | ^^^^ required by this bound in `SendSpawner::spawn` |
| 41 | = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) | 41 | = note: this error originates in the attribute macro `embassy_executor::task` (in Nightly builds, run with -Z macro-backtrace for more info) |
