Skip to content

Commit 3e8b61f

Browse files
author
zhuyunxing
committed
coverage. mcdc tests also report branch coverage
1 parent 69f82aa commit 3e8b61f

File tree

6 files changed

+105
-15
lines changed

6 files changed

+105
-15
lines changed

tests/coverage/mcdc/if.cov-map

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function name: mcdc_if::mcdc_check_a
1+
Function name: if::mcdc_check_a
22
Raw bytes (64): 0x[01, 01, 04, 01, 05, 09, 02, 0d, 0f, 09, 02, 08, 01, 0f, 01, 01, 09, 28, 00, 02, 01, 08, 00, 0e, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 05, 00, 0d, 00, 0e, 30, 0d, 09, 02, 00, 00, 00, 0d, 00, 0e, 0d, 00, 0f, 02, 06, 0f, 02, 0c, 02, 06, 0b, 03, 01, 00, 02]
33
Number of files: 1
44
- file 0 => global file 1
@@ -23,7 +23,7 @@ Number of file 0 mappings: 8
2323
- Code(Expression(2, Add)) at (prev + 3, 1) to (start + 0, 2)
2424
= (c3 + (c2 + (c0 - c1)))
2525

26-
Function name: mcdc_if::mcdc_check_b
26+
Function name: if::mcdc_check_b
2727
Raw bytes (64): 0x[01, 01, 04, 01, 05, 09, 02, 0d, 0f, 09, 02, 08, 01, 17, 01, 01, 09, 28, 00, 02, 01, 08, 00, 0e, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 05, 00, 0d, 00, 0e, 30, 0d, 09, 02, 00, 00, 00, 0d, 00, 0e, 0d, 00, 0f, 02, 06, 0f, 02, 0c, 02, 06, 0b, 03, 01, 00, 02]
2828
Number of files: 1
2929
- file 0 => global file 1
@@ -48,7 +48,7 @@ Number of file 0 mappings: 8
4848
- Code(Expression(2, Add)) at (prev + 3, 1) to (start + 0, 2)
4949
= (c3 + (c2 + (c0 - c1)))
5050

51-
Function name: mcdc_if::mcdc_check_both
51+
Function name: if::mcdc_check_both
5252
Raw bytes (64): 0x[01, 01, 04, 01, 05, 09, 02, 0d, 0f, 09, 02, 08, 01, 1f, 01, 01, 09, 28, 00, 02, 01, 08, 00, 0e, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 05, 00, 0d, 00, 0e, 30, 0d, 09, 02, 00, 00, 00, 0d, 00, 0e, 0d, 00, 0f, 02, 06, 0f, 02, 0c, 02, 06, 0b, 03, 01, 00, 02]
5353
Number of files: 1
5454
- file 0 => global file 1
@@ -73,7 +73,7 @@ Number of file 0 mappings: 8
7373
- Code(Expression(2, Add)) at (prev + 3, 1) to (start + 0, 2)
7474
= (c3 + (c2 + (c0 - c1)))
7575

76-
Function name: mcdc_if::mcdc_check_neither
76+
Function name: if::mcdc_check_neither
7777
Raw bytes (64): 0x[01, 01, 04, 01, 05, 09, 02, 0d, 0f, 09, 02, 08, 01, 07, 01, 01, 09, 28, 00, 02, 01, 08, 00, 0e, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 05, 00, 0d, 00, 0e, 30, 0d, 09, 02, 00, 00, 00, 0d, 00, 0e, 0d, 00, 0f, 02, 06, 0f, 02, 0c, 02, 06, 0b, 03, 01, 00, 02]
7878
Number of files: 1
7979
- file 0 => global file 1
@@ -98,7 +98,7 @@ Number of file 0 mappings: 8
9898
- Code(Expression(2, Add)) at (prev + 3, 1) to (start + 0, 2)
9999
= (c3 + (c2 + (c0 - c1)))
100100

