I'm not too strong with using lcov and shell scripting so it's a learning process for me. I understand the basics of making a code coverage report but I don't know the line of code to exclude certain directories. In a shell executable file I wrote the following code:
#!/bin/sh
ROOT_DIR=$1
DEST_DIR=$2
TARGET_DIR=$3
TARGET=$4
#init lcov
lcov -c -i -d $TARGET_DIR/.. -o $TARGET_DIR/cov_init.info
#run unit test executable
"$DEST_DIR/$TARGET"
#capture coverage after running executable
lcov -c -d $TARGET_DIR/.. -o $TARGET_DIR/cov_test.info
#I added this in-generate delta of coverage
lcov -a $TARGET_DIR/cov_init.info -a $TARGET_DIR/cov_test.info -o $TARGET_DIR/cov.info
# I added this in- Excludes some third party code
lcov --remove $TARGET_DIR/cov.info '/opt/*' '/usr/*' '$ROOT_DIR/Common?ExternalLibraries/*'
#I added this in-generate report
genhtml $TARGET_DIR/cov.info --ignore-errors source --output-directory $DEST_DIR/CoverageReport/$TARGET
xdg-open $DEST_DIR/CoverageReport/$TARGET/index.html &
I'm pretty sure I need to exclude the directories before I capture the coverage after running executable.