一、关于gcov工具

gcov伴随gcc 发布。gcc编译加入-fprofile-arcs -ftest-coverage

参数生成二进制程序,执行测试用例生成代码覆盖率信息。

1、如何使用gcov

用GCC编译的时候加上-fprofile-arcs -ftest-coverage选项,链接的时候也加上。

fprofile-arcs参数使gcc创建一个程序的流图,之后找到适合图的生成树。只有不在生成树中的弧被操纵(instrumented):gcc

添加了代码来清点这

些弧执行的次数。当这段弧是一个块的唯一出口或入口时,操纵工具代码(instrumentation

code)将会添加到块中,否则创建一个基础块来包含操纵

工具代码。gcov主要使用.gcno和.gcda两个文件。

.gcno是由-ftest-coverage产生的,它包含了重建基本块图和相应的块的源码的行号的信息。

.gcda是由加了-fprofile-arcs编译参数的编译后的文件运行所产生的,它包含了弧跳变的次数和其他的概要信息。

Gcov执行函数覆盖、语句覆盖和分支覆盖。

举个例子,程序代码由main.c和tmp.c两个文件组成,编译、链接、运行程序

编译:gcc -fprofile-arcs -ftest-coverage -o myapp main.c tmp.c

运行:./myapp

然后 输入

命令: gcov main.c,gcov tmp.c

这个时候当前目录下有了新的文档main.c.gcov,和tmp.c.gcov

若想保存覆盖率文件,上述命令修改为:

命令:gcov main.c >>yourfilename,gcov tmp.c >>yourfilename

查看结果:

-:

65:/***************************************************************************************

-:   66: * name         : main

-:   67: * return       : 0 OK

-:   68: *                other ERROR

-:   69: * history      : 2006-06-13

-:

70:****************************************************************************************/

-:   71:int main( int argc, char *argv[]

)                                                      /* the entrance

for program

*/

function main called 4 returned 100% blocks executed 81%

