Kill dangling test processes before running tests
[lttng-ci.git] / scripts / lttng-tools / build.sh
CommitLineData
3c85b52d 1#!/bin/bash -exu
b4005bbf 2#
3c85b52d 3# Copyright (C) 2016 - Jonathan Rajotte-Julien <jonathan.rajotte-julien@efficios.com>
b4005bbf
MJ
4# Michael Jeanson <mjeanson@efficios.com>
5#
6# This program is free software: you can redistribute it and/or modify
7# it under the terms of the GNU General Public License as published by
8# the Free Software Foundation, either version 3 of the License, or
9# (at your option) any later version.
10#
11# This program is distributed in the hope that it will be useful,
12# but WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14# GNU General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with this program. If not, see <http://www.gnu.org/licenses/>.
18
0cdaa21c 19# Version compare functions
b6e62a6a
MJ
20vercomp () {
21 set +u
22 if [[ "$1" == "$2" ]]; then
23 return 0
24 fi
25 local IFS=.
26 local i ver1=($1) ver2=($2)
27 # fill empty fields in ver1 with zeros
28 for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do
29 ver1[i]=0
30 done
31 for ((i=0; i<${#ver1[@]}; i++)); do
32 if [[ -z ${ver2[i]} ]]; then
33 # fill empty fields in ver2 with zeros
34 ver2[i]=0
35 fi
36 if ((10#${ver1[i]} > 10#${ver2[i]})); then
37 return 1
38 fi
39 if ((10#${ver1[i]} < 10#${ver2[i]})); then
40 return 2
41 fi
42 done
43 set -u
44 return 0
45}
46
0cdaa21c 47verlte() {
b6e62a6a
MJ
48 vercomp "$1" "$2"; local res="$?"
49 [ "$res" -eq "0" ] || [ "$res" -eq "2" ]
0cdaa21c
MJ
50}
51
52verlt() {
b6e62a6a
MJ
53 vercomp "$1" "$2"; local res="$?"
54 [ "$res" -eq "2" ]
0cdaa21c
MJ
55}
56
57vergte() {
b6e62a6a
MJ
58 vercomp "$1" "$2"; local res="$?"
59 [ "$res" -eq "0" ] || [ "$res" -eq "1" ]
0cdaa21c
MJ
60}
61
62vergt() {
b6e62a6a
MJ
63 vercomp "$1" "$2"; local res="$?"
64 [ "$res" -eq "1" ]
65}
66
67verne() {
68 vercomp "$1" "$2"; local res="$?"
69 [ "$res" -ne "0" ]
0cdaa21c
MJ
70}
71
212d2afd
MJ
72# Required parameters
73arch=${arch:-}
74conf=${conf:-}
75build=${build:-}
9699c0e7 76test_type=${test_type:-}
b4005bbf 77
212d2afd 78SRCDIR="$WORKSPACE/src/lttng-tools"
67122b96 79#TMPDIR="$WORKSPACE/tmp"
212d2afd
MJ
80PREFIX="$WORKSPACE/build"
81TAPDIR="$WORKSPACE/tap"
82
83
84# Create build and tmp directories
67122b96
MJ
85rm -rf "$PREFIX" "$TAPDIR"
86mkdir -p "$PREFIX" "$TAPDIR"
212d2afd 87
67122b96 88#export TMPDIR
72d087d4 89CFLAGS="-g -O2"
b4005bbf
MJ
90
91# liburcu
92URCU_INCS="$WORKSPACE/deps/liburcu/build/include/"
93URCU_LIBS="$WORKSPACE/deps/liburcu/build/lib/"
94
95# lttng-ust
96UST_INCS="$WORKSPACE/deps/lttng-ust/build/include/"
97UST_LIBS="$WORKSPACE/deps/lttng-ust/build/lib/"
95654431 98UST_JAVA="$WORKSPACE/deps/lttng-ust/build/share/java/"
b4005bbf
MJ
99
100# babeltrace
212d2afd 101#BABEL_INCS="$WORKSPACE/deps/babeltrace/build/include/"
b4005bbf
MJ
102BABEL_LIBS="$WORKSPACE/deps/babeltrace/build/lib/"
103BABEL_BINS="$WORKSPACE/deps/babeltrace/build/bin/"
104
b4005bbf 105
0cdaa21c
MJ
106# Set platform variables
107case "$arch" in
995ac8f2 108sol10-i386)
0cdaa21c
MJ
109 MAKE=gmake
110 TAR=gtar
111 NPROC=gnproc
112 BISON="bison"
113 YACC="$BISON -y"
a717a532 114 CFLAGS="${CFLAGS:-} -D_XOPEN_SOURCE=500"
0cdaa21c 115 RUN_TESTS="no"
ad11244c
MJ
116
117 export PATH="/opt/csw/bin:/usr/ccs/bin:$PATH"
0cdaa21c
MJ
118 ;;
119
995ac8f2 120sol11-i386)
0cdaa21c
MJ
121 MAKE=gmake
122 TAR=gtar
123 NPROC=nproc
cd808c9e 124 BISON="bison"
0cdaa21c 125 YACC="$BISON -y"
a717a532 126 CFLAGS="${CFLAGS:-} -D_XOPEN_SOURCE=500"
0cdaa21c
MJ
127 RUN_TESTS="no"
128
129 export PATH="$PATH:/usr/perl5/bin"
a717a532 130 CPPFLAGS="-I/opt/csw/include"
67acca04 131 LDFLAGS="-L/opt/csw/lib"
0cdaa21c
MJ
132 ;;
133
b6e62a6a
MJ
134macosx)
135 MAKE=make
136 TAR=tar
137 NPROC="getconf _NPROCESSORS_ONLN"
138 BISON="bison"
139 YACC="$BISON -y"
140 RUN_TESTS="no"
141
142 export PATH="/opt/local/bin:/opt/local/sbin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin"
a717a532 143 CPPFLAGS="-I/opt/local/include"
e6a2206f 144 LDFLAGS="-L/opt/local/lib"
b6e62a6a
MJ
145 ;;
146
61afb3c3
MJ
147cygwin|cygwin64|msys32|msys64)
148 MAKE=make
149 TAR=tar
150 NPROC=nproc
151 BISON="bison"
152 YACC="$BISON -y"
72d087d4 153 #CFLAGS=""
61afb3c3
MJ
154 RUN_TESTS="no"
155 ;;
156
0cdaa21c
MJ
157*)
158 MAKE=make
159 TAR=tar
160 NPROC=nproc
161 BISON="bison"
162 YACC="$BISON -y"
72d087d4 163 #CFLAGS=""
0cdaa21c
MJ
164 RUN_TESTS="yes"
165
166 PYTHON2=python2
167 PYTHON3=python3
168
169 P2_VERSION=$($PYTHON2 -c "import sys;print(sys.version[:3])")
170 P3_VERSION=$($PYTHON3 -c "import sys;print(sys.version[:3])")
171
172 UST_PYTHON2="$WORKSPACE/deps/lttng-ust/build/lib/python$P2_VERSION/site-packages"
173 UST_PYTHON3="$WORKSPACE/deps/lttng-ust/build/lib/python$P3_VERSION/site-packages"
174 ;;
175esac
176
9699c0e7
JR
177case "$test_type" in
178base)
179 RUN_TESTS_LONG_REGRESSION="no"
180 ;;
181full)
182 RUN_TESTS_LONG_REGRESSION="yes"
183 ;;
184*)
185 RUN_TESTS_LONG_REGRESSION="no"
186 ;;
187esac
0cdaa21c 188
212d2afd
MJ
189# Enter the source directory
190cd "$SRCDIR"
191
192# Run bootstrap in the source directory prior to configure
0cdaa21c
MJ
193./bootstrap
194
195# Get source version from configure script
212d2afd
MJ
196eval "$(grep '^PACKAGE_VERSION=' ./configure)"
197PACKAGE_VERSION=$(echo "$PACKAGE_VERSION"| sed 's/\-pre$//')
0cdaa21c
MJ
198
199
200# Export build flags
201case "$conf" in
202no-ust)
e6a2206f
JR
203 CPPFLAGS="${CPPFLAGS:-} -I$URCU_INCS"
204 LDFLAGS="${LDFLAGS:-} -L$URCU_LIBS"
b4005bbf 205 export LD_LIBRARY_PATH="$URCU_LIBS:$BABEL_LIBS:${LD_LIBRARY_PATH:-}"
0cdaa21c
MJ
206 ;;
207
208*)
e6a2206f
JR
209 CPPFLAGS="${CPPFLAGS:-} -I$URCU_INCS -I$UST_INCS"
210 LDFLAGS="${LDFLAGS:-} -L$URCU_LIBS -L$UST_LIBS"
b4005bbf 211 export LD_LIBRARY_PATH="$URCU_LIBS:$UST_LIBS:$BABEL_LIBS:${LD_LIBRARY_PATH:-}"
0cdaa21c
MJ
212 ;;
213esac
b4005bbf 214
0cdaa21c
MJ
215# The switch to build without UST changed in 2.8
216if vergte "$PACKAGE_VERSION" "2.8"; then
217 NO_UST="--without-lttng-ust"
218else
219 NO_UST="--disable-lttng-ust"
220fi
b4005bbf 221
6c3ec80e
MJ
222# Most build configs require the python bindings
223CONF_OPTS="--enable-python-bindings"
224export PYTHON="python3"
225export PYTHON_CONFIG="/usr/bin/python3-config"
226
0cdaa21c 227# Set configure options for each build configuration
b4005bbf 228case "$conf" in
0cdaa21c
MJ
229static)
230 echo "Static build"
6c3ec80e 231 CONF_OPTS+=" --enable-static --disable-shared"
0cdaa21c
MJ
232 ;;
233
0cdaa21c
MJ
234no-ust)
235 echo "Build without UST support"
6c3ec80e 236 CONF_OPTS+=" $NO_UST"
0cdaa21c
MJ
237 ;;
238
67122b96
MJ
239agents)
240 echo "Enable Java Agents"
0cdaa21c
MJ
241 export JAVA_HOME="/usr/lib/jvm/default-java"
242 export CLASSPATH="$UST_JAVA/*:/usr/share/java/*"
67122b96 243 CONF_OPTS+=" --enable-test-java-agent-all"
0cdaa21c 244
67122b96 245 echo "Enable Python agents"
0cdaa21c 246 export PYTHONPATH="$UST_PYTHON2:$UST_PYTHON3"
67122b96 247 CONF_OPTS+=" --enable-test-python-agent-all"
0cdaa21c
MJ
248 ;;
249
250relayd-only)
251 echo "Build relayd only"
b6e62a6a 252 CONF_OPTS="--disable-bin-lttng --disable-bin-lttng-consumerd --disable-bin-lttng-crash --disable-bin-lttng-sessiond --disable-extras --disable-man-pages $NO_UST"
0cdaa21c
MJ
253 ;;
254
22780fe6
JR
255debug-rcu)
256 echo "Enable RCU sanity checks for debugging"
257 CPPFLAGS="${CPPFLAGS:-} -DDEBUG_RCU"
258 ;;
259
0cdaa21c
MJ
260*)
261 echo "Standard build"
0cdaa21c 262 ;;
b4005bbf
MJ
263esac
264
0cdaa21c 265
b4005bbf 266# Build type
67122b96
MJ
267# oot : out-of-tree build
268# dist : build via make dist
269# oot-dist: build via make dist out-of-tree
270# * : normal tree build
b4005bbf 271#
0cdaa21c 272# Make sure to move to the build_path and run configure
b4005bbf 273# before continuing
212d2afd 274BUILD_PATH=$SRCDIR
b4005bbf 275case "$build" in
95654431
MJ
276 oot)
277 echo "Out of tree build"
278 BUILD_PATH=$WORKSPACE/oot
b6e62a6a
MJ
279 mkdir -p "$BUILD_PATH"
280 cd "$BUILD_PATH"
e6a2206f 281 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$SRCDIR/configure" --prefix="$PREFIX" $CONF_OPTS
95654431
MJ
282 ;;
283
284 dist)
67122b96 285 echo "Distribution tarball in-tree build"
95654431
MJ
286
287 # Initial configure and generate tarball
e6a2206f 288 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$SRCDIR/configure" $CONF_OPTS --enable-build-man-pages
0cdaa21c 289 $MAKE dist
95654431 290
67122b96 291 BUILD_PATH="$(mktemp -d)"
b6e62a6a
MJ
292 cp ./*.tar.* "$BUILD_PATH/"
293 cd "$BUILD_PATH"
95654431
MJ
294
295 # Ignore level 1 of tar
b6e62a6a 296 $TAR xvf ./*.tar.* --strip 1
95654431 297
67122b96 298 # Build in extracted source tree
e6a2206f 299 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
95654431
MJ
300 ;;
301
67122b96
MJ
302 oot-dist)
303 echo "Distribution tarball out of tree build"
304 BUILD_PATH="$(mktemp -d)"
305 cd "$BUILD_PATH"
306
307 # Initial configure and generate tarball
e6a2206f 308 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$SRCDIR/configure" $CONF_OPTS --enable-build-man-pages
67122b96
MJ
309 $MAKE dist
310
311 NEWSRC_PATH="$(mktemp -d)"
312 cp ./*.tar.* "$NEWSRC_PATH/"
313 cd "$NEWSRC_PATH"
314
315 # Ignore level 1 of tar
316 $TAR xvf ./*.tar.* --strip 1
317
318 BUILD_PATH="$(mktemp -d)"
319 cd "$BUILD_PATH"
320
321 # Build oot from extracted sources
e6a2206f 322 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$NEWSRC_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
67122b96
MJ
323 ;;
324
95654431 325 *)
95654431 326 echo "Standard tree build"
e6a2206f 327 MAKE=$MAKE BISON="$BISON" YACC="$YACC" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CPPFLAGS="$CPPFLAGS" "$BUILD_PATH/configure" --prefix="$PREFIX" $CONF_OPTS
95654431 328 ;;
b4005bbf
MJ
329esac
330
0cdaa21c 331# BUILD!
212d2afd 332$MAKE -j "$($NPROC)" V=1
0cdaa21c 333$MAKE install
b4005bbf
MJ
334
335# Run tests
0cdaa21c 336if [ "$RUN_TESTS" = "yes" ]; then
212d2afd 337 cd tests || exit 1
7671741c 338
0cdaa21c
MJ
339 # Allow core dumps
340 ulimit -c unlimited
341
cb864586
JG
342 # Kill any LTTng-related process
343 lttng_processes="$("$PGREP" -l 'lttng|gen-ust-.+')"
344 if [ $? -eq 0 ]; then
345 pids="$(cut -d ' ' -f 1 <<< "$lttng_processes" | tr '\n' ' ')"
346 kill -9 $pids
347 fi
348
0cdaa21c 349 # Add 'babeltrace' binary to PATH
7671741c 350 chmod +x "$BABEL_BINS/babeltrace"
0cdaa21c
MJ
351 export PATH="$PATH:$BABEL_BINS"
352
353 # Prepare tap output dirs
212d2afd
MJ
354 rm -rf "$TAPDIR"
355 mkdir -p "$TAPDIR"
356 mkdir -p "$TAPDIR/unit"
357 mkdir -p "$TAPDIR/fast_regression"
358 mkdir -p "$TAPDIR/with_bindings_regression"
9699c0e7
JR
359 if [ "$RUN_TESTS_LONG_REGRESSION" = "yes" ]; then
360 mkdir -p "$TAPDIR/long_regression"
361 fi
0cdaa21c 362
a4e98cc0
JR
363 # Force the lttng-sessiond path to /bin/true to prevent the spawing of a
364 # lttng-sessiond --daemonize on "lttng create"
365 export LTTNG_SESSIOND_PATH="/bin/true"
366
0cdaa21c
MJ
367 # Run 'unit_tests' and 'fast_regression' test suites for all configs except 'no-ust'
368 if [ "$conf" != "no-ust" ]; then
3c85b52d
MJ
369 # Run 'unit_tests', 2.8 and up has a new test suite
370 if vergte "$PACKAGE_VERSION" "2.8"; then
6827c67a 371 make --keep-going check
212d2afd 372 rsync -a --exclude 'test-suite.log' --include '*/' --include '*.log' --exclude='*'" $BUILD_PATH/tests/" "$TAPDIR"
3c85b52d 373 else
212d2afd
MJ
374 prove --merge -v --exec '' - < "$BUILD_PATH/tests/unit_tests" --archive "$TAPDIR/unit/" || true
375 prove --merge -v --exec '' - < "$BUILD_PATH/tests/fast_regression" --archive "$TAPDIR/fast_regression/" || true
6c3ec80e 376 prove --merge -v --exec '' - < "$BUILD_PATH/tests/with_bindings_regression" --archive "$TAPDIR/with_bindings_regression/" || true
3c85b52d 377 fi
9699c0e7
JR
378 if [ "$RUN_TESTS_LONG_REGRESSION" = "yes" ]; then
379 prove --merge -v --exec '' - < "$BUILD_PATH/tests/long_regression" --archive "$TAPDIR/long_regression/" || true
380 fi
0cdaa21c
MJ
381 else
382 # Regression is disabled for now, we need to adjust the testsuite for no ust builds.
3c85b52d 383 echo "Tests disabled for 'no-ust'."
0cdaa21c
MJ
384 fi
385
0cdaa21c 386 # TAP plugin is having a hard time with .yml files.
212d2afd 387 find "$TAPDIR" -name "meta.yml" -exec rm -f {} \;
0cdaa21c
MJ
388
389 # And also with files without extension, so rename all result to *.tap
212d2afd 390 find "$TAPDIR/" -type f -exec mv {} {}.tap \;
7671741c
MJ
391
392 cd -
b4005bbf
MJ
393fi
394
b4005bbf 395# Cleanup
0cdaa21c 396$MAKE clean
b4005bbf 397
0cdaa21c 398# Cleanup rpath in executables and shared libraries
212d2afd
MJ
399find "$PREFIX/bin" -type f -perm -0500 -exec chrpath --delete {} \;
400find "$PREFIX/lib" -name "*.so" -exec chrpath --delete {} \;
0cdaa21c
MJ
401
402# Remove libtool .la files
212d2afd 403find "$PREFIX/lib" -name "*.la" -exec rm -f {} \;
b4005bbf
MJ
404
405# Clean temp dir for dist build
0cdaa21c 406if [ "$build" = "dist" ]; then
212d2afd 407 cd "$SRCDIR"
7671741c 408 rm -rf "$BUILD_PATH"
b4005bbf 409fi
95654431
MJ
410
411# EOF
This page took 0.056424 seconds and 4 git commands to generate.