Code coverage using gcov on parallel run

試著忘記壹切 提交于 2021-02-18 06:25:31

问题


I have C/C++ code coverage setup with gcov for several files in the project. The executables are being run in parallel. This results in some shared piece of code to be run in parallel.

I am getting corrupt .da files or zero sized .da files. Is this a problem on parallel run?

Because two or more executable instance is trying to write on the same .da file for writing the coverage count for each statement in execution?

If so, is there any workaround?

Gcov version being used is 1.5


回答1:


I had a similar need and I solved it by setting up the GCOV_PREFIX environment variable.

According to the documentation:

GCOV_PREFIX contains the prefix to add to the absolute paths in the object file. Prefix can be absolute, or relative. The default is no prefix.

Setting GCOV_PREFIX to a custom directory, unique for each executable+execution, will force the runtime to generate '.gcda' in the specified directory instead of using the compilation one (where the '.gcno' are).

Once all the executions completed you'll be able to use them to generate the merged-run report.




回答2:


Well it seems you have already figured the root cause of the problem and looking for the work around.
I have successfully configured few projects for code coverage with gcov.
I would like to clear few things for you:

  • we get .gcno files for each of the source files instrumented with --coverage option during compilation.
  • And at the time of execution we get .gcda files for each one of gcno files.

.gcno files are just flow charts structure of the relevant source code files.
.gcda files are the actual coverage data generated at the time of execution.

So, in your situation .gcda (used to be .da in earlier versions) are having conflicts when two or more execution tries to write the same .gcda file simultaneously.

Simplest work around would be running the tests serially. (At least that's what I did )
you don't need to worry about losing coverage data as .gcda gets appended with every execution and not overwritten. Keep this in mind that you don't have to do re-compilation because it would change the .gcno files and the .gcda files from before will become useless.



来源:https://stackoverflow.com/questions/14643589/code-coverage-using-gcov-on-parallel-run

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!