27
Aug.2010
次序 代码 号令 时分 覆盖率 参数 分支 函数 新版 目次 次数 东西 消息 链接 文件 测试 不正 繁杂 语句 适宜 选项 上述 两个 时候 文档
GCOVJian∴Cha∴armlinuxDai∴Ma∴Fu∴Gai∴Lv壹! 对于gcov东西
gcov随同gcc 公布gcc编译参与-fprofile-arcs -ftest-coverage 参数天生贰进制次序递次!施行测试用例天生代码覆盖率消息
1!若何使用gcov
用GCC编译的时分加上-fprofile-arcs -ftest-coverage选项!链接的时分也加上
fprofile-arcs参数使gcc创立壹个次序递次的流!以后找到适宜的天生树只要不正在天生树中的弧被安排gcc增加了代码来盘点这些弧施行的次数当这段弧是壹个块的独壹出口或者出口时!安排东西代码
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 gt。gt。yourfilename!gcov tmp.c gt。gt。yourfilename
而这时候分的main.c.gcov!和tmp.c.gcov就包含了函数和代码施行次数的消息!我们能够检查结果
-: 65:/
-: 66: name : main
-: 67: return : 0 OK
-: 68: other ERROR
-: 69: history : 2006-06-13
-: 70: /
-: 71:int main / 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_name256 。
4: 80: char pwd = NULL 。
4: 81: char tmp = NULL 。
-: 82:
4: 83: if / file size larger than max size /
: 98: printf 。
: 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!分支测试
-c
Write branch frequencies as the number of branches taken! rather than the percentage of branches taken.
-v
Display the gcov version number .
//太繁杂了吧!我下面用了
-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.壹!对于gcov东西 gcov随同gcc 公布gcc编译参与-fprofile-arcs -ftest-coverage 参数天生贰进制次序递次!施
黑客资源网 http://www.hkzy.info
GCOVJian∴Cha∴armlinuxDai∴Ma∴Fu∴Gai∴Lv壹! 对于gcov东西
gcov随同gcc 公布gcc编译参与-fprofile-arcs -ftest-coverage 参数天生贰进制次序递次!施行测试用例天生代码覆盖率消息
1!若何使用gcov
用GCC编译的时分加上-fprofile-arcs -ftest-coverage选项!链接的时分也加上
fprofile-arcs参数使gcc创立壹个次序递次的流!以后找到适宜的天生树只要不正在天生树中的弧被安排gcc增加了代码来盘点这些弧施行的次数当这段弧是壹个块的独壹出口或者出口时!安排东西代码
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 gt。gt。yourfilename!gcov tmp.c gt。gt。yourfilename
而这时候分的main.c.gcov!和tmp.c.gcov就包含了函数和代码施行次数的消息!我们能够检查结果
-: 65:/
-: 66: name : main
-: 67: return : 0 OK
-: 68: other ERROR
-: 69: history : 2006-06-13
-: 70: /
-: 71:int main / 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_name256 。
4: 80: char pwd = NULL 。
4: 81: char tmp = NULL 。
-: 82:
4: 83: if / file size larger than max size /
: 98: printf 。
: 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!分支测试
-c
Write branch frequencies as the number of branches taken! rather than the percentage of branches taken.
-v
Display the gcov version number .
//太繁杂了吧!我下面用了
-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.壹!对于gcov东西 gcov随同gcc 公布gcc编译参与-fprofile-arcs -ftest-coverage 参数天生贰进制次序递次!施
黑客资源网 http://www.hkzy.info











协定Unix域socke
系统完美模拟vista界
