Skip to content

Commit 9e2ef02

Browse files
committed
Merge branch 'mr/pmderodat/special_filenames' into 'master'
compiler_wrappers-gcc.adb: fix handling of special filenames Closes #175 See merge request eng/das/cov/gnatcoverage!353 Fixes https://gitlab.adacore-it.com/eng/das/cov/gnatcoverage/-/issues/175
2 parents 52938b8 + f87a62f commit 9e2ef02

File tree

14 files changed

+287
-93
lines changed

14 files changed

+287
-93
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int
2+
bar (int a, int b, int c)
3+
{
4+
if (a)
5+
return b;
6+
else
7+
return c;
8+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
extern int foo (int i);
2+
extern int bar (int a, int b, int c);
23

34
int
45
main (void)
56
{
6-
int result = foo (0);
7+
int result = foo (0) + bar (1, 0, 2);
78
return result;
89
}

testsuite/tests/instr-cov/c_special_filenames/test.py

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,32 +3,56 @@
33
characters produces valid instrumented sources.
44
"""
55

6+
import os.path
7+
8+
from e3.fs import cp
9+
610
from SCOV.minicheck import build_run_and_coverage, check_xcov_reports
11+
from SUITE.control import env
712
from SUITE.context import thistest
813
from SUITE.cutils import Wdir
914
from SUITE.tutils import gprfor
1015
from SUITE.gprutils import GPRswitches
1116

1217

13-
tmp = Wdir('tmp_')
18+
tmp = Wdir("tmp_")
19+
20+
# Copy the sources in the temporary directory. Note that we cannot test the
21+
# case of a filename containing a double quote or a backslash on Windows
22+
# because of filename restrictions on that platform.
23+
copy_map = {
24+
"ada_main.adb": "ada_main.adb",
25+
"bar.c": "src bar.c" if env.build.os.name == "windows" else 'src\\"bar.c',
26+
"foo.c": "src foo$@.c",
27+
"main.c": "main.c",
28+
}
29+
for src, dest in copy_map.items():
30+
cp(os.path.join("..", src), dest)
31+
32+
# Compute the expected coverage report from the actual source filenames. Note
33+
# that in xcov filenames, "gnatcov coverage" first turns '\' to '/' (during
34+
# path separator canonicalization) and then the unique filename machinery turns
35+
# '/' to '-'.
36+
coverage_data = {
37+
"ada_main.adb": {"+": {7, 9}},
38+
"bar.c": {"+": {4, 5}, "-": {7}},
39+
"foo.c": {"+": {4}},
40+
"main.c": {"+": {7, 8}},
41+
}
42+
expected_report = {
43+
"{}.xcov".format(copy_map[filename].replace("\\", "-")): report
44+
for filename, report in coverage_data.items()
45+
}
1446

1547
build_run_and_coverage(
1648
gprsw=GPRswitches(
17-
root_project=gprfor(srcdirs=['..'], mains=['main.c', 'ada_main.adb'])
49+
root_project=gprfor(srcdirs=["."], mains=["main.c", "ada_main.adb"])
1850
),
19-
covlevel='stmt',
20-
mains=['main', 'ada_main'],
21-
extra_coverage_args=['-axcov', '--output-dir=xcov'],
22-
trace_mode='src',
23-
)
24-
check_xcov_reports(
25-
'*.xcov',
26-
{
27-
'main.c.xcov': {'+': {6}},
28-
'$foo@bar$.c.xcov': {'+': {4}},
29-
'ada_main.adb.xcov': {'+': {9}},
30-
},
31-
'xcov',
51+
covlevel="stmt",
52+
mains=["main", "ada_main"],
53+
extra_coverage_args=["-axcov", "--output-dir=xcov"],
54+
trace_mode="src",
3255
)
56+
check_xcov_reports("*.xcov", expected_report, "xcov")
3357

3458
thistest.result()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
int
2+
bar (int c)
3+
{
4+
return c + 1;
5+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
int
2+
foo (int a, int b)
3+
{
4+
if (a)
5+
return a;
6+
else
7+
return b;
8+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
extern int foo (int a, int b);
2+
extern int bar (int c);
3+
4+
int
5+
main (void)
6+
{
7+
foo (0, 1);
8+
bar (0);
9+
return 0;
10+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
"""
2+
Check that the integration instrumentation handles correctly filenames that
3+
contain spaces.
4+
"""
5+
6+
import os
7+
import os.path
8+
9+
from e3.fs import cp
10+
11+
from SUITE.control import env
12+
from SUITE.cutils import Wdir
13+
from SCOV.minicheck import check_xcov_reports
14+
from SUITE.tutils import cmdrun, srctracename_for, thistest, xcov
15+
16+
Wdir("tmp_")
17+
18+
# Copy the sources in the temporary directory. Note that we cannot test the
19+
# case of a filename containing a double quote or a backslash on Windows
20+
# because of filename restrictions on that platform.
21+
copy_map = {
22+
"bar.c": 'src bar.c' if env.build.os.name == "windows" else 'src\\"bar.c',
23+
"foo.c": "src foo$@.c",
24+
"test.c": "test.c",
25+
}
26+
for src, dest in copy_map.items():
27+
cp(os.path.join("..", src), dest)
28+
29+
# Compute the expected coverage report from the actual source filenames. Note
30+
# that in xcov filenames, "gnatcov coverage" first turns '\' to '/' (during
31+
# path separator canonicalization) and then the unique filename machinery turns
32+
# '/' to '-'.
33+
coverage_data = {
34+
"test.c": {"+": {7, 8, 9}},
35+
"foo.c": {"+": {4, 7}, "-": {5}},
36+
"bar.c": {"+": {4}},
37+
}
38+
expected_report = {
39+
"{}.xcov".format(copy_map[filename].replace("\\", "-")): report
40+
for filename, report in coverage_data.items()
41+
}
42+
43+
# Setup the instrumentation process
44+
sources = [os.path.abspath(filename) for filename in copy_map.values()]
45+
files = [f"--files={filename}" for filename in sources]
46+
xcov(
47+
["setup-integration", "--level=stmt", "--compilers=gcc", "--output-dir=."]
48+
+ files
49+
)
50+
51+
# Shadow the compiler driver with the generated wrapper
52+
env.add_search_path(env_var="PATH", path=os.getcwd())
53+
54+
# Build the test program and run it
55+
cmdrun(["gcc", "-o", "test program"] + sources, for_pgm=False)
56+
cmdrun(["test program"], for_pgm=False)
57+
58+
# Check coverage expectations
59+
sid_args = [f"--sid={filename}.sid" for filename in sources]
60+
xcov(
61+
["coverage", "-cstmt", "-axcov", srctracename_for("test")]
62+
+ sid_args
63+
)
64+
check_xcov_reports("*.xcov", expected_report)
65+
66+
thistest.result()

0 commit comments

Comments
 (0)