代码覆盖度测试,gcov
2011-07-07 12:24
211 查看
copy from gcc manual.
gcov is a tool you can use in conjunction with GCC to test code coverage in your programs.
gcov is a test coverage program. Use it in concert with GCC to analyze your programs
to help create more efficient, faster running code and to discover untested parts of your
program. You can use gcov as a profiling tool to help discover where your optimization
efforts will best affect your code. You can also use gcov along with the other profiling tool,
gprof, to assess which parts of your code use the greatest amount of computing time.
Profiling tools help you analyze your code’s performance. Using a profiler such as gcov
or gprof, you can find out some basic performance statistics, such as:
• how often each line of code executes
• what lines of code are actually executed
• how much computing time each section of code uses
Running the program will cause profile output to be generated. For each source file
compiled with ‘-fprofile-arcs’, an accompanying ‘.gcda’ file will be placed in the object
file directory.
Running gcov with your program’s source file names as arguments will now produce a
listing of the code along with frequency of execution for each line. For example, if your
program is called ‘tmp.c’, this is what you see when you use the basic gcov facility:
$gcc -fprofile-arcs -ftest-coverage tmp.c (1)
$ ./a.out (2)
$ gcov tmp.c (3)
90.00% of 10 source lines executed in file tmp.c
Creating tmp.c.gcov.
The file ‘tmp.c.gcov’ contains output from gcov. Here is a sample:
gcov is a tool you can use in conjunction with GCC to test code coverage in your programs.
gcov is a test coverage program. Use it in concert with GCC to analyze your programs
to help create more efficient, faster running code and to discover untested parts of your
program. You can use gcov as a profiling tool to help discover where your optimization
efforts will best affect your code. You can also use gcov along with the other profiling tool,
gprof, to assess which parts of your code use the greatest amount of computing time.
Profiling tools help you analyze your code’s performance. Using a profiler such as gcov
or gprof, you can find out some basic performance statistics, such as:
• how often each line of code executes
• what lines of code are actually executed
• how much computing time each section of code uses
Running the program will cause profile output to be generated. For each source file
compiled with ‘-fprofile-arcs’, an accompanying ‘.gcda’ file will be placed in the object
file directory.
Running gcov with your program’s source file names as arguments will now produce a
listing of the code along with frequency of execution for each line. For example, if your
program is called ‘tmp.c’, this is what you see when you use the basic gcov facility:
$gcc -fprofile-arcs -ftest-coverage tmp.c (1)
$ ./a.out (2)
$ gcov tmp.c (3)
90.00% of 10 source lines executed in file tmp.c
Creating tmp.c.gcov.
The file ‘tmp.c.gcov’ contains output from gcov. Here is a sample:
-: 0:Source:tmp.c -: 0:Graph:tmp.gcno -: 0:Data:tmp.gcda -: 0:Runs:1 -: 0:Programs:1 -: 1:#include <stdio.h> -: 2: -: 3:int main (void) 1: 4:{ 1: 5: int i, total; -: 6: 1: 7: total = 0; -: 8: 11: 9: for (i = 0; i < 10; i++) 10: 10: total += i; -: 11: 1: 12: if (total != 45) #####: 13: printf ("Failure\n"); -: 14: else 1: 15: printf ("Success\n"); 1: 16: return 0; -: 17:}
相关文章推荐
- gcov代码覆盖率使用gcov完成代码覆盖率的测试
- Linux平台代码覆盖率测试工具GCOV的前端工具LCOV简介
- Linux平台代码覆盖率测试工具GCOV简介
- 代码覆盖率测试工具gcov
- Linux平台代码覆盖率测试工具GCOV简介
- Linux平台代码覆盖率测试工具GCOV简介
- Linux平台代码覆盖率测试工具GCOV的前端工具LCOV简介
- GCOV的使用-测试代码覆盖率
- Linux平台代码覆盖率测试工具GCOV相关文件分析
- 使用gcov提高代码测试覆盖率
- CMake编译项目集成Gcov/Lcov代码覆盖率测试
- Linux平台代码覆盖率测试工具GCOV的前端工具LCOV简介
- 测试代码覆盖率-GCOV的使用
- 用gcov来测试代码覆盖率
- PostgreSQL C代码覆盖率测试(gcov, lcov)
- gcov测试代码覆盖率的命令
- gcov命令_Linux gcov 命令用法详解:测试程序的代码覆盖率的工具
- PostgreSQL C代码覆盖率测试(gcov, lcov)
- 转载_Linux平台代码覆盖率测试工具GCOV的前端工具LCOV简介
- 代码覆盖率测试工具:gcov+lcov