Skip to content

Commit df7984d

Browse files
author
Viviane Garese
committed
Merge branch 'dump-trigger-manual' into 'master'
Improve the usability of manual dump trigger Closes #84 See merge request eng/cov/gnatcoverage!212 When using the manual dump trigger option, a dump helper unit "gcvrt-db_manual.adb" is generated containing everything needed to perform a call to its Dump_Buffers procedure anywhere in the code. gnatcov will look for the pragma statement 'pragma Annotate (Xcov, Dump_Buffers)' in all sources and replace it with the actual call. Closes #84
2 parents 409dcbc + 3ffa022 commit df7984d

Some content is hidden

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

41 files changed

+1261
-124
lines changed

doc/gnatcov/src_traces.rst

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -273,12 +273,20 @@ For more restricted environments where, say, there is limited file IO available
273273
to the program, a ``--dump-channel=base64-stdout`` kind of output is needed in
274274
association with the restricted coverage runtime.
275275

276-
If none of the available automatic triggering option works out well, full
276+
If none of the available automatic triggering option work out well, full
277277
control is offered by the ``--dump-trigger=manual`` policy where the
278278
instrumenter doesn't actually add any code to main units for emitting the
279-
collected coverage data. You will have to emit this data somehow to allow
280-
analysing coverage afterwards, still, and can of course experiment with other
281-
possibilities just to get examples of possible ways to proceed.
279+
collected coverage data. You will have to indicate the point at which you wish
280+
to emit this data by inserting:
281+
282+
- a ``pragma Annotate (Xcov, Dump_Buffers);`` pragma statement in Ada code;
283+
- a ``/* GNATCOV_DUMP_BUFFERS */`` comment on its own line in C code
284+
285+
where necessary in your code. During instrumentation, |gcv| will replace them
286+
with a call to the procedure responsible for dumping the coverage buffers,
287+
at which point the source traces will be created during the execution of the
288+
program. Therefore, the pragma or comment should be placed at a location at
289+
which such a function call would be appropriate.
282290

283291
.. _instr-tracename:
284292

