有没有办法将两个gcov文件合并成一个?

9

我正在使用gcov对macOS平台进行覆盖率测试。我通过设置完成了xcode的配置:

1. Build Settings ==> Generate Test Coverage Files == Yes
2. Build Settings ==> Instrument Progaram Flow == Yes
3. Build Phases ==> Link Binary with library ==> add "libprofile_rt.dylib"

然后生成文件 "Test.d, Test.dia, Test.gcno, Test.gcda, Test.o",然后我使用gcov-4.2 -b Test.gcno命令生成Test.m.gcov文件(这是我想要的),但下次再运行测试用例时,文件 "Test.d, Test.dia, Test.gcno, Test.gcda, Test.o" 将会重新生成,数据将被重置。
因此,我有两个问题:
  1. Is there any way for me to make the data in these coverage files accumulated so that i can run so many times of my project and then generate files at the end.
  2. If the #1 is hopeless, could you tell me how to merge two Test.gcno files (generated by two times' running) into one. I try gcov in terminal, below are the options for gcov command:

    gcov-4.2 -help
    Usage: gcov [OPTION]... SOURCEFILE
    
    Print code coverage information.
    
      -h, --help                      Print this help, then exit
      -v, --version                   Print version number, then exit
      -a, --all-blocks                Show information for every basic block
      -b, --branch-probabilities      Include branch probabilities in output
      -c, --branch-counts             Given counts of branches taken
                                        rather than percentages
      -n, --no-output                 Do not create an output file
      -l, --long-file-names           Use long output file names for included
                                        source files
      -f, --function-summaries        Output summaries for each function
      -o, --object-directory DIR|FILE Search for object files in DIR or called FILE
      -p, --preserve-paths            Preserve all pathname components
      -u, --unconditional-branches    Show unconditional branch counts too
    
    For bug reporting instructions, please see:
    <URL:http://developer.apple.com/bugreporter>.
    

提前感谢您的所有帮助。

以下是相关的IT技术翻译:

1个回答

22
gcov 的常规工作流程为:
  1. 使用覆盖支持(-fprofile-arcs -ftest-coverage)进行编译和链接
  2. 运行您的可执行文件,可能多次运行,可能使用不同的参数/设置。这将在 .gcda 文件中创建累积使用信息
  3. 调用 gcov 以获取人类可读格式的覆盖统计信息(.gcov
因此,应用程序的连续运行将导致累积的覆盖率统计信息。只是这些累加将发生在 .gcda 文件中,而不是 .gcov 文件中,因此每次想要查看更新的统计数据时都必须重新运行 gcov

如果在多个Docker容器中执行了多个测试,有没有办法获取组合和不同的覆盖率报告? - kaixin liu
你有找到任何方法可以获取在多个Docker容器中执行的组合覆盖率报告吗? - Jerry

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接