Skip to content

Commit 1f423a6

Browse files
committed
coverage: Add a test for macros that only contain other macros
1 parent 63f4513 commit 1f423a6

3 files changed

Lines changed: 198 additions & 0 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
Function name: pass_through::uses_inner_macro
2+
Raw bytes (51): 0x[01, 01, 01, 01, 05, 09, 01, 24, 01, 00, 16, 01, 01, 08, 00, 1d, 05, 01, 09, 00, 0c, 05, 00, 0d, 00, 21, 05, 01, 09, 00, 15, 05, 01, 09, 00, 0c, 05, 00, 0d, 00, 20, 02, 01, 05, 00, 06, 01, 01, 01, 00, 02]
3+
Number of files: 1
4+
- file 0 => $DIR/pass-through.rs
5+
Number of expressions: 1
6+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
7+
Number of file 0 mappings: 9
8+
- Code(Counter(0)) at (prev + 36, 1) to (start + 0, 22)
9+
- Code(Counter(0)) at (prev + 1, 8) to (start + 0, 29)
10+
- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 12)
11+
- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 33)
12+
- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 21)
13+
- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 12)
14+
- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 32)
15+
- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 6)
16+
= (c0 - c1)
17+
- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
18+
Highest counter ID seen: c1
19+
20+
Function name: pass_through::uses_middle_macro
21+
Raw bytes (51): 0x[01, 01, 01, 01, 05, 09, 01, 2c, 01, 00, 17, 01, 01, 08, 00, 1d, 05, 01, 09, 00, 0c, 05, 00, 0d, 00, 22, 05, 01, 09, 00, 16, 05, 01, 09, 00, 0c, 05, 00, 0d, 00, 21, 02, 01, 05, 00, 06, 01, 01, 01, 00, 02]
22+
Number of files: 1
23+
- file 0 => $DIR/pass-through.rs
24+
Number of expressions: 1
25+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
26+
Number of file 0 mappings: 9
27+
- Code(Counter(0)) at (prev + 44, 1) to (start + 0, 23)
28+
- Code(Counter(0)) at (prev + 1, 8) to (start + 0, 29)
29+
- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 12)
30+
- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 34)
31+
- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 22)
32+
- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 12)
33+
- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 33)
34+
- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 6)
35+
= (c0 - c1)
36+
- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
37+
Highest counter ID seen: c1
38+
39+
Function name: pass_through::uses_outer_macro
40+
Raw bytes (51): 0x[01, 01, 01, 01, 05, 09, 01, 34, 01, 00, 16, 01, 01, 08, 00, 1d, 05, 01, 09, 00, 0c, 05, 00, 0d, 00, 21, 05, 01, 09, 00, 15, 05, 01, 09, 00, 0c, 05, 00, 0d, 00, 20, 02, 01, 05, 00, 06, 01, 01, 01, 00, 02]
41+
Number of files: 1
42+
- file 0 => $DIR/pass-through.rs
43+
Number of expressions: 1
44+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
45+
Number of file 0 mappings: 9
46+
- Code(Counter(0)) at (prev + 52, 1) to (start + 0, 22)
47+
- Code(Counter(0)) at (prev + 1, 8) to (start + 0, 29)
48+
- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 12)
49+
- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 33)
50+
- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 21)
51+
- Code(Counter(1)) at (prev + 1, 9) to (start + 0, 12)
52+
- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 32)
53+
- Code(Expression(0, Sub)) at (prev + 1, 5) to (start + 0, 6)
54+
= (c0 - c1)
55+
- Code(Counter(0)) at (prev + 1, 1) to (start + 0, 2)
56+
Highest counter ID seen: c1
57+
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
LL| |#![feature(coverage_attribute)]
2+
LL| |//@ edition: 2024
3+
LL| |
4+
LL| |// Test that when a macro expands to another macro, without any significant
5+
LL| |// spans of its own, that this doesn't cause coverage instrumentation to give
6+
LL| |// up and ignore the inner spans.
7+
LL| |
8+
LL| |macro_rules! inner_macro {
9+
LL| | () => {
10+
LL| | if core::hint::black_box(true) {
11+
LL| | say("true");
12+
LL| | } else {
13+
LL| | say("false");
14+
LL| | }
15+
LL| | };
16+
LL| |}
17+
LL| |
18+
LL| |macro_rules! middle_macro {
19+
LL| | () => {
20+
LL| | inner_macro!()
21+
LL| | };
22+
LL| |}
23+
LL| |
24+
LL| |macro_rules! outer_macro {
25+
LL| | () => {
26+
LL| | middle_macro!()
27+
LL| | };
28+
LL| |}
29+
LL| |
30+
LL| |// In each of these three functions, the macro call should be instrumented,
31+
LL| |// and should have an execution count of 1.
32+
LL| |//
33+
LL| |// Each function contains some extra code to ensure that control flow is
34+
LL| |// non-trivial.
35+
LL| |
36+
LL| 1|fn uses_inner_macro() {
37+
LL| 1| if core::hint::black_box(true) {
38+
LL| 1| say("before inner_macro");
39+
LL| 1| inner_macro!();
40+
LL| 1| say("after inner_macro");
41+
LL| 0| }
42+
LL| 1|}
43+
LL| |
44+
LL| 1|fn uses_middle_macro() {
45+
LL| 1| if core::hint::black_box(true) {
46+
LL| 1| say("before middle_macro");
47+
LL| 1| middle_macro!();
48+
LL| 1| say("after middle_macro")
49+
LL| 0| }
50+
LL| 1|}
51+
LL| |
52+
LL| 1|fn uses_outer_macro() {
53+
LL| 1| if core::hint::black_box(true) {
54+
LL| 1| say("before outer_macro");
55+
LL| 1| outer_macro!();
56+
LL| 1| say("after outer_macro");
57+
LL| 0| }
58+
LL| 1|}
59+
LL| |
60+
LL| |#[coverage(off)]
61+
LL| |fn main() {
62+
LL| | uses_inner_macro();
63+
LL| | uses_middle_macro();
64+
LL| | uses_outer_macro();
65+
LL| |}
66+
LL| |
67+
LL| |#[coverage(off)]
68+
LL| |fn say(message: &str) {
69+
LL| | println!("{message}");
70+
LL| |}
71+
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
#![feature(coverage_attribute)]
2+
//@ edition: 2024
3+
4+
// Test that when a macro expands to another macro, without any significant
5+
// spans of its own, that this doesn't cause coverage instrumentation to give
6+
// up and ignore the inner spans.
7+
8+
macro_rules! inner_macro {
9+
() => {
10+
if core::hint::black_box(true) {
11+
say("true");
12+
} else {
13+
say("false");
14+
}
15+
};
16+
}
17+
18+
macro_rules! middle_macro {
19+
() => {
20+
inner_macro!()
21+
};
22+
}
23+
24+
macro_rules! outer_macro {
25+
() => {
26+
middle_macro!()
27+
};
28+
}
29+
30+
// In each of these three functions, the macro call should be instrumented,
31+
// and should have an execution count of 1.
32+
//
33+
// Each function contains some extra code to ensure that control flow is
34+
// non-trivial.
35+
36+
fn uses_inner_macro() {
37+
if core::hint::black_box(true) {
38+
say("before inner_macro");
39+
inner_macro!();
40+
say("after inner_macro");
41+
}
42+
}
43+
44+
fn uses_middle_macro() {
45+
if core::hint::black_box(true) {
46+
say("before middle_macro");
47+
middle_macro!();
48+
say("after middle_macro")
49+
}
50+
}
51+
52+
fn uses_outer_macro() {
53+
if core::hint::black_box(true) {
54+
say("before outer_macro");
55+
outer_macro!();
56+
say("after outer_macro");
57+
}
58+
}
59+
60+
#[coverage(off)]
61+
fn main() {
62+
uses_inner_macro();
63+
uses_middle_macro();
64+
uses_outer_macro();
65+
}
66+
67+
#[coverage(off)]
68+
fn say(message: &str) {
69+
println!("{message}");
70+
}

0 commit comments

Comments
 (0)