2
votes

I am using gcov for a c++ test executable that spawns a child process. The child process contains a shared object library.The test process, child process, and the shared object library are all compiled in separate directories. I am using the -fprofile-arcs -ftest-coverage flags for compilation and linking. When I compile, I get .gcno files for the child process and the shared library. But when I run the executable, I am only able to get coverage output for the parent process.

My question is, are there any special steps to getting coverage of this child process with its shared library?

The gcc help forum question here (regarding gcov with shared object libraries) explains that the shared library must be built in the same directory as the one you are running your executable.

Does this mean that in order to get test coverage, I must compile every component(parent test process, child process, and shared object library) in the same directory?

1

1 Answers

0
votes

Here's what I did to get gcov working ...

  1. I compiled the shared object library and the two executables in their respective directories, and I made sure to use the flags when compiling and linking them(-fprofile-arcs -ftest-coverage). The location of these binaries turned out to not be important. What was important was using the flags, which allows for gcc to instrument the code.

  2. I copied the resulting .so, and two executables to a directory.

  3. I then ran the test executable, which started(forked) the other(child) executable which linked to the shared object library.

  4. As a result of running the executable, a .gcno file was produced for each .cpp. Each .gcno file was located in the same location as its corresponding .cpp file.

  5. Then I ran "gcov *.cpp" on the source files I wanted code coverage for.

  6. Executing Step 5 results in one .gcda file for each .cpp that I ran gcov on. These are the actual files that show the code coverage. Open them up in your favorite editor and view away.