Skip to content

Commit c45ee4b

Browse files
committed
Coverage tests for remaining TerminatorKinds and async, improve Assert
Tested and validate results for panic unwind, panic abort, assert!() macro, TerminatorKind::Assert (for example, numeric overflow), and async/await. Implemented a previous documented idea to change Assert handling to be the same as FalseUnwind and Goto, so it doesn't get its own BasicCoverageBlock anymore. This changed a couple of coverage regions, but I validated those changes are not any worse than the prior results, and probably help assure some consistency (even if some people might disagree with how the code region is consistently computed). Fixed issue with async/await. AggregateKind::Generator needs to be handled like AggregateKind::Closure; coverage span for the outer async function should not "cover" the async body, which is actually executed in a separate "closure" MIR.
1 parent 1f95c91 commit c45ee4b

File tree

142 files changed

+10102
-867
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

142 files changed

+10102
-867
lines changed

compiler/rustc_mir/src/util/generic_graphviz.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,13 @@ impl<
116116

117117
write!(w, r#"<table border="0" cellborder="1" cellspacing="0">"#)?;
118118

119-
// FIXME(richkadel): Need generic way to know if node header should have a different color
119+
// FIXME(richkadel): If/when migrating the MIR graphviz to this generic implementation,
120+
// we need generic way to know if node header should have a different color. For example,
121+
// for MIR:
122+
//
120123
// let (blk, bgcolor) = if data.is_cleanup {
121-
// (format!("{:?} (cleanup)", node), "lightblue")
124+
// let color = if dark_mode { "royalblue" } else { "lightblue" };
125+
// (format!("{:?} (cleanup)", node), color)
122126
// } else {
123127
// let color = if dark_mode { "dimgray" } else { "gray" };
124128
// (format!("{:?}", node), color)

src/doc/unstable-book/src/compiler-flags/source-based-code-coverage.md

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
# `source-based-code-coverage`
22

3-
The feature request for this feature is: [#34701]
4-
5-
The Major Change Proposal (MCP) for this feature is: [#278](https://github.com/rust-lang/compiler-team/issues/278)
3+
The tracking issue for this feature is: [#79121](https://github.com/rust-lang/rust/issues/79121).
64

75
------------------------
86

src/test/run-make-fulldeps/coverage-reports-base/Makefile

+3
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ endif
5454
%: $(SOURCEDIR)/%.rs
5555
# Compile the test program with coverage instrumentation and generate relevant MIR.
5656
$(RUSTC) $(SOURCEDIR)/$@.rs \
57+
$$( grep -q '^\/\/ require-rust-edition-2018' $(SOURCEDIR)/$@.rs && \
58+
echo "--edition=2018" \
59+
) \
5760
-Zinstrument-coverage \
5861
-Clink-dead-code=$(LINK_DEAD_CODE)
5962

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"data": [
3+
{
4+
"files": [
5+
{
6+
"filename": "../coverage/abort.rs",
7+
"summary": {
8+
"functions": {
9+
"count": 2,
10+
"covered": 2,
11+
"percent": 100
12+
},
13+
"instantiations": {
14+
"count": 2,
15+
"covered": 2,
16+
"percent": 100
17+
},
18+
"lines": {
19+
"count": 15,
20+
"covered": 13,
21+
"percent": 86.66666666666667
22+
},
23+
"regions": {
24+
"count": 10,
25+
"covered": 9,
26+
"notcovered": 1,
27+
"percent": 90
28+
}
29+
}
30+
}
31+
],
32+
"totals": {
33+
"functions": {
34+
"count": 2,
35+
"covered": 2,
36+
"percent": 100
37+
},
38+
"instantiations": {
39+
"count": 2,
40+
"covered": 2,
41+
"percent": 100
42+
},
43+
"lines": {
44+
"count": 15,
45+
"covered": 13,
46+
"percent": 86.66666666666667
47+
},
48+
"regions": {
49+
"count": 10,
50+
"covered": 9,
51+
"notcovered": 1,
52+
"percent": 90
53+
}
54+
}
55+
}
56+
],
57+
"type": "llvm.coverage.json.export",
58+
"version": "2.0.1"
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"data": [
3+
{
4+
"files": [
5+
{
6+
"filename": "../coverage/assert.rs",
7+
"summary": {
8+
"functions": {
9+
"count": 2,
10+
"covered": 2,
11+
"percent": 100
12+
},
13+
"instantiations": {
14+
"count": 2,
15+
"covered": 2,
16+
"percent": 100
17+
},
18+
"lines": {
19+
"count": 13,
20+
"covered": 10,
21+
"percent": 76.92307692307693
22+
},
23+
"regions": {
24+
"count": 14,
25+
"covered": 12,
26+
"notcovered": 2,
27+
"percent": 85.71428571428571
28+
}
29+
}
30+
}
31+
],
32+
"totals": {
33+
"functions": {
34+
"count": 2,
35+
"covered": 2,
36+
"percent": 100
37+
},
38+
"instantiations": {
39+
"count": 2,
40+
"covered": 2,
41+
"percent": 100
42+
},
43+
"lines": {
44+
"count": 13,
45+
"covered": 10,
46+
"percent": 76.92307692307693
47+
},
48+
"regions": {
49+
"count": 14,
50+
"covered": 12,
51+
"notcovered": 2,
52+
"percent": 85.71428571428571
53+
}
54+
}
55+
}
56+
],
57+
"type": "llvm.coverage.json.export",
58+
"version": "2.0.1"
59+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
{
2+
"data": [
3+
{
4+
"files": [
5+
{
6+
"filename": "../coverage/async.rs",
7+
"summary": {
8+
"functions": {
9+
"count": 9,
10+
"covered": 9,
11+
"percent": 100
12+
},
13+
"instantiations": {
14+
"count": 9,
15+
"covered": 9,
16+
"percent": 100
17+
},
18+
"lines": {
19+
"count": 31,
20+
"covered": 30,
21+
"percent": 96.7741935483871
22+
},
23+
"regions": {
24+
"count": 21,
25+
"covered": 18,
26+
"notcovered": 3,
27+
"percent": 85.71428571428571
28+
}
29+
}
30+
}
31+
],
32+
"totals": {
33+
"functions": {
34+
"count": 9,
35+
"covered": 9,
36+
"percent": 100
37+
},
38+
"instantiations": {
39+
"count": 9,
40+
"covered": 9,
41+
"percent": 100
42+
},
43+
"lines": {
44+
"count": 31,
45+
"covered": 30,
46+
"percent": 96.7741935483871
47+
},
48+
"regions": {
49+
"count": 21,
50+
"covered": 18,
51+
"notcovered": 3,
52+
"percent": 85.71428571428571
53+
}
54+
}
55+
}
56+
],
57+
"type": "llvm.coverage.json.export",
58+
"version": "2.0.1"
59+
}

src/test/run-make-fulldeps/coverage-reports-base/expected_export_coverage.conditions.json

+14-14
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
"percent": 100
1717
},
1818
"lines": {
19-
"count": 49,
20-
"covered": 23,
21-
"percent": 46.93877551020408
19+
"count": 64,
20+
"covered": 33,
21+
"percent": 51.5625
2222
},
2323
"regions": {
24-
"count": 69,
25-
"covered": 18,
26-
"notcovered": 51,
27-
"percent": 26.08695652173913
24+
"count": 88,
25+
"covered": 25,
26+
"notcovered": 63,
27+
"percent": 28.40909090909091
2828
}
2929
}
3030
}
@@ -41,15 +41,15 @@
4141
"percent": 100
4242
},
4343
"lines": {
44-
"count": 49,
45-
"covered": 23,
46-
"percent": 46.93877551020408
44+
"count": 64,
45+
"covered": 33,
46+
"percent": 51.5625
4747
},
4848
"regions": {
49-
"count": 69,
50-
"covered": 18,
51-
"notcovered": 51,
52-
"percent": 26.08695652173913
49+
"count": 88,
50+
"covered": 25,
51+
"notcovered": 63,
52+
"percent": 28.40909090909091
5353
}
5454
}
5555
}

