We have a large body of C/C++ code that is cross-compiled for an embedded Linux target. We've recently begun implementing unit tests (using gmock/gtest) that are run on our development server (which is Linux as well). The unit tests are executed automatically when check-ins are detected (we're using Microsoft Azure pipeline).
We're using gcov and lcov to analyze & report code coverage during those unit tests, which has worked out fairly well. However, given that we didn't start out unit testing, a large portion of our codebase is not covered by unit tests. An interesting metric beyond "what is the unit test coverage for those files being unit tested" is "how much of our entire codebase is being covered by unit tests", which includes those files not currently being unit tested. With gcov, you need to actually compile & link a given source file and then execute the resulting program to get the possible coverage data for that file.
I have used the following script but it generates report for the classes that has unit test.:
# Get the path to the current folder
SCRIPT_DIR=$(pwd)
# SRC_DIR is the directory containing the .gcno files (%{buildDir} in Qt Creator)
SRC_DIR="$SCRIPT_DIR/../../build-KEBPLCComService-Desktop-Debug/"
# COV_DIR is the directory where the coverage results will be stored
COV_DIR="$SCRIPT_DIR/../coverage"
############################################################################################################
# Path where the HTML files should be saved
HTML_RESULTS="${COV_DIR}""/html"
# Create the html folder if it does not exists
mkdir -p ${HTML_RESULTS}
# Generate our initial info
lcov -d "${SRC_DIR}" -c -o "${COV_DIR}/coverage.info"
# Remove some paths/files which we don't want to calculate the code coverage (e.g. third party libraries) and generate a new coverage file filtered (feel free to edit it when necessary)
lcov -r "${COV_DIR}/coverage.info" "*Qt*.framework*" "*.h" "*/tests/*" "*Xcode.app*" "*.moc" "*moc_*.cpp" "*/test/*" "*/build*/*" -o "${COV_DIR}/coverage-filtered.info"
# Generate the HTML files
genhtml -o "${HTML_RESULTS}" "${COV_DIR}/coverage-filtered.info"
# Reset our counts
lcov -d "${COV_DIR}" -z
# Open the index.html
firefox "${HTML_RESULTS}/index.html"
How can i get code coverage for entire codebase?