-
Notifications
You must be signed in to change notification settings - Fork 12.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
coverage: Branch coverage tests for lazy boolean operators
- Loading branch information
Showing
3 changed files
with
370 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
Function name: lazy_boolean::branch_and | ||
Raw bytes (42): 0x[01, 01, 03, 09, 0a, 05, 09, 05, 09, 06, 01, 13, 01, 01, 10, 03, 04, 09, 00, 0a, 05, 00, 0d, 00, 0e, 20, 09, 0a, 00, 0d, 00, 0e, 09, 00, 12, 00, 13, 03, 01, 05, 01, 02] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 3 | ||
- expression 0 operands: lhs = Counter(2), rhs = Expression(2, Sub) | ||
- expression 1 operands: lhs = Counter(1), rhs = Counter(2) | ||
- expression 2 operands: lhs = Counter(1), rhs = Counter(2) | ||
Number of file 0 mappings: 6 | ||
- Code(Counter(0)) at (prev + 19, 1) to (start + 1, 16) | ||
- Code(Expression(0, Add)) at (prev + 4, 9) to (start + 0, 10) | ||
= (c2 + (c1 - c2)) | ||
- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 14) | ||
- Branch { true: Counter(2), false: Expression(2, Sub) } at (prev + 0, 13) to (start + 0, 14) | ||
true = c2 | ||
false = (c1 - c2) | ||
- Code(Counter(2)) at (prev + 0, 18) to (start + 0, 19) | ||
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 1, 2) | ||
= (c2 + (c1 - c2)) | ||
|
||
Function name: lazy_boolean::branch_or | ||
Raw bytes (44): 0x[01, 01, 04, 09, 0e, 05, 09, 05, 09, 05, 09, 06, 01, 1b, 01, 01, 10, 03, 04, 09, 00, 0a, 05, 00, 0d, 00, 0e, 20, 09, 0e, 00, 0d, 00, 0e, 0e, 00, 12, 00, 13, 03, 01, 05, 01, 02] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 4 | ||
- expression 0 operands: lhs = Counter(2), rhs = Expression(3, Sub) | ||
- expression 1 operands: lhs = Counter(1), rhs = Counter(2) | ||
- expression 2 operands: lhs = Counter(1), rhs = Counter(2) | ||
- expression 3 operands: lhs = Counter(1), rhs = Counter(2) | ||
Number of file 0 mappings: 6 | ||
- Code(Counter(0)) at (prev + 27, 1) to (start + 1, 16) | ||
- Code(Expression(0, Add)) at (prev + 4, 9) to (start + 0, 10) | ||
= (c2 + (c1 - c2)) | ||
- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 14) | ||
- Branch { true: Counter(2), false: Expression(3, Sub) } at (prev + 0, 13) to (start + 0, 14) | ||
true = c2 | ||
false = (c1 - c2) | ||
- Code(Expression(3, Sub)) at (prev + 0, 18) to (start + 0, 19) | ||
= (c1 - c2) | ||
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 1, 2) | ||
= (c2 + (c1 - c2)) | ||
|
||
Function name: lazy_boolean::chain | ||
Raw bytes (149): 0x[01, 01, 13, 11, 07, 0b, 16, 15, 1a, 09, 0d, 05, 09, 05, 09, 09, 0d, 47, 25, 4b, 21, 19, 1d, 03, 19, 03, 19, 3e, 1d, 03, 19, 3e, 1d, 03, 19, 47, 25, 4b, 21, 19, 1d, 13, 01, 24, 01, 01, 10, 03, 04, 09, 00, 0a, 05, 00, 0d, 00, 12, 20, 09, 16, 00, 0d, 00, 12, 09, 00, 16, 00, 1b, 20, 0d, 1a, 00, 16, 00, 1b, 0d, 00, 1f, 00, 24, 20, 11, 15, 00, 1f, 00, 24, 11, 00, 28, 00, 2d, 03, 01, 05, 00, 11, 43, 03, 09, 00, 0a, 03, 00, 0d, 00, 12, 20, 19, 3e, 00, 0d, 00, 12, 3e, 00, 16, 00, 1b, 20, 1d, 3a, 00, 16, 00, 1b, 3a, 00, 1f, 00, 24, 20, 21, 25, 00, 1f, 00, 24, 25, 00, 28, 00, 2d, 43, 01, 05, 01, 02] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 19 | ||
- expression 0 operands: lhs = Counter(4), rhs = Expression(1, Add) | ||
- expression 1 operands: lhs = Expression(2, Add), rhs = Expression(5, Sub) | ||
- expression 2 operands: lhs = Counter(5), rhs = Expression(6, Sub) | ||
- expression 3 operands: lhs = Counter(2), rhs = Counter(3) | ||
- expression 4 operands: lhs = Counter(1), rhs = Counter(2) | ||
- expression 5 operands: lhs = Counter(1), rhs = Counter(2) | ||
- expression 6 operands: lhs = Counter(2), rhs = Counter(3) | ||
- expression 7 operands: lhs = Expression(17, Add), rhs = Counter(9) | ||
- expression 8 operands: lhs = Expression(18, Add), rhs = Counter(8) | ||
- expression 9 operands: lhs = Counter(6), rhs = Counter(7) | ||
- expression 10 operands: lhs = Expression(0, Add), rhs = Counter(6) | ||
- expression 11 operands: lhs = Expression(0, Add), rhs = Counter(6) | ||
- expression 12 operands: lhs = Expression(15, Sub), rhs = Counter(7) | ||
- expression 13 operands: lhs = Expression(0, Add), rhs = Counter(6) | ||
- expression 14 operands: lhs = Expression(15, Sub), rhs = Counter(7) | ||
- expression 15 operands: lhs = Expression(0, Add), rhs = Counter(6) | ||
- expression 16 operands: lhs = Expression(17, Add), rhs = Counter(9) | ||
- expression 17 operands: lhs = Expression(18, Add), rhs = Counter(8) | ||
- expression 18 operands: lhs = Counter(6), rhs = Counter(7) | ||
Number of file 0 mappings: 19 | ||
- Code(Counter(0)) at (prev + 36, 1) to (start + 1, 16) | ||
- Code(Expression(0, Add)) at (prev + 4, 9) to (start + 0, 10) | ||
= (c4 + ((c5 + (c2 - c3)) + (c1 - c2))) | ||
- Code(Counter(1)) at (prev + 0, 13) to (start + 0, 18) | ||
- Branch { true: Counter(2), false: Expression(5, Sub) } at (prev + 0, 13) to (start + 0, 18) | ||
true = c2 | ||
false = (c1 - c2) | ||
- Code(Counter(2)) at (prev + 0, 22) to (start + 0, 27) | ||
- Branch { true: Counter(3), false: Expression(6, Sub) } at (prev + 0, 22) to (start + 0, 27) | ||
true = c3 | ||
false = (c2 - c3) | ||
- Code(Counter(3)) at (prev + 0, 31) to (start + 0, 36) | ||
- Branch { true: Counter(4), false: Counter(5) } at (prev + 0, 31) to (start + 0, 36) | ||
true = c4 | ||
false = c5 | ||
- Code(Counter(4)) at (prev + 0, 40) to (start + 0, 45) | ||
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 0, 17) | ||
= (c4 + ((c5 + (c2 - c3)) + (c1 - c2))) | ||
- Code(Expression(16, Add)) at (prev + 3, 9) to (start + 0, 10) | ||
= (((c6 + c7) + c8) + c9) | ||
- Code(Expression(0, Add)) at (prev + 0, 13) to (start + 0, 18) | ||
= (c4 + ((c5 + (c2 - c3)) + (c1 - c2))) | ||
- Branch { true: Counter(6), false: Expression(15, Sub) } at (prev + 0, 13) to (start + 0, 18) | ||
true = c6 | ||
false = ((c4 + ((c5 + (c2 - c3)) + (c1 - c2))) - c6) | ||
- Code(Expression(15, Sub)) at (prev + 0, 22) to (start + 0, 27) | ||
= ((c4 + ((c5 + (c2 - c3)) + (c1 - c2))) - c6) | ||
- Branch { true: Counter(7), false: Expression(14, Sub) } at (prev + 0, 22) to (start + 0, 27) | ||
true = c7 | ||
false = (((c4 + ((c5 + (c2 - c3)) + (c1 - c2))) - c6) - c7) | ||
- Code(Expression(14, Sub)) at (prev + 0, 31) to (start + 0, 36) | ||
= (((c4 + ((c5 + (c2 - c3)) + (c1 - c2))) - c6) - c7) | ||
- Branch { true: Counter(8), false: Counter(9) } at (prev + 0, 31) to (start + 0, 36) | ||
true = c8 | ||
false = c9 | ||
- Code(Counter(9)) at (prev + 0, 40) to (start + 0, 45) | ||
- Code(Expression(16, Add)) at (prev + 1, 5) to (start + 1, 2) | ||
= (((c6 + c7) + c8) + c9) | ||
|
||
Function name: lazy_boolean::nested_mixed | ||
Raw bytes (159): 0x[01, 01, 18, 07, 22, 11, 36, 3b, 11, 09, 0d, 26, 0d, 05, 09, 05, 09, 05, 09, 26, 0d, 05, 09, 09, 0d, 3b, 11, 09, 0d, 3b, 11, 09, 0d, 19, 5f, 1d, 21, 03, 15, 15, 19, 52, 56, 15, 19, 03, 15, 19, 5f, 1d, 21, 13, 01, 31, 01, 01, 10, 03, 04, 09, 00, 0a, 05, 00, 0e, 00, 13, 20, 09, 26, 00, 0e, 00, 13, 26, 00, 17, 00, 1d, 20, 0d, 22, 00, 17, 00, 1d, 3b, 00, 23, 00, 28, 20, 11, 36, 00, 23, 00, 28, 36, 00, 2c, 00, 33, 03, 01, 05, 00, 11, 5b, 03, 09, 00, 0a, 03, 00, 0e, 00, 13, 20, 15, 56, 00, 0e, 00, 13, 15, 00, 17, 00, 1c, 20, 19, 52, 00, 17, 00, 1c, 4f, 00, 22, 00, 28, 20, 1d, 21, 00, 22, 00, 28, 1d, 00, 2c, 00, 33, 5b, 01, 05, 01, 02] | ||
Number of files: 1 | ||
- file 0 => global file 1 | ||
Number of expressions: 24 | ||
- expression 0 operands: lhs = Expression(1, Add), rhs = Expression(8, Sub) | ||
- expression 1 operands: lhs = Counter(4), rhs = Expression(13, Sub) | ||
- expression 2 operands: lhs = Expression(14, Add), rhs = Counter(4) | ||
- expression 3 operands: lhs = Counter(2), rhs = Counter(3) | ||
- expression 4 operands: lhs = Expression(9, Sub), rhs = Counter(3) | ||
- expression 5 operands: lhs = Counter(1), rhs = Counter(2) | ||
- expression 6 operands: lhs = Counter(1), rhs = Counter(2) | ||
- expression 7 operands: lhs = Counter(1), rhs = Counter(2) | ||
- expression 8 operands: lhs = Expression(9, Sub), rhs = Counter(3) | ||
- expression 9 operands: lhs = Counter(1), rhs = Counter(2) | ||
- expression 10 operands: lhs = Counter(2), rhs = Counter(3) | ||
- expression 11 operands: lhs = Expression(14, Add), rhs = Counter(4) | ||
- expression 12 operands: lhs = Counter(2), rhs = Counter(3) | ||
- expression 13 operands: lhs = Expression(14, Add), rhs = Counter(4) | ||
- expression 14 operands: lhs = Counter(2), rhs = Counter(3) | ||
- expression 15 operands: lhs = Counter(6), rhs = Expression(23, Add) | ||
- expression 16 operands: lhs = Counter(7), rhs = Counter(8) | ||
- expression 17 operands: lhs = Expression(0, Add), rhs = Counter(5) | ||
- expression 18 operands: lhs = Counter(5), rhs = Counter(6) | ||
- expression 19 operands: lhs = Expression(20, Sub), rhs = Expression(21, Sub) | ||
- expression 20 operands: lhs = Counter(5), rhs = Counter(6) | ||
- expression 21 operands: lhs = Expression(0, Add), rhs = Counter(5) | ||
- expression 22 operands: lhs = Counter(6), rhs = Expression(23, Add) | ||
- expression 23 operands: lhs = Counter(7), rhs = Counter(8) | ||
Number of file 0 mappings: 19 | ||
- Code(Counter(0)) at (prev + 49, 1) to (start + 1, 16) | ||
- Code(Expression(0, Add)) at (prev + 4, 9) to (start + 0, 10) | ||
= ((c4 + ((c2 + c3) - c4)) + ((c1 - c2) - c3)) | ||
- Code(Counter(1)) at (prev + 0, 14) to (start + 0, 19) | ||
- Branch { true: Counter(2), false: Expression(9, Sub) } at (prev + 0, 14) to (start + 0, 19) | ||
true = c2 | ||
false = (c1 - c2) | ||
- Code(Expression(9, Sub)) at (prev + 0, 23) to (start + 0, 29) | ||
= (c1 - c2) | ||
- Branch { true: Counter(3), false: Expression(8, Sub) } at (prev + 0, 23) to (start + 0, 29) | ||
true = c3 | ||
false = ((c1 - c2) - c3) | ||
- Code(Expression(14, Add)) at (prev + 0, 35) to (start + 0, 40) | ||
= (c2 + c3) | ||
- Branch { true: Counter(4), false: Expression(13, Sub) } at (prev + 0, 35) to (start + 0, 40) | ||
true = c4 | ||
false = ((c2 + c3) - c4) | ||
- Code(Expression(13, Sub)) at (prev + 0, 44) to (start + 0, 51) | ||
= ((c2 + c3) - c4) | ||
- Code(Expression(0, Add)) at (prev + 1, 5) to (start + 0, 17) | ||
= ((c4 + ((c2 + c3) - c4)) + ((c1 - c2) - c3)) | ||
- Code(Expression(22, Add)) at (prev + 3, 9) to (start + 0, 10) | ||
= (c6 + (c7 + c8)) | ||
- Code(Expression(0, Add)) at (prev + 0, 14) to (start + 0, 19) | ||
= ((c4 + ((c2 + c3) - c4)) + ((c1 - c2) - c3)) | ||
- Branch { true: Counter(5), false: Expression(21, Sub) } at (prev + 0, 14) to (start + 0, 19) | ||
true = c5 | ||
false = (((c4 + ((c2 + c3) - c4)) + ((c1 - c2) - c3)) - c5) | ||
- Code(Counter(5)) at (prev + 0, 23) to (start + 0, 28) | ||
- Branch { true: Counter(6), false: Expression(20, Sub) } at (prev + 0, 23) to (start + 0, 28) | ||
true = c6 | ||
false = (c5 - c6) | ||
- Code(Expression(19, Add)) at (prev + 0, 34) to (start + 0, 40) | ||
= ((c5 - c6) + (((c4 + ((c2 + c3) - c4)) + ((c1 - c2) - c3)) - c5)) | ||
- Branch { true: Counter(7), false: Counter(8) } at (prev + 0, 34) to (start + 0, 40) | ||
true = c7 | ||
false = c8 | ||
- Code(Counter(7)) at (prev + 0, 44) to (start + 0, 51) | ||
- Code(Expression(22, Add)) at (prev + 1, 5) to (start + 1, 2) | ||
= (c6 + (c7 + c8)) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
LL| |#![feature(coverage_attribute)] | ||
LL| |//@ edition: 2021 | ||
LL| |//@ compile-flags: -Zcoverage-options=branch | ||
LL| |//@ llvm-cov-flags: --show-branches=count | ||
LL| | | ||
LL| |// Tests for branch coverage of the lazy boolean operators `&&` and `||`, | ||
LL| |// as ordinary expressions that aren't part of an `if` condition or similar. | ||
LL| | | ||
LL| |use core::hint::black_box; | ||
LL| | | ||
LL| |// Helper macro to prevent start-of-function spans from being merged into | ||
LL| |// spans on the lines we care about. | ||
LL| |macro_rules! no_merge { | ||
LL| | () => { | ||
LL| | for _ in 0..1 {} | ||
LL| | }; | ||
LL| |} | ||
LL| | | ||
LL| 15|fn branch_and(a: bool, b: bool) { | ||
LL| 15| no_merge!(); | ||
LL| | | ||
LL| | // |13 |18 (no branch) | ||
LL| 15| let c = a && b; | ||
^12 | ||
------------------ | ||
| Branch (LL:13): [True: 12, False: 3] | ||
------------------ | ||
LL| 15| black_box(c); | ||
LL| 15|} | ||
LL| | | ||
LL| 15|fn branch_or(a: bool, b: bool) { | ||
LL| 15| no_merge!(); | ||
LL| | | ||
LL| | // |13 |18 (no branch) | ||
LL| 15| let c = a || b; | ||
^3 | ||
------------------ | ||
| Branch (LL:13): [True: 12, False: 3] | ||
------------------ | ||
LL| 15| black_box(c); | ||
LL| 15|} | ||
LL| | | ||
LL| |// Test for chaining one operator several times. | ||
LL| 16|fn chain(x: u32) { | ||
LL| 16| no_merge!(); | ||
LL| | | ||
LL| | // |13 |22 |31 |40 (no branch) | ||
LL| 16| let c = x > 1 && x > 2 && x > 4 && x > 8; | ||
^14 ^13 ^11 | ||
------------------ | ||
| Branch (LL:13): [True: 14, False: 2] | ||
| Branch (LL:22): [True: 13, False: 1] | ||
| Branch (LL:31): [True: 11, False: 2] | ||
------------------ | ||
LL| 16| black_box(c); | ||
LL| | | ||
LL| | // |13 |22 |31 |40 (no branch) | ||
LL| 16| let d = x < 1 || x < 2 || x < 4 || x < 8; | ||
^15 ^14 ^12 | ||
------------------ | ||
| Branch (LL:13): [True: 1, False: 15] | ||
| Branch (LL:22): [True: 1, False: 14] | ||
| Branch (LL:31): [True: 2, False: 12] | ||
------------------ | ||
LL| 16| black_box(d); | ||
LL| 16|} | ||
LL| | | ||
LL| |// Test for nested combinations of different operators. | ||
LL| 16|fn nested_mixed(x: u32) { | ||
LL| 16| no_merge!(); | ||
LL| | | ||
LL| | // |14 |23 |35 |44 (no branch) | ||
LL| 16| let c = (x < 4 || x >= 9) && (x < 2 || x >= 10); | ||
^12 ^11 ^9 | ||
------------------ | ||
| Branch (LL:14): [True: 4, False: 12] | ||
| Branch (LL:23): [True: 7, False: 5] | ||
| Branch (LL:35): [True: 2, False: 9] | ||
------------------ | ||
LL| 16| black_box(c); | ||
LL| | | ||
LL| | // |14 |23 |34 |44 (no branch) | ||
LL| 16| let d = (x < 4 && x < 1) || (x >= 8 && x >= 10); | ||
^4 ^15 ^8 | ||
------------------ | ||
| Branch (LL:14): [True: 4, False: 12] | ||
| Branch (LL:23): [True: 1, False: 3] | ||
| Branch (LL:34): [True: 8, False: 7] | ||
------------------ | ||
LL| 16| black_box(d); | ||
LL| 16|} | ||
LL| | | ||
LL| |#[coverage(off)] | ||
LL| |fn main() { | ||
LL| | // Use each set of arguments (2^n) times, so that each combination has a | ||
LL| | // unique sum, and we can use those sums to verify expected control flow. | ||
LL| | // 1x (false, false) | ||
LL| | // 2x (false, true) | ||
LL| | // 4x (true, false) | ||
LL| | // 8x (true, true) | ||
LL| | for a in [false, true, true, true, true] { | ||
LL| | for b in [false, true, true] { | ||
LL| | branch_and(a, b); | ||
LL| | branch_or(a, b); | ||
LL| | } | ||
LL| | } | ||
LL| | | ||
LL| | for x in 0..16 { | ||
LL| | chain(x); | ||
LL| | nested_mixed(x); | ||
LL| | } | ||
LL| |} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#![feature(coverage_attribute)] | ||
//@ edition: 2021 | ||
//@ compile-flags: -Zcoverage-options=branch | ||
//@ llvm-cov-flags: --show-branches=count | ||
|
||
// Tests for branch coverage of the lazy boolean operators `&&` and `||`, | ||
// as ordinary expressions that aren't part of an `if` condition or similar. | ||
|
||
use core::hint::black_box; | ||
|
||
// Helper macro to prevent start-of-function spans from being merged into | ||
// spans on the lines we care about. | ||
macro_rules! no_merge { | ||
() => { | ||
for _ in 0..1 {} | ||
}; | ||
} | ||
|
||
fn branch_and(a: bool, b: bool) { | ||
no_merge!(); | ||
|
||
// |13 |18 (no branch) | ||
let c = a && b; | ||
black_box(c); | ||
} | ||
|
||
fn branch_or(a: bool, b: bool) { | ||
no_merge!(); | ||
|
||
// |13 |18 (no branch) | ||
let c = a || b; | ||
black_box(c); | ||
} | ||
|
||
// Test for chaining one operator several times. | ||
fn chain(x: u32) { | ||
no_merge!(); | ||
|
||
// |13 |22 |31 |40 (no branch) | ||
let c = x > 1 && x > 2 && x > 4 && x > 8; | ||
black_box(c); | ||
|
||
// |13 |22 |31 |40 (no branch) | ||
let d = x < 1 || x < 2 || x < 4 || x < 8; | ||
black_box(d); | ||
} | ||
|
||
// Test for nested combinations of different operators. | ||
fn nested_mixed(x: u32) { | ||
no_merge!(); | ||
|
||
// |14 |23 |35 |44 (no branch) | ||
let c = (x < 4 || x >= 9) && (x < 2 || x >= 10); | ||
black_box(c); | ||
|
||
// |14 |23 |34 |44 (no branch) | ||
let d = (x < 4 && x < 1) || (x >= 8 && x >= 10); | ||
black_box(d); | ||
} | ||
|
||
#[coverage(off)] | ||
fn main() { | ||
// Use each set of arguments (2^n) times, so that each combination has a | ||
// unique sum, and we can use those sums to verify expected control flow. | ||
// 1x (false, false) | ||
// 2x (false, true) | ||
// 4x (true, false) | ||
// 8x (true, true) | ||
for a in [false, true, true, true, true] { | ||
for b in [false, true, true] { | ||
branch_and(a, b); | ||
branch_or(a, b); | ||
} | ||
} | ||
|
||
for x in 0..16 { | ||
chain(x); | ||
nested_mixed(x); | ||
} | ||
} |