4:   72:{

4:   73:        int loop = 0 ;

4:   74:        int ret = OK ;

4:   75:        int empty_line = 0 ;

4:   76:        int code_line = 0 ;

4:   77:        int annotation_line = 0 ;

4:   78:        struct stat file_stat

;                                                         /* use for

file state */

4:   79:        char recu_name[256] ;

4:   80:        char *pwd = NULL ;

4:   81:        char *tmp = NULL ;

-:   82:

4:   83:        if( argc = MAX_FILE

){                                    /* file size larger than max size

*/

#####:   98:                        printf( "file [%s] size is

over 64K! \ncontinue....\n", argv[loop] ) ;

#####:   99:                        continue ;

-: 100:                }

##### 这就是表示没跑到的

各个参数使用如下:

gcov [-b] [-c] [-v] [-n] [-l] [-f] [-o directory] sourcefile

-b

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.

//b(ranch),分支测试

-c

Write branch frequencies as the number of branches taken, rather

than the percentage of branches taken.

-v

Display the gcov version number (on the standard error stream).

//太简单了吧,我上面用了

-n

Do not create the gcov output file.

-l

Create long file names for included source files. For example, if

the header file `x.h' contains code, and was included in the

file `a.c', then running gcov on the file `a.c' will produce an

output file called `a.c.x.h.gcov' instead of `x.h.gcov'. This can

be useful if `x.h' is included in multiple source files.

-f

Output summaries for each function in addition to the file level

summary.

-o

The directory where the object files live. Gcov will search for

`.bb', `.bbg', and `.da' files in this directory.

新版的是这么说的

-o directory│file

--object-directory directory

--object-file file

Specify either the directory containing the gcov data files,

or the

object path name. The .gcno, and .gcda data files are

searched for

using this option. If a directory is specified, the data

files are

in that directory and named after the source file name,

without its

extension. If a file is specified here, the data files are

named

after that file, without its extension. If this option is

not sup-

plied, it defaults to the current directory.

其他的更有新版的-u,

-u

--unconditional-branches

When branch counts are given, include those of unconditional

branches. Unconditional branches are normally not

interesting.

-p

--preserve-paths

p; Preserve complete path information in the

names of generated .gcov

files. Without this option, just the filename component is

used.

With this option, all directories are used, with ’/’

characters

translated to ’#’ characters, ’.’ directory components

removed and

’..’ components renamed to ’^’. This is useful if

sourcefiles are

in several different directories. It also affects the -l

option.

二、关于lcov

Lcov则是上的gcov 结果展现的一个前端,可以将覆盖率信息转换成html展现。

1、如何使用lcov

Makefile 在编译和link环节都加入 -fprofile-arcs -ftest-coverage 选项

收集覆盖率数据生成app.info文件

命令:cov --directory .   --capture --output-file myapp.info

Capturing coverage data from .

Found gcov version: 3.4.6

Scanning . for .gcda files ...

Found 1 data files in .

Processing ./TestQuery.gcda

Finished .info-file creation

转换成html格式

命令:genhtml -o results app.info

Reading data file app.info

Found 18 entries.

Found common filename prefix "/home/search/isearch_yb/src"

Writing .css and .png files.

Generating output.

Processing file cpp/core/basis/GlobalDef.h

Processing file cpp/core/search/QueryCache.h

...

Writing directory view page.

Overall coverage rate: 117 of 514 lines (22.8%)

2、查看html文件

html包含代码覆盖的详细信息

更多命令选项

参考资料

1、

C语言代码覆盖率测试软件,代码覆盖率检测工具GCOV相关推荐

  1. 主板装机测试软件,主板检测工具:PSPident v0.74.1版发布

    软件分享:CG yangjinglin PSPident是一款PSP主机适用的主板检测工具,直接安装在PSP中,运行之后即可看到当前PSP主机的主板型号等参数信息.目前软件的作者jas0nuk更新了该 ...

  2. 测试支持硬件的软件,硬件检测工具AIDA64 v5.97版发布:支持Win10春季创意者更新...

    IT之家3月28日消息 知名PC硬件检测工具AIDA64今天发布了v5.97版本更新,本次更新实现了64位AVX-512加速基准测试,增加了对华硕ROG RGB LED主板和显卡的传感器值的监控,并支 ...

  3. 新系统如何测试软件,怎样检测电脑能否升级到最新的Windows11系统?官方检测工具帮你一招搞定!...

    日前,微软正式发布了Windows11系统,新的Windows11操作系统不仅采用了全新的居中设计的开始键以及任务栏,同时还取消了Windows8引入的实时磁贴设计,取而代之的是最近文档.应用程序以及 ...

  4. 如何查看计算机硬盘的软件内存条,内存检测工具,内存检测软件 - 内存条检测工具就用金山卫士 - 安全专题...

    在去电脑城去买内存条,不知道该内存条怎么样,怕自己遇到不法奸商.金山卫士已经集成 内存条检测工具,可以智能监测到该内存所有信息以及该内存性能怎么样. 内存检测工具 就用金山卫士 许多网民从电脑城购买回 ...

  5. uart协议测试软件,串口通信测试工具(格西烽火)

    格西烽火是一个基于串口通信的多功能测试工具.研发和测试人员可以利用它来接收和显示串口数据,快速创建.运行和管理各种直接激励源和协议激励源,并以项目文件的方式进行组织,彻底地把多变的通信规约脱离通信软件 ...

  6. 三款好用的软件代码检测工具

    Fortify 是一款由 Hewlett Packard Enterprise (HPE) 公司开发的源代码检测工具,Fortify可以检测代码中的安全漏洞和缺陷共900多种,它通过对应用程序的源代码 ...

  7. 电脑新机测试软件,怎么检测新买电脑是否是新机

    当我们打算买一台笔记本时,谁都不希望自己买到的是一台展示机甚至是返修机. 网上介绍了很多购机的检验方法,比方说看包装口的封条.查看出风口有没有灰尘等等.但道高一尺,魔高一丈,这些痕迹,往往会被老道的奸 ...

  8. pc应用软件自动升级测试,软件自动检查更新工具(CheckUpDate)

    CheckUpDate是一款帮你检测软件是否有更新的工具,对于一些网络小编来说每天需要去软件官网查看软件是否有新版本是一件非常麻烦的事情,这款软件支持检测一些热门软件是否有更新版本.配合系统的计划任务 ...

  9. monkey测试软件,Monkey自动化测试工具

    概述 Monkey是中的一个命令行工具,可以运行在模拟器里或实际设备中.它向系统发送伪随机的用户事件流(如按键输入.触摸屏输入.手势输入等),实现对正在开发的应用程序进行压力.Monkey测试是一种为 ...

最新文章

  1. fixed the link error 1000 in vc2008
  2. 【黑马程序员】————预处理指令1-宏定义
  3. Eclipse 中 Maven 项目默认JDK版本为1.5 的解决方法
  4. 初识Docker-Docker的安装
  5. rabbitmq 不同的消费者消费同一个队列_消息队列王者--rabbitMQ深入理解--工作过程、消费模式、持久化等...
  6. SSH2框架多数据源配置原理和方式
  7. 纯html网页重定向与跳转
  8. 【ZBrush笔刷收集】一百多个实用笔刷和Alpah,以及笔刷使用方法,全部免费
  9. Cisco Packet Tracer 6.2 安装教程 | 计算机网络
  10. Cypress系列(21)- 可操作类型的命令 之 check()、uncheck()
  11. wow.js插件,让滚动动画更简单,让生活更美好
  12. 博客在六个方面降低网络营销费用
  13. 如何用列表解析式生成 2个小数位 的 python 列表
  14. Windows修改本地域名解析文件hosts
  15. 想裁剪视频时长,用电脑怎么裁剪视频时长
  16. PE文件格式”1.9版 完整译文
  17. 计算机考试函数应用题及答案,2016年全国职称计算机考试EXCEL考前练习题4
  18. 智慧城市建设,目前所面临的技术瓶颈是什么?
  19. 5G 中的SDN/NFV 和云计算
  20. 2008北京奥运会足球赛程(男足)

热门文章

  1. 赫夫曼树赫夫曼编码的创建
  2. Kaggle图像识别竞赛 Plant Seedlings Classification(植物幼苗分类)具体实现
  3. [2023年的每一天]1. 15 看了一天的 B站
  4. Fumark支持SLI双卡测试设置
  5. android系统息屏设置_安卓实现熄屏功能。
  6. 重庆华侨城跨界联合潮牌T.M.D PCP发财潮流文化艺术聚会国庆开档
  7. 尚邮——Wopus周六聚会大图分享(2009-12-28 11:50:01)
  8. Html+Css+JavaScript基础知识点
  9. java noi和io
  10. 我的世界使用mysql数据库_mysql数据库常用命令笔记