gcov tests code coverage during build or run?

Asked

Viewed 95 times

0

I read about gcov for the first time in the Tor documentation, what it says:

'-' before a line means
that the compiler generated no code for that line.  '######' means that the
line was never reached.  Lines with numbers were called that number of times.

There is not exactly a Tor test suite and, from the above description, it seems that gcov tests line coverage during compilation.

Other references I found on the gcov imply that it is used to detect which lines were hit during the run (either during normal use or by a test suite). But they don’t make that very clear. What, after all, is the function of gcov?

1 answer

1

gcov works by using instrumentalization of the code. For example: to check which functions are called, it adds code at the beginning of all functions to save the name of the function itself in a file. The same applies to any other measurement you want to make. At the time of code execution you will get a list of all functions called in the file.

It is done so because many analyses are very difficult or even impossible to perform statically (without executing the code). In particular on behalf of halting problem, any such analysis will be limited in some way. And in the particular case of gcov, he wants to locate parts of the code that are never executed. This is highly dependent on the input given in Runtime. Static analysis can divide the code into three groups only: will certainly be executed, will never be executed and may be executed. The last group can be eliminated in Runtime.

  • I understood the difference between what is possible between coverage check on Runtime vs statically, but which of the two does gcov?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.