首先,当然哥不介意你鄙视我在网上找的资料研究!

  白盒覆盖率是啥东东这个问题大家自己查百度啦!我也不太懂,就知道它不是个东西,就这样开始吧(MT一般是先摸四蹄呢还是先黑金币呢?这是个问题)!

  首先:linux先Clear一下,然后呢再ls下。然后呢再找个CPP文件。其实生成覆盖率主要就一个参数的问题。因为g++那啥已经带了获取覆盖率的功能。

下面是执行获取覆盖率的一个流程:其中红色字体是敲入的重要命令。

[lixiang@localhost cjj]$ clear
[lixiang@localhost cjj]$ ls
ctest.c voctorTest.cpp
[lixiang@localhost cjj]$ g++ -fprofile-arcs -ftest-coverage voctorTest.cpp -o test
[lixiang@localhost cjj]$ ls
ctest.c test voctorTest.bb voctorTest.bbg voctorTest.cpp
[lixiang@localhost cjj]$ ./test
start test:

vector include num:120

end test
[lixiang@localhost cjj]$ ls
ctest.c test voctorTest.bb voctorTest.bbg voctorTest.cpp voctorTest.da
[lixiang@localhost cjj]$ gcov voctorTest.cpp
100.00% of 1 source lines executed in file /usr/include/c++/3.2.2/new
Creating new.gcov.
100.00% of 1 source lines executed in file /usr/include/c++/3.2.2/iostream
Creating iostream.gcov.
100.00% of 2 source lines executed in file /usr/include/c++/3.2.2/bits/stl_uninitialized.h
Creating stl_uninitialized.h.gcov.
42.86% of 14 source lines executed in file /usr/include/c++/3.2.2/bits/stl_algobase.h
Creating stl_algobase.h.gcov.
100.00% of 6 source lines executed in file /usr/include/c++/3.2.2/bits/stl_iterator.h
Creating stl_iterator.h.gcov.
100.00% of 4 source lines executed in file /usr/include/c++/3.2.2/bits/stl_construct.h
Creating stl_construct.h.gcov.
73.81% of 42 source lines executed in file /usr/include/c++/3.2.2/bits/stl_vector.h
Creating stl_vector.h.gcov.
100.00% of 6 source lines executed in file /usr/include/c++/3.2.2/bits/stl_alloc.h
Creating stl_alloc.h.gcov.
100.00% of 8 source lines executed in file voctorTest.cpp
Creating voctorTest.cpp.gcov.
[lixiang@localhost cjj]$ ls
ctest.c stl_construct.h.gcov voctorTest.bb
iostream.gcov stl_iterator.h.gcov voctorTest.bbg
new.gcov stl_uninitialized.h.gcov voctorTest.cpp
stl_algobase.h.gcov stl_vector.h.gcov voctorTest.cpp.gcov
stl_alloc.h.gcov test voctorTest.da

执行完后:其中覆盖率数据保存在voctorTest.cpp.gcov这个文件中。可以用cat命令查看覆盖率信息,查看的结果如下:

[lixiang@localhost cjj]$ cat voctorTest.cpp.gcov
#include "iostream"
#include<vector>
using namespace std;
int main()
1 {
3 vector<int> vec;
1 vec.push_back(120);
1 cout<<"start test:\r\n"<<endl;
1 cout<<"vector include num:"<<vec[0]<<"\r\n"<<endl;
1 cout<<"end test"<<endl;
1 return 0;
1 }
[lixiang@localhost cjj]$

其中文件每行前面的数字代表着执行的次数。如下图解释的一样一样的。该图也是拷贝其他文章的奥。

OK,这里覆盖率数据就算得到和显示出来并看到了,然后其实他们有的人还用LCov把该报告转换成html文件,由于哥今天安装了WinSCP神器软件,所以俺也准备试试,可以下载到本地来看看,有意思,好玩,好玩!LCov主要是看到第二篇文章。

