2

How to get .gcda (gcov)/ coverage if the test run is infinitive or the test run is long and I would like to get temporary results? For example, I am interested in test coverage after 1 minute of execution.

gcc -I${PWD} -fprofile-arcs -O0 --coverage program.c -o test-coverage $ ./test-coverage Terminated: 15

If I terminate the process then .gcda wouldn't be created. Is any way to restore or get temporary values before process termination?

Alex Reinking
  • 16,724
  • 5
  • 52
  • 86

1 Answers1

1

You need to modify the program so that the coverage data is flushed.

The following is for gcc compiler and gcov.

// Reference: https://gcc.gnu.org/onlinedocs/gcc/Gcov-and-Optimization.html
// pre 11 gcc : extern "C" void __gcov_flush(void);
extern "C" void __gcov_dump(void);

[[noreturn]] void terminateHandler()
{
  __gcov_dump();
  std::abort();
}

In main():

  std::set_terminate(&terminateHandler);

Given you have to build for coverage you can conditionally compile the above code.

You may need to also link against the gcov library.

Damian Dixon
  • 889
  • 8
  • 21