Skip to content

Commit ba060bf

Browse files
committed
testsuite: check warnings in gnatcov output
Check warnings for every gnatcov command rather than for "gnatcov instrument" only. Fix the fallout regressions by adapting the testcases. Also remove unused auto_languages parameter from the xcov function.
1 parent 6eb0c63 commit ba060bf

File tree

39 files changed

+147
-80
lines changed

39 files changed

+147
-80
lines changed

testsuite/Qualif/Common/UnitsOfInterest/GPR/Robustness/BadUnitInAttr/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,9 @@
2121
),
2222
covlevel="stmt",
2323
mains=["main"],
24-
tolerate_instrument_messages="no unit.*in project",
24+
tolerate_instrument_messages="no unit .* in project",
2525
extra_coverage_args=["-axcov"],
26+
tolerate_coverage_messages="no unit .* in project",
2627
)
2728

2829
log_file = (

testsuite/Qualif/Common/UnitsOfInterest/GPR/Robustness/BadUnitInSwitch/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@
1818
),
1919
covlevel="stmt",
2020
mains=["main"],
21-
tolerate_instrument_messages="no unit.*in the projects of interest",
21+
tolerate_instrument_messages="no unit .* in the projects of interest",
2222
extra_coverage_args=["-axcov"],
23+
tolerate_coverage_messages="no unit .* in the projects of interest",
2324
)
2425