101-
Function name: mcdc_if::mcdc_check_not_tree_decision
101+
Function name: if::mcdc_check_not_tree_decision
102102
Raw bytes (87): 0x[01, 01, 08, 01, 05, 02, 09, 05, 09, 0d, 1e, 02, 09, 11, 1b, 0d, 1e, 02, 09, 0a, 01, 31, 01, 03, 0a, 28, 00, 03, 03, 08, 00, 15, 30, 05, 02, 01, 02, 03, 00, 09, 00, 0a, 02, 00, 0e, 00, 0f, 30, 09, 1e, 03, 02, 00, 00, 0e, 00, 0f, 0b, 00, 14, 00, 15, 30, 11, 0d, 02, 00, 00, 00, 14, 00, 15, 11, 00, 16, 02, 06, 1b, 02, 0c, 02, 06, 17, 03, 01, 00, 02]
103103
Number of files: 1
104104
- file 0 => global file 1
@@ -133,7 +133,7 @@ Number of file 0 mappings: 10
133133
- Code(Expression(5, Add)) at (prev + 3, 1) to (start + 0, 2)
134134
= (c4 + (c3 + ((c0 - c1) - c2)))
135135

136-
Function name: mcdc_if::mcdc_check_tree_decision
136+
Function name: if::mcdc_check_tree_decision
137137
Raw bytes (87): 0x[01, 01, 08, 01, 05, 05, 0d, 05, 0d, 0d, 11, 09, 02, 1b, 1f, 0d, 11, 09, 02, 0a, 01, 27, 01, 03, 09, 28, 00, 03, 03, 08, 00, 15, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 05, 00, 0e, 00, 0f, 30, 0d, 0a, 02, 00, 03, 00, 0e, 00, 0f, 0a, 00, 13, 00, 14, 30, 11, 09, 03, 00, 00, 00, 13, 00, 14, 1b, 00, 16, 02, 06, 1f, 02, 0c, 02, 06, 17, 03, 01, 00, 02]
138138
Number of files: 1
139139
- file 0 => global file 1
@@ -168,7 +168,23 @@ Number of file 0 mappings: 10
168168
- Code(Expression(5, Add)) at (prev + 3, 1) to (start + 0, 2)
169169
= ((c3 + c4) + (c2 + (c0 - c1)))
170170

171-
Function name: mcdc_if::mcdc_nested_if
171+
Function name: if::mcdc_ignore_single_branch
172+
Raw bytes (33): 0x[01, 01, 01, 01, 05, 05, 01, 46, 01, 01, 09, 20, 05, 02, 01, 08, 00, 09, 05, 00, 0a, 02, 06, 02, 02, 0c, 02, 06, 01, 03, 01, 00, 02]
173+
Number of files: 1
174+
- file 0 => global file 1
175+
Number of expressions: 1
176+
- expression 0 operands: lhs = Counter(0), rhs = Counter(1)
177+
Number of file 0 mappings: 5
178+
- Code(Counter(0)) at (prev + 70, 1) to (start + 1, 9)
179+
- Branch { true: Counter(1), false: Expression(0, Sub) } at (prev + 1, 8) to (start + 0, 9)
180+
true = c1
181+
false = (c0 - c1)
182+
- Code(Counter(1)) at (prev + 0, 10) to (start + 2, 6)
183+
- Code(Expression(0, Sub)) at (prev + 2, 12) to (start + 2, 6)
184+
= (c0 - c1)
185+
- Code(Counter(0)) at (prev + 3, 1) to (start + 0, 2)
186+
187+
Function name: if::mcdc_nested_if
172188
Raw bytes (124): 0x[01, 01, 0d, 01, 05, 02, 09, 05, 09, 1b, 15, 05, 09, 1b, 15, 05, 09, 11, 15, 02, 09, 2b, 32, 0d, 2f, 11, 15, 02, 09, 0e, 01, 3b, 01, 01, 09, 28, 00, 02, 01, 08, 00, 0e, 30, 05, 02, 01, 00, 02, 00, 08, 00, 09, 02, 00, 0d, 00, 0e, 30, 09, 32, 02, 00, 00, 00, 0d, 00, 0e, 1b, 01, 09, 01, 0d, 28, 01, 02, 01, 0c, 00, 12, 30, 16, 15, 01, 02, 00, 00, 0c, 00, 0d, 16, 00, 11, 00, 12, 30, 0d, 11, 02, 00, 00, 00, 11, 00, 12, 0d, 00, 13, 02, 0a, 2f, 02, 0a, 00, 0b, 32, 01, 0c, 02, 06, 27, 03, 01, 00, 02]
173189
Number of files: 1
174190
- file 0 => global file 1

