|
From: Lieske, R. <Rob...@ca...> - 2008-02-07 10:37:41
|
Hi,
as I already mentioned, I found out, that the code coverage reported by
valgrind is dependend on compiler settings. It does not matter, whether
callgrind, cachegrind, covergrind or exp-vcov is used.
Here is a small testing setup to reproduce the problem:
Take the following sample code:
=======
/* HelloWorld.c */
#include <stdio.h>
main()
{
printf("Hello World \n");
int i = 0;
for (i = 0; i <= 5; i++) {
if (i > 5) {
printf("Wert von i: %d\n", i);
} else {
printf("zu klein...\n");
}
}
}
=======
As can be seen when run, the code in line #9 is not reached.
As I also want to use the results of gcov, I compile the code with the
command line:
$ gcc -g -O0 -o helloworld -fprofile-arcs -ftest-coverage helloworld.c
Then I run helloworld with valgrind (does not matter which tool is used,
the result with cachgrind, callgrind and covergrind is the same; just
requires another program (kchachegrind) to view the results):
$ valgrind --tool=exp-vcov helloworld
View the results:
$ perl /opt/VCOV/exp-vcov/vc_annotate vcov.out
... reports 100.0% (8 of 8 lines) coverage in helloworld.c.
As is seen, when the code is executed (or from code inspection *g*),
line #9 is not reached. This is also reported from gcov:
$ gcov helloworld.c
File 'helloworld.c'
Lines executed:85.71% of 7
When helloworld.c is compiled without -fprofile-arcs, the valgrind-tools
report the correct result of 87.5% (7 of 8 lines).
The parameter -test-coverage is not related to the problem, it solely
depends on parameter -fprofile-arcs.
Can you comment on this?
TIA,
Robert
PS: I will continue to evaluate gcov and its related tools. If you have
some experience to share, please drop me a mail.
|
|
From: Nicholas N. <nj...@cs...> - 2008-02-07 21:19:04
|
On Thu, 7 Feb 2008, Lieske, Robert wrote: > When helloworld.c is compiled without -fprofile-arcs, the valgrind-tools > report the correct result of 87.5% (7 of 8 lines). > The parameter -test-coverage is not related to the problem, it solely > depends on parameter -fprofile-arcs. Interesting. VCov is entirely at the mercy of the debug info generated by the compiler. I'd suggest not using -fprofile-arcs with VCov (and I'll put that in the docs). Other than that, I don't have much to add. N |
|
From: Lieske, R. <Rob...@ca...> - 2008-02-08 07:57:29
|
Hi, >> When helloworld.c is compiled without -fprofile-arcs, the >> valgrind-tools report the correct result of 87.5% (7 of 8 lines). >> The parameter -test-coverage is not related to the problem, it solely >> depends on parameter -fprofile-arcs. > Interesting. VCov is entirely at the mercy of the debug info generated by the compiler. > I'd suggest not using -fprofile-arcs with VCov (and I'll put that in the docs). > Other than that, I don't have much to add. As already said, the problem is not specific to your VCov, I just used it because no additional program (kcachegrind) is required to view the statistics. All Valgrind tools (cachegrind, callgrind, covergrind) have the same problem, which suggests, that the problem is of general nature with valgrind. Best regards, Robert PS: I ran into a lot of trouble installing ggcov on my Suse9.3 box. If someone knows of another GUI for gcov, please let me know. |