Skip to content

Commit 8d7ca36

Browse files
committed
Merge branch 'pmderodat/ignore_file_scopes' into 'master'
SC_Obligations: fix loading of scopes for ignored source files Closes #149 See merge request eng/das/cov/gnatcoverage!325 This fixes an assertion failure: when remapping source files from the scopes loaded from a SID/checkpoint, scopes whose identifier references ignored source files will lose their identifier. Such scopes will remain, but users will not be able to mark them of interest. Note that, even though this is not a regression compared to the state of things currently in the `master` branch, this leaves things in an unsatisfying state: consolidation of scopes during SID/checkpoint loading will not necessarily restore identifiers that `--ignore-source-files` has affected previously. Future work on `--subprograms` and/or scope in reports should address this. Fixes eng/das/cov/gnatcoverage#149
2 parents 017c1a4 + 254f439 commit 8d7ca36

File tree

7 files changed

+284
-124
lines changed

7 files changed

+284
-124
lines changed

testsuite/tests/subp_of_interest/src/pkg.adb

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,34 @@
11
with Ada.Text_IO; use Ada.Text_IO;
22

33
package body Pkg is
4+
5+
---------
6+
-- Foo --
7+
---------
8+
49
procedure Foo (I : Integer) is
510
begin
611
Put_Line ("Hello from Foo!");
712
end Foo;
813

14+
---------
15+
-- Bar --
16+
---------
17+
918
procedure Bar is
1019
procedure Nested_Bar_1 is null;
20+
procedure Nested_Bar_2;
21+
1122
Dummy_Decl : Boolean;
12-
procedure Nested_Bar_2 is null;
23+
24+
------------------
25+
-- Nested_Bar_2 --
26+
------------------
27+
28+
procedure Nested_Bar_2 is
29+
begin
30+
Put_Line ("Hello from Nested_Bar_2!");
31+
end Nested_Bar_2;
1332
begin
1433
Nested_Bar_1;
1534
Nested_Bar_2;

testsuite/tests/subp_of_interest/src/pkg.ads

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,6 @@ pragma Ada_2012;
33
package Pkg is
44
procedure Foo (I : Integer) with Pre => I > 0;
55
procedure Bar;
6+
7+
I : Integer;
68
end Pkg;

testsuite/tests/subp_of_interest/test.py

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ def check_xcov(label, args, expected_output=""):
5353
# that the coverage report contains only coverage data for the specified
5454
# subprograms for source traces. For binary traces, simply check that the
5555
# gnatcov coverage invocation yields the expected warning.
56+
ckpt_filename = "trace.ckpt"
5657
check_xcov(
5758
"xcov_subp",
5859
cov_args
5960
+ [
6061
"--save-checkpoint",
61-
"trace.ckpt",
62+
ckpt_filename,
6263
f"--subprograms={pkg_spec}:4",
63-
f"--subprograms={pkg_body}:10",
64-
f"--subprograms={pkg_body}:12",
64+
f"--subprograms={pkg_body}:19",
65+
f"--subprograms={pkg_body}:20",
6566
],
6667
expected_output=(
6768
""
@@ -70,12 +71,14 @@ def check_xcov(label, args, expected_output=""):
7071
" with binary traces."
7172
),
7273
)
74+
cov_ckpt_args = cov_args[:-1] + ["--checkpoint", ckpt_filename]
7375
if src_traces:
7476
check_xcov_reports(
7577
"*.xcov",
7678
{
7779
"main.adb.xcov": {},
78-
"pkg.adb.xcov": {"+": {6, 10, 12}},
80+
"pkg.ads.xcov": {},
81+
"pkg.adb.xcov": {"+": {11, 19, 30}},
7982
},
8083
"xcov_subp",
8184
)
@@ -84,20 +87,37 @@ def check_xcov(label, args, expected_output=""):
8487
# specific subprogram. To do this, produce a new coverage report from the
8588
# checkpoint without using the --subprograms switch.
8689
thistest.log("== xcov_no_subp ==")
87-
check_xcov(
88-
"xcov_no_subp",
89-
cov_args[:-1]
90-
+ ["--checkpoint", "trace.ckpt"],
91-
)
90+
check_xcov("xcov_no_subp", cov_ckpt_args)
9291
check_xcov_reports(
9392
"*.xcov",
9493
{
9594
"main.adb.xcov": {"-": {5, 6}},
96-
"pkg.adb.xcov": {"+": {6, 10, 12}, "-": {11, 14, 15, 16}},
95+
"pkg.ads.xcov": {"-": {7}},
96+
"pkg.adb.xcov": {"+": {11, 19, 30}, "-": {22, 33, 34, 35}},
9797
},
9898
"xcov_no_subp",
9999
)
100100

101+
# Check that we can still select subprograms of interest declared in the
102+
# package body, when the package specification is ignored through
103+
# --ignored-source-files.
104+
thistest.log("== xcov_ignore ==")
105+
check_xcov(
106+
"xcov_ignore",
107+
cov_args + [
108+
f"--subprograms={pkg_body}:20",
109+
"--ignore-source-files=pkg.ads",
110+
],
111+
)
112+
check_xcov_reports(
113+
"*.xcov",
114+
{
115+
"main.adb.xcov": {},
116+
"pkg.adb.xcov": {"+": {30}},
117+
},
118+
"xcov_ignore",
119+
)
120+
101121
# Also check the warnings when the subprogram switch is ill-formed
102122

103123
# Case 1: missing colon in the argument

tools/gnatcov/annotations.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -426,7 +426,7 @@ package body Annotations is
426426
for SCO of LI.SCOs.all loop
427427
Traverse_SCO (ST, SCO);
428428
end loop;
429-
if not Is_Active (ST, Subps_Of_Interest) then
429+
if not In_Scope_Of_Interest (ST) then
430430
return;
431431
end if;
432432
end if;

tools/gnatcov/coverage-source.adb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2003,7 +2003,7 @@ package body Coverage.Source is
20032003
is
20042004
begin
20052005
Traverse_SCO (ST, SCO);
2006-
if Is_Active (ST, Subps_Of_Interest) then
2006+
if In_Scope_Of_Interest (ST) then
20072007
Update_SCI (SCO, Tag, Process);
20082008
end if;
20092009
end Update_SCI_Wrapper;

0 commit comments

Comments
 (0)