Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I tell gcov to ignore un-hittable lines of C++ code?

I'm using gcov to measure coverage in my C++ code. I'd like to get to 100% coverage, but am hampered by the fact that there are some lines of code that are theoretically un-hittable (methods that are required to be implemented but which are never called, default branches of switch statements, etc.). Each of these branches contains an assert( false ); statement, but gcov still marks them as un-hit.

I'd like to be able to tell gcov to ignore these branches. Is there any way to give gcov that information -- by annotating the source code, or by any other mechanism?

like image 430
jchl Avatar asked Aug 24 '10 09:08

jchl


People also ask

What is GCOV code coverage?

Gcov is a source code coverage analysis and statement-by-statement profiling tool. Gcov generates exact counts of the number of times each statement in a program is executed and annotates source code to add instrumentation. Gcov comes as a standard utility with the GNU Compiler Collection (GCC) suite.

What is LCOV?

LCOV is a graphical tool for GCC's coverage testing with gcov. It creates HTML pages containing the source code annotated with coverage information by collecting gcov data from multiple source files.

What are branches in GCOV?

The "Branch" column shows the branches that have been executed (✔) or skipped (x). This corresponds to the entries in the GCOV file. The "Exec" column shows how often a certain line has been executed. The "Source" column shows the actual source code.


1 Answers

Please use lcov. It hides gcov's complexity, produces nice output, allows detailed output per test, features easy file filtering and - ta-taa - line markers for already reviewed lines:

From geninfo(1):

The following markers are recognized by geninfo:

  • LCOV_EXCL_LINE
    • Lines containing this marker will be excluded.
  • LCOV_EXCL_START
    • Marks the beginning of an excluded section. The current line is part of this section.
  • LCOV_EXCL_STOP
    • Marks the end of an excluded section. The current line not part of this section.
like image 58
Torsten Scheck Avatar answered Oct 04 '22 13:10

Torsten Scheck