travis: Create coverage report via codecov.io
[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
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-aikpub2 --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
68 TARGET=
69 CFLAGS="$CFLAGS -mno-ms-bitfields"
70 DEPS="gcc-mingw-w64-base"
71 case "$TEST" in
72 win64)
73 CONFIG="--host=x86_64-w64-mingw32 $CONFIG"
74 DEPS="gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-x86-64-dev $DEPS"
75 CC="x86_64-w64-mingw32-gcc"
76 ;;
77 win32)
78 CONFIG="--host=i686-w64-mingw32 $CONFIG"
79 # currently only works on 12.04, so use mingw-w64-dev instead of mingw-w64-i686-dev
80 DEPS="gcc-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-dev $DEPS"
81 CC="i686-w64-mingw32-gcc"
82 ;;
83 esac
84 ;;
85 osx)
86 # use the same options as in the Homebrew Formula
87 CONFIG="--disable-defaults --enable-charon --enable-cmd --enable-constraints
88 --enable-curl --enable-eap-gtc --enable-eap-identity
89 --enable-eap-md5 --enable-eap-mschapv2 --enable-ikev1 --enable-ikev2
90 --enable-kernel-libipsec --enable-kernel-pfkey
91 --enable-kernel-pfroute --enable-nonce --enable-openssl
92 --enable-osx-attr --enable-pem --enable-pgp --enable-pkcs1
93 --enable-pkcs8 --enable-pki --enable-pubkey --enable-revocation
94 --enable-scepclient --enable-socket-default --enable-sshkey
95 --enable-stroke --enable-swanctl --enable-unity --enable-updown
96 --enable-x509 --enable-xauth-generic"
97 DEPS="bison gettext openssl curl"
98 BREW_PREFIX=$(brew --prefix)
99 export PATH=$BREW_PREFIX/opt/bison/bin:$PATH
100 export ACLOCAL_PATH=$BREW_PREFIX/opt/gettext/share/aclocal:$ACLOCAL_PATH
101 for pkg in openssl curl
102 do
103 PKG_CONFIG_PATH=$BREW_PREFIX/opt/$pkg/lib/pkgconfig:$PKG_CONFIG_PATH
104 CPPFLAGS="-I$BREW_PREFIX/opt/$pkg/include $CPPFLAGS"
105 LDFLAGS="-L$BREW_PREFIX/opt/$pkg/lib $LDFLAGS"
106 done
107 export PKG_CONFIG_PATH
108 export CPPFLAGS
109 export LDFLAGS
110 ;;
111 dist)
112 TARGET=distcheck
113 ;;
114 apidoc)
115 DEPS="doxygen"
116 CONFIG="--disable-defaults"
117 TARGET=apidoc
118 ;;
119 *)
120 echo "$0: unknown test $TEST" >&2
121 exit 1
122 ;;
123 esac
124
125 if test "$1" = "deps"; then
126 case "$TRAVIS_OS_NAME" in
127 linux)
128 sudo apt-get update -qq && \
129 sudo apt-get install -qq bison flex gperf gettext $DEPS
130 ;;
131 osx)
132 brew update && \
133 # workaround for issue #6352
134 brew uninstall --force libtool && brew install libtool && \
135 brew install $DEPS
136 ;;
137 esac
138 exit $?
139 fi
140
141 if test "$1" = "pydeps"; then
142 test -z "$PYDEPS" || sudo pip -q install $PYDEPS
143 exit $?
144 fi
145
146 CONFIG="$CONFIG
147 --disable-dependency-tracking
148 --enable-silent-rules
149 --enable-test-vectors
150 --enable-monolithic=${MONOLITHIC-no}
151 --enable-leak-detective=${LEAK_DETECTIVE-no}"
152
153 echo "$ ./autogen.sh"
154 ./autogen.sh || exit $?
155 echo "$ CC=$CC CFLAGS=\"$CFLAGS\" ./configure $CONFIG"
156 CC="$CC" CFLAGS="$CFLAGS" ./configure $CONFIG || exit $?
157
158 case "$TEST" in
159 apidoc)
160 exec 2>make.warnings
161 ;;
162 *)
163 ;;
164 esac
165
166 echo "$ make $TARGET"
167 make -j4 $TARGET || exit $?
168
169 case "$TEST" in
170 apidoc)
171 if test -s make.warnings; then
172 cat make.warnings
173 exit 1
174 fi
175 ;;
176 *)
177 ;;
178 esac