Skip to content

coverage: Use Waker::noop in async tests #118969

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
152 changes: 50 additions & 102 deletions tests/coverage/async.cov-map

Large diffs are not rendered by default.

43 changes: 17 additions & 26 deletions tests/coverage/async.coverage
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
LL| |#![feature(coverage_attribute)]
LL| |#![feature(noop_waker)]
LL| |#![allow(unused_assignments, dead_code)]
LL| |
LL| |// compile-flags: --edition=2018 -C opt-level=1
LL| |// edition: 2018
LL| |// compile-flags: -Copt-level=1
LL| |
LL| 1|async fn c(x: u8) -> u8 {
LL| 1| if x == 8 {
Expand Down Expand Up @@ -108,32 +110,21 @@
LL| 1|}
LL| |
LL| |mod executor {
LL| | use core::{
LL| | future::Future,
LL| | pin::Pin,
LL| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
LL| | };
LL| |
LL| 1| pub fn block_on<F: Future>(mut future: F) -> F::Output {
LL| 1| let mut future = unsafe { Pin::new_unchecked(&mut future) };
LL| 1| use std::hint::unreachable_unchecked;
LL| 1| static VTABLE: RawWakerVTable = RawWakerVTable::new(
LL| 1| |_| unsafe { unreachable_unchecked() }, // clone
^0
LL| 1| |_| unsafe { unreachable_unchecked() }, // wake
^0
LL| 1| |_| unsafe { unreachable_unchecked() }, // wake_by_ref
^0
LL| 1| |_| (),
LL| 1| );
LL| 1| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
LL| 1| let mut context = Context::from_waker(&waker);
LL| | use core::future::Future;
LL| | use core::pin::pin;
LL| | use core::task::{Context, Poll, Waker};
LL| |
LL| | #[coverage(off)]
LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output {
LL| | let mut future = pin!(future);
LL| | let waker = Waker::noop();
LL| | let mut context = Context::from_waker(&waker);
LL| |
LL| | loop {
LL| 1| if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
LL| 1| break val;
LL| 0| }
LL| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
LL| | break val;
LL| | }
LL| | }
LL| 1| }
LL| | }
LL| |}

26 changes: 10 additions & 16 deletions tests/coverage/async.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#![feature(coverage_attribute)]
#![feature(noop_waker)]
#![allow(unused_assignments, dead_code)]

// compile-flags: --edition=2018 -C opt-level=1
// edition: 2018
// compile-flags: -Copt-level=1

