travis: Don't build TSS2 as root
[strongswan.git] / scripts / test.sh
index d8a4ec5..8f573ce 100755 (executable)
@@ -1,6 +1,60 @@
 #!/bin/sh
 # Build script for Travis CI
 
+build_botan()
+{
+       # same revision used in the build recipe of the testing environment
+       BOTAN_REV=2.8.0
+       BOTAN_DIR=$TRAVIS_BUILD_DIR/../botan
+
+       if test -d "$BOTAN_DIR"; then
+               return
+       fi
+
+       # if the leak detective is enabled we have to disable threading support
+       # (used for std::async) as that causes invalid frees somehow, the
+       # locking allocator causes a static leak via the first function that
+       # references it (e.g. crypter or hasher), so we disable that too
+       if test "$LEAK_DETECTIVE" = "yes"; then
+               BOTAN_CONFIG="--without-os-features=threads
+                                         --disable-modules=locking_allocator"
+       fi
+       # disable some larger modules we don't need for the tests
+       BOTAN_CONFIG="$BOTAN_CONFIG --disable-modules=pkcs11,tls,x509,xmss"
+
+       git clone https://github.com/randombit/botan.git $BOTAN_DIR &&
+       cd $BOTAN_DIR &&
+       git checkout -qf $BOTAN_REV &&
+       python ./configure.py --amalgamation $BOTAN_CONFIG &&
+       make -j4 libs >/dev/null &&
+       sudo make install >/dev/null &&
+       sudo ldconfig || exit $?
+       cd -
+}
+
+build_tss2()
+{
+       TSS2_REV=2.1.0
+       TSS2_PKG=tpm2-tss-$TSS2_REV
+       TSS2_DIR=$TRAVIS_BUILD_DIR/../$TSS2_PKG
+       TSS2_SRC=https://github.com/tpm2-software/tpm2-tss/releases/download/$TSS2_REV/$TSS2_PKG.tar.gz
+
+       if test -d "$TSS2_DIR"; then
+               return
+       fi
+
+       # the default version of libgcrypt in Ubuntu 14.04 is too old
+       sudo apt-get update -qq && \
+       sudo apt-get install -qq libgcrypt20-dev &&
+       curl -L $TSS2_SRC | tar xz -C $TRAVIS_BUILD_DIR/.. &&
+       cd $TSS2_DIR &&
+       ./configure &&
+       make -j4 >/dev/null &&
+       sudo make install >/dev/null &&
+       sudo ldconfig || exit $?
+       cd -
+}
+
 if test -z $TRAVIS_BUILD_DIR; then
        TRAVIS_BUILD_DIR=$PWD
 fi
@@ -26,19 +80,28 @@ gcrypt)
        CONFIG="--disable-defaults --enable-pki --enable-gcrypt --enable-pkcs1"
        DEPS="libgcrypt11-dev"
        ;;
+botan)
+       CONFIG="--disable-defaults --enable-pki --enable-botan --enable-pem"
+       # we can't use the old package that comes with Ubuntu so we build from
+       # the current master until 2.8.0 is released and then probably switch to
+       # that unless we need newer features (at least 2.7.0 plus PKCS#1 patch is
+       # currently required)
+       DEPS=""
+       if test "$1" = "deps"; then
+               build_botan
+       fi
+       ;;
 printf-builtin)
        CONFIG="--with-printf-hooks=builtin"
        ;;
-all|coverage)
+all|coverage|sonarcloud)
        CONFIG="--enable-all --disable-android-dns --disable-android-log
-                       --disable-dumm --disable-kernel-pfroute --disable-keychain
+                       --disable-kernel-pfroute --disable-keychain
                        --disable-lock-profiler --disable-padlock --disable-fuzzing
                        --disable-osx-attr --disable-tkm --disable-uci
-                       --disable-systemd --disable-soup --disable-unwind-backtraces
+                       --disable-soup --disable-unwind-backtraces
                        --disable-svc --disable-dbghelp-backtraces --disable-socket-win
                        --disable-kernel-wfp --disable-kernel-iph --disable-winhttp"
-       # Ubuntu 14.04 does provide a too old libtss2-dev
-       CONFIG="$CONFIG --disable-tss-tss2"
        # not enabled on the build server
        CONFIG="$CONFIG --disable-af-alg"
        if test "$TEST" != "coverage"; then
@@ -49,10 +112,13 @@ all|coverage)
        fi
        DEPS="$DEPS libcurl4-gnutls-dev libsoup2.4-dev libunbound-dev libldns-dev
                  libmysqlclient-dev libsqlite3-dev clearsilver-dev libfcgi-dev