2526
log_file = (

testsuite/Qualif/Common/UnitsOfInterest/GPR/Robustness/MissingLI/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
what = "ALI"
4242

4343
log_file = "coverage.log"
44-
xcov(xcov_args, out=log_file)
44+
xcov(xcov_args, out=log_file, tolerate_messages=".")
4545
thistest.fail_if_not_equal(
4646
"gnatcov output",
4747
"warning: no {} file found for unit helper".format(what),

testsuite/Qualif/Common/UnitsOfInterest/GPR/Robustness/NoContribPrj/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,9 @@ def run_test(
103103
covlevel="stmt",
104104
mains=["main"],
105105
gpr_obj_dir="obj-main",
106-
tolerate_instrument_messages="project.*provides no unit",
106+
tolerate_instrument_messages="project .* provides no unit",
107107
extra_coverage_args=["-axcov"],
108+
tolerate_coverage_messages="project .* provides no unit",
108109
)
109110

110111
log_file = (

testsuite/Qualif/Common/UnitsOfInterest/GPR/Robustness/SourcesAttr/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ def try_one(subdir, extra_covargs, xreports, xwarnings):
4444
covlevel="stmt",
4545
mains=["test_t"],
4646
extra_coverage_args=["--annotate=xcov"] + extra_covargs,
47+
tolerate_coverage_messages=".",
4748
)
4849

4950
check_xcov_reports("obj", xreports)

testsuite/Qualif/Common/UnitsOfInterest/GPR/Robustness/UnitNotInProjects/test.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,9 @@
4343
covlevel="stmt",
4444
mains=["main"],
4545
gpr_obj_dir="obj-main",
46-
tolerate_instrument_messages="no unit.*in the projects",
46+
tolerate_instrument_messages="no unit .* in the projects",
4747
extra_coverage_args=["-axcov"],
48+
tolerate_coverage_messages="no unit .* in the projects",
4849
)
4950

5051
log_file = (

testsuite/SCOV/instr.py

Lines changed: 12 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
from SUITE.context import thistest
99
from SUITE.control import env
10-
from SUITE.cutils import contents_of, copy_to_dir, ext, indent
10+
from SUITE.cutils import contents_of, ext, copy_to_dir
1111
from SUITE.tutils import RUNTIME_INFO, GNATCOV_INFO, locate_gpr_file, xcov
1212

1313

@@ -58,7 +58,6 @@ def xcov_instrument(
5858
register_failure=True,
5959
auto_config_args=True,
6060
auto_target_args=True,
61-
auto_languages=True,
6261
):
6362
"""
6463
Run "gnatcov instrument" on a project.
@@ -87,7 +86,6 @@ def xcov_instrument(
8786
:param bool register_failure: See SUITE.tutils.xcov.
8887
:param bool auto_config_args: See SUITE.tutils.xcov.
8988
:param bool auto_target_args: See SUITE.tutils.xcov.
90-
:param bool auto_languages: See SUITE.tutils.xcov.
9189
9290
See SUITE.tutils.xcov for the other supported options.
9391
"""
@@ -137,20 +135,9 @@ def xcov_instrument(
137135
if thistest.options.block:
138136
args.append("--instrument-block")
139137

140-
out = out or "instrument.log"
141-
result = xcov(
142-
args,
143-
out=out,
144-
err=err,
145-
register_failure=register_failure,
146-
auto_config_args=auto_config_args,
147-
auto_target_args=auto_target_args,
148-
auto_languages=auto_languages,
149-
)
150-
151138
# When no message is to be tolerated, fallback to an actual regexp
152139
# that will never match:
153-
re_tolerate_messages = tolerate_messages or "__NEVER_IN_A_WARNING___"
140+
re_tolerate_messages = tolerate_messages or ""
154141

155142
# For qualification purposes, tolerate possible warnings about
156143
# inexistant object dirs from older gnatcov versions, typically
@@ -163,36 +150,16 @@ def xcov_instrument(
163150
for mre in ["object directory.*not found", re_tolerate_messages]
164151
)
165152

166-
if register_failure:
167-
output = contents_of(out)
168-
169-
# Check for unexpected messages. Beware that the "warning:"
170-
# indication at least is not necessarily at the beginning of
171-
# a line, as in
172-
#
173-
# app.gpr:4:23: warning: object directory "obj" not found
174-
175-
messages = re.findall(
176-
pattern=r"(?:!!!|\*\*\*|warning:).*$",
177-
string=output,
178-
flags=re.MULTILINE,
179-
)
180-
181-
unexpected_messages = [
182-
w
183-
for w in messages
184-
if not re.search(pattern=re_tolerate_messages, string=w)
185-
]
186-
thistest.fail_if(
187-
unexpected_messages,
188-
f"Unexpected messages in the output of 'gnatcov instrument':"
189-
f"\n{indent(output)}"
190-
+ (
191-
f"\n(allowed: {tolerate_messages})"
192-
if tolerate_messages
193-
else ""
194-
),
195-
)
153+
out = out or "instrument.log"
154+
result = xcov(
155+
args,
156+
out=out,
157+
err=err,
158+
register_failure=register_failure,
159+
auto_config_args=auto_config_args,
160+
auto_target_args=auto_target_args,
161+
tolerate_messages=re_tolerate_messages,
162+
)
196163

197164
return result
198165

testsuite/SCOV/minicheck.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ def build_and_run(
6868
program_env=None,
6969
tolerate_instrument_messages=None,
7070
exec_args=None,
71-
auto_languages=True,
7271
manual_prj_name=None,
7372
auto_config_args=True,
7473
):
@@ -142,7 +141,6 @@ def build_and_run(
142141
output.
143142
:param None|list[str] exec_args: List of arguments to pass to the
144143
executable. This will only work for native configurations.
145-
:param bool auto_languages: See SUITE.tutils.xcov.
146144
:param None|str manual_prj_name: When the dump trigger is manual, several
147145
traces files (one per project) can be emitted if there are dump buffers
148146
procedure calls in at least two distinct projects. This is the name of
@@ -283,7 +281,6 @@ def gprbuild_wrapper(root_project):
283281
out="instrument.log",
284282
register_failure=register_failure,
285283
tolerate_messages=tolerate_instrument_messages,
286-
auto_languages=auto_languages,
287284
auto_config_args=auto_config_args,
288285
)
289286
gprbuild_wrapper(gprsw.root_project)
@@ -431,6 +428,7 @@ def build_run_and_coverage(
431428
err=None,
432429
register_failure=True,
433430
auto_config_args=True,
431+
tolerate_coverage_messages=None,
434432
**kwargs,
435433
):
436434
"""
@@ -442,6 +440,10 @@ def build_run_and_coverage(
442440
`out` and `err` are forwarded to `xcov`, `register_failure` and
443441
`auto_config_args` are reported to `xcov` and `build_and_run`, other
444442
arguments are forwarded to `build_and_run`.
443+
444+
If tolerate_coverage_messages is not None, filter out error or warning
445+
messages from the "gnatcov coverage" output matching the regular
446+
expression.
445447
"""
446448
xcov_args = build_and_run(
447449
register_failure=register_failure,
@@ -454,6 +456,7 @@ def build_run_and_coverage(
454456
out=out,
455457
err=err,
456458
register_failure=register_failure,
459+
tolerate_messages=tolerate_coverage_messages,
457460
)
458461

459462

testsuite/SUITE/tutils.py

Lines changed: 66 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@
3434
)
3535
from SUITE.context import ROOT_DIR, thistest
3636

37-
3837
# Then mind our own business
3938

4039
from SUITE.cutils import (
4140
FatalError,
4241
contents_of,
42+
indent,
4343
list_to_file,
4444
text_to_file,
4545
to_list,
@@ -874,20 +874,27 @@ def xcov(
874874
auto_config_args=True,
875875
auto_target_args=True,
876876
force_project_args=False,
877-
auto_languages=True,
877+
tolerate_messages=None,
878878
):
879879
"""
880-
Run xcov with arguments ARGS, timeout control, valgrind control if
881-
available and enabled, output directed to OUT and failure registration if
882-
register_failure is True. Return the process status descriptor. ARGS may be
883-
a list or a whitespace separated strings.
884-
885-
If AUTO_LANGUAGES is True, the gnatcov sub-command is "instrument" and the
886-
testsuite is not in qualification mode, automatically pass the
887-
--restricted-to-languages argument to enable all the languages to test.
888-
889-
See xcov_suite_args for the meaning of AUTO_*_ARGS and FORCE_PROJECT_ARGS
890-
arguments.
880+
Run "gnatcov".
881+
882+
:param list[str] args: arguments to pass to gnatcov.
883+
:param None|str out: if not None, redirect gnatcov output to out.
884+
:param None|str err: if not None, redirect gnatcov error output to err.
885+
:param None|str inp: if not None, redirect gnatcov input to inp.
886+
:param None|dict[str, str] env: If not none, environment variables for the
887+
program to run.
888+
:param bool register_failure: If True, register execution failure.
889+
:param bool auto_config_args: see xcov_suite_args.
890+
:param bool auto_target_args: see xcov_suite_args.
891+
:param bool force_project_args: see xcov_suite_args.
892+
:param None|str tolerate_messages: If not None, a re pattern of warning
893+
or error messsages tolerated in the tool output. Messages not matching
894+
this pattern will cause a test failure when register_failure is True.
895+
896+
:rtype: Run
897+
:return: Process status descriptor for the gnatcov invocation.
891898
"""
892899

893900
# Defensive code: running "gnatcov setup" with no prefix will install
@@ -941,6 +948,43 @@ def xcov(
941948
for_pgm=(covcmd == "run"),
942949
)
943950

951+
# When no message is to be tolerated, fallback to an actual regexp
952+
# that will never match:
953+
re_tolerate_messages = tolerate_messages or "__NEVER_IN_A_WARNING___"
954+
955+
# Do not check warnings when running the testsuite in binary traces mode,
956+
# as it would require modifying / adapting too many tests.
957+
if register_failure and thistest.options.trace_mode == "src":
958+
output = contents_of(out) if out else p.out
959+
960+
# Check for unexpected messages. Beware that the "warning:"
961+
# indication at least is not necessarily at the beginning of
962+
# a line, as in
963+
#
964+
# app.gpr:4:23: warning: object directory "obj" not found
965+
966+
messages = re.findall(
967+
pattern=r"(?:!!!|\*\*\*|warning:).*$",
968+
string=output,
969+
flags=re.MULTILINE,
970+
)
971+
972+
unexpected_messages = [
973+
w
974+
for w in messages
975+
if not re.search(pattern=re_tolerate_messages, string=w)
976+
]
977+
thistest.fail_if(
978+
unexpected_messages,
979+
f"Unexpected messages in the output of 'gnatcov {covcmd}':"
980+
f"\n{indent(output)}"
981+
+ (
982+
f"\n(allowed: {tolerate_messages})"
983+
if tolerate_messages
984+
else ""
985+
),
986+
)
987+
944988
if thistest.options.enable_valgrind == "memcheck":
945989
memcheck_log = contents_of(MEMCHECK_LOG)
946990
thistest.fail_if(
@@ -1008,6 +1052,7 @@ def xrun(
10081052
register_failure=register_failure,
10091053
auto_config_args=auto_config_args,
10101054
auto_target_args=auto_target_args,
1055+
tolerate_messages=".",
10111056
)
10121057

10131058

@@ -1271,6 +1316,7 @@ def xcov_annotate(
12711316
register_failure=True,
12721317
auto_config_args=True,
12731318
auto_target_args=True,
1319+
tolerate_messages=None,
12741320
):
12751321
"""
12761322
Invoke "gnatcov annotate" with the correct arguments to generate
@@ -1288,6 +1334,7 @@ def xcov_annotate(
12881334
will be added. Defaults to None.
12891335
:param list[str] | None extra_args: extra arguments passed on the command
12901336
line. Defaults to None.
1337+
:param str | None tolerate_messages: see documentation of xcov.
12911338
"""
12921339
args = ["add-annotation"]
12931340
args.extend(annotation.cmd_line_args())
@@ -1306,10 +1353,11 @@ def xcov_annotate(
13061353
register_failure=register_failure,
13071354
auto_config_args=auto_config_args,
13081355
auto_target_args=auto_target_args,
1356+
tolerate_messages=tolerate_messages,
13091357
)
13101358

13111359

1312-
def generate_annotations(annotations, subdir=""):
1360+
def generate_annotations(annotations, subdir="", tolerate_messages=None):
13131361
"""
13141362
Setup a temporary working directory in which an annotation file
13151363
will be generated from annotations, using gnatcov add-annotation
@@ -1334,6 +1382,9 @@ def generate_annotations(annotations, subdir=""):
13341382
# Generate the annotations
13351383
for annotation in annotations:
13361384
xcov_annotate(
1337-
annotation, annot_in_files=[annot_file], annot_out_file=annot_file
1385+
annotation,
1386+
annot_in_files=[annot_file],
1387+
annot_out_file=annot_file,
1388+
tolerate_messages=tolerate_messages,
13381389
)
13391390
return annot_file

testsuite/tests/14-unused-separate/uncompilable/test.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
covlevel="stmt",
2323
mains=["main"],
2424
extra_coverage_args=["--annotate=xcov"],
25+
tolerate_coverage_messages="no ALI file found for unit pkg.bar",
2526
)
2627

2728
thistest.fail_if(

testsuite/tests/15-non-instr-cons/test.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@
4040
xcov(xcov_args + ["--save-checkpoint=test_f.ckpt", trace_f])
4141

4242
# Try to consolidate the checkpoint
43-
xcov(xcov_args + ["-Ctest_t.ckpt", "-Ctest_f.ckpt", "-axcov"])
43+
xcov(
44+
xcov_args + ["-Ctest_t.ckpt", "-Ctest_f.ckpt", "-axcov"],
45+
tolerate_messages=(
46+
"warning: Specifying units of interest through --units"
47+
" has no effect on checkpoints"
48+
),
49+
)
4450

4551
check_xcov_reports("obj", {"pkg.ads.xcov": {"?": {10}, "+": {5, 6, 7}}})
4652

testsuite/tests/354-source-encoding/test.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,11 @@ def check_report(
211211
argv = xcov_args + [f"--output-dir=out-{label}"]
212212
if encoding is not None:
213213
argv.append(f"--source-encoding={encoding}")
214-
xcov(argv, out=log_file)
214+
215+
tolerate_messages = (
216+
"|".join(expected_warnings) if expected_warnings else None
217+
)
218+
xcov(argv, out=log_file, tolerate_messages=tolerate_messages)
215219

216220
# Check that we have exacly the expected warnings
217221
thistest.fail_if_not_equal(
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src-traces DEAD Test specific to binary traces

testsuite/tests/IA21-009-nested-scos/test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55

66
Wdir("tmp_")
77
gprbuild(gprfor(["nested_same_sloc.adb"], srcdirs="../src"))
8-
xcov(["map-routines", "--scos=obj/nested_same_sloc.ali"])
8+
xcov(["map-routines", "--scos=obj/nested_same_sloc.ali", "nested_same_sloc"])
99
thistest.result()

testsuite/tests/L613-012/test.opt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
src-traces DEAD Test specific to binary traces

0 commit comments

Comments
 (0)