zoukankan      html  css  js  c++  java
  • 覆盖率測试工具gcov的前端工具_LCOV_简单介绍

    1、Gcov是进行代码运行的覆盖率统计的工具。它随着gcc的公布一起公布的,它的使用也非常easy,须要在编译和链接的时候加上-fprofile-arcs -ftest-coverage生成二进制文件,gcov主要使用.gcno和.gcda两个文件。.gcno是由-ftest-coverage产生的。它包括了重建基本块图和对应的块的源代码的行号的信息。

    .gcda是由加了-fprofile-arcs编译參数的编译后的文件运行所产生的。它包括了弧跳变的次数和其它的概要信息。gcda文件的生成须要先运行可运行文件才干生成。

    生成gcda文件之后运行命令gcov *.cpp就会在屏幕上打印出測试的覆盖率。并同一时候生成文件“*cpp.gcov”,然后用vi打开就能够看见哪行被覆盖掉了。

     

    2、lcov的安装非常easy,下载源代码运行make install就能够了,在生成的“*.cpp.gcov"文件里运行lcov --directory  .   --capture --output-file app.info生成info文件。再运行genhtml  -o  results  app.info就会生成result文件夹。生成的html文件就在result文件夹下。

    ___________________________

    http://www.linuxidc.com/Linux/2011-05/36544.htm

    Content

    1. Lcov是什么?

    2. 怎样在Linux平台安装Lcov?

    3. 怎样使用Lcov?

    (1) 使用lcov收集覆盖率数据并写入文件

    (2) 使用genhtml生成基于HTML的输出

    (3) 该样例的图形显示

    4. 编译lcov自带样例

    5. 其它相关工具

    (1) gcov-dump

    (2) ggcov

     

     

    1. Lcov是什么?


    是GCOV图形化的前端工具
    是Linux Test Project维护的开放源代码工具,最初被设计用来支持Linux内核覆盖率的度量
    基于Html输出。并生成一棵完整的HTML树
    输出包括概述、覆盖率百分比、图表。能高速浏览覆盖率数据
    支持大项目,提供三个级别的视图:文件夹视图、文件视图、源代码视图

    Use lcov to collect coverage data and genhtml to create HTML pages. Coverage data can either be collected from the currently running Linux kernel or from a user space application. To do this, you  have  to  complete the following preparation steps:

     

    For Linux kernel coverage:

      Follow  the setup instructions for the gcov-kernel infrastructure:

    http://ltp.sourceforge.net/coverage/gcov.php

     

    For user space application coverage:

      Compile the application with GCC using the options "-fprofile-arcs" and "-ftest-coverage".

     

    2. 怎样在Linux平台安装Lcov?

    # wget http://downloads.sourceforge.net/ltp/lcov-1.9.tar.gz

    # tar -zxvf lcov-1.9.tar.gz

    # cd lcov-1.9

    # ls

    bin      contrib  descriptions.tests  lcovrc    man     rpm

    CHANGES  COPYING  example             Makefile  README

    # make install

    不须要编译,直接安装就可以,lcov, gendesc, genhtml, geninfo, genpng将被安装到/usr/bin文件夹。

     

    3. 怎样使用Lcov?

     

    以Linux平台代码覆盖率測试工具GCOV简单介绍一文的样例为例。

     

    (1) 使用lcov收集覆盖率数据并写入文件 

    # lcov --capture --directory . --output-file test.info --test-name test

    Capturing coverage data from .

    Found gcov version: 4.1.2

    Scanning . for .gcda files ...

    Found 1 data files in .

    Processing test.gcda

    Finished .info-file creation

    .表示当前文件夹,收集coverage data,即.gcda文件里的信息,并写入test.info文件,且取名为test

    其它选项请參考lcov的manual页。

     

    test.info文件内容例如以下。

    TN:test

    SF:/home/zubo/gcc/2011-04-10.sample/test.c

    FN:4,main

    FNDA:1,main

    FNF:1

    FNH:1

    BRDA:9,2,0,10

    BRDA:9,2,1,1

    BRDA:12,0,0,0

    BRDA:12,0,1,1

    BRF:4

    BRH:3

    DA:4,1

    DA:7,1

    DA:9,11

    DA:10,10

    DA:12,1

    DA:13,0

    DA:15,1

    DA:16,1

    LF:8

    LH:7

    end_of_record

    (2) 使用genhtml生成基于HTML的输出


    # genhtml test.info --output-directory output --title "a simple test" --show-details --legend

    Reading data file test.info

    Found 1 entries.

    Found common filename prefix "/home/zubo"

    Writing .css and .png files.

    Generating output.

    Processing file gcc/2011-04-10.sample/test.c

    Writing directory view page.

    Overall coverage rate:

      lines......: 87.5% (7 of 8 lines)

      functions..: 100.0% (1 of 1 function)

      branches...: 75.0% (3 of 4 branches)

    选项解释请參考genhtml的manual页。cd到output文件夹。能够看到。生成了非常多相关文件,例如以下。


    # cd output

    # ls

    amber.png    gcov.css    index-sort-b.html  ruby.png

    emerald.png  glass.png   index-sort-f.html  snow.png

    gcc          index.html  index-sort-l.html  updown.png

    (3) 该样例的图形显示

     

    (3.1) top level的视图

     

     

    (3.2) 文件或函数的视图

     

    4. 编译lcov自带样例

     

    # cd /usr/src/lcov-1.9/example

    # make

     

    编译、运行自带样例并查看结果是高速学习某个工具最好的方法。

    从example的makefile文件和编译输出,都能够学习相关概念和命令的用法。Html输出能够由/usr/src/lcov-1.9/example/output/index.html查看。

    读者可自行实验。


  • 相关阅读:
    Java集合——Map接口
    Django 创建一个返回当前时间的页面
    python 练习 后台返回当前时间
    python 练习 simple_server 判断路径及返回函数
    通过 docker 来搭建 Jenkins
    Bitbucket 触发内网 Jenkins Build
    jQuery 扩展方法
    HTML 练习滑动
    HTML 练习淡入淡出
    HTML 练习显示隐藏
  • 原文地址:https://www.cnblogs.com/jzssuanfa/p/7080754.html
Copyright © 2011-2022 走看看