testsuite/SCOV/minicheck.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def build_and_run(gprsw, covlevel, mains, extra_coverage_args, scos=None,
3737
gprsw_for_coverage=None, scos_for_run=True,
3838
register_failure=True, program_env=None,
3939
tolerate_instrument_messages=None, exec_args=None,
40-
auto_languages=True):
40+
auto_languages=True, manual_prj_name=None):
4141
"""
4242
Prepare a project to run a coverage analysis on it.
4343
@@ -108,6 +108,10 @@ def build_and_run(gprsw, covlevel, mains, extra_coverage_args, scos=None,
108108
:param None|list[str] exec_args: List of arguments to pass to the
109109
executable. This will only work for native configurations.
110110
:param bool auto_languages: See SUITE.tutils.xcov.
111+
:param None|str manual_proj_name: when the dump trigger is manual, several
112+
traces files (one per project) can be emitted if there are dump buffers
113+
procedure calls in at least two distinct projects. This is the name of
114+
the project which trace we want to consider.
111115
112116
:rtype: list[str]
113117
:return: Incomplete list of arguments to pass to `xcov` in order to run
@@ -283,7 +287,9 @@ def gprbuild_wrapper(root_project):
283287
# Remove potential existing source trace files: the name is
284288
# non-deterministic by default, so we want to avoid getting
285289
# multiple traces in the current directory.
286-
rm(srctrace_pattern_for(m))
290+
rm(srctrace_pattern_for(m,
291+
dump_trigger == "manual",
292+
manual_prj_name))
287293

288294
out_file = out_file_.format(m)
289295
run_cov_program(exepath(m), out=out_file, env=program_env,
@@ -307,14 +313,20 @@ def gprbuild_wrapper(root_project):
307313
trace_file = None
308314

309315
if known_channel in [None, "bin-file"]:
310-
trace_file = srctracename_for(m, register_failure=False)
316+
trace_file = srctracename_for(m,
317+
register_failure=False,
318+
manual=dump_trigger == "manual",
319+
manual_prj_name=manual_prj_name)
311320

312321
if (not trace_file
313322
and (known_channel == "base64-stdout"
314-
or "source trace file ==" in contents_of(out_file))
315-
):
323+
or "source trace file ==" in contents_of(out_file))):
324+
316325
# Pick a trace name that is compatible with srctracename_for
317-
trace_file = srctrace_pattern_for(m).replace("*", "unique")
326+
src_pattern = srctrace_pattern_for(m,
327+
dump_trigger == "manual",
328+
manual_prj_name)
329+
trace_file = src_pattern.replace("*", "unique")
318330

319331
# Here we're really supposed to have a trace in the output
320332
# so we can be a tad stricter on the conversion outcome.

testsuite/SUITE/tutils.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -453,12 +453,21 @@ def tracename_for(pgmname):
453453
return exename_for(pgmname) + ".trace"
454454

455455

456-
def srctrace_pattern_for(pgmname):
457-
"""Glob pattern for the source trace file for the given program name"""
458-
return exename_for(pgmname) + "*.srctrace"
456+
def srctrace_pattern_for(pgmname, manual=False, manual_prj_name=None):
457+
"""
458+
Glob pattern for the source trace file for the given program name.
459+
460+
:param bool manual: Indicates if the trace file was created as a result of
461+
a manual dump buffers procedure call.
462+
:param None|str manual_prj_name: Trace files emitted in manual dump trigger
463+
mode contain the name of the relevant project in their name.
464+
manual_prj_name is the name of the project which trace we want to find.
465+
"""
466+
return (manual_prj_name if manual else exename_for(pgmname)) + "*.srctrace"
459467

460468

461-
def srctracename_for(pgmname, register_failure=True):
469+
def srctracename_for(pgmname, register_failure=True, manual=False,
470+
manual_prj_name=None):
462471
"""
463472
Name for the source trace file for the given program name.
464473
@@ -470,7 +479,7 @@ def srctracename_for(pgmname, register_failure=True):
470479
stops the testcase. If "register_failure" is False, we just return None in
471480
that case.
472481
"""
473-
pattern = srctrace_pattern_for(pgmname)
482+
pattern = srctrace_pattern_for(pgmname, manual, manual_prj_name)
474483
trace_files = glob.glob(pattern)
475484

476485
if len(trace_files) == 1:
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package body Lib1 is
2+
function Foo return Integer
3+
is
4+
Res : constant Integer := 1;
5+
begin
6+
pragma Annotate (Xcov, Dump_Buffers);
7+
return Res;
8+
end Foo;
9+
end Lib1;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package Lib1 is
2+
function Foo return Integer;
3+
end Lib1;
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package body Lib2 is
2+
function Bar return Integer
3+
is
4+
Res : constant Integer := 1;
5+
begin
6+
pragma Annotate (Xcov, Dump_Buffers);
7+
return Res;
8+
end Bar;
9+
end Lib2;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package Lib2 is
2+
function Bar return Integer;
3+
end Lib2;
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
pragma Ada_2012;
2+
3+
with Lib1;
4+
with Lib2;
5+
with Manual_Dump;
6+
7+
procedure Main is
8+
9+
procedure Increment (J : in out Integer)
10+
is
11+
begin
12+
J := J + 1;
13+
end Increment;
14+
15+
I : Integer := 1;
16+
begin
17+
-- The only call that should not count as a violation when never executed
18+
-- is that of the dump buffers procedure.
19+
if 1 = I + 1 then
20+
pragma Annotate (Xcov, Dump_Buffers);
21+
I := I+ 1;
22+
end if;
23+
24+
Increment (I);
25+
pragma Annotate (Xcov, Dump_Buffers);
26+
I := I + Lib1.Foo;
27+
I := I + Lib2.Bar;
28+
Manual_Dump.Dump;
29+
Increment (I);
30+
end Main;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package body Manual_Dump is
2+
procedure Dump is
3+
begin
4+
pragma Annotate (Xcov, Dump_Buffers);
5+
end Dump;
6+
end Manual_Dump;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package Manual_Dump is
2+
procedure Dump;
3+
end Manual_Dump;

0 commit comments

Comments
 (0)