1414from 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
4219def 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
6993thistest .result ()
0 commit comments