Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add codecov.io support #91

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
1c8ab53
add codecov.io support
Oct 31, 2019
3ff0dce
fixup! add codecov.io support
Oct 31, 2019
dbf01a5
fixup! add codecov.io support
Nov 2, 2019
2750095
fixup! add codecov.io support
Nov 5, 2019
f5e3725
cleanup (#1)
rhaschke Nov 9, 2019
4e9301b
code build support from ros package
tylerjw Nov 15, 2019
89c2671
travis test for code-coverage
tylerjw Nov 15, 2019
0581d2c
fixup! travis test for code-coverage
tylerjw Nov 15, 2019
93bb2a5
Update README.md
tylerjw Nov 15, 2019
a860246
Update README.md
tylerjw Nov 16, 2019
be93423
add support for TEST_WHITELIST
Nov 16, 2019
a95ddd7
fixup! add support for TEST_WHITELIST
Nov 16, 2019
21a7ecb
fixup! add support for TEST_WHITELIST
Nov 16, 2019
2448440
fixup! add support for TEST_WHITELIST
Nov 16, 2019
248c635
fixup! add support for TEST_WHITELIST
Nov 17, 2019
974df38
Update README.md
tylerjw Nov 17, 2019
522ed45
Update README.md
tylerjw Nov 17, 2019
5bd9305
make unit test cmake match example in README
Nov 17, 2019
bfe4b2f
respond to review
Nov 17, 2019
54b8ba0
add .codecov.yml back into readme
Nov 18, 2019
8515b98
Update test_pkgs/valid/CMakeLists.txt
tylerjw Nov 18, 2019
1b4273f
Update test_pkgs/valid/CMakeLists.txt
tylerjw Nov 18, 2019
28c9091
gcov ignore files in test directory
tylerjw Nov 19, 2019
098f5dd
remove codecov.yml instructions from README.md
tylerjw Nov 19, 2019
50302b7
test whitelist applied to build
tylerjw Nov 19, 2019
fa69f0a
fixup! test whitelist applied to build
tylerjw Nov 19, 2019
81bac21
redirect output of codecov script to avoid filling logs
Nov 20, 2019
7a6be1e
fixup! redirect output of codecov script to avoid filling logs
Nov 20, 2019
e370f5c
fixup! redirect output of codecov script to avoid filling logs
Nov 20, 2019
6d04961
set compile flag to improve ccache hit rate
Nov 20, 2019
949b5ed
add support for ccache enviroment variables
Nov 20, 2019
09db83a
reduce complexity of catkin build line
Nov 20, 2019
38e96b4
set ccache base dir
Nov 20, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ env:
- TEST=clang-format # check code formatting for compliance to .clang-format rules
- TEST=clang-tidy-fix # perform static code analysis and compliance check against .clang-tidy rules
- TEST=catkin_lint # perform catkin_lint checks
- TEST=code-coverage # perform code coverage report
# pull in packages from a local .rosinstall file
- UPSTREAM_WORKSPACE=moveit.rosinstall
# pull in packages from a remote .rosinstall file and run for a non-default ROS_DISTRO
Expand Down Expand Up @@ -143,3 +144,25 @@ It's also possible to run the script without using docker. To this end, issue th
export ROS_WS=/tmp/ros_ws # define a new ROS workspace location
mkdir $ROS_WS # and create it
.moveit_ci/travis.sh

## Enabling codecov.io reporting

For codecov to work you need to build and link your C++ code with specific parameters. To enable this we use the ROS package [code_coverage](https://github.com/mikeferguson/code_coverage). Using the `code-coverage` test in your repo requires the following two changes:

1. Add `<test_depend>code_coverage</test_depend>` to your package.xml
2. Add this to your `CMakeLists.txt`:

```cmake
# to run: catkin_make -DENABLE_COVERAGE_TESTING=ON package_name_coverage
if(CATKIN_ENABLE_TESTING AND ENABLE_COVERAGE_TESTING)
tylerjw marked this conversation as resolved.
Show resolved Hide resolved
find_package(code_coverage REQUIRED) # catkin package ros-*-code-coverage
include(CodeCoverage)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just released 0.3.0 with @rhaschke improvements - once that propagates through the build farm and gets sync'd you'll be able to drop this line

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which line? The find_package or the include? Can you link me to your changes?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The include -- see mikeferguson/code_coverage#15 for details (again, I just did the release, it's probably 2 weeks before it syncs all the way through the build farm).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, cool. Hopefully I'll get this merged quickly and then I can make a small PR to remove this line once your change propagates.

APPEND_COVERAGE_COMPILER_FLAGS()
set(COVERAGE_EXCLUDES "*/test/*")
tylerjw marked this conversation as resolved.
Show resolved Hide resolved
add_code_coverage(NAME ${PROJECT_NAME}_coverage)
tylerjw marked this conversation as resolved.
Show resolved Hide resolved
tylerjw marked this conversation as resolved.
Show resolved Hide resolved
endif()
```

Then you can use the `code-coverage` test and it will run the script provided by [codecov.io](codecov.io) which runs `gcov` to generate the reports and then compiles them into a report and uploads them to their servers.

If you are using this on a private github repo you will need to set the `CODECOV_TOKEN` enviroment variable in the `global` section of your `.travis.yml` file to the value you can find on the settings page of your project on codecov.io.
10 changes: 9 additions & 1 deletion test_pkgs/valid/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,14 @@ include_directories(
${catkin_INCLUDE_DIRS}
)

if(CATKIN_ENABLE_TESTING)
if (CATKIN_ENABLE_TESTING)
tylerjw marked this conversation as resolved.
Show resolved Hide resolved
catkin_add_gtest(${PROJECT_NAME} test.cpp)
endif()

# to run: catkin_make -DENABLE_COVERAGE_TESTING=ON package_name_coverage
tylerjw marked this conversation as resolved.
Show resolved Hide resolved
if(CATKIN_ENABLE_TESTING AND ENABLE_COVERAGE_TESTING)
find_package(code_coverage REQUIRED) # catkin package ros-*-code-coverage
tylerjw marked this conversation as resolved.
Show resolved Hide resolved
include(CodeCoverage)
APPEND_COVERAGE_COMPILER_FLAGS()
add_code_coverage(NAME ${PROJECT_NAME}_coverage)
tylerjw marked this conversation as resolved.
Show resolved Hide resolved
endif()
1 change: 1 addition & 0 deletions test_pkgs/valid/package.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

<buildtool_depend>catkin</buildtool_depend>
<test_depend>rosunit</test_depend>
<test_depend>code_coverage</test_depend>

<export>
</export>
Expand Down
21 changes: 21 additions & 0 deletions travis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ function docker_cp {
function run_docker() {
run_script BEFORE_DOCKER_SCRIPT

# get ci enviroment parameters to pass into docker for codecov
# this is a list of docker parameters to include enviroment variables
CI_ENV_PARAMS=`bash <(curl -s https://codecov.io/env)`
# The following two varaibles are needed for codecov to work locally
export ${VCS_BRANCH_NAME:=$(git rev-parse --abbrev-ref HEAD)}
export ${VCS_COMMIT_ID:=$(git rev-parse HEAD)}

# Choose the docker container to use
if [ -n "${ROS_REPO:=}" ] && [ -n "${DOCKER_IMAGE:=}" ]; then
echo -e $(colorize YELLOW "DOCKER_IMAGE=$DOCKER_IMAGE overrides ROS_REPO=$ROS_REPO setting")
Expand Down Expand Up @@ -79,12 +86,14 @@ function run_docker() {
-e TEST_PKG \
-e TEST \
-e TEST_BLACKLIST \
-e TEST_WHITELIST \
-e WARNINGS_OK \
-e ABI_BASE_URL \
-e CC=${CC_FOR_BUILD:-${CC:-cc}} \
-e CXX=${CXX_FOR_BUILD:-${CXX:-c++}} \
-e CFLAGS \
-e CXXFLAGS \
$CI_ENV_PARAMS \
-v $(pwd):/root/$REPOSITORY_NAME \
-v ${CCACHE_DIR:-$HOME/.ccache}:/root/.ccache \
-t \
Expand Down Expand Up @@ -167,6 +176,9 @@ function run_early_tests() {
abi) # abi-checker requires debug symbols
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug -DCMAKE_CXX_FLAGS_DEBUG=\"-g -Og\""
;;
code-coverage) # code coverage test requres specific compiler and linker arguments
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=Debug -DENABLE_COVERAGE_TESTING=ON"
;;
*)
echo -e $(colorize RED "Unknown TEST: $t")
EARLY_RESULT=$(( ${EARLY_RESULT:-0} + 1 ))
Expand Down Expand Up @@ -290,6 +302,12 @@ function test_workspace() {
echo -e $(colorize YELLOW Test blacklist: $(colorize THIN $TEST_BLACKLIST))
test -n "$TEST_BLACKLIST" && catkin config --blacklist $TEST_BLACKLIST &> /dev/null

# Consider TEST_WHITELIST
TEST_WHITELIST=$(unify_list " ,;" ${TEST_WHITELIST:-})
echo -e $(colorize YELLOW Test whitelist: $(colorize THIN $TEST_WHITELIST))
test -n "$TEST_WHITELIST" && catkin config --whitelist $TEST_WHITELIST &> /dev/null

tylerjw marked this conversation as resolved.
Show resolved Hide resolved

# Also blacklist external packages
local all_pkgs source_pkgs blacklist_pkgs
all_pkgs=$(catkin_topological_order $ROS_WS/src --only-names)
Expand Down Expand Up @@ -371,6 +389,9 @@ for t in $(unify_list " ,;" "$TEST") ; do
(source ${MOVEIT_CI_DIR}/check_abi.sh)
test $? -eq 0 || result=$(( ${result:-0} + 1 ))
;;
code-coverage)
travis_run --title "codecov.io report upload" bash <(curl -s https://codecov.io/bash) -s $ROS_WS -R $ROS_WS/src/$REPOSITORY_NAME
;;
esac
done
# Run warnings check
Expand Down
6 changes: 5 additions & 1 deletion unit_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ rosdep() {
echo "Dummy rosdep $*"
}

all_groups="sanity warnings catkin_lint clang-format clang-tidy-fix clang-tidy-check"
all_groups="sanity warnings catkin_lint clang-format clang-tidy-fix clang-tidy-check code-coverage"
skip_groups="${SKIP:-}"
# process options
while true ; do
Expand Down Expand Up @@ -120,6 +120,10 @@ for group in $test_groups ; do
run_test 0 $0:$LINENO "clang-tidy-check on 'valid' package, warnings forbidden" TEST_PKG=valid TEST=clang-tidy-check WARNINGS_OK=false
run_test 1 $0:$LINENO "clang-tidy-check on 'clang_tidy' package, warnings forbidden" TEST_PKG=clang_tidy TEST=clang-tidy-check WARNINGS_OK=false
;;
code-coverage)
run_test 0 $0:$LINENO "code-coverage on 'valid' package, warnings forbidden" TEST_PKG=valid TEST=code-coverage WARNINGS_OK=false
run_test 1 $0:$LINENO "code-coverage on 'warnings' package, warnings forbidden" TEST_PKG=warnings TEST=code-coverage WARNINGS_OK=false
;;
*) echo -e $(colorize YELLOW "Unknown test group '$group'.")
echo "Known groups are: $all_groups" ;;
esac
Expand Down