forked from dejaniraai/packml_ros2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtravis_2.sh
executable file
·284 lines (233 loc) · 11.8 KB
/
travis_2.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#!/bin/bash
# -*- indent-tabs-mode: nil -*-
export ROS_CI_DIR=$(dirname ${BASH_SOURCE:-$0}) #path to directory running the current script
export REPOSITORY_NAME=$(basename $PWD) #name of repository to test
export ROS_WS=${ROS_WS:-/root/ros_ws} #location of workspace
ROS_CI_TRAVIS_TIMEOUT=${ROS_CI_TRAVIS_TIMEOUT:-47} #50 minutes minus safety margin
#Loading helper functions
source ${ROS_CI_DIR}/util.sh
#Colcon output handling
COLCON_EVENT_HANDLING="--event-handlers desktop_notification- status-"
function update_system() {
travis_fold start update "Updating system packages"
# Update the sources
travis_run apt-get -qq update
# Make sure the packages are up-to-date
travis_run apt-get -qq dist-upgrade
# Make sure autoconf is installed and python3-lxml for the tests
travis_run apt-get -qq install -y autoconf python3-lxml
# Install wstool and wget
travis_run apt-get -qq install -y python-wstool wget
# Install extra dependencies for particular package to compile
echo -e $(colorize BLUE Installing custom dependencies for this package)
travis_run ./extra_dependencies.sh
# Install clang-tidy stuff if needed
[[ "$TEST" == *clang-tidy* ]] && travis_run apt-get -qq install -y clang-tidy
# run-clang-tidy is part of clang-tools in Bionic, but not in Xenial -> ignore failure
[ "$TEST" == *clang-tidy-fix* ] && travis_run_true apt-get -qq install -y clang-tools
# Install abi-compliance-checker if needed
[[ "$TEST" == *abi* ]] && travis_run_true apt-get -qq install -y abi-dumper abi-compliance-checker links
# Enable ccache
travis_run apt-get -qq install ccache
export PATH=/usr/lib/ccache:$PATH
# Setup rosdep - note: "rosdep init" is already setup in base ROS Docker image
travis_run rosdep update
travis_fold end update
}
function prepare_or_run_early_tests() {
# Check for different tests. clang-format and ament_lint will trigger an early exit
# However, they can only run when $CI_SOURCE_PATH is already available. If not try later again.
if ! [ -d "$CI_SOURCE_PATH" ] ; then return 0; fi
# EARLY_RESULT="" -> no early exit, EARLY_RESULT=0 -> early success, otherwise early failure
local EARLY_RESULT
for t in $(unify_list " ,;" "$TEST") ; do
case "$t" in
clang-format)
(source ${ROS_CI_DIR}/check_clang_format.sh) # run in subshell to not exit
EARLY_RESULT=$(( ${EARLY_RESULT:-0} + $? ))
;;
ament_lint)
(source ${ROS_CI_DIR}/check_ament_lint.sh) # run in subshell to not exit
EARLY_RESULT=$(( ${EARLY_RESULT:-0} + $? ))
;;
clang-tidy-check) # run clang-tidy along with compiler and report warning
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_CXX_CLANG_TIDY=clang-tidy"
;;
clang-tidy-fix) # run clang-tidy -fix and report code changes in the end
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_EXPORT_COMPILE_COMMANDS=ON"
;;
abi) # abi-checker requires debug symbols
CMAKE_ARGS="$CMAKE_ARGS -DCMAKE_BUILD_TYPE=RelWithDebInfo"
;;
*)
echo -e $(colorize RED "Unknown TEST: $t")
EARLY_RESULT=$(( ${EARLY_RESULT:-0} + 1 ))
;;
esac
done
test -n "$EARLY_RESULT" && exit $EARLY_RESULT
}
# Install and run xvfb to allow for X11-based unittests on DISPLAY :99
function run_xvfb() {
travis_fold start xvfb "Starting virtual X11 server to allow for X11-based unit tests"
travis_run apt-get -qq install xvfb mesa-utils
travis_run "Xvfb -screen 0 640x480x24 :99 &"
export DISPLAY=:99.0
travis_run_true glxinfo -B
travis_fold end xvfb
}
function prepare_ros_workspace() {
travis_fold start ros.ws "Setting up ROS workspace"
travis_run_simple mkdir -p $ROS_WS/src
travis_run_simple cd $ROS_WS/src
# Pull additional packages into the ros workspace
travis_run wstool init .
for item in $(unify_list " ,;" ${UPSTREAM_WORKSPACE:-debian}) ; do
echo "Adding $item"
case "$item" in
debian)
echo "Obtaining debian packages for all upstream dependencies."
break ;;
https://github.com/*) # clone from github
# extract url and optional branch from item=<url>#<branch>
item="${item}#"
url=${item%%#*}
branch=${item#*#}; branch=${branch%#}; branch=${branch:+--branch ${branch}}
travis_run_true git clone -q --depth 1 $branch $url
test $? -ne 0 && echo -e "$(colorize RED Failed clone repository. Aborting.)" && exit 2
continue ;;
http://* | https://* | file://*) ;; # use url as is
*) item="file://$CI_SOURCE_PATH/$item" ;; # turn into proper url
esac
travis_run_true wstool merge -k $item
test $? -ne 0 && echo -e "$(colorize RED Failed to find rosinstall file. Aborting.)" && exit 2
done
# Download upstream packages into workspace
if [ -e .rosinstall ]; then
# ensure that the to-be-tested package is not in .rosinstall
travis_run_true wstool rm $REPOSITORY_NAME
# perform shallow checkout: only possible with wstool init
travis_run_simple mv .rosinstall rosinstall
travis_run cat rosinstall
travis_run wstool init --shallow . rosinstall
fi
# Link in the repo we are testing
if [ "$(dirname $CI_SOURCE_PATH)" != $PWD ] ; then
travis_run_simple --title "Symlinking to-be-tested repo $CI_SOURCE_PATH into ROS workspace" ln -s $CI_SOURCE_PATH .
fi
# Fetch clang-tidy configs
if [ "$TEST" == clang-tidy-check ] ; then
# clang-tidy-check essentially runs during the build process for *all* packages.
# However, we only want to check one repository ($CI_SOURCE_PATH).
# Thus, we provide a dummy .clang-tidy config file as a fallback for the whole workspace
travis_run_simple --no-assert cp $ROS_CI_DIR/.dummy-clang-tidy $ROS_WS/src/.clang-tidy
fi
#if [[ "$TEST" == clang-tidy-* ]] ; then
# Ensure a useful .clang-tidy config file is present in the to-be-tested repo ($CI_SOURCE_PATH)
# [ -f $CI_SOURCE_PATH/.clang-tidy ] || \
# travis_run --title "Fetching default clang-tidy config from MoveIt" \
# wget -nv https://raw.githubusercontent.com/ros-planning/moveit2/moveit2-ci/.clang-tidy \
# -O $CI_SOURCE_PATH/.clang-tidy
# travis_run --display "Applying the following clang-tidy checks:" cat $CI_SOURCE_PATH/.clang-tidy
#fi
# run BEFORE_SCRIPT, which might modify the workspace further
#run_script BEFORE_SCRIPT
# For debugging: list the files in workspace's source folder
travis_run_simple cd $ROS_WS/src
travis_run --title "List files in ROS workspace's source folder" ls --color=auto -alhF
# Install source-based package dependencies
travis_run rosdep install -y -q -r -n --from-paths . --ignore-src --rosdistro $ROS_DISTRO #--skip-keys "moveit_msgs octomap_msgs object_recognition_msgs"
# Change to base of workspace
travis_run_simple cd $ROS_WS
# Validate that we have some packages to build
test -z "$(colcon list --names-only)" && echo -e "$(colorize RED Workspace $ROS_WS has no packages to build. Terminating.)" && exit 1
travis_fold end ros.ws
}
function build_workspace() {
echo -e $(colorize GREEN Building Workspace)
# Console output fix for: "WARNING: Could not encode unicode characters"
export PYTHONIOENCODING=UTF-8
# Change to base of workspace
travis_run_simple cd $ROS_WS
# COLCON_IGNORE packages that cause the build to fail
# TODO: review this
#travis_run_simple touch $ROS_WS/src/image_common/camera_calibration_parsers/COLCON_IGNORE
#travis_run_simple touch $ROS_WS/src/image_common/camera_info_manager/COLCON_IGNORE
# For a command that doesn’t produce output for more than 10 minutes, prefix it with travis_run_wait
travis_run_wait 60 --title "colcon build" colcon build --merge-install $COLCON_CMAKE_ARGS $COLCON_EVENT_HANDLING
# Allow to verify ccache usage
travis_run --title "ccache statistics" ccache -s
}
function test_workspace() {
echo -e $(colorize GREEN Testing Workspace)
travis_run_simple --title "Sourcing newly built install space" source install/setup.bash
# Consider TEST_BLACKLIST
#TEST_BLACKLIST=$(unify_list " ,;" $TEST_BLACKLIST)
#echo -e $(colorize YELLOW Test blacklist: $(colorize THIN $TEST_BLACKLIST))
# Also blacklist external packages
all_pkgs=$(colcon list --topological-order --names-only --base-paths $ROS_WS 2> /dev/null)
source_pkgs=$(colcon list --topological-order --names-only --base-paths $CI_SOURCE_PATH 2> /dev/null)
blacklist_pkgs=$(filter_out "$source_pkgs" "$all_pkgs")
# Run tests, suppressing the error output (confuses Travis display?)
#travis_run_wait --title "colcon test" "colcon test --packages-skip $TEST_BLACKLIST $blacklist $COLCON_EVENT_HANDLING --merge-install 2>/dev/null"
travis_fold start test.results "Test results"
travis_run_wait ros2 run packml_sm packml_sm_utest
travis_run_wait ros2 run packml_ros packml_ros_utest
travis_run_wait python3 -m coverage run $ROS_WS/src/packml_ros2/packml_plc/packml_plc/test_packml_plc_listener.py
travis_run_wait python3 -m coverage run $ROS_WS/src/packml_ros2/packml_plc/packml_plc/test_packml_plc_sender.py
travis_fold end test.results
# Create badge
travis_run_simple cd /root/
travis_run_simple mkdir test
travis_run cd $ROS_WS
travis_run lcov -c --initial --rc lcov_branch_coverage=1 --directory build --output-file /root/test/initialcoverage.info
travis_run lcov -c --rc lcov_branch_coverage=1 --directory build --output-file /root/test/testcoverage.info
travis_run lcov -a /root/test/initialcoverage.info -a /root/test/testcoverage.info --rc lcov_branch_coverage=1 --o /root/test/fullcoverage.info
#travis_run cat /root/test/fullcoverage.info | xargs echo -e
#travis_run lcov -e /root/test/fullcoverage.info '$ROS_WS/*' --rc lcov_branch_coverage=1 --output-file /root/test/workspacecoverage.info
travis_run lcov -r /root/test/fullcoverage.info '*/ros_ws/build/*' '*/ros_ws/install/*' '*/ros_ws/log/*' '*/usr/*' '*/opt/*' --rc lcov_branch_coverage=1 --output-file /root/test/projectcoverage.info
travis_run_wait coveralls-lcov --repo-token "XZxohKIDSP1NA7cgA8TbsSIGDZBqo08JS" /root/test/projectcoverage.info
}
###########################################################################################################
# main program
# If we are here, we can assume we are inside a Docker container
echo "Inside Docker container"
# Prepend current dir if path is not yet absolute
[[ "$ROS_CI_DIR" != /* ]] && ROS_CI_DIR=$PWD/$ROS_CI_DIR
if [[ "$CI_SOURCE_PATH" != /* ]] ; then
# If CI_SOURCE_PATH is not yet absolute
if [ -d "$PWD/$CI_SOURCE_PATH" ] ; then
CI_SOURCE_PATH=$PWD/$CI_SOURCE_PATH # prepend with current dir, if that's feasible
else
# otherwise assume the folder will be created in $ROS_WS/src
CI_SOURCE_PATH=$ROS_WS/src/$CI_SOURCE_PATH
fi
fi
# normalize WARNINGS_OK to 0/1. Originally we accept true, yes, or 1 to allow warnings.
test ${WARNINGS_OK:=true} == true -o "$WARNINGS_OK" == 1 -o "$WARNINGS_OK" == yes && WARNINGS_OK=1 || WARNINGS_OK=0
# Define CC/CXX defaults and print compiler version info
travis_run --title "CXX compiler info" $CXX --version
update_system
prepare_or_run_early_tests
run_xvfb
prepare_ros_workspace
prepare_or_run_early_tests
build_workspace
test_workspace
# Run all remaining tests
for t in $(unify_list " ,;" "$TEST") ; do
case "$t" in
clang-tidy-fix)
(source ${ROS_CI_DIR}/check_clang_tidy.sh)
test $? -eq 0 || result=$(( ${result:-0} + 1 ))
;;
abi)
(source ${ROS_CI_DIR}/check_abi.sh)
test $? -eq 0 || result=$(( ${result:-0} + 1 ))
;;
esac
done
# Run warnings check
#(source ${ROS_CI_DIR}/check_warnings.sh)
#test $? -eq 0 || result=$(( ${result:-0} + 1 ))
#exit ${result:-0}