Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to force gcov to extract data, even when program is aborted

Tags:

c

gcov

klee

I'm using a test-generating tool called KLEE, that creates lots of tests for my C99-Code. Afterwards I run the tests and check line coverage with gcov. Gcov seems to update coverage data at the end of the run upon successful completion.

However, some tests fail (assert statements that are not true), which leads to aborting the program and gcov not counting the lines covered in this run.

Is there any way that gcov flushes information on any exit (not only on successful)?

like image 529
Henning Avatar asked Jul 14 '11 20:07

Henning


1 Answers

Call void __gcov_flush(void) (from libgcov.a which is linked in by -fprofile-arcs option of compiler) in your assert code, just before killing and application (e.g. change abort(); into __gcov_flush();abort();). This one will call an gcov_exit function (it is statically defined in libgcov). gcov_exit is the main functions to save collected coverage into file. It is registered by __gcov_init with atfork(); and your assert ignores atfork when kills an application.

Another way of solving this is to find why your assert ignores atfork()-registered functions.

like image 120
osgx Avatar answered Nov 07 '22 13:11

osgx