Skip to content

Commit 1a5129b

Browse files
committed
Merge branch 'leo/112-non-instr_dc_warn' into 'master'
Instrument.Common: Do not warn for big BDD in stmt+decision Closes #112 See merge request eng/cov/gnatcoverage!243 gnatcov emits a warning when encountering a decision with too many paths to keep track of. This warning is not relevant for decision coverage as the non instrumentation of the individual conditions does not affect the accuracy of the coverage report for level stmt+decision. This change removes the warning when MC/DC coverage is not enabled. Closes eng/cov/gnatcoverage#112
2 parents 9970963 + 842cfe8 commit 1a5129b

File tree

2 files changed

+60
-36
lines changed

2 files changed

+60
-36
lines changed

testsuite/tests/U416-006-big-bdd/test.py

Lines changed: 59 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,30 +14,7 @@
1414
from SUITE.gprutils import GPRswitches
1515

1616

17-
tmp = Wdir("tmp_")
18-
19-
gpr = gprfor(mains=["test_eval.adb"], srcdirs=["../src"], langs=["Ada", "C"])
20-
21-
build_run_and_coverage(
22-
gprsw=GPRswitches(root_project=gpr),
23-
extra_coverage_args=["--annotate=xcov"],
24-
covlevel="stmt+mcdc",
25-
mains=["test_eval"],
26-
trace_mode="src",
27-
tolerate_instrument_messages=\
28-
"Number of distinct paths .* exceeds the limit",
29-
)
30-
31-
check_xcov_reports(
32-
"*.xcov",
33-
expected_cov={
34-
"test_eval.adb.xcov": {"+": {11, 13, 19, 20}},
35-
"testconditions.adb.xcov": {"?": {17}, "+": {22, 23, 24, 25, 26, 27}},
36-
"compute.c.xcov": {"?": {4}, "+": {5, 6}},
37-
},
38-
cwd="obj",
39-
)
40-
17+
tmp = Wdir()
4118

4219
def warning_re_for(filename, sloc):
4320
"""
@@ -53,17 +30,64 @@ def warning_re_for(filename, sloc):
5330
).format(filename=re.escape(filename), sloc=re.escape(sloc))
5431

5532

56-
# The order in which sources are instrumented is not specified, so sort lines
57-
# in the output of "gnatcov instrument" to get deterministic test execution.
58-
log = "\n".join(sorted(contents_of("instrument.log").splitlines()))
33+
def do_one_level(level):
34+
tmp.to_subdir(f"tmp_{level}")
35+
thistest.log(f"===== {level} =====")
36+
37+
gpr = gprfor(mains=["test_eval.adb"], srcdirs=["../src"], langs=["Ada", "C"])
38+
39+
build_run_and_coverage(
40+
gprsw=GPRswitches(root_project=gpr),
41+
extra_coverage_args=["--annotate=xcov"],
42+
covlevel=level,
43+
mains=["test_eval"],
44+
trace_mode="src",
45+
tolerate_instrument_messages=(
46+
"Number of distinct paths .* exceeds the limit"
47+
if level == "stmt+mcdc"
48+
else None
49+
),
50+
)
51+
52+
expected_cov = {
53+
"test_eval.adb.xcov": {"+": {11, 13, 19, 20}},
54+
"testconditions.adb.xcov": {"+": {22, 23, 24, 25, 26, 27}},
55+
"compute.c.xcov": {"+": {5, 6}},
56+
}
57+
58+
# For stmt+decision, the BDD is still computed, but the non-instrumentation
59+
# of the conditions has no impact on stmt+decision coverage reports.
60+
# As such, we expect no warnings or errors in the log and no undetermined
61+
# coverage items in the report.
62+
63+
if level == "stmt+mcdc":
64+
expected_cov["testconditions.adb.xcov"]['?'] = {17}
65+
expected_cov["compute.c.xcov"]['?'] = {4}
66+
else:
67+
expected_cov["testconditions.adb.xcov"]['+'].add(17)
68+
expected_cov["compute.c.xcov"]['+'].add(4)
69+
70+
check_xcov_reports("*.xcov", expected_cov, cwd="obj")
71+
72+
if level == "stmt+mcdc":
73+
# The order in which sources are instrumented is not specified, so sort
74+
# lines in the output of "gnatcov instrument" to get deterministic test
75+
# execution.
76+
log = "\n".join(sorted(contents_of("instrument.log").splitlines()))
77+
78+
thistest.fail_if_no_match(
79+
what="Unexpected/missing warnings for MC/DC path limit",
80+
regexp="^" + "\n".join([
81+
warning_re_for("compute.c", "4:11"),
82+
warning_re_for("testconditions.adb", "17:9"),
83+
]),
84+
actual=log,
85+
)
86+
87+
# Run the mcdc case
88+
do_one_level("stmt+mcdc")
5989

60-
thistest.fail_if_no_match(
61-
what="Unexpected/missing warnings for MC/DC path limit",
62-
regexp="^" + "\n".join([
63-
warning_re_for("compute.c", "4:11"),
64-
warning_re_for("testconditions.adb", "17:9"),
65-
]),
66-
actual=log,
67-
)
90+
# Then the decision case
91+
do_one_level("stmt+decision")
6892

6993
thistest.result()

tools/gnatcov/instrument-common.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ package body Instrument.Common is
201201

202202
-- Warn if the number of paths exceeded the limit
203203

204-
if Path_Count = 0 then
204+
if Path_Count = 0 and then Coverage.MCDC_Coverage_Enabled then
205205
Diagnostics.Report
206206
(Decision_Sloc,
207207
"Number of distinct paths in the decision exceeds the limit"

0 commit comments

Comments
 (0)