Multi-process coverage reports

755 views Asked by At

I am trying to monitor the code coverage of my C++ project. As I stated in a previous question, I need to use coroutines and other advanced C++2a features, so I am using clang++ to compile it. I found out here that one can use the -coverage flag when compiling with clang++ (along, obviously, with -O0 and -g).

Along with the executable file, this produces a .gcno file, containing the map of the executable. When the executable is ran, an additional .gcda file is generated, containing the actual profiling data.

I noticed that if I run the executable multiple times the coverage outputs are nicely and properly merged in the .gcda file, which is very good.

Now, I'm wondering if it's safe to run simultaneously multiple instances of the executable.

Before anyone suggests to run the test sequentially: I am running them sequentially, but my application uses a lot of networking, and some of the tests require multiple instances to communicate together (I am using Docker to simulate a network, and netem to get kind-of-realistic link scenarios).

Will running many instances of the same executable together cause any problem? I can imagine that if any locking mechanism is implemented, the coverage data will be safely and atomically written to the .gcda file, and if other executables need to perform the dump they'll wait until the lock is released. However, I couldn't find anywhere a guarantee that this actually happens.

1

There are 1 answers

0
Marco Castelluccio On

GCOV profiling should be multi-process safe since Clang 7.

In Clang 6 there were two bugs preventing it from working, https://bugs.llvm.org/show_bug.cgi?id=34923 and https://bugs.llvm.org/show_bug.cgi?id=35464, but they are now fixed.

Infact, we are currently using it to collect coverage data for Firefox, which is multiprocess. We both have multiple processes in Firefox itself, and we also run tests (for some specific test suites) in parallel.