async fn c(x: u8) -> u8 {
if x == 8 {
Expand Down Expand Up @@ -101,22 +103,14 @@ fn main() {
}

mod executor {
use core::{
future::Future,
pin::Pin,
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
};
use core::future::Future;
use core::pin::pin;
use core::task::{Context, Poll, Waker};

#[coverage(off)]
pub fn block_on<F: Future>(mut future: F) -> F::Output {
let mut future = unsafe { Pin::new_unchecked(&mut future) };
use std::hint::unreachable_unchecked;
static VTABLE: RawWakerVTable = RawWakerVTable::new(
|_| unsafe { unreachable_unchecked() }, // clone
|_| unsafe { unreachable_unchecked() }, // wake
|_| unsafe { unreachable_unchecked() }, // wake_by_ref
|_| (),
);
let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
let mut future = pin!(future);
let waker = Waker::noop();
let mut context = Context::from_waker(&waker);

loop {
Expand Down
96 changes: 12 additions & 84 deletions tests/coverage/async2.cov-map
Original file line number Diff line number Diff line change
@@ -1,130 +1,58 @@
Function name: async2::async_func
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0b, 01, 00, 17]
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0d, 01, 00, 17]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 11, 1) to (start + 0, 23)
- Code(Counter(0)) at (prev + 13, 1) to (start + 0, 23)

Function name: async2::async_func::{closure#0}
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 0b, 17, 03, 09, 05, 03, 0a, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02]
Raw bytes (28): 0x[01, 01, 02, 01, 05, 05, 02, 04, 01, 0d, 17, 03, 09, 05, 03, 0a, 02, 06, 02, 02, 06, 00, 07, 07, 01, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 2
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
- expression 1 operands: lhs = Counter(1), rhs = Expression(0, Sub)
Number of file 0 mappings: 4
- Code(Counter(0)) at (prev + 11, 23) to (start + 3, 9)
- Code(Counter(0)) at (prev + 13, 23) to (start + 3, 9)
- Code(Counter(1)) at (prev + 3, 10) to (start + 2, 6)
- Code(Expression(0, Sub)) at (prev + 2, 6) to (start + 0, 7)
= (c0 - c1)
- Code(Expression(1, Add)) at (prev + 1, 1) to (start + 0, 2)
= (c1 + (c0 - c1))

Function name: async2::async_func_just_println
Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 01, 00, 24]
Raw bytes (9): 0x[01, 01, 00, 01, 01, 15, 01, 00, 24]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 19, 1) to (start + 0, 36)
- Code(Counter(0)) at (prev + 21, 1) to (start + 0, 36)

Function name: async2::async_func_just_println::{closure#0}
Raw bytes (9): 0x[01, 01, 00, 01, 01, 13, 24, 02, 02]
Raw bytes (9): 0x[01, 01, 00, 01, 01, 15, 24, 02, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 19, 36) to (start + 2, 2)

Function name: async2::executor::block_on::<async2::async_func::{closure#0}>
Raw bytes (40): 0x[01, 01, 03, 0b, 05, 01, 05, 01, 05, 06, 01, 27, 05, 0a, 36, 02, 0d, 20, 00, 23, 0b, 00, 27, 00, 49, 02, 01, 17, 00, 1a, 05, 01, 0e, 00, 0f, 02, 02, 05, 00, 06]
Number of files: 1
- file 0 => global file 1
Number of expressions: 3
- expression 0 operands: lhs = Expression(2, Add), rhs = Counter(1)
- expression 1 operands: lhs = Counter(0), rhs = Counter(1)
- expression 2 operands: lhs = Counter(0), rhs = Counter(1)
Number of file 0 mappings: 6
- Code(Counter(0)) at (prev + 39, 5) to (start + 10, 54)
- Code(Expression(0, Sub)) at (prev + 13, 32) to (start + 0, 35)
= ((c0 + c1) - c1)
- Code(Expression(2, Add)) at (prev + 0, 39) to (start + 0, 73)
= (c0 + c1)
- Code(Expression(0, Sub)) at (prev + 1, 23) to (start + 0, 26)
= ((c0 + c1) - c1)
- Code(Counter(1)) at (prev + 1, 14) to (start + 0, 15)
- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 0, 6)
= ((c0 + c1) - c1)

Function name: async2::executor::block_on::<async2::async_func_just_println::{closure#0}>
Raw bytes (40): 0x[01, 01, 03, 0b, 05, 01, 05, 01, 05, 06, 01, 27, 05, 0a, 36, 02, 0d, 20, 00, 23, 0b, 00, 27, 00, 49, 02, 01, 17, 00, 1a, 05, 01, 0e, 00, 0f, 02, 02, 05, 00, 06]
Number of files: 1
- file 0 => global file 1
Number of expressions: 3
- expression 0 operands: lhs = Expression(2, Add), rhs = Counter(1)
- expression 1 operands: lhs = Counter(0), rhs = Counter(1)
- expression 2 operands: lhs = Counter(0), rhs = Counter(1)
Number of file 0 mappings: 6
- Code(Counter(0)) at (prev + 39, 5) to (start + 10, 54)
- Code(Expression(0, Sub)) at (prev + 13, 32) to (start + 0, 35)
= ((c0 + c1) - c1)
- Code(Expression(2, Add)) at (prev + 0, 39) to (start + 0, 73)
= (c0 + c1)
- Code(Expression(0, Sub)) at (prev + 1, 23) to (start + 0, 26)
= ((c0 + c1) - c1)
- Code(Counter(1)) at (prev + 1, 14) to (start + 0, 15)
- Code(Expression(0, Sub)) at (prev + 2, 5) to (start + 0, 6)
= ((c0 + c1) - c1)

Function name: async2::executor::block_on::VTABLE::{closure#0}
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2b, 11, 00, 31]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 43, 17) to (start + 0, 49)

Function name: async2::executor::block_on::VTABLE::{closure#1}
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2c, 11, 00, 31]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 44, 17) to (start + 0, 49)

Function name: async2::executor::block_on::VTABLE::{closure#2}
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2d, 11, 00, 31]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 45, 17) to (start + 0, 49)

Function name: async2::executor::block_on::VTABLE::{closure#3}
Raw bytes (9): 0x[01, 01, 00, 01, 01, 2e, 11, 00, 13]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 46, 17) to (start + 0, 19)
- Code(Counter(0)) at (prev + 21, 36) to (start + 2, 2)