src/test/run-make-fulldeps/coverage-reports-base/expected_export_coverage.inner_items.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
"percent": 100
1717
},
1818
"lines": {
19-
"count": 26,
20-
"covered": 26,
19+
"count": 27,
20+
"covered": 27,
2121
"percent": 100
2222
},
2323
"regions": {
24-
"count": 15,
25-
"covered": 13,
24+
"count": 11,
25+
"covered": 9,
2626
"notcovered": 2,
27-
"percent": 86.66666666666667
27+
"percent": 81.81818181818183
2828
}
2929
}
3030
}
@@ -41,15 +41,15 @@
4141
"percent": 100
4242
},
4343
"lines": {
44-
"count": 26,
45-
"covered": 26,
44+
"count": 27,
45+
"covered": 27,
4646
"percent": 100
4747
},
4848
"regions": {
49-
"count": 15,
50-
"covered": 13,
49+
"count": 11,
50+
"covered": 9,
5151
"notcovered": 2,
52-
"percent": 86.66666666666667
52+
"percent": 81.81818181818183
5353
}
5454
}
5555
}

src/test/run-make-fulldeps/coverage-reports-base/expected_export_coverage.nested_loops.json

+10-10
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@
1616
"percent": 100
1717
},
1818
"lines": {
19-
"count": 21,
19+
"count": 22,
2020
"covered": 16,
21-
"percent": 76.19047619047619
21+
"percent": 72.72727272727273
2222
},
2323
"regions": {
24-
"count": 18,
25-
"covered": 14,
24+
"count": 17,
25+
"covered": 13,
2626
"notcovered": 4,
27-
"percent": 77.77777777777779
27+
"percent": 76.47058823529412
2828
}
2929
}
3030
}
@@ -41,15 +41,15 @@
4141
"percent": 100
4242
},
4343
"lines": {
44-
"count": 21,
44+
"count": 22,
4545
"covered": 16,
46-
"percent": 76.19047619047619
46+
"percent": 72.72727272727273
4747
},
4848
"regions": {
49-
"count": 18,
50-
"covered": 14,
49+
"count": 17,
50+
"covered": 13,
5151
"notcovered": 4,
52-
"percent": 77.77777777777779
52+
"percent": 76.47058823529412
5353
}
5454
}
5555
}

0 commit comments

Comments
 (0)