f79d2d9fbaebbfdd7ad19b940b936d9cdd44728f
[strongswan.git] / scripts / test.sh
1 #!/bin/sh
2 # Build script for Travis CI
3
4 build_botan()
5 {
6 # same revision used in the build recipe of the testing environment
7 BOTAN_REV=2.8.0
8 BOTAN_DIR=$TRAVIS_BUILD_DIR/../botan
9
10 if test -d "$BOTAN_DIR"; then
11 return
12 fi
13
14 # if the leak detective is enabled we have to disable threading support
15 # (used for std::async) as that causes invalid frees somehow, the
16 # locking allocator causes a static leak via the first function that
17 # references it (e.g. crypter or hasher), so we disable that too
18 if test "$LEAK_DETECTIVE" = "yes"; then
19 BOTAN_CONFIG="--without-os-features=threads
20 --disable-modules=locking_allocator"
21 fi
22 # disable some larger modules we don't need for the tests
23 BOTAN_CONFIG="$BOTAN_CONFIG --disable-modules=pkcs11,tls,x509,xmss"
24
25 git clone https://github.com/randombit/botan.git $BOTAN_DIR &&
26 cd $BOTAN_DIR &&
27 git checkout -qf $BOTAN_REV &&
28 python ./configure.py --amalgamation $BOTAN_CONFIG &&
29 make -j4 libs >/dev/null &&
30 sudo make install >/dev/null &&
31 sudo ldconfig || exit $?
32 cd -
33 }
34
35 build_tss2()
36 {
37 TSS2_REV=2.1.0
38 TSS2_PKG=tpm2-tss-$TSS2_REV
39 TSS2_DIR=$TRAVIS_BUILD_DIR/../$TSS2_PKG
40 TSS2_SRC=https://github.com/tpm2-software/tpm2-tss/releases/download/$TSS2_REV/$TSS2_PKG.tar.gz
41
42 if test -d "$TSS2_DIR"; then
43 return
44 fi
45
46 # the default version of libgcrypt in Ubuntu 14.04 is too old
47 sudo apt-get update -qq && \
48 sudo apt-get install -qq libgcrypt20-dev &&
49 curl -L $TSS2_SRC | tar xz -C $TRAVIS_BUILD_DIR/.. &&
50 cd $TSS2_DIR &&
51 ./configure &&
52 sudo make -j4 install >/dev/null &&
53 sudo ldconfig || exit $?
54 cd -
55 }
56
57 if test -z $TRAVIS_BUILD_DIR; then
58 TRAVIS_BUILD_DIR=$PWD
59 fi
60
61 cd $TRAVIS_BUILD_DIR
62
63 TARGET=check
64
65 DEPS="libgmp-dev"
66
67 CFLAGS="-g -O2 -Wall -Wno-format -Wno-format-security -Wno-pointer-sign -Werror"
68
69 case "$TEST" in
70 default)
71 # should be the default, but lets make sure
72 CONFIG="--with-printf-hooks=glibc"
73 ;;
74 openssl)
75 CONFIG="--disable-defaults --enable-pki --enable-openssl"
76 DEPS="libssl-dev"
77 ;;
78 gcrypt)
79 CONFIG="--disable-defaults --enable-pki --enable-gcrypt --enable-pkcs1"
80 DEPS="libgcrypt11-dev"
81 ;;
82 botan)
83 CONFIG="--disable-defaults --enable-pki --enable-botan --enable-pem"
84 # we can't use the old package that comes with Ubuntu so we build from
85 # the current master until 2.8.0 is released and then probably switch to
86 # that unless we need newer features (at least 2.7.0 plus PKCS#1 patch is
87 # currently required)
88 DEPS=""
89 if test "$1" = "deps"; then
90 build_botan
91 fi
92 ;;
93 printf-builtin)
94 CONFIG="--with-printf-hooks=builtin"
95 ;;
96 all|coverage|sonarcloud)
97 CONFIG="--enable-all --disable-android-dns --disable-android-log
98 --disable-kernel-pfroute --disable-keychain
99 --disable-lock-profiler --disable-padlock --disable-fuzzing
100 --disable-osx-attr --disable-tkm --disable-uci
101 --disable-soup --disable-unwind-backtraces
102 --disable-svc --disable-dbghelp-backtraces --disable-socket-win
103 --disable-kernel-wfp --disable-kernel-iph --disable-winhttp"
104 # not enabled on the build server
105 CONFIG="$CONFIG --disable-af-alg"
106 if test "$TEST" != "coverage"; then
107 CONFIG="$CONFIG --disable-coverage"
108 else
109 # not actually required but configure checks for it
110 DEPS="$DEPS lcov"
111 fi
112 DEPS="$DEPS libcurl4-gnutls-dev libsoup2.4-dev libunbound-dev libldns-dev
113 libmysqlclient-dev libsqlite3-dev clearsilver-dev libfcgi-dev
114 libpcsclite-dev libpam0g-dev binutils-dev libunwind8-dev libnm-dev
115 libjson0-dev iptables-dev python-pip libtspi-dev libsystemd-dev"
116 PYDEPS="pytest"
117 if test "$1" = "deps"; then
118 build_botan
119 build_tss2
120 fi
121 ;;
122 win*)
123 CONFIG="--disable-defaults --enable-svc --enable-ikev2
124 --enable-ikev1 --enable-static --enable-test-vectors --enable-nonce
125 --enable-constraints --enable-revocation --enable-pem --enable-pkcs1
126 --enable-pkcs8 --enable-x509 --enable-pubkey --enable-acert
127 --enable-eap-tnc --enable-eap-ttls --enable-eap-identity
128 --enable-updown --enable-ext-auth --enable-libipsec
129 --enable-tnccs-20 --enable-imc-attestation --enable-imv-attestation
130 --enable-imc-os --enable-imv-os --enable-tnc-imv --enable-tnc-imc
131 --enable-pki --enable-swanctl --enable-socket-win
132 --enable-kernel-iph --enable-kernel-wfp --enable-winhttp"
133 # no make check for Windows binaries unless we run on a windows host
134 if test "$APPVEYOR" != "True"; then
135 TARGET=
136 else
137 CONFIG="$CONFIG --enable-openssl"
138 CFLAGS="$CFLAGS -I/c/OpenSSL-$TEST/include"
139 LDFLAGS="-L/c/OpenSSL-$TEST"
140 export LDFLAGS
141 fi
142 CFLAGS="$CFLAGS -mno-ms-bitfields"
143 DEPS="gcc-mingw-w64-base"
144 case "$TEST" in
145 win64)
146 CONFIG="--host=x86_64-w64-mingw32 $CONFIG --enable-dbghelp-backtraces"
147 DEPS="gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-x86-64-dev $DEPS"
148 CC="x86_64-w64-mingw32-gcc"
149 ;;
150 win32)
151 CONFIG="--host=i686-w64-mingw32 $CONFIG"
152 DEPS="gcc-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-i686-dev $DEPS"
153 CC="i686-w64-mingw32-gcc"
154 ;;
155 esac
156 ;;
157 osx)
158 # this causes a false positive in ip-packet.c since Xcode 8.3
159 CFLAGS="$CFLAGS -Wno-address-of-packed-member"
160 # use the same options as in the Homebrew Formula
161 CONFIG="--disable-defaults --enable-charon --enable-cmd --enable-constraints
162 --enable-curl --enable-eap-gtc --enable-eap-identity
163 --enable-eap-md5 --enable-eap-mschapv2 --enable-ikev1 --enable-ikev2
164 --enable-kernel-libipsec --enable-kernel-pfkey
165 --enable-kernel-pfroute --enable-nonce --enable-openssl
166 --enable-osx-attr --enable-pem --enable-pgp --enable-pkcs1
167 --enable-pkcs8 --enable-pki --enable-pubkey --enable-revocation
168 --enable-scepclient --enable-socket-default --enable-sshkey
169 --enable-stroke --enable-swanctl --enable-unity --enable-updown
170 --enable-x509 --enable-xauth-generic"
171 DEPS="bison gettext openssl curl"
172 BREW_PREFIX=$(brew --prefix)
173 export PATH=$BREW_PREFIX/opt/bison/bin:$PATH
174 export ACLOCAL_PATH=$BREW_PREFIX/opt/gettext/share/aclocal:$ACLOCAL_PATH
175 for pkg in openssl curl
176 do
177 PKG_CONFIG_PATH=$BREW_PREFIX/opt/$pkg/lib/pkgconfig:$PKG_CONFIG_PATH
178 CPPFLAGS="-I$BREW_PREFIX/opt/$pkg/include $CPPFLAGS"
179 LDFLAGS="-L$BREW_PREFIX/opt/$pkg/lib $LDFLAGS"
180 done
181 export PKG_CONFIG_PATH
182 export CPPFLAGS
183 export LDFLAGS
184 ;;
185 fuzzing)
186 CFLAGS="$CFLAGS -DNO_CHECK_MEMWIPE"
187 CONFIG="--enable-fuzzing --enable-static --disable-shared --disable-scripts
188 --enable-imc-test --enable-tnccs-20"
189 # don't run any of the unit tests
190 export TESTS_RUNNERS=
191 # prepare corpora
192 if test -z "$1"; then
193 if test -z "$FUZZING_CORPORA"; then
194 git clone --depth 1 https://github.com/strongswan/fuzzing-corpora.git fuzzing-corpora
195 export FUZZING_CORPORA=$TRAVIS_BUILD_DIR/fuzzing-corpora
196 fi
197 # these are about the same as those on OSS-Fuzz (except for the
198 # symbolize options and strip_path_prefix)
199 export ASAN_OPTIONS=redzone=16:handle_sigill=1:strict_string_check=1:\
200 allocator_release_to_os_interval_ms=500:strict_memcmp=1:detect_container_overflow=1:\
201 coverage=0:allocator_may_return_null=1:use_sigaltstack=1:detect_stack_use_after_return=1:\
202 alloc_dealloc_mismatch=0:detect_leaks=1:print_scariness=1:max_uar_stack_size_log=16:\
203 handle_abort=1:check_malloc_usable_size=0:quarantine_size_mb=10:detect_odr_violation=0:\
204 symbolize=1:handle_segv=1:fast_unwind_on_fatal=0:external_symbolizer_path=/usr/bin/llvm-symbolizer-3.5
205 fi
206 ;;
207 dist)
208 TARGET=distcheck
209 ;;
210 apidoc)
211 DEPS="doxygen"
212 CONFIG="--disable-defaults"
213 TARGET=apidoc
214 ;;
215 *)
216 echo "$0: unknown test $TEST" >&2
217 exit 1
218 ;;
219 esac
220
221 if test "$1" = "deps"; then
222 case "$TRAVIS_OS_NAME" in
223 linux)
224 sudo apt-get update -qq && \
225 sudo apt-get install -qq bison flex gperf gettext $DEPS
226 ;;
227 osx)
228 brew update && \
229 # workaround for issue #6352
230 brew uninstall --force libtool && brew install libtool && \
231 brew install $DEPS
232 ;;
233 esac
234 exit $?
235 fi
236
237 if test "$1" = "pydeps"; then
238 test -z "$PYDEPS" || pip -q install --user $PYDEPS
239 exit $?
240 fi
241
242 CONFIG="$CONFIG
243 --disable-dependency-tracking
244 --enable-silent-rules
245 --enable-test-vectors
246 --enable-monolithic=${MONOLITHIC-no}
247 --enable-leak-detective=${LEAK_DETECTIVE-no}"
248
249 echo "$ ./autogen.sh"
250 ./autogen.sh || exit $?
251 echo "$ CC=$CC CFLAGS=\"$CFLAGS\" ./configure $CONFIG"
252 CC="$CC" CFLAGS="$CFLAGS" ./configure $CONFIG || exit $?
253
254 case "$TEST" in
255 apidoc)
256 exec 2>make.warnings
257 ;;
258 *)
259 ;;
260 esac
261
262 echo "$ make $TARGET"
263 case "$TEST" in
264 sonarcloud)
265 # without target, coverage is currently not supported anyway because
266 # sonarqube only supports gcov, not lcov
267 build-wrapper-linux-x86-64 --out-dir bw-output make -j4 || exit $?
268 ;;
269 *)
270 make -j4 $TARGET || exit $?
271 ;;
272 esac
273
274 case "$TEST" in
275 apidoc)
276 if test -s make.warnings; then
277 cat make.warnings
278 exit 1
279 fi
280 ;;
281 sonarcloud)
282 sonar-scanner \
283 -Dsonar.projectKey=strongswan \
284 -Dsonar.projectVersion=$(git describe)+${TRAVIS_BUILD_NUMBER} \
285 -Dsonar.sources=. \
286 -Dsonar.cfamily.build-wrapper-output=bw-output || exit $?
287 ;;
288 *)
289 ;;
290 esac