无论如何将两个gcov文件合并为一个

jim*_*wan 9 code-coverage gcov

我在macosx平台上使用gcov进行覆盖测试.我按设置完成了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"
Run Code Online (Sandbox Code Playgroud)

然后生成文件" 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. 有没有办法让我累积这些覆盖文件中的数据,以便我可以运行我的项目这么多次,然后在最后生成文件.
  2. 如果#1没有希望,你能告诉我如何将merge two Test.gcno文件(由两次"运行"生成)合二为一.我在终端尝试gcov,下面是gcov命令的选项:

    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>.
    
    Run Code Online (Sandbox Code Playgroud)

感谢您的所有帮助

小智 16

通常的工作流程gcov

  1. 编译并链接到覆盖支持(-fprofile-arcs -ftest-coverage)
  2. 可能使用不同的参数/设置多次运行您的可执行文件.这将在.gcda文件中创建累积使用信息
  3. 调用gcov以人类可读的格式获取覆盖率统计信息(.gcov)

所以基本上,应用程序的连续运行将导致累积的覆盖率统计.只是这些累积将发生在.gcda文件中,而不是.gcov文件中,因此gcov每次要查看更新的统计信息时都必须重新运行.