How to make gcov retrieve data even when a program is interrupted

I use a test tool called KLEE, which creates a lot of tests for my C99 code. Subsequently, I run the tests and check the line coverage with gcov. Gcov seems to update coverage data at the end of execution on success.

However, some tests fail (they claim statements that are not true), which leads to the interruption of the program and gcov, not counting the lines included in this run.

Is there a way that gcov clears information from any output (not just successful)?

+7
source share
1 answer

Call void __gcov_flush(void) (from libgcov.a linked using the -fprofile-arcs compiler option) in your assert code before killing and applying (for example, change abort(); to __gcov_flush();abort(); ). This will call the gcov_exit function (it is statically defined in libgcov). gcov_exit are the main functions for saving collected coverage to a file. It is registered __gcov_init with atfork() ; and your statement ignores the attack when killing the application.

Another way to resolve this issue is to find out why your statement ignores atfork() -registered functions.

+7
source

All Articles