Skip to content

Commit

Permalink
!! (WIP) enable branch coverage in all tests
Browse files Browse the repository at this point in the history
(This is mostly for flushing out issues with branch coverage; not sure whether
I actually want to merge something like this.)
  • Loading branch information
Zalathar committed Nov 26, 2023
1 parent a5e014f commit d2a4cb1
Show file tree
Hide file tree
Showing 79 changed files with 2,764 additions and 1,176 deletions.
4 changes: 2 additions & 2 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2491,7 +2491,7 @@ impl<'test> TestCx<'test> {
rustc.arg(dir_opt);
}
CoverageMap => {
rustc.arg("-Cinstrument-coverage");
rustc.args(["-Zunstable-options", "-Cinstrument-coverage=branch"]);
// These tests only compile to LLVM IR, so they don't need the
// profiler runtime to be present.
rustc.arg("-Zno-profiler-runtime");
Expand All @@ -2501,7 +2501,7 @@ impl<'test> TestCx<'test> {
rustc.arg("-Copt-level=2");
}
CoverageRun => {
rustc.arg("-Cinstrument-coverage");
rustc.args(["-Zunstable-options", "-Cinstrument-coverage=branch"]);
// Coverage reports are sometimes sensitive to optimizations,
// and the current snapshots assume `opt-level=2` unless
// overridden by `compile-flags`.
Expand Down
76 changes: 49 additions & 27 deletions tests/coverage/abort.cov-map
Original file line number Diff line number Diff line change
@@ -1,57 +1,79 @@
Function name: abort::main
Raw bytes (105): 0x[01, 01, 12, 01, 47, 05, 09, 03, 0d, 42, 11, 03, 0d, 11, 3e, 42, 11, 03, 0d, 3b, 15, 11, 3e, 42, 11, 03, 0d, 15, 36, 3b, 15, 11, 3e, 42, 11, 03, 0d, 05, 09, 0d, 01, 0d, 01, 01, 1b, 03, 02, 0b, 00, 18, 42, 01, 0c, 00, 19, 11, 00, 1a, 02, 0a, 3e, 02, 0a, 00, 0b, 3b, 02, 0c, 00, 19, 15, 00, 1a, 00, 31, 36, 00, 31, 00, 32, 33, 04, 0c, 00, 19, 05, 00, 1a, 00, 31, 09, 00, 31, 00, 32, 47, 01, 09, 00, 17, 0d, 02, 05, 01, 02]
Raw bytes (147): 0x[01, 01, 19, 01, 63, 05, 09, 03, 0d, 03, 0d, 5e, 11, 03, 0d, 5e, 11, 03, 0d, 11, 5a, 5e, 11, 03, 0d, 57, 15, 11, 5a, 5e, 11, 03, 0d, 57, 15, 11, 5a, 5e, 11, 03, 0d, 15, 52, 57, 15, 11, 5a, 5e, 11, 03, 0d, 05, 09, 11, 01, 0d, 01, 01, 1b, 03, 02, 0b, 00, 18, 20, 5e, 0d, 00, 0b, 00, 18, 5e, 01, 0c, 00, 19, 20, 11, 5a, 00, 0c, 00, 19, 11, 00, 1a, 02, 0a, 5a, 02, 0a, 00, 0b, 57, 02, 0c, 00, 19, 20, 15, 52, 00, 0c, 00, 19, 15, 00, 1a, 00, 31, 52, 00, 31, 00, 32, 4f, 04, 0c, 00, 19, 20, 05, 09, 00, 0c, 00, 19, 05, 00, 1a, 00, 31, 09, 00, 31, 00, 32, 63, 01, 09, 00, 17, 0d, 02, 05, 01, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 18
- expression 0 operands: lhs = Counter(0), rhs = Expression(17, Add)
Number of expressions: 25
- expression 0 operands: lhs = Counter(0), rhs = Expression(24, Add)
- expression 1 operands: lhs = Counter(1), rhs = Counter(2)
- expression 2 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 3 operands: lhs = Expression(16, Sub), rhs = Counter(4)
- expression 4 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 5 operands: lhs = Counter(4), rhs = Expression(15, Sub)
- expression 6 operands: lhs = Expression(16, Sub), rhs = Counter(4)
- expression 3 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 4 operands: lhs = Expression(23, Sub), rhs = Counter(4)
- expression 5 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 6 operands: lhs = Expression(23, Sub), rhs = Counter(4)
- expression 7 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 8 operands: lhs = Expression(14, Add), rhs = Counter(5)
- expression 9 operands: lhs = Counter(4), rhs = Expression(15, Sub)
- expression 10 operands: lhs = Expression(16, Sub), rhs = Counter(4)
- expression 11 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 12 operands: lhs = Counter(5), rhs = Expression(13, Sub)
- expression 13 operands: lhs = Expression(14, Add), rhs = Counter(5)
- expression 14 operands: lhs = Counter(4), rhs = Expression(15, Sub)
- expression 15 operands: lhs = Expression(16, Sub), rhs = Counter(4)
- expression 16 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 17 operands: lhs = Counter(1), rhs = Counter(2)
Number of file 0 mappings: 13
- expression 8 operands: lhs = Counter(4), rhs = Expression(22, Sub)
- expression 9 operands: lhs = Expression(23, Sub), rhs = Counter(4)
- expression 10 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 11 operands: lhs = Expression(21, Add), rhs = Counter(5)
- expression 12 operands: lhs = Counter(4), rhs = Expression(22, Sub)
- expression 13 operands: lhs = Expression(23, Sub), rhs = Counter(4)
- expression 14 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 15 operands: lhs = Expression(21, Add), rhs = Counter(5)
- expression 16 operands: lhs = Counter(4), rhs = Expression(22, Sub)
- expression 17 operands: lhs = Expression(23, Sub), rhs = Counter(4)
- expression 18 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 19 operands: lhs = Counter(5), rhs = Expression(20, Sub)
- expression 20 operands: lhs = Expression(21, Add), rhs = Counter(5)
- expression 21 operands: lhs = Counter(4), rhs = Expression(22, Sub)
- expression 22 operands: lhs = Expression(23, Sub), rhs = Counter(4)
- expression 23 operands: lhs = Expression(0, Add), rhs = Counter(3)
- expression 24 operands: lhs = Counter(1), rhs = Counter(2)
Number of file 0 mappings: 17
- Code(Counter(0)) at (prev + 13, 1) to (start + 1, 27)
- Code(Expression(0, Add)) at (prev + 2, 11) to (start + 0, 24)
= (c0 + (c1 + c2))
- Code(Expression(16, Sub)) at (prev + 1, 12) to (start + 0, 25)
- Branch { true: Expression(23, Sub), false: Counter(3) } at (prev + 0, 11) to (start + 0, 24)
true = ((c0 + (c1 + c2)) - c3)
false = c3
- Code(Expression(23, Sub)) at (prev + 1, 12) to (start + 0, 25)
= ((c0 + (c1 + c2)) - c3)
- Branch { true: Counter(4), false: Expression(22, Sub) } at (prev + 0, 12) to (start + 0, 25)
true = c4
false = (((c0 + (c1 + c2)) - c3) - c4)
- Code(Counter(4)) at (prev + 0, 26) to (start + 2, 10)
- Code(Expression(15, Sub)) at (prev + 2, 10) to (start + 0, 11)
- Code(Expression(22, Sub)) at (prev + 2, 10) to (start + 0, 11)
= (((c0 + (c1 + c2)) - c3) - c4)
- Code(Expression(14, Add)) at (prev + 2, 12) to (start + 0, 25)
- Code(Expression(21, Add)) at (prev + 2, 12) to (start + 0, 25)
= (c4 + (((c0 + (c1 + c2)) - c3) - c4))
- Branch { true: Counter(5), false: Expression(20, Sub) } at (prev + 0, 12) to (start + 0, 25)
true = c5
false = ((c4 + (((c0 + (c1 + c2)) - c3) - c4)) - c5)
- Code(Counter(5)) at (prev + 0, 26) to (start + 0, 49)
- Code(Expression(13, Sub)) at (prev + 0, 49) to (start + 0, 50)
- Code(Expression(20, Sub)) at (prev + 0, 49) to (start + 0, 50)
= ((c4 + (((c0 + (c1 + c2)) - c3) - c4)) - c5)
- Code(Expression(12, Add)) at (prev + 4, 12) to (start + 0, 25)
- Code(Expression(19, Add)) at (prev + 4, 12) to (start + 0, 25)
= (c5 + ((c4 + (((c0 + (c1 + c2)) - c3) - c4)) - c5))
- Branch { true: Counter(1), false: Counter(2) } at (prev + 0, 12) to (start + 0, 25)
true = c1
false = c2
- Code(Counter(1)) at (prev + 0, 26) to (start + 0, 49)
- Code(Counter(2)) at (prev + 0, 49) to (start + 0, 50)
- Code(Expression(17, Add)) at (prev + 1, 9) to (start + 0, 23)
- Code(Expression(24, Add)) at (prev + 1, 9) to (start + 0, 23)
= (c1 + c2)
- Code(Counter(3)) at (prev + 2, 5) to (start + 1, 2)

Function name: abort::might_abort
Raw bytes (21): 0x[01, 01, 01, 01, 05, 03, 01, 04, 01, 01, 14, 05, 02, 09, 01, 24, 02, 02, 0c, 03, 02]
Raw bytes (28): 0x[01, 01, 01, 01, 05, 04, 01, 04, 01, 01, 14, 20, 05, 02, 01, 08, 00, 14, 05, 01, 09, 01, 24, 02, 02, 0c, 03, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 1
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
Number of file 0 mappings: 3
Number of file 0 mappings: 4
- Code(Counter(0)) at (prev + 4, 1) to (start + 1, 20)
- Code(Counter(1)) at (prev + 2, 9) to (start + 1, 36)
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 8) to (start + 0, 20)
true = c1
false = (c0 - c1)
- Code(Counter(1)) at (prev + 1, 9) to (start + 1, 36)
- Code(Expression(0, Sub)) at (prev + 2, 12) to (start + 3, 2)
= (c0 - c1)

15 changes: 15 additions & 0 deletions tests/coverage/abort.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
LL| |
LL| 12|extern "C" fn might_abort(should_abort: bool) {
LL| 12| if should_abort {
------------------
| Branch (LL:8): [True: 0, False: 12]
------------------
LL| 0| println!("aborting...");
LL| 0| panic!("panics and aborts");
LL| 12| } else {
Expand All @@ -13,17 +16,29 @@
LL| 1|fn main() -> Result<(), u8> {
LL| 1| let mut countdown = 10;
LL| 11| while countdown > 0 {
------------------
| Branch (LL:11): [True: 10, False: 1]
------------------
LL| 10| if countdown < 5 {
------------------
| Branch (LL:12): [True: 4, False: 6]
------------------
LL| 4| might_abort(false);
LL| 6| }
LL| | // See discussion (below the `Notes` section) on coverage results for the closing brace.
LL| 10| if countdown < 5 { might_abort(false); } // Counts for different regions on one line.
^4 ^6
------------------
| Branch (LL:12): [True: 4, False: 6]
------------------
LL| | // For the following example, the closing brace is the last character on the line.
LL| | // This shows the character after the closing brace is highlighted, even if that next
LL| | // character is a newline.
LL| 10| if countdown < 5 { might_abort(false); }
^4 ^6
------------------
| Branch (LL:12): [True: 4, False: 6]
------------------
LL| 10| countdown -= 1;
LL| | }
LL| 1| Ok(())
Expand Down
43 changes: 29 additions & 14 deletions tests/coverage/assert.cov-map
Original file line number Diff line number Diff line change
@@ -1,40 +1,55 @@
Function name: assert::main
Raw bytes (65): 0x[01, 01, 08, 01, 1b, 05, 1f, 09, 0d, 03, 11, 16, 05, 03, 11, 05, 1f, 09, 0d, 09, 01, 09, 01, 01, 1b, 03, 02, 0b, 00, 18, 16, 01, 0c, 00, 1a, 05, 00, 1b, 02, 0a, 12, 02, 13, 00, 20, 09, 00, 21, 02, 0a, 0d, 02, 0a, 00, 0b, 1b, 01, 09, 00, 17, 11, 02, 05, 01, 02]
Raw bytes (92): 0x[01, 01, 0b, 01, 27, 05, 2b, 09, 0d, 03, 11, 03, 11, 22, 05, 03, 11, 22, 05, 03, 11, 05, 2b, 09, 0d, 0c, 01, 09, 01, 01, 1b, 03, 02, 0b, 00, 18, 20, 22, 11, 00, 0b, 00, 18, 22, 01, 0c, 00, 1a, 20, 05, 1e, 00, 0c, 00, 1a, 05, 00, 1b, 02, 0a, 1e, 02, 13, 00, 20, 20, 09, 0d, 00, 13, 00, 20, 09, 00, 21, 02, 0a, 0d, 02, 0a, 00, 0b, 27, 01, 09, 00, 17, 11, 02, 05, 01, 02]
Number of files: 1
- file 0 => global file 1
Number of expressions: 8
- expression 0 operands: lhs = Counter(0), rhs = Expression(6, Add)
- expression 1 operands: lhs = Counter(1), rhs = Expression(7, Add)
Number of expressions: 11
- expression 0 operands: lhs = Counter(0), rhs = Expression(9, Add)
- expression 1 operands: lhs = Counter(1), rhs = Expression(10, Add)
- expression 2 operands: lhs = Counter(2), rhs = Counter(3)
- expression 3 operands: lhs = Expression(0, Add), rhs = Counter(4)
- expression 4 operands: lhs = Expression(5, Sub), rhs = Counter(1)
- expression 5 operands: lhs = Expression(0, Add), rhs = Counter(4)
- expression 6 operands: lhs = Counter(1), rhs = Expression(7, Add)
- expression 7 operands: lhs = Counter(2), rhs = Counter(3)
Number of file 0 mappings: 9
- expression 4 operands: lhs = Expression(0, Add), rhs = Counter(4)
- expression 5 operands: lhs = Expression(8, Sub), rhs = Counter(1)
- expression 6 operands: lhs = Expression(0, Add), rhs = Counter(4)
- expression 7 operands: lhs = Expression(8, Sub), rhs = Counter(1)
- expression 8 operands: lhs = Expression(0, Add), rhs = Counter(4)
- expression 9 operands: lhs = Counter(1), rhs = Expression(10, Add)
- expression 10 operands: lhs = Counter(2), rhs = Counter(3)
Number of file 0 mappings: 12
- Code(Counter(0)) at (prev + 9, 1) to (start + 1, 27)
- Code(Expression(0, Add)) at (prev + 2, 11) to (start + 0, 24)
= (c0 + (c1 + (c2 + c3)))
- Code(Expression(5, Sub)) at (prev + 1, 12) to (start + 0, 26)
- Branch { true: Expression(8, Sub), false: Counter(4) } at (prev + 0, 11) to (start + 0, 24)
true = ((c0 + (c1 + (c2 + c3))) - c4)
false = c4
- Code(Expression(8, Sub)) at (prev + 1, 12) to (start + 0, 26)
= ((c0 + (c1 + (c2 + c3))) - c4)
- Branch { true: Counter(1), false: Expression(7, Sub) } at (prev + 0, 12) to (start + 0, 26)
true = c1
false = (((c0 + (c1 + (c2 + c3))) - c4) - c1)
- Code(Counter(1)) at (prev + 0, 27) to (start + 2, 10)
- Code(Expression(4, Sub)) at (prev + 2, 19) to (start + 0, 32)
- Code(Expression(7, Sub)) at (prev + 2, 19) to (start + 0, 32)
= (((c0 + (c1 + (c2 + c3))) - c4) - c1)
- Branch { true: Counter(2), false: Counter(3) } at (prev + 0, 19) to (start + 0, 32)
true = c2
false = c3
- Code(Counter(2)) at (prev + 0, 33) to (start + 2, 10)
- Code(Counter(3)) at (prev + 2, 10) to (start + 0, 11)
- Code(Expression(6, Add)) at (prev + 1, 9) to (start + 0, 23)
- Code(Expression(9, Add)) at (prev + 1, 9) to (start + 0, 23)
= (c1 + (c2 + c3))
- Code(Counter(4)) at (prev + 2, 5) to (start + 1, 2)

Function name: assert::might_fail_assert
Raw bytes (21): 0x[01, 01, 01, 01, 05, 03, 01, 04, 01, 02, 0f, 02, 02, 25, 00, 3d, 05, 01, 01, 00, 02]
Raw bytes (28): 0x[01, 01, 01, 01, 05, 04, 01, 04, 01, 02, 0f, 02, 02, 25, 00, 3d, 05, 01, 01, 00, 02, 20, 05, 02, 2e, 15, 00, 2e]
Number of files: 1
- file 0 => global file 1
Number of expressions: 1
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
Number of file 0 mappings: 3
Number of file 0 mappings: 4
- Code(Counter(0)) at (prev + 4, 1) to (start + 2, 15)
- Code(Expression(0, Sub)) at (prev + 2, 37) to (start + 0, 61)
= (c0 - c1)
- Code(Counter(1)) at (prev + 1, 1) to (start + 0, 2)
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 46, 21) to (start + 0, 46)
true = c1
false = (c0 - c1)

9 changes: 9 additions & 0 deletions tests/coverage/assert.coverage
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,18 @@
LL| 1|fn main() -> Result<(), u8> {
LL| 1| let mut countdown = 10;
LL| 11| while countdown > 0 {
------------------
| Branch (LL:11): [True: 11, False: 0]
------------------
LL| 11| if countdown == 1 {
------------------
| Branch (LL:12): [True: 1, False: 10]
------------------
LL| 1| might_fail_assert(3);
LL| 10| } else if countdown < 5 {
------------------
| Branch (LL:19): [True: 3, False: 6]
------------------
LL| 3| might_fail_assert(2);
LL| 6| }
LL| 10| countdown -= 1;
Expand Down
Loading

0 comments on commit d2a4cb1

Please sign in to comment.