如何使用GCOV计算核心C程序的测试柜的代码覆盖范围?
C程序包含一个.c和.h文件。
当C程序编译并运行时,它询问命令行输入(该程序继续要求输入,直到用户输入“再见”并单击Enter)。
测试柜包括大量和.out格式文件。
.in文件是命令行的输入,.out文件是程序的输出。
我有运行.in格式文件的.sh文件,并将输出与.out格式文件进行比较。我的测试用例(.in,.out文件)位于一个称为“ tests”的文件夹中。
我发现在GCOV中使用的参数无法使用.sh格式文件。
我不知道如何计算我的测试柜的代码覆盖范围,并找到我的测试柜未涵盖哪些代码行?
The C program comprises a .c and .h files.
When the C program compiles and runs, it asks command line input(the program continues ask for input until user enter "bye" and click enter).
The testcases includes lots of .in and .out format files.
The .in file is the input of command line,.out file is the output of the program.
I have the .sh file that runs the .in format file and compare output with .out format file.My test cases(.in,.out files) are in a folder called "tests".
I found the argument that use in gcov can't use the .sh format file.
I wonder how to calculate the code coverage of my testcases and find which lines of code are not covered by my testcases?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以简单地添加测试覆盖率:
在编译选项中,添加
-fprofile-arcs -ftest-coverage
。这样,生成的可执行程序每次调用时都会生成统计信息(在.gcno
/.gcda
文件中)。执行
.sh
测试文件要求
gcov
生成统计文件:输入gcov -m *.c
,这将产生.c.gcov
包含覆盖率测试结果的文件。例如,我们可以创建以下程序并测试它。
结果文件将是:
You can add test coverage simply:
In your compilation option, add
-fprofile-arcs -ftest-coverage
. That way, the produced executable program produce statistics each times it is called (in.gcno
/.gcda
files).Execute you
.sh
test fileAsk
gcov
to generate statistics files: typegcov -m *.c
, that will produce.c.gcov
files containing the coverage test results.For instance, We can create the following program and test it.
The result file will be: