LinuxCommandLibrary

lcov

Generate code coverage reports

SYNOPSIS

lcov [options]

PARAMETERS

--capture
    Capture coverage data. Requires additional options to specify where to capture data from.

--directory directory
    Specify the top-level source code directory.

--base-directory directory
    Base directory of the source code. Used to resolve relative paths.

--initial
    Capture initial zero coverage data for each function.

--zerocounters
    Resets all coverage counters to zero after capturing.

--output-file file
    Write data to file. (Default is stdout)

--extract info-file pattern
    Extract data from the specified info file which matches the given pattern.

--remove info-file pattern
    Remove data from the specified info file which matches the given pattern.

--list info-file
    List the content of the specified info file.

--info info-file
    Read coverage data from the specified info file.

--gcov-tool path
    Specify the path to the gcov tool. Useful when it is not in the system PATH

--compat-libtool
    Enable libtool compatibility mode.

--rc setting=value
    Override configuration file settings. See lcovrc(5) man page.

--version
    Show program version number and exit.

--help
    Show program usage information and exit.

DESCRIPTION

lcov is a command-line tool for collecting and processing code coverage data generated by the gcov tool (part of the GNU Compiler Collection). It allows developers to create HTML reports that visually represent which parts of their source code have been executed during testing.

It's typically used in conjunction with build systems and test suites to provide an overview of the effectiveness of tests. lcov can merge coverage data from multiple runs, filter out unwanted files or directories, and generate summaries that show the overall coverage percentage. The primary output is an info file that can then be used to generate HTML reports.

By examining these reports, developers can identify areas of code that are not being adequately tested and improve the test suite to achieve higher code coverage, leading to more robust software.

CAVEATS

lcov relies on the accuracy of the gcov data. Incorrect compiler flags or build configurations can lead to misleading coverage results.
It's crucial to ensure that debugging information (-g) is included during compilation to enable gcov to track line numbers.

CONFIGURATION

lcov behavior can be customized through a configuration file (lcovrc). This file allows specifying default directories, filtering patterns, and other settings to tailor the tool to specific project needs.
Example settings include defining the GCOV_PREFIX and GENHTML_OPTS.

INTEGRATION WITH BUILD SYSTEMS

lcov can be seamlessly integrated with build systems like Make, CMake, or Autotools. By adding lcov commands to the build process, coverage data can be automatically collected during testing. This enables continuous monitoring of code coverage with each build.

HISTORY

lcov was developed as a tool to facilitate code coverage analysis in Linux environments. It provides a higher-level interface to gcov, simplifying the process of collecting, merging, and visualizing coverage data. Its usage has become widespread in continuous integration and testing workflows to monitor and improve code quality.

SEE ALSO

gcov(1)

Copied to clipboard