【发布时间】:2021-09-09 03:46:21
【问题描述】:
共有三个文件u1.c、u2.c和common.c
ut1.c 的内容
#include<stdio.h>
void fun1();
int main(){
fun1();
}
ut2.c 的内容
#include<stdio.h>
void fun2();
int main(){
fun2();
}
common.c 的内容
void fun1(){
printf("fun1\n");
}
void fun2(){
printf("fun2\n");
}
编译步骤:-
gcc -Wall -fprofile-arcs -ftest-coverage ut1.c common.c -o ut1
gcc -Wall -fprofile-arcs -ftest-coverage ut2.c common.c -o ut2
执行步骤:-
./ut1
./ut2
现在在运行 gcov common.c 时,只会出现 fun2 覆盖范围。
-: 0:Source:common.c
-: 0:Graph:common.gcno
-: 0:Data:common.gcda
-: 0:Runs:1
-: 0:Programs:1
-: 1:void fun1(){
-: 2: printf("fun1\n");
-: 3:}
-: 4:
1: 5:void fun2(){
1: 6: printf("fun2\n");
1: 7:}
【问题讨论】:
标签: c unit-testing gcov lcov gcovr