Skip to content

Commit

Permalink
Use fastcov to speed up coverage for CI (#2391)
Browse files Browse the repository at this point in the history
* Use fastcov
  • Loading branch information
ruffsl authored Jun 8, 2021
1 parent 980f8ec commit 2c9b2c9
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 49 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ _steps:
codecov_version=$(grep -o 'VERSION=\"[0-9\.]*\"' codecov | cut -d'"' -f2)
shasum -a 512 -c <(curl -s "https://raw.githubusercontent.com/codecov/codecov-bash/${codecov_version}/SHA512SUM" | grep -w "codecov")
bash codecov \
-f "lcov/project_coverage.info" \
-f "lcov/total_coverage.info" \
-R "src/navigation2" \
-F "project" \
-Z || echo 'Codecov upload failed'
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ RUN apt-get update && \
lcov \
python3-pip \
&& pip3 install \
fastcov \
git+https://github.com/ruffsl/colcon-cache.git@c1cedadc1ac6131fe825d075526ed4ae8e1b473c \
&& rosdep update \
&& rm -rf /var/lib/apt/lists/*
Expand Down
68 changes: 20 additions & 48 deletions tools/code_coverage_report.bash
Original file line number Diff line number Diff line change
Expand Up @@ -36,64 +36,36 @@ for opt in "$@" ; do
done

set -o xtrace
mkdir -p $LCOVDIR
mkdir -p ${LCOVDIR}

# Generate initial zero-coverage data.
# This adds files that were otherwise not run to the report
lcov --capture --initial \
--directory build \
--output-file ${LCOVDIR}/initial_coverage.info \
--rc lcov_branch_coverage=0
# Ignore certain packages:
# - messages, which are auto generated files
# - system tests, which are themselves all test artifacts
# - rviz plugins, which are not used for real navigation
INCLUDE_PACKAGES=$(
colcon list \
--paths-only \
--packages-ignore-regex \
".*_msgs" \
".*_tests" \
".*_rviz.*" \
| xargs)

# Capture executed code data.
lcov --capture \
--directory build \
--output-file ${LCOVDIR}/test_coverage.info \
--rc lcov_branch_coverage=0

# Combine the initial zero-coverage report with the executed lines report.
lcov \
--add-tracefile ${LCOVDIR}/initial_coverage.info \
--add-tracefile ${LCOVDIR}/test_coverage.info \
--output-file ${LCOVDIR}/full_coverage.info \
--rc lcov_branch_coverage=0

# Only include files that are within this workspace.
# (eg filter out stdio.h etc)
lcov \
--extract ${LCOVDIR}/full_coverage.info \
"${PWD}/*" \
--output-file ${LCOVDIR}/workspace_coverage.info \
--rc lcov_branch_coverage=0

# Remove files in the build subdirectory.
# Those are generated files (like messages, services, etc)
# And system tests, which are themselves all test artifacts
# And rviz plugins, which are not used for real navigation
lcov \
--remove ${LCOVDIR}/workspace_coverage.info \
"${PWD}/build/*" \
--remove ${LCOVDIR}/workspace_coverage.info \
"${PWD}/*/dwb_msgs/*" \
--remove ${LCOVDIR}/workspace_coverage.info \
"${PWD}/*/nav2_msgs/*" \
--remove ${LCOVDIR}/workspace_coverage.info \
"${PWD}/*/nav_2d_msgs/*" \
--remove ${LCOVDIR}/workspace_coverage.info \
"${PWD}/*/nav2_system_tests/*" \
--remove ${LCOVDIR}/workspace_coverage.info \
"${PWD}/*/nav2_rviz_plugins/*" \
--output-file ${LCOVDIR}/project_coverage.info \
--rc lcov_branch_coverage=0
fastcov \
-d build \
--exclude test/ \
--include $INCLUDE_PACKAGES \
--output ${LCOVDIR}/total_coverage.info --lcov

if [ $COVERAGE_REPORT_VIEW = codecovio ]; then
curl -s https://codecov.io/bash > codecov
codecov_version=$(grep -o 'VERSION=\"[0-9\.]*\"' codecov | cut -d'"' -f2)
shasum -a 512 -c <(curl -s "https://raw.githubusercontent.com/codecov/codecov-bash/${codecov_version}/SHA512SUM" | grep -w "codecov")
bash codecov \
-f ${LCOVDIR}/project_coverage.info \
-f ${LCOVDIR}/total_coverage.info \
-R src/navigation2
elif [ $COVERAGE_REPORT_VIEW = genhtml ]; then
genhtml ${LCOVDIR}/project_coverage.info \
genhtml ${LCOVDIR}/total_coverage.info \
--output-directory ${LCOVDIR}/html
fi

0 comments on commit 2c9b2c9

Please sign in to comment.