238102f320cdc406bf4aee8be754d491a1f9df89
[strongswan.git] / scripts / test.sh
1 #!/bin/sh
2 # Build script for Travis CI
3
4 if test -z $TRAVIS_BUILD_DIR; then
5 TRAVIS_BUILD_DIR=$PWD
6 fi
7
8 cd $TRAVIS_BUILD_DIR
9
10 TARGET=check
11
12 DEPS="libgmp-dev"
13
14 CFLAGS="-g -O2 -Wall -Wno-format -Wno-format-security -Wno-pointer-sign -Werror"
15
16 case "$TEST" in
17 default)
18 # should be the default, but lets make sure
19 CONFIG="--with-printf-hooks=glibc"
20 ;;
21 openssl)
22 CONFIG="--disable-defaults --enable-pki --enable-openssl"
23 DEPS="libssl-dev"
24 ;;
25 gcrypt)
26 CONFIG="--disable-defaults --enable-pki --enable-gcrypt --enable-pkcs1"
27 DEPS="libgcrypt11-dev"
28 ;;
29 printf-builtin)
30 CONFIG="--with-printf-hooks=builtin"
31 ;;
32 all|coverage)
33 CONFIG="--enable-all --disable-android-dns --disable-android-log
34 --disable-dumm --disable-kernel-pfroute --disable-keychain
35 --disable-lock-profiler --disable-padlock --disable-fuzzing
36 --disable-osx-attr --disable-tkm --disable-uci
37 --disable-systemd --disable-soup --disable-unwind-backtraces
38 --disable-svc --disable-dbghelp-backtraces --disable-socket-win
39 --disable-kernel-wfp --disable-kernel-iph --disable-winhttp"
40 # Ubuntu 14.04 does provide a too old libtss2-dev
41 CONFIG="$CONFIG --disable-tss-tss2"
42 # not enabled on the build server
43 CONFIG="$CONFIG --disable-af-alg"
44 if test "$TEST" != "coverage"; then
45 CONFIG="$CONFIG --disable-coverage"
46 else
47 # not actually required but configure checks for it
48 DEPS="$DEPS lcov"
49 fi
50 DEPS="$DEPS libcurl4-gnutls-dev libsoup2.4-dev libunbound-dev libldns-dev
51 libmysqlclient-dev libsqlite3-dev clearsilver-dev libfcgi-dev
52 libnm-glib-dev libnm-glib-vpn-dev libpcsclite-dev libpam0g-dev
53 binutils-dev libunwind8-dev libjson0-dev iptables-dev python-pip
54 libtspi-dev"
55 PYDEPS="pytest"
56 ;;
57 win*)
58 CONFIG="--disable-defaults --enable-svc --enable-ikev2
59 --enable-ikev1 --enable-static --enable-test-vectors --enable-nonce
60 --enable-constraints --enable-revocation --enable-pem --enable-pkcs1
61 --enable-pkcs8 --enable-x509 --enable-pubkey --enable-acert
62 --enable-eap-tnc --enable-eap-ttls --enable-eap-identity
63 --enable-updown --enable-ext-auth --enable-libipsec
64 --enable-tnccs-20 --enable-imc-attestation --enable-imv-attestation
65 --enable-imc-os --enable-imv-os --enable-tnc-imv --enable-tnc-imc
66 --enable-pki --enable-swanctl --enable-socket-win"
67 # no make check for Windows binaries unless we run on a windows host
68 if test "$APPVEYOR" != "True"; then
69 TARGET=
70 fi
71 CFLAGS="$CFLAGS -mno-ms-bitfields"
72 DEPS="gcc-mingw-w64-base"
73 case "$TEST" in
74 win64)
75 # headers on 12.04 are too old, so we only build the plugins here
76 CONFIG="--host=x86_64-w64-mingw32 $CONFIG --enable-dbghelp-backtraces
77 --enable-kernel-iph --enable-kernel-wfp --enable-winhttp"
78 DEPS="gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-x86-64-dev $DEPS"
79 CC="x86_64-w64-mingw32-gcc"
80 # apply patch to MinGW headers
81 if test "$APPVEYOR" != "True" -a -z "$1"; then
82 sudo patch -f -p 4 -d /usr/share/mingw-w64/include < src/libcharon/plugins/kernel_wfp/mingw-w64-4.8.1.diff
83 fi
84 ;;
85 win32)
86 CONFIG="--host=i686-w64-mingw32 $CONFIG"
87 # currently only works on 12.04, so use mingw-w64-dev instead of mingw-w64-i686-dev
88 DEPS="gcc-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-dev $DEPS"
89 CC="i686-w64-mingw32-gcc"
90 ;;
91 esac
92 ;;
93 osx)
94 # use the same options as in the Homebrew Formula
95 CONFIG="--disable-defaults --enable-charon --enable-cmd --enable-constraints
96 --enable-curl --enable-eap-gtc --enable-eap-identity
97 --enable-eap-md5 --enable-eap-mschapv2 --enable-ikev1 --enable-ikev2
98 --enable-kernel-libipsec --enable-kernel-pfkey
99 --enable-kernel-pfroute --enable-nonce --enable-openssl
100 --enable-osx-attr --enable-pem --enable-pgp --enable-pkcs1
101 --enable-pkcs8 --enable-pki --enable-pubkey --enable-revocation
102 --enable-scepclient --enable-socket-default --enable-sshkey
103 --enable-stroke --enable-swanctl --enable-unity --enable-updown
104 --enable-x509 --enable-xauth-generic"
105 DEPS="bison gettext openssl curl"
106 BREW_PREFIX=$(brew --prefix)
107 export PATH=$BREW_PREFIX/opt/bison/bin:$PATH
108 export ACLOCAL_PATH=$BREW_PREFIX/opt/gettext/share/aclocal:$ACLOCAL_PATH
109 for pkg in openssl curl
110 do
111 PKG_CONFIG_PATH=$BREW_PREFIX/opt/$pkg/lib/pkgconfig:$PKG_CONFIG_PATH
112 CPPFLAGS="-I$BREW_PREFIX/opt/$pkg/include $CPPFLAGS"
113 LDFLAGS="-L$BREW_PREFIX/opt/$pkg/lib $LDFLAGS"
114 done
115 export PKG_CONFIG_PATH
116 export CPPFLAGS
117 export LDFLAGS
118 ;;
119 dist)
120 TARGET=distcheck
121 ;;
122 apidoc)
123 DEPS="doxygen"
124 CONFIG="--disable-defaults"
125 TARGET=apidoc
126 ;;
127 *)
128 echo "$0: unknown test $TEST" >&2
129 exit 1
130 ;;
131 esac
132
133 if test "$1" = "deps"; then
134 case "$TRAVIS_OS_NAME" in
135 linux)
136 sudo apt-get update -qq && \
137 sudo apt-get install -qq bison flex gperf gettext $DEPS
138 ;;
139 osx)
140 brew update && \
141 # workaround for issue #6352
142 brew uninstall --force libtool && brew install libtool && \
143 brew install $DEPS
144 ;;
145 esac
146 exit $?
147 fi
148
149 if test "$1" = "pydeps"; then
150 test -z "$PYDEPS" || sudo pip -q install $PYDEPS
151 exit $?
152 fi
153
154 CONFIG="$CONFIG
155 --disable-dependency-tracking
156 --enable-silent-rules
157 --enable-test-vectors
158 --enable-monolithic=${MONOLITHIC-no}
159 --enable-leak-detective=${LEAK_DETECTIVE-no}"
160
161 echo "$ ./autogen.sh"
162 ./autogen.sh || exit $?
163 echo "$ CC=$CC CFLAGS=\"$CFLAGS\" ./configure $CONFIG"
164 CC="$CC" CFLAGS="$CFLAGS" ./configure $CONFIG || exit $?
165
166 case "$TEST" in
167 apidoc)
168 exec 2>make.warnings
169 ;;
170 *)
171 ;;
172 esac
173
174 echo "$ make $TARGET"
175 make -j4 $TARGET || exit $?
176
177 case "$TEST" in
178 apidoc)
179 if test -s make.warnings; then
180 cat make.warnings
181 exit 1
182 fi
183 ;;
184 *)
185 ;;
186 esac