Function name: async2::main
Raw bytes (9): 0x[01, 01, 00, 01, 01, 17, 01, 07, 02]
Raw bytes (9): 0x[01, 01, 00, 01, 01, 19, 01, 07, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 0
Number of file 0 mappings: 1
- Code(Counter(0)) at (prev + 23, 1) to (start + 7, 2)
- Code(Counter(0)) at (prev + 25, 1) to (start + 7, 2)

Function name: async2::non_async_func
Raw bytes (26): 0x[01, 01, 01, 05, 00, 04, 01, 03, 01, 03, 09, 05, 03, 0a, 02, 06, 00, 02, 06, 00, 07, 03, 01, 01, 00, 02]
Raw bytes (26): 0x[01, 01, 01, 05, 00, 04, 01, 05, 01, 03, 09, 05, 03, 0a, 02, 06, 00, 02, 06, 00, 07, 03, 01, 01, 00, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 1
- expression 0 operands: lhs = Counter(1), rhs = Zero
Number of file 0 mappings: 4
- Code(Counter(0)) at (prev + 3, 1) to (start + 3, 9)
- Code(Counter(0)) at (prev + 5, 1) to (start + 3, 9)
- Code(Counter(1)) at (prev + 3, 10) to (start + 2, 6)
- Code(Zero) at (prev + 2, 6) to (start + 0, 7)
- Code(Expression(0, Add)) at (prev + 1, 1) to (start + 0, 2)
Expand Down
80 changes: 15 additions & 65 deletions tests/coverage/async2.coverage
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
LL| |// compile-flags: --edition=2018
LL| |#![feature(coverage_attribute)]
LL| |#![feature(noop_waker)]
LL| |// edition: 2018
LL| |
LL| 1|fn non_async_func() {
LL| 1| println!("non_async_func was covered");
Expand Down Expand Up @@ -32,73 +34,21 @@
LL| 1|}
LL| |
LL| |mod executor {
LL| | use core::{
LL| | future::Future,
LL| | pin::Pin,
LL| | task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
LL| | };
LL| | use core::future::Future;
LL| | use core::pin::pin;
LL| | use core::task::{Context, Poll, Waker};
LL| |
LL| 2| pub fn block_on<F: Future>(mut future: F) -> F::Output {
LL| 2| let mut future = unsafe { Pin::new_unchecked(&mut future) };
LL| 2| use std::hint::unreachable_unchecked;
LL| 2| static VTABLE: RawWakerVTable = RawWakerVTable::new(
LL| 2| |_| unsafe { unreachable_unchecked() }, // clone
^0
LL| 2| |_| unsafe { unreachable_unchecked() }, // wake
^0
LL| 2| |_| unsafe { unreachable_unchecked() }, // wake_by_ref
^0
LL| 2| |_| (),
LL| 2| );
LL| 2| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
LL| 2| let mut context = Context::from_waker(&waker);
LL| | #[coverage(off)]
LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output {
LL| | let mut future = pin!(future);
LL| | let waker = Waker::noop();
LL| | let mut context = Context::from_waker(&waker);
LL| |
LL| | loop {
LL| 2| if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
LL| 2| break val;
LL| 0| }
LL| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
LL| | break val;
LL| | }
LL| | }
LL| 2| }
------------------
| async2::executor::block_on::<async2::async_func::{closure#0}>:
| LL| 1| pub fn block_on<F: Future>(mut future: F) -> F::Output {
| LL| 1| let mut future = unsafe { Pin::new_unchecked(&mut future) };
| LL| 1| use std::hint::unreachable_unchecked;
| LL| 1| static VTABLE: RawWakerVTable = RawWakerVTable::new(
| LL| 1| |_| unsafe { unreachable_unchecked() }, // clone
| LL| 1| |_| unsafe { unreachable_unchecked() }, // wake
| LL| 1| |_| unsafe { unreachable_unchecked() }, // wake_by_ref
| LL| 1| |_| (),
| LL| 1| );
| LL| 1| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
| LL| 1| let mut context = Context::from_waker(&waker);
| LL| |
| LL| | loop {
| LL| 1| if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
| LL| 1| break val;
| LL| 0| }
| LL| | }
| LL| 1| }
------------------
| async2::executor::block_on::<async2::async_func_just_println::{closure#0}>:
| LL| 1| pub fn block_on<F: Future>(mut future: F) -> F::Output {
| LL| 1| let mut future = unsafe { Pin::new_unchecked(&mut future) };
| LL| 1| use std::hint::unreachable_unchecked;
| LL| 1| static VTABLE: RawWakerVTable = RawWakerVTable::new(
| LL| 1| |_| unsafe { unreachable_unchecked() }, // clone
| LL| 1| |_| unsafe { unreachable_unchecked() }, // wake
| LL| 1| |_| unsafe { unreachable_unchecked() }, // wake_by_ref
| LL| 1| |_| (),
| LL| 1| );
| LL| 1| let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
| LL| 1| let mut context = Context::from_waker(&waker);
| LL| |
| LL| | loop {
| LL| 1| if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
| LL| 1| break val;
| LL| 0| }
| LL| | }
| LL| 1| }
------------------
LL| | }
LL| |}

24 changes: 9 additions & 15 deletions tests/coverage/async2.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
// compile-flags: --edition=2018
#![feature(coverage_attribute)]
#![feature(noop_waker)]
// edition: 2018

fn non_async_func() {
println!("non_async_func was covered");
Expand Down Expand Up @@ -30,22 +32,14 @@ fn main() {
}

mod executor {
use core::{
future::Future,
pin::Pin,
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
};
use core::future::Future;
use core::pin::pin;
use core::task::{Context, Poll, Waker};

#[coverage(off)]
pub fn block_on<F: Future>(mut future: F) -> F::Output {
let mut future = unsafe { Pin::new_unchecked(&mut future) };
use std::hint::unreachable_unchecked;
static VTABLE: RawWakerVTable = RawWakerVTable::new(
|_| unsafe { unreachable_unchecked() }, // clone
|_| unsafe { unreachable_unchecked() }, // wake
|_| unsafe { unreachable_unchecked() }, // wake_by_ref
|_| (),
);
let waker = unsafe { Waker::from_raw(RawWaker::new(core::ptr::null(), &VTABLE)) };
let mut future = pin!(future);
let waker = Waker::noop();
let mut context = Context::from_waker(&waker);

loop {
Expand Down
Loading