First install Lcov, I install the version is lcov-1.9
-
write a app.c file with the following code:
#include <stdio.h>
# Include <time.h>
#include <stdlib.h>
Void Main ()
{
int a=3;
int b=4;
int c=5;
if (a>b&&a>c)//Determine if A is the maximum
{
if (b>c)
{
printf ("A>b>c");
}else
{
printf ("a>c>b");
}
else if (b>a&&b>c)//Determine if B is the maximum
{
if (a>c)
{
printf ("b>a>c");
}else
{
printf ("B>c>a");
}
else if (c>b&&c>a)//Determine if C is the maximum
{
if (a>b)
{
printf ("c>a>b");
}else
{
printf ("C>b>a");
}
}
[Email protected] test]# Gcc-fprofile-arcs-ftest-coverage-o MYAPPAA app.c
[Email protected] test]#./myapp
[Email protected] test]# Gcov app.c
File ' app.c '
Lines executed:58.82% of 17
App.c:creating ' App.c.gcov '
[[email protected] test]# ls
App.c App.c.gcov app.gcda app.gcno MyApp
[Email protected] test]# lcov-d./-O Myapp.info-b. -C
Capturing coverage data from./
Found Gcov version:4.4.7
Scanning./For. gcda files ...
Found 1 data files in./
Processing APP.GCDA
Finished. Info-file Creation
[[email protected] test]# ls
App.c app.gcda app.gcno MyApp myapp.info
[Email protected] test]# Genhtml-o Myapp_restul myapp.info
Reading Data File Myapp.info
Found 1 entries.
Found common filename prefix "/opt"
Writing. css and. png files.
Generating output.
Processing file zhaogh/test/app.c
Writing Directory View page.
Overall Coverage Rate:
Lines ...: 58.8% (ten of lines)
Functions.: 100.0% (1 of 1 function)
Branches ...: 33.3% (6 of branches)
SZ Myapp_restul
Then open index to see the coverage of code execution
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M02/6F/25/wKioL1WTTwmQpUaZAARDsYBm_gM973.jpg "title=" Lcov.png "alt=" Wkiol1wttwmqpuazaardsybm_gm973.jpg "/>
This article is from the "bad-kbase" blog, make sure to keep this source http://bad51men.blog.51cto.com/3141086/1669649
Lcov for Linux Use