坑爹了.........    哥hai 没安装LCov........    无语中:

下载一个Lcov来安装,提示依赖项没有,添加个命令来执行nodeps  其中在nodeps前面要加”--“   记住是两个”-“,不然会提示”-nodeps:unknown option“

安装时又提示:cannot get exclusive lock  on /var/lib/rpm/packages

该问题我猜是由于安装软件莫得权限,然后查资料果然正确,需要root权限,但是想到root权限安装的软件普通用户是不是基本都能用呢?所以我试下:

经过上面的折腾,觉得应该正确安装命令应该是:

rpm -ihv --nodeps lcov-1.10-1.noarch.rpm

参考文章:http://linux.sheup.com/linux/linux5218.htm

http://www.jb51.net/os/RedHat/1277.html

好辛苦,终于安装LCov成功了。安装过程中还遇到几个问题。

rpmdb:unable to join the environment

该问题主要是由于文件出了问题样,应该是系统文件,然后参考如下文章:http://blog.csdn.net/avilifans/article/details/17751545

使用export LD_ASSUME_KERNEL =2.2.25这个命令,即可解决了。

安装成功LCov后:

[lixiang@localhost lixiang]$ lcov
lcov: Need one of options -z, -c, -a, -e, -r, -l, --diff or --summary
Use lcov --help to get usage information
[lixiang@localhost lixiang]$

然后执行LCov,下面是整个命令过程,红色加粗为输入命令:

