1 / 17
文档名称:

GCC Code Coverage Tools代码覆盖率测试工具.doc

格式:doc   页数:17页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

GCC Code Coverage Tools代码覆盖率测试工具.doc

上传人:aluyuw1 2016/3/31 文件大小:0 KB

下载得到文件列表

GCC Code Coverage Tools代码覆盖率测试工具.doc

相关文档

文档介绍

文档介绍:GCC C ode C overage Tools 代码覆盖率测试工具 ******@asiainfo- 第1 章什么是 gcov gcov 是伴随着 gcc 一起发布的代码覆盖率测试工具。通过 gcov 配合 gcc 对你的程序进行分析, 帮助你发现程序中未测试的代码并对代码进行最有效的优化。 gcov 可以与其他分析工具一起使用,如 gprof , 它可以用来评估你的代码中那部分消耗的 CPU 时间最多。分析工具可以帮助你分析你的代码的性能,使用 gcov 或者 gprof 能够获得最基本的性能数据,如: ?每行代码的执行频率?那行代码被实际执行过?每个代码段的执行 CPU 时间一旦你知道了以上这些信息你就可以对你的代码进行更好的优化, gcov 能够让你清楚地知道那些地方需要优化。软件开发者可以在测试用例中增加覆盖率测试来提高发布软件的质量, 和清楚地知道测试用例对程序代码覆盖情况,还有哪些测试用例需要添加来更好的保障产品质量。如果你计划使用 gcov 来测试你的代码那么在代码编译的时候就不能打开编译器的优化选项,因为优化后的会去掉符号信息甚至对代码结构进行调整优化,这样就没有足够的信息去对应源码,例如那些是 CPU 开销最大的热点代码。同样, 因为 gcov 是按行( 最低粒度) 累积统计的, 所以它适合每行只有一条语句的编程风格。假如你的代码中存在使用复杂的宏来展开循环或者其他控制结构, 那么他的统计信息看其来就没那么有用了, 因为它只会统计宏调用的地方, 而不是统计展开后的代码, 最好的办法就是用内联函数代替这些复杂的宏。 gcov 将会生成一个名为 的 logfile 文件来保存 文件每行的被执行的次数,你可以使用这个 logfile 配合 gprof 来协助你对你程序进行性能微调, gprof 生成时间信息能够配合 gcov 生成的数据一起使用。 gcov 只能和 gcc 配合一起工作,它将不与其它任何分析工具或者测试覆盖率的机制相兼容。第2 章如何使用 gcov gcov [options] sourcefiles gcov accepts the following options: -h --help Display help about using gcov (on the standard output), and exit without doing any further processing. -v --version Display the gcov version number (on the standard output), and exit without doing any further processing. -a --all-blocks Write individual execution counts for every basic block. Normally gcov outputs execution counts only for the main blocks of a line. With this option you can determine if blocks within a single line are not being executed. -b --branch-probabilities Write branch frequencies to the output file, and write branch summary info to the standard output. This option allows you to see how often each branch in your program was taken. Unconditional branches will not be shown, unless the -u option is given. -c --branch-counts Write branch frequencies as the number of branches taken, rather than the percentage of branches taken. -n --no-output Do not create the gcov output file. -l --long-file-names Create long file names for included source files. For example, if the header file contains code, and was included in