gcov和lcov的对C++代码覆盖率生成以及与Hudson的集成

本文介绍了如何利用gcov和lcov工具进行C++代码覆盖率测试,并展示了在Hudson中执行shell脚本生成覆盖率报告的过程。首先,gcov作为GCC的配套工具用于测试代码覆盖率,而lcov作为gcov的图形前端,生成包含覆盖率信息的HTML源代码。接着,文章详细说明了lcov的安装步骤,并提供了在Hudson中构建项目时执行的三个命令,用于生成.info文件、合并信息并生成HTML报告。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Gcov - a Test Coverage Program

gcov is a tool you can use in conjunction with GCC to test code coverage in your programs. It’s no need to install independently. gcov works only on code compiled with GCC. It is not compatible with any other profiling or test coverage mechanism.

 Lcov - the LTP GCOV extension

LCOV is a graphical front-end for GCC's coverage testing tool gcov. It collects gcov data for multiple source files and creates HTML pages containing the source code annotated with coverage information. It also adds overview pages for easy navigation within the file structure. LCOV supports statement, function and branch coverage measurement.

Installing LCOV

The LCOV package is available as either RPM or tarball from:   http://ltp.sourceforge.net/coverage/lcov.php

I got lcov-1.9.tar.gz. To install the tarball, unpack it to a directory and run:

[root@Server lcov-1.9]# make install

 

Build -- Execute Shell in Hudson

Command 1

#generate .info file for test case codes

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib:/usr/lib64:/lib:/lib64:/usr/local/lib

cd ./client/testunit/lcov

make clean

make

./driver

gcov *.cpp *.h

lcov -d . -t 'driver' -o 'test.info' -b . -c

Command 2

#generate .info file for client codes

cd ./client/src/client

gcov *.cpp

lcov -d . -t '../../testunit/lcov/driver' -o 'client.info' -b . -c

Command 3

#merge the .info files and generate html report

cd ./client

lcov -add-tracefile  ./src/client/client.info -a ./testunit/lcov/test.info -o ./result.info

genhtml -o result result.info

#copy the html pages to apache web server, can be ignored the two lines

rm -rf /usr/local/apache2/htdocs/MPI/

cp -rf ./result /usr/local/apache2/htdocs/MPI/

 Post-build Actions

 

 Publish HTML reports 加入index.html的路径,如图所示

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值