gcc 中参数-ftest-coverage -fprofile-arcs 使用
2014-08-26 15:00
204 查看
利用gcov检测覆盖率
例子:
#include <stdio.h>
int _abs(int a)
{
if (a < 0) {
a = 0-a;
}
return a;
}
int _max(int a, int b)
{
int max = a;
if (a < b) {
max = b;
}
return max;
}
void sort( int list[], int size)
{
int i, j, temp, swap = 1;
while (swap) {
swap = 0;
for ( i = (size-1) ; i >= 0 ; i-- ) {
for ( j = 1 ; j <= i ; j++ ) {
if ( list[j-1] > list[j] ) {
temp = list[j-1];
list[j-1] = list[j];
list[j] = temp;
swap = 1;
}
}
}
}
}
int main()
{
int x = 4;
int a = 15,b = 20;
int theList[10]={10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
int i;
sort( theList, 10 );
for (i = 0 ; i < 10 ; i++) {
printf("%d\n", theList[i]);
}
printf("Hello Ubuntu!!\n");
printf("abs(%d) is %d\n",x,_abs(x));
printf("max(%d,%d) is %d\n",a,b,_max(a,b));
return 0;
}
编译
gcc -fprofile-arcs -ftest-coverage Hello.c
运行:
./a
1
2
3
4
5
6
7
8
9
10
Hello Ubuntu!!
abs(4) is 4
max(15,20) is 20
$ gcov -b Hello.c
File 'Hello.c'
Lines executed:96.88% of 32
Branches executed:100.00% of 14
Taken at least once:85.71% of 14
Calls executed:100.00% of 7
Creating 'Hello.c.gcov'
$ gcov Hello.c
File 'Hello.c'
Lines executed:96.88% of 32
Creating 'Hello.c.gcov'
以上是执行的效果,自己作为以后查看备份在这里。
例子:
#include <stdio.h>
int _abs(int a)
{
if (a < 0) {
a = 0-a;
}
return a;
}
int _max(int a, int b)
{
int max = a;
if (a < b) {
max = b;
}
return max;
}
void sort( int list[], int size)
{
int i, j, temp, swap = 1;
while (swap) {
swap = 0;
for ( i = (size-1) ; i >= 0 ; i-- ) {
for ( j = 1 ; j <= i ; j++ ) {
if ( list[j-1] > list[j] ) {
temp = list[j-1];
list[j-1] = list[j];
list[j] = temp;
swap = 1;
}
}
}
}
}
int main()
{
int x = 4;
int a = 15,b = 20;
int theList[10]={10, 9, 8, 7, 6, 5, 4, 3, 2, 1};
int i;
sort( theList, 10 );
for (i = 0 ; i < 10 ; i++) {
printf("%d\n", theList[i]);
}
printf("Hello Ubuntu!!\n");
printf("abs(%d) is %d\n",x,_abs(x));
printf("max(%d,%d) is %d\n",a,b,_max(a,b));
return 0;
}
编译
gcc -fprofile-arcs -ftest-coverage Hello.c
运行:
./a
1
2
3
4
5
6
7
8
9
10
Hello Ubuntu!!
abs(4) is 4
max(15,20) is 20
$ gcov -b Hello.c
File 'Hello.c'
Lines executed:96.88% of 32
Branches executed:100.00% of 14
Taken at least once:85.71% of 14
Calls executed:100.00% of 7
Creating 'Hello.c.gcov'
$ gcov Hello.c
File 'Hello.c'
Lines executed:96.88% of 32
Creating 'Hello.c.gcov'
以上是执行的效果,自己作为以后查看备份在这里。
相关文章推荐
- gcc 参数 -fprofile-arcs -ftest-coverage作用
- gcc 参数 -fprofile-arcs -ftest-coverage作用
- [转]GCC使用指南及gcc最佳编译参数
- 转载:QTP的Test参数以及顶级Action参数的使用
- arm-linux-gcc 常用参数讲解 gcc编译器使用方法
- 关于GCC中同时使用动态和静态库链接的操作参数和解释
- 使用gcc编译时,头文件和库的位置指定参数
- 小议Test-Path参数IsVaild的使用限制
- GCC中同时使用动态和静态库链接的操作参数
- arm-linux-gcc 常用参数讲解 gcc编译器使用方法
- arm-linux-gcc 常用参数讲解 gcc编译器使用方法
- 使用libdwraf写的一个读取GCC -g参数编译生成的调试信息的例子
- gcc coverage test tool: gcov
- Gcc中使用profile工具优化代码
- QTP的Test参数以及顶级Action参数的使用
- 转:关于GCC中同时使用动态和静态库链接的操作参数和解释
- gcc 参数使用实例
- 转:关于GCC中同时使用动态和静态库链接的操作参数和解释
- gcc命令中参数c和o混合使用的详解
- gcc 使用中常用的参数及命令