Skip to content

Commit 4f73a58

Browse files
committed
[integrated-instrumentation] normalize paths for files of interest
gnatcov used to leave paths passed to the --files switch un-normalized, which resulted in some units of interest being ignored at instrumentation time.
1 parent 3893436 commit 4f73a58

File tree

4 files changed

+76
-2
lines changed

4 files changed

+76
-2
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
project(HelloWorld)
2+
cmake_minimum_required(VERSION 3.0)
3+
4+
add_executable(hello_world main.c)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include <stdio.h>
2+
3+
int
4+
main()
5+
{
6+
printf("Hello world!\n");
7+
return 0;
8+
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
"""
2+
Regression test: gnatcov used to leave paths passed to the --files switch
3+
un-normalized, which resulted in some units of interest being ignored at
4+
instrumentation time.
5+
"""
6+
7+
import os
8+
import os.path
9+
10+
from SUITE.control import env
11+
from SUITE.cutils import Wdir
12+
from SCOV.minicheck import check_xcov_reports
13+
from SUITE.tutils import cmdrun, srctracename_for, thistest, xcov
14+
15+
Wdir("tmp_")
16+
17+
cwd = os.getcwd()
18+
19+
# Setup the instrumentation process
20+
xcov(
21+
[
22+
"setup-integration",
23+
f"--files={os.path.join(cwd, '..', 'main.c')}",
24+
"--compilers=gcc",
25+
]
26+
)
27+
28+
# Shadow the compiler driver with the generated wrapper
29+
env.add_search_path(env_var="PATH", path=cwd)
30+
31+
# Then, run the build process unchanged
32+
compiler_wrapper = os.path.join(cwd, 'gcc')
33+
cmdrun(["cmake", "..", f"-DCMAKE_C_COMPILER={compiler_wrapper}"], for_pgm=False)
34+
cmdrun(["make"], for_pgm=False)
35+
36+
# Run the executable
37+
cmdrun(["hello_world"], for_pgm=False)
38+
39+
# Check coverage expectations
40+
xcov(
41+
[
42+
"coverage",
43+
"--level=stmt",
44+
"--sid=main.c.sid",
45+
"-axcov",
46+
srctracename_for("main"),
47+
]
48+
)
49+
check_xcov_reports("*.xcov", {"main.c.xcov": {"+": {6, 7}}})
50+
51+
thistest.result()

tools/gnatcov/gnatcov_bits_specific.adb

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ with GNAT.OS_Lib;
2929
with GNAT.Regexp;
3030
with GNAT.Strings; use GNAT.Strings;
3131

32+
with GNATCOLL.VFS;
33+
3234
with System.Multiprocessors;
3335

3436
with Snames;
@@ -112,7 +114,7 @@ procedure GNATcov_Bits_Specific is
112114
Compiler_Drivers : Inputs.Inputs_Type;
113115
Source_Rebase_Inputs : Inputs.Inputs_Type;
114116
Source_Search_Inputs : Inputs.Inputs_Type;
115-
Subprograms_Inputs : Inputs.Inputs_Type;
117+
Subprograms_Inputs : Inputs.Inputs_Type;
116118
Text_Start : Pc_Type := 0;
117119
Output : String_Access := null;
118120
Tag : String_Access := null;
@@ -566,7 +568,16 @@ procedure GNATcov_Bits_Specific is
566568
Copy_Arg_List (Opt_Ignore_Source_Files, Ignored_Source_Files);
567569
Copy_Arg_List (Opt_Files, Files_Of_Interest);
568570
Copy_Arg_List (Opt_Compiler_Wrappers, Compiler_Drivers);
569-
Switches.Files_Of_Interest := To_String_Set (Files_Of_Interest);
571+
572+
for File of Files_Of_Interest loop
573+
declare
574+
use GNATCOLL.VFS;
575+
F : constant Virtual_File := Create (+File.Name.all);
576+
begin
577+
F.Normalize_Path;
578+
Switches.Files_Of_Interest.Include (+(+Full_Name (F)));
579+
end;
580+
end loop;
570581

571582
-- Compute the languages for which we want coverage analysis, or enable
572583
-- just the default ones.

0 commit comments

Comments
 (0)