tests/coverage/mcdc/if.coverage

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,15 @@
22
LL| |//@ edition: 2021
33
LL| |//@ min-llvm-version: 18
44
LL| |//@ compile-flags: -Zcoverage-options=mcdc
5-
LL| |//@ llvm-cov-flags: --show-mcdc
5+
LL| |//@ llvm-cov-flags: --show-branches=count --show-mcdc
66
LL| |
77
LL| 2|fn mcdc_check_neither(a: bool, b: bool) {
88
LL| 2| if a && b {
99
^0
1010
------------------
11+
| Branch (LL:8): [True: 0, False: 2]
12+
| Branch (LL:13): [True: 0, False: 0]
13+
------------------
1114
|---> MC/DC Decision Region (LL:8) to (LL:14)
1215
|
1316
| Number of Conditions: 2
@@ -34,6 +37,9 @@
3437
LL| 2| if a && b {
3538
^1
3639
------------------
40+
| Branch (LL:8): [True: 1, False: 1]
41+
| Branch (LL:13): [True: 1, False: 0]
42+
------------------
3743
|---> MC/DC Decision Region (LL:8) to (LL:14)
3844
|
3945
| Number of Conditions: 2
@@ -60,6 +66,9 @@
6066
LL| 2|fn mcdc_check_b(a: bool, b: bool) {
6167
LL| 2| if a && b {
6268
------------------
69+
| Branch (LL:8): [True: 2, False: 0]
70+
| Branch (LL:13): [True: 1, False: 1]
71+
------------------
6372
|---> MC/DC Decision Region (LL:8) to (LL:14)
6473
|
6574
| Number of Conditions: 2
@@ -87,6 +96,9 @@
8796
LL| 3| if a && b {
8897
^2
8998
------------------
99+
| Branch (LL:8): [True: 2, False: 1]
100+
| Branch (LL:13): [True: 1, False: 1]
101+
------------------
90102
|---> MC/DC Decision Region (LL:8) to (LL:14)
91103
|
92104
| Number of Conditions: 2
@@ -117,6 +129,10 @@
117129
LL| 4| if a && (b || c) {
118130
^3 ^2
119131
------------------
132+
| Branch (LL:8): [True: 3, False: 1]
133+
| Branch (LL:14): [True: 1, False: 2]
134+
| Branch (LL:19): [True: 1, False: 1]
135+
------------------
120136
|---> MC/DC Decision Region (LL:8) to (LL:21)
121137
|
122138
| Number of Conditions: 3
@@ -150,6 +166,10 @@
150166
LL| 4| if (a || b) && c {
151167
^1
152168
------------------
169+
| Branch (LL:9): [True: 3, False: 1]
170+
| Branch (LL:14): [True: 1, False: 0]
171+
| Branch (LL:20): [True: 2, False: 2]
172+
------------------
153173
|---> MC/DC Decision Region (LL:8) to (LL:21)
154174
|
155175
| Number of Conditions: 3
@@ -180,6 +200,9 @@
180200
LL| 3| if a || b {
181201
^0
182202
------------------
203+
| Branch (LL:8): [True: 3, False: 0]
204+
| Branch (LL:13): [True: 0, False: 0]
205+
------------------
183206
|---> MC/DC Decision Region (LL:8) to (LL:14)
184207
|
185208
| Number of Conditions: 2
@@ -200,6 +223,9 @@
200223
LL| 3| if b && c {
201224
^2
202225
------------------
226+
| Branch (LL:12): [True: 2, False: 1]
227+
| Branch (LL:17): [True: 1, False: 1]
228+
------------------
203229
|---> MC/DC Decision Region (LL:12) to (LL:18)
204230
|
205231
| Number of Conditions: 2
@@ -225,6 +251,17 @@
225251
LL| 0| }
226252
LL| 3|}
227253
LL| |
254+
LL| 2|fn mcdc_ignore_single_branch(a: bool) {
255+
LL| 2| if a {
256+
------------------
257+
| Branch (LL:8): [True: 1, False: 1]
258+
------------------
259+
LL| 1| say("a");
260+
LL| 1| } else {
261+
LL| 1| say("not a");
262+
LL| 1| }
263+
LL| 2|}
264+
LL| |
228265
LL| |#[coverage(off)]
229266
LL| |fn main() {
230267
LL| | mcdc_check_neither(false, false);
@@ -253,6 +290,9 @@
253290
LL| | mcdc_nested_if(true, false, true);
254291
LL| | mcdc_nested_if(true, true, true);
255292
LL| | mcdc_nested_if(true, true, false);
293+
LL| |
294+
LL| | mcdc_ignore_single_branch(true);
295+
LL| | mcdc_ignore_single_branch(false);
256296
LL| |}
257297
LL| |
258298
LL| |#[coverage(off)]

tests/coverage/mcdc/if.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ edition: 2021
33
//@ min-llvm-version: 18
44
//@ compile-flags: -Zcoverage-options=mcdc
5-
//@ llvm-cov-flags: --show-mcdc
5+
//@ llvm-cov-flags: --show-branches=count --show-mcdc
66

77
fn mcdc_check_neither(a: bool, b: bool) {
88
if a && b {
@@ -67,6 +67,14 @@ fn mcdc_nested_if(a: bool, b: bool, c: bool) {
6767
}
6868
}
6969

70+
fn mcdc_ignore_single_branch(a: bool) {
71+
if a {
72+
say("a");
73+
} else {
74+
say("not a");
75+
}
76+
}
77+
7078
#[coverage(off)]
7179
fn main() {
7280
mcdc_check_neither(false, false);
@@ -95,6 +103,9 @@ fn main() {
95103
mcdc_nested_if(true, false, true);
96104
mcdc_nested_if(true, true, true);
97105
mcdc_nested_if(true, true, false);
106+
107+
mcdc_ignore_single_branch(true);
108+
mcdc_ignore_single_branch(false);
98109
}
99110

100111
#[coverage(off)]

tests/coverage/mcdc/nested_if.cov-map

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Function name: mcdc_nested_if::doubly_nested_if_in_condition
1+
Function name: nested_if::doubly_nested_if_in_condition
22
Raw bytes (168): 0x[01, 01, 0e, 01, 05, 05, 11, 05, 11, 26, 19, 05, 11, 19, 1d, 19, 1d, 1d, 22, 26, 19, 05, 11, 11, 15, 09, 02, 0d, 37, 09, 02, 14, 01, 0f, 01, 01, 09, 28, 02, 02, 01, 08, 00, 4e, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 30, 0d, 09, 02, 00, 00, 00, 0d, 00, 4e, 05, 00, 10, 00, 11, 28, 01, 02, 00, 10, 00, 36, 30, 11, 26, 01, 00, 02, 00, 10, 00, 11, 30, 15, 21, 02, 00, 00, 00, 15, 00, 36, 26, 00, 18, 00, 19, 28, 00, 02, 00, 18, 00, 1e, 30, 19, 22, 01, 02, 00, 00, 18, 00, 19, 19, 00, 1d, 00, 1e, 30, 1a, 1d, 02, 00, 00, 00, 1d, 00, 1e, 1a, 00, 21, 00, 25, 1f, 00, 2f, 00, 34, 2b, 00, 39, 00, 3e, 21, 00, 48, 00, 4c, 0d, 00, 4f, 02, 06, 37, 02, 0c, 02, 06, 33, 03, 01, 00, 02]
33
Number of files: 1
44
- file 0 => global file 1
@@ -57,7 +57,7 @@ Number of file 0 mappings: 20
5757
- Code(Expression(12, Add)) at (prev + 3, 1) to (start + 0, 2)
5858
= (c3 + (c2 + (c0 - c1)))
5959

60-
Function name: mcdc_nested_if::nested_if_in_condition
60+
Function name: nested_if::nested_if_in_condition
6161
Raw bytes (120): 0x[01, 01, 0b, 01, 05, 05, 11, 05, 11, 1e, 15, 05, 11, 11, 15, 1e, 15, 05, 11, 09, 02, 0d, 2b, 09, 02, 0e, 01, 07, 01, 01, 09, 28, 01, 02, 01, 08, 00, 2e, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 30, 0d, 09, 02, 00, 00, 00, 0d, 00, 2e, 05, 00, 10, 00, 11, 28, 00, 02, 00, 10, 00, 16, 30, 11, 1e, 01, 00, 02, 00, 10, 00, 11, 1e, 00, 15, 00, 16, 30, 15, 1a, 02, 00, 00, 00, 15, 00, 16, 17, 00, 19, 00, 1d, 1a, 00, 27, 00, 2c, 0d, 00, 2f, 02, 06, 2b, 02, 0c, 02, 06, 27, 03, 01, 00, 02]
6262
Number of files: 1
6363
- file 0 => global file 1
@@ -102,7 +102,7 @@ Number of file 0 mappings: 14
102102
- Code(Expression(9, Add)) at (prev + 3, 1) to (start + 0, 2)
103103
= (c3 + (c2 + (c0 - c1)))
104104

105-
Function name: mcdc_nested_if::nested_in_then_block_in_condition
105+
Function name: nested_if::nested_in_then_block_in_condition
106106
Raw bytes (176): 0x[01, 01, 12, 01, 05, 05, 11, 05, 11, 3a, 15, 05, 11, 11, 15, 33, 19, 11, 15, 19, 1d, 19, 1d, 1d, 2e, 33, 19, 11, 15, 3a, 15, 05, 11, 09, 02, 0d, 47, 09, 02, 14, 01, 22, 01, 01, 09, 28, 02, 02, 01, 08, 00, 4b, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 30, 0d, 09, 02, 00, 00, 00, 0d, 00, 4b, 05, 00, 10, 00, 11, 28, 00, 02, 00, 10, 00, 16, 30, 11, 3a, 01, 00, 02, 00, 10, 00, 11, 3a, 00, 15, 00, 16, 30, 15, 36, 02, 00, 00, 00, 15, 00, 16, 33, 00, 1c, 00, 1d, 28, 01, 02, 00, 1c, 00, 22, 30, 19, 2e, 01, 02, 00, 00, 1c, 00, 1d, 19, 00, 21, 00, 22, 30, 26, 1d, 02, 00, 00, 00, 21, 00, 22, 26, 00, 25, 00, 29, 2b, 00, 33, 00, 38, 36, 00, 44, 00, 49, 0d, 00, 4c, 02, 06, 47, 02, 0c, 02, 06, 43, 03, 01, 00, 02]
107107
Number of files: 1
108108
- file 0 => global file 1
@@ -166,7 +166,7 @@ Number of file 0 mappings: 20
166166
- Code(Expression(16, Add)) at (prev + 3, 1) to (start + 0, 2)
167167
= (c3 + (c2 + (c0 - c1)))
168168

169-
Function name: mcdc_nested_if::nested_single_condition_decision
169+
Function name: nested_if::nested_single_condition_decision
170170
Raw bytes (85): 0x[01, 01, 06, 01, 05, 05, 11, 05, 11, 09, 02, 0d, 17, 09, 02, 0b, 01, 17, 01, 04, 09, 28, 00, 02, 04, 08, 00, 29, 30, 05, 02, 01, 02, 00, 00, 08, 00, 09, 30, 0d, 09, 02, 00, 00, 00, 0d, 00, 29, 05, 00, 10, 00, 11, 20, 11, 0a, 00, 10, 00, 11, 11, 00, 14, 00, 19, 0a, 00, 23, 00, 27, 0d, 00, 2a, 02, 06, 17, 02, 0c, 02, 06, 13, 03, 01, 00, 02]
171171
Number of files: 1
172172
- file 0 => global file 1

tests/coverage/mcdc/nested_if.coverage

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,17 @@
22
LL| |//@ edition: 2021
33
LL| |//@ min-llvm-version: 18
44
LL| |//@ compile-flags: -Zcoverage-options=mcdc
5-
LL| |//@ llvm-cov-flags: --show-mcdc
5+
LL| |//@ llvm-cov-flags: --show-branches=count --show-mcdc
66
LL| |
77
LL| 4|fn nested_if_in_condition(a: bool, b: bool, c: bool) {
88
LL| 4| if a && if b || c { true } else { false } {
99
^3 ^2 ^2 ^1
1010
------------------
11+
| Branch (LL:8): [True: 3, False: 1]
12+
| Branch (LL:13): [True: 2, False: 1]
13+
| Branch (LL:16): [True: 1, False: 2]
14+
| Branch (LL:21): [True: 1, False: 1]
15+
------------------
1116
|---> MC/DC Decision Region (LL:8) to (LL:46)
1217
|
1318
| Number of Conditions: 2
@@ -53,6 +58,13 @@
5358
LL| 4| if a && if b || if c && d { true } else { false } { false } else { true } {
5459
^3 ^2 ^1 ^1 ^1 ^2 ^1
5560
------------------
61+
| Branch (LL:8): [True: 3, False: 1]
62+
| Branch (LL:13): [True: 1, False: 2]
63+
| Branch (LL:16): [True: 1, False: 2]
64+
| Branch (LL:21): [True: 1, False: 1]
65+
| Branch (LL:24): [True: 1, False: 1]
66+
| Branch (LL:29): [True: 1, False: 0]
67+
------------------
5668
|---> MC/DC Decision Region (LL:8) to (LL:78)
5769
|
5870
| Number of Conditions: 2
@@ -117,6 +129,10 @@
117129
LL| 3| if a && if b { false } else { true } {
118130
^2 ^1 ^1
119131
------------------
132+
| Branch (LL:8): [True: 2, False: 1]
133+
| Branch (LL:13): [True: 1, False: 1]
134+
| Branch (LL:16): [True: 1, False: 1]
135+
------------------
120136
|---> MC/DC Decision Region (LL:8) to (LL:41)
121137
|
122138
| Number of Conditions: 2
@@ -145,6 +161,13 @@
145161
LL| 7| if a && if b || c { if d && e { true } else { false } } else { false } {
146162
^6 ^5 ^5 ^2 ^1 ^4 ^1
147163
------------------
164+
| Branch (LL:8): [True: 6, False: 1]
165+
| Branch (LL:13): [True: 1, False: 5]
166+
| Branch (LL:16): [True: 1, False: 5]
167+
| Branch (LL:21): [True: 4, False: 1]
168+
| Branch (LL:28): [True: 2, False: 3]
169+
| Branch (LL:33): [True: 1, False: 1]
170+
------------------
148171
|---> MC/DC Decision Region (LL:8) to (LL:75)
149172
|
150173
| Number of Conditions: 2

tests/coverage/mcdc/nested_if.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//@ edition: 2021
33
//@ min-llvm-version: 18
44
//@ compile-flags: -Zcoverage-options=mcdc
5-
//@ llvm-cov-flags: --show-mcdc
5+
//@ llvm-cov-flags: --show-branches=count --show-mcdc
66

77
fn nested_if_in_condition(a: bool, b: bool, c: bool) {
88
if a && if b || c { true } else { false } {

0 commit comments

Comments
 (0)