Gcov: Difference between revisions

From ASCEND
Jump to navigation Jump to search
No edit summary
 
(4 intermediate revisions by the same user not shown)
Line 21: Line 21:
* <tt>gcov</tt> shows results one file at a time. Tools like <tt>[http://ggcov.sf.net/ ggcov]</tt>, <tt>[http://linux.die.net/man/1/lcov lcov]</tt>, <tt>[https://software.sandia.gov/trac/fast/wiki/gcovr gcovr]</tt> can give some aggregated coveraged data, create GUI/HTML output, and convert to 'cobertura' output format for use with other tools.
* <tt>gcov</tt> shows results one file at a time. Tools like <tt>[http://ggcov.sf.net/ ggcov]</tt>, <tt>[http://linux.die.net/man/1/lcov lcov]</tt>, <tt>[https://software.sandia.gov/trac/fast/wiki/gcovr gcovr]</tt> can give some aggregated coveraged data, create GUI/HTML output, and convert to 'cobertura' output format for use with other tools.
* See also gprof if you want information about time spent in different functions.
* See also gprof if you want information about time spent in different functions.
== lcov ==
The [http://ltp.sourceforge.net/coverage/lcov.php lcov] tool can be used to produce nice, easy-to-read coverage reports from our CUnit test suite (and probably more).
'''Note:''' we found that the version of LCOV available in the Ubuntu repositories was not functional, and the newer code from <tt>git clone https://github.com/linux-test-project/lcov.git</tt> needed to be used. It can be built and installed using <tt>sudo make install</tt>, which will install it to <tt>/usr/local/bin/lcov</tt>.
To run lcov with ASCEND, try the following:
<source lang=sh>
#!/bin/bash
LCOV=/usr/local/bin/lcov
GENHTML=/usr/local/bin/genhtml
scons MALLOC_DEBUG=1 GCOV=1 CC=gcc CXX=g++ -j4 -c test ascend models solvers
scons -j4 test ascend models solvers
$LCOV -c -i -d . mycov-1.info
ASCENDLIBRARY=models:solvers/qrslv LD_LIBRARY_PATH=. test/test general_color general_dstring general_hashpjw general_list general_listio \
general_mem general_pool general_pretty general_stack general_table \
general_tm_time general_ospath general_env general_ltmatrix general_ascMalloc \
utilities_ascEnvVar utilities_ascPrint \
utilities_ascSignal utilities_readln utilities_set linear_qrrank linear_mtx \
compiler_basics  compiler_expr compiler_fixfree  compiler_fixassign
$LCOV -c -d . mycov-2.info
$LCOV -a mycov-1.info -a mycov-2.info -o mycov-tot.info
$LCOV -r mycov-tot.info "*stdout*" -o mycov-tot2.info
$GENHTML mycov-tot2.info
</source>
Note that the command <tt>$LCOV -r mycov-tot.info "*stdout*" -o mycov-tot2.info</tt> is required, because of the way the {{src|ascend/compiler/scanner.l}} file is compiled. In the gcov output it is shown with a source-code filename of <stdout>, which is incorrect/false.
The above approach has been implemented in a Python script {{srcbranch|relerrorlist|test/test-cov.py}} which be run to produce full coverage reports for the [[CUnit]] test suite in ASCEND. So far we don't have any coverage testing from the Python or C++ parts.


== ggcov ==
== ggcov ==

Latest revision as of 04:40, 17 September 2017

We can do coverage testing of ASCEND using the 'gcov' tool. To do this, build ASCEND using 'scons GCOV=1' (see building ASCEND for more details) and the coverage 'instrumentation' will be added.

To get coverage information in plaintext form, for a single code file, you can use the gcov command, eg

Invalid language.

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

a4c, abap, abc, abnf, actionscript, ada, agda, alan, algol, ampl, amtrix, applescript, arc, arm, as400cl, ascend, asciidoc, asp, aspect, assembler, ats, autohotkey, autoit, avenue, awk, ballerina, bat, bbcode, bcpl, bibtex, biferno, bison, blitzbasic, bms, bnf, boo, c, carbon, ceylon, charmm, chill, chpl, clean, clearbasic, clipper, clojure, clp, cmake, cobol, coffeescript, coldfusion, conf, cpp2, critic, crk, crystal, cs_block_regex, csharp, css, d, dart, delphi, diff, dockerfile, dts, dylan, ebnf, ebnf2, eiffel, elixir, elm, email, erb, erlang, euphoria, exapunks, excel, express, factor, fame, fasm, felix, fish, fortran77, fortran90, frink, fsharp, fstab, fx, gambas, gdb, gdscript, go, graphviz, haml, hare, haskell, haxe, hcl, html, httpd, hugo, icon, idl, idlang, inc_luatex, informix, ini, innosetup, interlis, io, jam, jasmin, java, javascript, js_regex, json, jsp, jsx, julia, kotlin, ldif, less, lhs, lilypond, limbo, lindenscript, lisp, logtalk, lotos, lotus, lua, luban, makefile, maple, markdown, matlab, maya, mercury, meson, miranda, mod2, mod3, modelica, moon, ms, msl, mssql, mxml, n3, nasal, nbc, nemerle, netrexx, nginx, nice, nim, nix, nsis, nxc, oberon, objc, ocaml, octave, oorexx, org, os, oz, paradox, pas, pdf, perl, php, pike, pl1, plperl, plpython, pltcl, po, polygen, pony, pov, powershell, pro, progress, ps, psl, pure, purebasic, purescript, pyrex, python, q, qmake, qml, qu, r, rebol, rego, rexx, rnc, rpg, rpl, rst, ruby, rust, s, sam, sas, scad, scala, scilab, scss, shellscript, slim, small, smalltalk, sml, snmp, snobol, solidity, spec, spn, sql, squirrel, styl, svg, swift, sybase, tcl, tcsh, terraform, tex, toml, tsql, tsx, ttcn3, txt, typescript, upc, vala, vb, verilog, vhd, vimscript, vue, wat, whiley, wren, xml, xpp, yaiff, yaml, yaml_ansible, yang, zig, znn

Important notes

  • You don't get complete gcov data if a program exits or aborts prematurely. You can get a trace though by calling __gcov_flush() at some point close to where the error occurs (maybe you can even call it from GDB, haven't tried that). See this page.
  • gcov shows results one file at a time. Tools like ggcov, lcov, gcovr can give some aggregated coveraged data, create GUI/HTML output, and convert to 'cobertura' output format for use with other tools.
  • See also gprof if you want information about time spent in different functions.

lcov

The lcov tool can be used to produce nice, easy-to-read coverage reports from our CUnit test suite (and probably more).

Note: we found that the version of LCOV available in the Ubuntu repositories was not functional, and the newer code from git clone https://github.com/linux-test-project/lcov.git needed to be used. It can be built and installed using sudo make install, which will install it to /usr/local/bin/lcov.

To run lcov with ASCEND, try the following:

Invalid language.

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

a4c, abap, abc, abnf, actionscript, ada, agda, alan, algol, ampl, amtrix, applescript, arc, arm, as400cl, ascend, asciidoc, asp, aspect, assembler, ats, autohotkey, autoit, avenue, awk, ballerina, bat, bbcode, bcpl, bibtex, biferno, bison, blitzbasic, bms, bnf, boo, c, carbon, ceylon, charmm, chill, chpl, clean, clearbasic, clipper, clojure, clp, cmake, cobol, coffeescript, coldfusion, conf, cpp2, critic, crk, crystal, cs_block_regex, csharp, css, d, dart, delphi, diff, dockerfile, dts, dylan, ebnf, ebnf2, eiffel, elixir, elm, email, erb, erlang, euphoria, exapunks, excel, express, factor, fame, fasm, felix, fish, fortran77, fortran90, frink, fsharp, fstab, fx, gambas, gdb, gdscript, go, graphviz, haml, hare, haskell, haxe, hcl, html, httpd, hugo, icon, idl, idlang, inc_luatex, informix, ini, innosetup, interlis, io, jam, jasmin, java, javascript, js_regex, json, jsp, jsx, julia, kotlin, ldif, less, lhs, lilypond, limbo, lindenscript, lisp, logtalk, lotos, lotus, lua, luban, makefile, maple, markdown, matlab, maya, mercury, meson, miranda, mod2, mod3, modelica, moon, ms, msl, mssql, mxml, n3, nasal, nbc, nemerle, netrexx, nginx, nice, nim, nix, nsis, nxc, oberon, objc, ocaml, octave, oorexx, org, os, oz, paradox, pas, pdf, perl, php, pike, pl1, plperl, plpython, pltcl, po, polygen, pony, pov, powershell, pro, progress, ps, psl, pure, purebasic, purescript, pyrex, python, q, qmake, qml, qu, r, rebol, rego, rexx, rnc, rpg, rpl, rst, ruby, rust, s, sam, sas, scad, scala, scilab, scss, shellscript, slim, small, smalltalk, sml, snmp, snobol, solidity, spec, spn, sql, squirrel, styl, svg, swift, sybase, tcl, tcsh, terraform, tex, toml, tsql, tsx, ttcn3, txt, typescript, upc, vala, vb, verilog, vhd, vimscript, vue, wat, whiley, wren, xml, xpp, yaiff, yaml, yaml_ansible, yang, zig, znn

Note that the command $LCOV -r mycov-tot.info "*stdout*" -o mycov-tot2.info is required, because of the way the ascend/compiler/scanner.l file is compiled. In the gcov output it is shown with a source-code filename of <stdout>, which is incorrect/false.

The above approach has been implemented in a Python script relerrorlist:test/test-cov.py which be run to produce full coverage reports for the CUnit test suite in ASCEND. So far we don't have any coverage testing from the Python or C++ parts.

ggcov

A GUI for 'gcov' exists, ggcov, see also this presentation for details. The following process can be used on Ubuntu 12.04:

  1. download ggcov 0.8.4 from here (note that the GIT code linked from the ggcov SF.net page is currently buggy)
  2. install the Glade and GNOME UI developer libraries for your distro. On Ubuntu, use apt-get install libglade2-dev libgnomeui-dev.
  3. ./configure --prefix=/usr/local
  4. make -j4

Currently, ggcov gets all confused if there aren't *.o files to match the *.gcno files produced by the --coverage instrumentation in GCC. You can quickly create at least the need .o files by copying all the .os files that SCons produces to corresponding .o files:

Invalid language.

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

a4c, abap, abc, abnf, actionscript, ada, agda, alan, algol, ampl, amtrix, applescript, arc, arm, as400cl, ascend, asciidoc, asp, aspect, assembler, ats, autohotkey, autoit, avenue, awk, ballerina, bat, bbcode, bcpl, bibtex, biferno, bison, blitzbasic, bms, bnf, boo, c, carbon, ceylon, charmm, chill, chpl, clean, clearbasic, clipper, clojure, clp, cmake, cobol, coffeescript, coldfusion, conf, cpp2, critic, crk, crystal, cs_block_regex, csharp, css, d, dart, delphi, diff, dockerfile, dts, dylan, ebnf, ebnf2, eiffel, elixir, elm, email, erb, erlang, euphoria, exapunks, excel, express, factor, fame, fasm, felix, fish, fortran77, fortran90, frink, fsharp, fstab, fx, gambas, gdb, gdscript, go, graphviz, haml, hare, haskell, haxe, hcl, html, httpd, hugo, icon, idl, idlang, inc_luatex, informix, ini, innosetup, interlis, io, jam, jasmin, java, javascript, js_regex, json, jsp, jsx, julia, kotlin, ldif, less, lhs, lilypond, limbo, lindenscript, lisp, logtalk, lotos, lotus, lua, luban, makefile, maple, markdown, matlab, maya, mercury, meson, miranda, mod2, mod3, modelica, moon, ms, msl, mssql, mxml, n3, nasal, nbc, nemerle, netrexx, nginx, nice, nim, nix, nsis, nxc, oberon, objc, ocaml, octave, oorexx, org, os, oz, paradox, pas, pdf, perl, php, pike, pl1, plperl, plpython, pltcl, po, polygen, pony, pov, powershell, pro, progress, ps, psl, pure, purebasic, purescript, pyrex, python, q, qmake, qml, qu, r, rebol, rego, rexx, rnc, rpg, rpl, rst, ruby, rust, s, sam, sas, scad, scala, scilab, scss, shellscript, slim, small, smalltalk, sml, snmp, snobol, solidity, spec, spn, sql, squirrel, styl, svg, swift, sybase, tcl, tcsh, terraform, tex, toml, tsql, tsx, ttcn3, txt, typescript, upc, vala, vb, verilog, vhd, vimscript, vue, wat, whiley, wren, xml, xpp, yaiff, yaml, yaml_ansible, yang, zig, znn

If you do that, then ggcov gives bunch of warning due to symbol conflicts (static functions are used in ASCEND with the same name in more that one location, probably we can fix these with some renaming and/or merging):

Callgraph name collision: /home/john/ascend/ascend/compiler/logrelation.c:DoBreakPoint and /home/john/ascend/ascend/compiler/instance_io.c:DoBreakPoint
Callgraph name collision: /home/john/ascend/ascend/compiler/rel_common.c:CmpP and /home/john/ascend/ascend/compiler/exprsym.c:CmpP
Callgraph name collision: /home/john/ascend/ascend/compiler/relation.c:realloc_term_stack and /home/john/ascend/ascend/compiler/logrelation.c:realloc_term_stack

Other than that, ggcov seems to work OK now.

Error creating thumbnail: File missing
GGCOV showing the results of test/test general_ospath, which has fairly reasonable coverage in testing at this stage.

To get fresh tallies of covered code you might need to remove the coverage data, eg

Invalid language.

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

a4c, abap, abc, abnf, actionscript, ada, agda, alan, algol, ampl, amtrix, applescript, arc, arm, as400cl, ascend, asciidoc, asp, aspect, assembler, ats, autohotkey, autoit, avenue, awk, ballerina, bat, bbcode, bcpl, bibtex, biferno, bison, blitzbasic, bms, bnf, boo, c, carbon, ceylon, charmm, chill, chpl, clean, clearbasic, clipper, clojure, clp, cmake, cobol, coffeescript, coldfusion, conf, cpp2, critic, crk, crystal, cs_block_regex, csharp, css, d, dart, delphi, diff, dockerfile, dts, dylan, ebnf, ebnf2, eiffel, elixir, elm, email, erb, erlang, euphoria, exapunks, excel, express, factor, fame, fasm, felix, fish, fortran77, fortran90, frink, fsharp, fstab, fx, gambas, gdb, gdscript, go, graphviz, haml, hare, haskell, haxe, hcl, html, httpd, hugo, icon, idl, idlang, inc_luatex, informix, ini, innosetup, interlis, io, jam, jasmin, java, javascript, js_regex, json, jsp, jsx, julia, kotlin, ldif, less, lhs, lilypond, limbo, lindenscript, lisp, logtalk, lotos, lotus, lua, luban, makefile, maple, markdown, matlab, maya, mercury, meson, miranda, mod2, mod3, modelica, moon, ms, msl, mssql, mxml, n3, nasal, nbc, nemerle, netrexx, nginx, nice, nim, nix, nsis, nxc, oberon, objc, ocaml, octave, oorexx, org, os, oz, paradox, pas, pdf, perl, php, pike, pl1, plperl, plpython, pltcl, po, polygen, pony, pov, powershell, pro, progress, ps, psl, pure, purebasic, purescript, pyrex, python, q, qmake, qml, qu, r, rebol, rego, rexx, rnc, rpg, rpl, rst, ruby, rust, s, sam, sas, scad, scala, scilab, scss, shellscript, slim, small, smalltalk, sml, snmp, snobol, solidity, spec, spn, sql, squirrel, styl, svg, swift, sybase, tcl, tcsh, terraform, tex, toml, tsql, tsx, ttcn3, txt, typescript, upc, vala, vb, verilog, vhd, vimscript, vue, wat, whiley, wren, xml, xpp, yaiff, yaml, yaml_ansible, yang, zig, znn