[lixiang@localhost lixiang]$ ls
file SaveSoft
[lixiang@localhost lixiang]$ lcov
lcov: Need one of options -z, -c, -a, -e, -r, -l, --diff or --summary
Use lcov --help to get usage information
[lixiang@localhost lixiang]$ [lixiang@localhost lixiang]$ lcov
-bash: [lixiang@localhost: command not found
[lixiang@localhost lixiang]$ lcov: Need one of options -z, -c, -a, -e, -r, -l, --diff or --summary
-bash: lcov:: command not found
[lixiang@localhost lixiang]$ Use lcov --help to get usage information
-bash: Use: command not found
[lixiang@localhost lixiang]$ [lixiang@localhost lixiang]$
-bash: [lixiang@localhost: command not found
[lixiang@localhost lixiang]$ ls
file SaveSoft
[lixiang@localhost lixiang]$ cd file
[lixiang@localhost file]$ ls
addpe c shellscript
[lixiang@localhost file]$ cd addpe
[lixiang@localhost addpe]$ ls
add.c add.o cjj main.c makefile prcessadmin
add.h CExample1.c ExTest main.o oldfile TestOpenFile.c
[lixiang@localhost addpe]$ cd cjj
[lixiang@localhost cjj]$ ls
ctest.c stl_construct.h.gcov voctorTest.bb
iostream.gcov stl_iterator.h.gcov voctorTest.bbg
new.gcov stl_uninitialized.h.gcov voctorTest.cpp
stl_algobase.h.gcov stl_vector.h.gcov voctorTest.cpp.gcov
stl_alloc.h.gcov test voctorTest.da
[lixiang@localhost cjj]$ lcov -c -d ./ -o app.info
Capturing coverage data from ./
Found gcov version: 3.2.2
Scanning ./ for .da files ...
Found 1 data files in ./
Processing voctorTest.da
geninfo: WARNING: cannot find an entry for iostream.gcov in .bb file, skipping file!
geninfo: WARNING: cannot find an entry for new.gcov in .bb file, skipping file!
geninfo: WARNING: cannot find an entry for stl_algobase.h.gcov in .bb file, skipping file!
geninfo: WARNING: cannot find an entry for stl_alloc.h.gcov in .bb file, skipping file!
geninfo: WARNING: cannot find an entry for stl_construct.h.gcov in .bb file, skipping file!
geninfo: WARNING: cannot find an entry for stl_iterator.h.gcov in .bb file, skipping file!
geninfo: WARNING: cannot find an entry for stl_uninitialized.h.gcov in .bb file, skipping file!
geninfo: WARNING: cannot find an entry for stl_vector.h.gcov in .bb file, skipping file!
geninfo: WARNING: no data found for /usr/include/c++/3.2.2/iostream
geninfo: WARNING: no data found for /usr/include/c++/3.2.2/bits/stl_algobase.h
geninfo: WARNING: no data found for /usr/include/c++/3.2.2/bits/stl_vector.h
geninfo: WARNING: no data found for /usr/include/c++/3.2.2/bits/stl_alloc.h
geninfo: WARNING: no data found for /usr/include/c++/3.2.2/bits/stl_construct.h
geninfo: WARNING: no data found for /usr/include/c++/3.2.2/bits/stl_iterator.h
geninfo: WARNING: no data found for /usr/include/c++/3.2.2/bits/stl_uninitialized.h
geninfo: WARNING: no data found for /usr/include/c++/3.2.2/new
Finished .info-file creation
[lixiang@localhost cjj]$ ls
app.info test voctorTest.bbg voctorTest.da
ctest.c voctorTest.bb voctorTest.cpp
[lixiang@localhost cjj]$ cat app.info
TN:
SF:/home/lixiang/file/addpe/cjj/voctorTest.cpp
DA:5,1
DA:6,3
DA:7,1
DA:8,1
DA:9,1
DA:10,1
DA:11,1
DA:12,1
LF:8
LH:8
end_of_record
[lixiang@localhost cjj]$ genhtml app.info -o cc_result
Reading data file app.info
Found 1 entries.
Found common filename prefix "/home/lixiang/file/addpe"
Writing .css and .png files.
Generating output.
Processing file cjj/voctorTest.cpp
Writing directory view page.
Overall coverage rate:
lines......: 100.0% (8 of 8 lines)
functions..: no data found
[lixiang@localhost cjj]$

其中:

lcov:我想查看下LCov是否安装成功。(证明了在root下安装的软件可以在普通用户下使用。但是注意,我安装的时候用普通用户的保存的安装包好像有点问题。)

lcov -c -d ./ -o app.info:这条命令是创建覆盖率中间文件app.info 该文件可以用cat、vi查看。前提该文件夹下有gcov后缀的文件存在,即该文件是生成覆盖率信息的文件夹下。

genhtml app.info -o cc_result:通过lcov自带的genhtml转换为html文件并放在cc_result文件夹下。

获取到的覆盖率结果如下:

总结获取覆盖率步骤:

      1. 编译链接带覆盖率参数的源代码;

  2. 运行测试程序;

  3. 使用gcov获取文本形式的覆盖率数据;

  4. 使用lcov获取html形式的覆盖率数据;

参考了这篇文章:

http://blog.163.com/bobile45@126/blog/static/96061992201382025729313/

http://linux.ctocio.com.cn/85/12444085.shtml

  

Linux覆盖率一点研究:获取覆盖率数据的更多相关文章

  1. I.MX6 Android Linux shell MMPF0100 i2c 获取数据

    #!/system/bin/busybox ash # # I.MX6 Android Linux shell MMPF0100 i2c 获取数据 # 说明: # 本文主要记录通过shell脚本来获取 ...

  2. Linux中Curl命令couldn't connect to host解决方案 php操作Curl(http,https)无法获取远程数据解决方案

    本人在做百度账户第三方登录接口,获取百度token,利用php操作curl post方式发送请求token,出现couldn't connect to host错误.经过调试测试,最后终于成功.回头写 ...

  3. 室内定位系列(二)——仿真获取RSS数据

    很多情况下大家都采用实际测量的数据进行定位算法的性能分析和验证,但是实际测量的工作量太大.数据不全面.灵活性较小,采用仿真的方法获取RSS数据是另一种可供选择的方式.本文介绍射线跟踪技术的基本原理,以 ...

  4. Opencv+MFC获取摄像头数据,显示在Picture控件

    分为两步:OpenCV获取摄像头数据+图像在Picture上显示 第一步:OpenCV获取摄像头数据 参考:http://www.cnblogs.com/epirus/archive/2012/06/ ...

  5. JSONP 跨域请求 - 获取JSON数据

    如何用原生方式使用JSONP? 下边这一DEMO实际上是JSONP的简单表现形式,在客户端声明回调函数之后,客户端通过script标签向服务器跨域请求数据,然后服务端返回相应的数据并动态执行回调函数. ...

  6. C#开发微信门户及应用(14)-在微信菜单中采用重定向获取用户数据

    我曾经在系列文章中的<C#开发微信门户及应用(11)--微信菜单的多种表现方式介绍>中介绍了微信菜单里面的重定向操作,通过这个重定向操作,我们可以获取一个code值,然后获取用户的open ...

  7. linux c程序中获取shell脚本输出的实现方法

    linux c程序中获取shell脚本输出的实现方法 1. 前言Unix界有一句名言:“一行shell脚本胜过万行C程序”,虽然这句话有些夸张,但不可否认的是,借助脚本确实能够极大的简化一些编程工作. ...

  8. android—获取网络数据

    取网络数据主要靠发交易(或者说请求,接口等),而这些交易由java中的网络通信,HttpURLConnection和HttpClient实现,以下是具体例子.   大家都知道,网络通信,发送请求有两种 ...

  9. Jquery 模板插件 jquery.tmpl.js 的使用方法(1):基本语法,绑定,each循环,ajax获取json数据

    jquery.tmpl.js 是一个模板js  ,主要有2个方法 (1):$.template()方法,将一段script或者是Html编译为模板,例如 $.template('myTemplate' ...

随机推荐

  1. wind取交易日历n day数据

    days=AlldaysPeriod=Mw.tdaysoffset(5,'20171212','days=Tradingdays;Period=D')

  2. 把word文档中的所有图片导出

    把word文档中的所有图片导出 end

  3. python基础教程-第三章-使用字符串

    本章将会介绍如何使用字符串何世华其他的值(如打印特殊格式的字符串),并简单了解下利用字符串的分割.联接.搜索等方法能做些什么 3.1 基本字符串操作 所有标准的序列操作(索引.分片.乘法.判断成员资格 ...

  4. WebApi系列~基于RESTful标准的Web Api

    微软的web api是在vs2012上的mvc4项目绑定发行的,它提出的web api是完全基于RESTful标准的,完全不同于之前的(同是SOAP协议的)wcf和webService,它是简单,代码 ...

  5. github上面建立分支

    首先是有一个github的账户,然后随便开个项目. 好了,现在把git命令行打开,输入下面几行代码. git clone https://github.com/user/repository.git ...

  6. config配置文件的一些东西

    /* 模板相关配置 */ 'TMPL_PARSE_STRING' => array( '__STATIC__' => __ROOT__ . '/Public/static', '__ADD ...

  7. POJ 2229 Sumsets

    Sumsets Time Limit: 2000MS   Memory Limit: 200000K Total Submissions: 11892   Accepted: 4782 Descrip ...

  8. 使用Javascript中变量的setter属性

    在讲JDK的动态代理方法之前,不妨先想想如果让你来实现一个可以任意类的任意方法的代理类,该怎么实现?有个很naive的做法,通过反射获得Class和Method,再调用该方法,并且实现一些代理的方法. ...

  9. 使用VMware Workstation 12.5.2新建虚拟机

    关于VMware版本:VMware10可以支持32位和64位操作系统,VMware11及以上版本只能支持64位Win7及以上版本的操作系统!同时,VMware Workstation 10.0正式版发 ...

  10. Visro 应用的前端模板工具介绍 -JsRender

    1.什么是JsRender: JsRender是一款JavaScript模版引擎,是具有简单直观,功能强大,可扩展的,早期版本是基于JQUERY 写的,后来作者重构了,就不再依赖JQUERY了. 它的 ...