gcc需要静态注入目标程序编译选项,在编译链接的时候加入2个选项(-ftest-coverage -fprofile-arcs ),编译结束之后会生成 .gcno 文件,而经过静态注入的目标程序在“正常结束”后,会在运行目录下产生.gcda数据文件,通过gcov工具就可产生覆盖率数据结果。
-
-ftest-coverage
Produce a notes file that the gcov code-coverage utility (see gcov—a Test Coverage Program) can use to show program coverage. Each source file’s note file is called auxname.gcno. Refer to the -fprofile-arcs option above for a description of auxname and instructions on how to generate test coverage data. Coverage data matches the source files more closely if you do not optimize.
让编译器生成与源代码同名的.gcno文件(note file),这种文件含有重建基本块依赖图和将源代码关联至基本块的必要信息。 -
-fprofile-arcs
Add code so that program flow arcs are instrumented. During execution the program records how many times each branch and call is executed and how many times it is taken or returns. When the compiled