Skip to content

Commit 3446ca5

Browse files
coverage: Add test to codify existing behavior
Currently `await` is only counted towards coverage if the containing function is suspended and resumed at least once. A future commit will fix this and update the test to reflect the new behavior.
1 parent 9c01301 commit 3446ca5

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

Diff for: tests/coverage/await_ready.cov-map

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Function name: await_ready::await_ready
2+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 0a, 01, 00, 1e]
3+
Number of files: 1
4+
- file 0 => global file 1
5+
Number of expressions: 0
6+
Number of file 0 mappings: 1
7+
- Code(Counter(0)) at (prev + 10, 1) to (start + 0, 30)
8+
9+
Function name: await_ready::await_ready::{closure#0}
10+
Raw bytes (19): 0x[01, 01, 00, 03, 01, 0a, 1e, 02, 0c, 05, 03, 0a, 00, 0f, 09, 01, 01, 00, 02]
11+
Number of files: 1
12+
- file 0 => global file 1
13+
Number of expressions: 0
14+
Number of file 0 mappings: 3
15+
- Code(Counter(0)) at (prev + 10, 30) to (start + 2, 12)
16+
- Code(Counter(1)) at (prev + 3, 10) to (start + 0, 15)
17+
- Code(Counter(2)) at (prev + 1, 1) to (start + 0, 2)
18+
19+
Function name: await_ready::main
20+
Raw bytes (9): 0x[01, 01, 00, 01, 01, 10, 01, 03, 02]
21+
Number of files: 1
22+
- file 0 => global file 1
23+
Number of expressions: 0
24+
Number of file 0 mappings: 1
25+
- Code(Counter(0)) at (prev + 16, 1) to (start + 3, 2)
26+

Diff for: tests/coverage/await_ready.coverage

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |#![feature(custom_inner_attributes)] // for #![rustfmt::skip]
3+
LL| |#![feature(noop_waker)]
4+
LL| |#![rustfmt::skip]
5+
LL| |//@ edition: 2021
6+
LL| |
7+
LL| |#[coverage(off)]
8+
LL| |async fn ready() -> u8 { 1 }
9+
LL| |
10+
LL| 1|async fn await_ready() -> u8 {
11+
LL| 1| // FIXME(#98712): await is only covered if the function yields
12+
LL| 1| ready()
13+
LL| 0| .await
14+
LL| 1|}
15+
LL| |
16+
LL| 1|fn main() {
17+
LL| 1| let mut future = Box::pin(await_ready());
18+
LL| 1| executor::block_on(future.as_mut());
19+
LL| 1|}
20+
LL| |
21+
LL| |mod executor {
22+
LL| | use core::future::Future;
23+
LL| | use core::pin::pin;
24+
LL| | use core::task::{Context, Poll, Waker};
25+
LL| |
26+
LL| | #[coverage(off)]
27+
LL| | pub fn block_on<F: Future>(mut future: F) -> F::Output {
28+
LL| | let mut future = pin!(future);
29+
LL| | let mut context = Context::from_waker(Waker::noop());
30+
LL| |
31+
LL| | loop {
32+
LL| | if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
33+
LL| | break val;
34+
LL| | }
35+
LL| | }
36+
LL| | }
37+
LL| |}
38+

Diff for: tests/coverage/await_ready.rs

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#![feature(coverage_attribute)]
2+
#![feature(custom_inner_attributes)] // for #![rustfmt::skip]
3+
#![feature(noop_waker)]
4+
#![rustfmt::skip]
5+
//@ edition: 2021
6+
7+
#[coverage(off)]
8+
async fn ready() -> u8 { 1 }
9+
10+
async fn await_ready() -> u8 {
11+
// FIXME(#98712): await is only covered if the function yields
12+
ready()
13+
.await
14+
}
15+
16+
fn main() {
17+
let mut future = Box::pin(await_ready());
18+
executor::block_on(future.as_mut());
19+
}
20+
21+
mod executor {
22+
use core::future::Future;
23+
use core::pin::pin;
24+
use core::task::{Context, Poll, Waker};
25+
26+
#[coverage(off)]
27+
pub fn block_on<F: Future>(mut future: F) -> F::Output {
28+
let mut future = pin!(future);
29+
let mut context = Context::from_waker(Waker::noop());
30+
31+
loop {
32+
if let Poll::Ready(val) = future.as_mut().poll(&mut context) {
33+
break val;
34+
}
35+
}
36+
}
37+
}

0 commit comments

Comments
 (0)