-                 libnm-glib-dev libnm-glib-vpn-dev libpcsclite-dev libpam0g-dev
-                 binutils-dev libunwind8-dev libjson0-dev iptables-dev python-pip
-                 libtspi-dev"
+                 libpcsclite-dev libpam0g-dev binutils-dev libunwind8-dev libnm-dev
+                 libjson0-dev iptables-dev python-pip libtspi-dev libsystemd-dev"
        PYDEPS="pytest"
+       if test "$1" = "deps"; then
+               build_botan
+               build_tss2
+       fi
        ;;
 win*)
        CONFIG="--disable-defaults --enable-svc --enable-ikev2
@@ -63,7 +129,8 @@ win*)
                        --enable-updown --enable-ext-auth --enable-libipsec
                        --enable-tnccs-20 --enable-imc-attestation --enable-imv-attestation
                        --enable-imc-os --enable-imv-os --enable-tnc-imv --enable-tnc-imc
-                       --enable-pki --enable-swanctl --enable-socket-win"
+                       --enable-pki --enable-swanctl --enable-socket-win
+                       --enable-kernel-iph --enable-kernel-wfp --enable-winhttp"
        # no make check for Windows binaries unless we run on a windows host
        if test "$APPVEYOR" != "True"; then
                TARGET=
@@ -77,20 +144,13 @@ win*)
        DEPS="gcc-mingw-w64-base"
        case "$TEST" in
        win64)
-               # headers on 12.04 are too old, so we only build the plugins here
-               CONFIG="--host=x86_64-w64-mingw32 $CONFIG --enable-dbghelp-backtraces
-                               --enable-kernel-iph --enable-kernel-wfp --enable-winhttp"
+               CONFIG="--host=x86_64-w64-mingw32 $CONFIG --enable-dbghelp-backtraces"
                DEPS="gcc-mingw-w64-x86-64 binutils-mingw-w64-x86-64 mingw-w64-x86-64-dev $DEPS"
                CC="x86_64-w64-mingw32-gcc"
-               # apply patch to MinGW headers
-               if test "$APPVEYOR" != "True" -a -z "$1"; then
-                       sudo patch -f -p 4 -d /usr/share/mingw-w64/include < src/libcharon/plugins/kernel_wfp/mingw-w64-4.8.1.diff
-               fi
                ;;
        win32)
                CONFIG="--host=i686-w64-mingw32 $CONFIG"
-               # currently only works on 12.04, so use mingw-w64-dev instead of mingw-w64-i686-dev
-               DEPS="gcc-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-dev $DEPS"
+               DEPS="gcc-mingw-w64-i686 binutils-mingw-w64-i686 mingw-w64-i686-dev $DEPS"
                CC="i686-w64-mingw32-gcc"
                ;;
        esac
@@ -125,7 +185,8 @@ osx)
        ;;
 fuzzing)
        CFLAGS="$CFLAGS -DNO_CHECK_MEMWIPE"
-       CONFIG="--enable-fuzzing --enable-static --disable-shared --disable-scripts"
+       CONFIG="--enable-fuzzing --enable-static --disable-shared --disable-scripts
+                       --enable-imc-test --enable-tnccs-20"
        # don't run any of the unit tests
        export TESTS_RUNNERS=
        # prepare corpora
@@ -175,7 +236,7 @@ if test "$1" = "deps"; then
 fi
 
 if test "$1" = "pydeps"; then
-       test -z "$PYDEPS" || sudo pip -q install $PYDEPS
+       test -z "$PYDEPS" || pip -q install --user $PYDEPS
        exit $?
 fi
 
@@ -200,7 +261,16 @@ apidoc)
 esac
 
 echo "$ make $TARGET"
-make -j4 $TARGET || exit $?
+case "$TEST" in
+sonarcloud)
+       # without target, coverage is currently not supported anyway because
+       # sonarqube only supports gcov, not lcov
+       build-wrapper-linux-x86-64 --out-dir bw-output make -j4 || exit $?
+       ;;
+*)
+       make -j4 $TARGET || exit $?
+       ;;
+esac
 
 case "$TEST" in
 apidoc)
@@ -209,6 +279,13 @@ apidoc)
                exit 1
        fi
        ;;
+sonarcloud)
+       sonar-scanner \
+               -Dsonar.projectKey=strongswan \
+               -Dsonar.projectVersion=$(git describe)+${TRAVIS_BUILD_NUMBER} \
+               -Dsonar.sources=. \
+               -Dsonar.cfamily.build-wrapper-output=bw-output || exit $?
+       ;;
 *)
        ;;
 esac