1212from e3 .testsuite .process import check_call
1313from e3 .testsuite .result import Log , TestStatus
1414
15-
1615# Root directory of respectively the testsuite and the gnatcoll
1716# repository.
1817TESTSUITE_ROOT_DIR = os .path .dirname (
2221DEFAULT_TIMEOUT = 5 * 60 # 5 minutes
2322
2423
25- def make_gnatcoll (work_dir , debug = False , gcov = False , gnatcov = False ):
26- """Build gnatcoll core with or without gcov instrumentation.
24+ def make_gnatcoll (work_dir , debug = False ):
25+ """Build gnatcoll core.
2726
2827 :param str work_dir: Working directory. GNATcoll is built in `build` subdir
2928 and installed in `install` subdir.
3029
3130 :param bool debug: Whether to build GNATCOLL in debug mode. Otherwise, use
32- the prod mode. Note that gcov and gnatcov modes automatically enable
33- debug mode.
34-
35- :param bool gcov: If true, build GNATCOLL with gcov instrumentation in
36- debgu mode.
37-
38- :param bool gnatcov: If True, build GNATCOLL with the compile options that
39- GNATcoverage require in debug mode.
31+ the prod mode.
4032
4133 :return: A triplet (project path, source path, object path).
4234 :rtype: (str, str, str)
4335 :raise AssertError: In case compilation of installation fails.
4436 """
45- assert not (gcov and gnatcov )
46-
47- if gcov :
48- tag = ' (gcov)'
49- elif gnatcov :
50- tag = ' (gnatcov)'
51- else :
52- tag = ''
53- logging .info ('Compiling gnatcoll{}' .format (tag ))
37+ logging .info ('Compiling gnatcoll' )
5438
5539 # Create build tree structure
5640 build_dir = os .path .join (work_dir , 'build' )
@@ -62,16 +46,7 @@ def make_gnatcoll(work_dir, debug=False, gcov=False, gnatcov=False):
6246 make_gnatcoll_cmd = [
6347 'make' , '-f' , os .path .join (GNATCOLL_ROOT_DIR , 'Makefile' ),
6448 'ENABLE_SHARED=no' ,
65- 'BUILD={}' .format ('DEBUG' if debug or gcov or gnatcov else 'PROD' )]
66- if gcov :
67- make_gnatcoll_cmd += [
68- 'GPRBUILD_OPTIONS=-cargs -fprofile-arcs -ftest-coverage'
69- ' -cargs:Ada -gnatwn'
70- ' -gargs' ]
71- elif gnatcov :
72- make_gnatcoll_cmd += [
73- 'GPRBUILD_OPTIONS=-cargs -fdump-scos -fpreserve-control-flow'
74- ' -gargs' ]
49+ 'BUILD={}' .format ('DEBUG' if debug else 'PROD' )]
7550
7651 # Build & Install
7752 p = Run (make_gnatcoll_cmd , cwd = build_dir , timeout = DEFAULT_TIMEOUT )
@@ -89,7 +64,6 @@ def make_gnatcoll(work_dir, debug=False, gcov=False, gnatcov=False):
8964def gprbuild (driver ,
9065 project_file = None ,
9166 cwd = None ,
92- gcov = False ,
9367 scenario = None ,
9468 gpr_project_path = None ,
9569 timeout = DEFAULT_TIMEOUT ,
@@ -103,8 +77,6 @@ def gprbuild(driver,
10377 :param cwd: directory in which to run gprbuild. If None the gprbuild build
10478 is run in the default working dir for the test.
10579 :type cwd: str | None
106- :param gcov: if True link with gcov libraries
107- :type gcov: bool
10880 :param scenario: scenario variable values
10981 :type scenario: dict
11082 :param gpr_project_path: if not None prepent this value to GPR_PROJECT_PATH
@@ -125,24 +97,13 @@ def gprbuild(driver,
12597 'support' , 'test.gpr' )
12698 scenario ['TEST_SOURCES' ] = driver .test_env ['test_dir' ]
12799
100+ scenario_cmd = []
101+ for k , v in scenario .items ():
102+ scenario_cmd .append ('-X%s=%s' % (k , v ))
103+
128104 if cwd is None :
129105 cwd = driver .test_env ['working_dir' ]
130106 mkdir (cwd )
131- gprbuild_cmd = [
132- 'gprbuild' , '--relocate-build-tree' , '-p' , '-P' , project_file ]
133- for k , v in scenario .items ():
134- gprbuild_cmd .append ('-X%s=%s' % (k , v ))
135- if gcov :
136- gprbuild_cmd += ['-largs' , '-lgcov' , '-cargs' ,
137- '-fprofile-arcs' , '-ftest-coverage' , '-g' ]
138- elif driver .env .gnatcov :
139- # TODO: GNATcoverage relies on debug info to do its magic. It needs
140- # consistent paths to source files in the debug info, so do not build
141- # tests with debug info, as they will reference installed sources
142- # (while GNATCOLL objects reference original sources).
143- gprbuild_cmd += ['-g0' ]
144- if driver .env .is_cross :
145- gprbuild_cmd .append ("--target={target}" .format (target = driver .env .target .triplet ))
146107
147108 # Adjust process environment
148109 env = kwargs .pop ('env' , None )
@@ -156,6 +117,36 @@ def gprbuild(driver,
156117 new_gpr_path += os .path .pathsep + os .environ ['GPR_PROJECT_PATH' ]
157118 env ['GPR_PROJECT_PATH' ] = new_gpr_path
158119
120+ # Determine the gprbuild command line
121+ gprbuild_cmd = [
122+ 'gprbuild' , '--relocate-build-tree' , '-p' , '-P' , project_file
123+ ] + scenario_cmd
124+
125+ if driver .env .gnatcov :
126+ from drivers .gnatcov import COVERAGE_LEVEL
127+
128+ gnatcov_cmd = [
129+ "gnatcov" , "instrument" , "--level" , COVERAGE_LEVEL ,
130+ "--relocate-build-tree" ,
131+ "--dump-trigger=atexit" ,
132+ "--projects" , "gnatcoll" ,
133+ "--externally-built-projects" ,
134+ "-XEXTERNALLY_BUILT=true" ,
135+ "--no-subprojects" ,
136+ "-P" , project_file ] + scenario_cmd
137+
138+ check_call (driver , gnatcov_cmd ,
139+ cwd = cwd ,
140+ env = env ,
141+ ignore_environ = ignore_environ ,
142+ timeout = timeout ,
143+ ** kwargs )
144+ gprbuild_cmd += [
145+ "-margs" , "-v" , "-g" , "-O0" , "--src-subdirs=gnatcov-instr" , "--implicit-with=gnatcov_rts" , "-XLIBRARY_TYPE=static" , "-XEXTERNALLY_BUILT=true" ]
146+
147+ if driver .env .is_cross :
148+ gprbuild_cmd .append ("--target={target}" .format (target = driver .env .target .triplet ))
149+
159150 check_call (
160151 driver ,
161152 gprbuild_cmd ,
@@ -169,8 +160,7 @@ def gprbuild(driver,
169160
170161
171162def bin_check_call (driver , cmd , slot , test_name = None , result = None , timeout = None ,
172- env = None , cwd = None ):
173-
163+ env = None , cwd = None , ** kwargs ):
174164 if cwd is None and "working_dir" in driver .test_env :
175165 cwd = driver .test_env ["working_dir" ]
176166 if result is None :
@@ -220,6 +210,7 @@ def bin_check_call(driver, cmd, slot, test_name=None, result=None, timeout=None,
220210
221211 # Append the status code and process output to the log to ease post-mortem
222212 # investigation.
213+ result .log += f"Cmd_Line: { ' ' .join (cmd )} "
223214 result .log += "Status code: {}\n " .format (process .status )
224215 result .log += "Output:\n "
225216
@@ -245,13 +236,13 @@ def run_test_program(driver, cmd, slot, test_name=None, result=None, **kwargs):
245236 Run a test program. This dispatches to running it under Valgrind or
246237 "gnatcov run", depending on the testsuite options.
247238 """
248- from drivers .gnatcov import gnatcov_run
239+ from drivers .gnatcov import gnatcov_call
249240 from drivers .valgrind import check_call_valgrind
250241
251242 if driver .env .valgrind :
252243 wrapper = check_call_valgrind
253244 elif driver .env .gnatcov :
254- wrapper = gnatcov_run
245+ wrapper = gnatcov_call
255246 else :
256247 wrapper = bin_check_call
257248
0 commit comments