Skip to content

Commit 8250550

Browse files
committed
Refactor 'py2lcov' translator:
- Simplify use model: support 'direct' translation from Coverage.py '.dat' file to LCOV format - without requiring explicit XML conversion step by user. - Translate multiple .dat and/or .xml files in single execution. - Add 'py2lcov --version-script ...' parameter - to enable version checking in Python coverage data. - Derive function coverpoints. See 'py2lcov --help' for more information. Signed-off-by: Henry Cox <[email protected]>
1 parent 28df644 commit 8250550

File tree

10 files changed

+756
-152
lines changed

10 files changed

+756
-152
lines changed

Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,8 @@ rpms: lcov-$(VERSION).tar.gz
237237
ifeq ($(COVERAGE), 1)
238238
# write to .../tests/cover_db
239239
export COVER_DB := $(shell echo `pwd`/tests/cover_db)
240-
export HTML_RPT := ./perlcov
240+
export PYCOV_DB := $(shell echo `pwd`/tests/pycov.dat)
241+
export HTML_RPT := ./lcov_coverage
241242
endif
242243
export TESTCASE_ARGS
243244

README

Lines changed: 69 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Further README contents
5555
bin/genhtml - Tool for creating HTML output from LCOV data
5656
bin/gendesc - Tool for creating description files as used by genhtml
5757
bin/perl2lcov - Tool to translate Perl Devel::Cover data to lcov format
58+
bin/py2lcov - Tool to translate Python Coverage.py to lcov format
5859
bin/geninfo - Internal tool (creates LCOV data files)
5960
bin/genpng - Internal tool (creates png overviews of source files)
6061
man - Directory containing man pages for included tools
@@ -180,45 +181,88 @@ Point the web browser of your choice to the resulting index.html file.
180181

181182
5. An example of how to access coverage data for a user space program
182183
---------------------------------------------------------------------
183-
Requirements: compile the program in question using GCC with the options
184-
'-fprofile-arcs -ftest-coverage' or '--coverage'. During linking, make sure
185-
to specify '-lgcov' or '--coverage'.
186184

187-
Assuming the compile directory is called "appdir", do the following:
185+
a) Capture current coverage state to a file:
188186

189-
a) Resetting counters
187+
i) C/C++ code:
190188

191-
lcov --directory appdir --zerocounters
189+
Compile your program using the '--coverage' GCC or LLVM
190+
option. During linking, make sure to specify '--coverage':
192191

193-
b) Capturing the current coverage state to a file
192+
$ gcc -o myTest --coverage simple.c
193+
OR
194+
$ gcc -c file1.c file2.c ... --coverage
195+
$ gcc -o myOtherTest --coverage file1.o file2.o ....
194196

195-
lcov --directory appdir --capture --output-file app.info
197+
Run your testcase at least once:
196198

197-
Note that this step only works after the application has
198-
been started and stopped at least once. Otherwise lcov will
199-
abort with an error mentioning that there are no data/.gcda files.
199+
$ path/to/my/testcase/myTest
200200

201-
The GCC runtime emits coverage data (the .gcda files) in an atexit
202-
callback. If your application exits abnormally or crashes before
203-
the callback is executed, then no coverage data will be available.
201+
Capture the current coverage state to a file:
204202

205-
c) Getting HTML output
203+
$ lcov --directory path/to/my/testcase --capture --output-file app.info
206204

207-
genhtml app.info
205+
Note that runtime coverage data exists only after the application has
206+
been started and stopped at least once. Otherwise, no data wil be found
207+
and lcov will abort with an error mentioning that there are no data/.gcda
208+
files.
208209

209-
d) Generating a differential coverage report
210+
The coverage runtime emits data (the .gcda files) in an atexit
211+
callback. If your application exits abnormally or crashes before
212+
the callback is executed, then no coverage data will be available.
210213

211-
See the example in .../example (run "make test_differential")
212-
as well as the examples in .../tests/gendiffcov.
214+
For further information on the gcc profiling mechanism, please
215+
consult the gcov man page.
213216

214-
Point the web browser of your choice to the resulting index.html file.
217+
See 'man lcov' for more information - especially if your build/test
218+
environment is not trivial.
219+
220+
ii) Python code:
221+
222+
- install the Coverage.py module
223+
224+
- execute your testcase to produce python coverage data:
225+
226+
$ COVERAGE_FILE=./pycov.dat coverage run --append --branch \
227+
myPythonScript [my script args]
228+
229+
- translate Python coverage data to LCOV format:
230+
231+
$ py2lcov -o pycov.info [py2lcov_options] pycov.dat [x.dat]+
232+
233+
See 'py2lcov --help' and the Coverage.py documentation for more
234+
information.
235+
236+
iii) Perl code:
237+
238+
- install the Devel::Cover module
239+
240+
- execute your testcase to produce perl coverage data:
241+
242+
$ perl -MDevel::Cover=-db,perlcov_db,-coverage,statement,branch,condition,subroutine,-silent,1 myPerlTest.pl [my script args]
243+
244+
- translate Perl coverage data to LCOV format:
245+
246+
$ perl2lcov --output perlcov.info perlcov_db [perl2lcov options]
247+
248+
See 'perl2lcov --help' and the Devel::Cover documentation for more
249+
information.
250+
251+
b) Generate an HTML coverage report:
252+
253+
Generate an HTML report, combining all of your LCOV data files:
254+
255+
$ genhtml -o html_report app.info pycov.info perlcov.info
256+
257+
Point the web browser of your choice to the resulting file:
258+
html_report/index.html.
259+
260+
See 'man genhtml' for more details.
215261

216-
Please note that independently of where the application is installed or
217-
from which directory it is run, the --directory statement needs to
218-
point to the directory in which the application was compiled.
262+
c) Generate a differential coverage report:
219263

220-
For further information on the gcc profiling mechanism, please also
221-
consult the gcov man page.
264+
See the example in .../example (run "make test_differential")
265+
as well as the examples in .../tests/gendiffcov.
222266

223267

224268
6. New features:

0 commit comments

Comments
 (0)