blob: f898f57f39d4e87e0506daa466d78b1e9863994b [file] [log] [blame]
#!/usr/bin/env bash
# SPDX-License-Identifier: BSD-3-Clause
set -eo pipefail
source $DOCKER_BUILD_DIR/.ci/docker-prelude.sh
export CONFIGURE_OPTIONS=
if [ -d build ]; then
rm -rf build
fi
if [ -d ./build-no-tests ]; then
rm -rf build-no-tests
fi
if [ -d ./config_test ]; then
rm -rf config_test
fi
if [ -z "$WITH_CRYPTO" ]; then
echo "variable WITH_CRYPTO not set, defaulting to ossl"
export WITH_CRYPTO="ossl"
fi
if [ "$WITH_CRYPTO" != "ossl" ]; then
export CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS --disable-fapi"
fi
./bootstrap
# Is it a fuzz run, if so build the fuzz test and exit.
if [ "$GEN_FUZZ" == "1" ]; then
./configure --with-fuzzing=libfuzzer --enable-tcti-fuzzing \
--disable-tcti-device --disable-tcti-mssim --disable-tcti-swtpm \
--disable-shared --with-crypto="$WITH_CRYPTO"
make -j$(nproc) check
exit 0
fi
if [ "$TEST_TCTI_CONFIG" != "true" ]; then
#
# General build runs
#
# build with no tests enabled
mkdir ./build-no-tests
pushd ./build-no-tests
echo "PWD: $(pwd)"
echo "ls -la ../ $(ls -la ../)"
../configure --with-crypto=$WITH_CRYPTO $CONFIGURE_OPTIONS
make -j$(nproc)
popd
# build with all tests enabled
mkdir ./build
pushd ./build
if [ "$CC" == "gcc" ]; then
export CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS --enable-code-coverage";
fi
if [ "$SCANBUILD" == "yes" ]; then
scan-build --status-bugs ../configure --enable-unit --enable-integration --with-crypto=$WITH_CRYPTO $CONFIGURE_OPTIONS
elif [ "$CC" == "clang" ]; then
../configure --enable-unit --enable-integration --with-crypto=$WITH_CRYPTO $CONFIGURE_OPTIONS
else
if [ "$WITH_TCTI" == "mssim" ]; then
../configure --with-sanitizer=undefined,address --disable-tcti-swtpm --enable-unit --enable-integration --with-crypto=$WITH_CRYPTO $CONFIGURE_OPTIONS
else
../configure --with-sanitizer=undefined,address --enable-unit --enable-integration --with-crypto=$WITH_CRYPTO $CONFIGURE_OPTIONS
fi
fi
if [ "$SCANBUILD" == "yes" ]; then
scan-build --status-bugs make -j distcheck
elif [ "$CC" == "clang" ]; then
make -j distcheck
else
make -j check
fi
popd
else # TEST_TCTI_CONFIG == true
mkdir ./config_test
pushd ./config_test
if [ "$CC" == "gcc" ]; then
# No TCTI - expect to fail
echo "========================== START TEST - NO TCTI =========================="
(../configure --disable-doxygen-doc --enable-unit --enable-integration --disable-tcti-swtpm --disable-tcti-mssim --disable-tcti-device && exit 1) || echo "failed as expected";
# only device TCTI
echo "========================== START TEST - device TCTI =========================="
mkdir -p ./dev/tpm0 && ../configure --disable-doxygen-doc --enable-unit --enable-integration --disable-tcti-swtpm --disable-tcti-mssim --enable-tcti-device --with-device=./dev/tpm0
make -j check TESTS="test/unit/tcti-device" && rm -rf ./dev
# only mssim TCTI
echo "========================== START TEST - mssim TCTI =========================="
../configure --disable-doxygen-doc --enable-unit --enable-integration --disable-tcti-swtpm --enable-tcti-mssim --disable-tcti-device
make -j check TESTS="test/unit/tcti-mssim"
# device and mssim TCTIs
echo "========================== START TEST - mssim & device TCTI =========================="
../configure --disable-doxygen-doc --enable-unit --enable-integration --disable-tcti-swtpm --enable-tcti-mssim --enable-tcti-device
make -j check TESTS="test/unit/tcti-device test/unit/tcti-mssim"
# only swtmp TCTI
echo "========================== START TEST - swtpm TCTI =========================="
../configure --disable-doxygen-doc --enable-unit --enable-integration --enable-tcti-swtpm --disable-tcti-mssim --disable-tcti-device
make -j check TESTS="test/unit/tcti-swtpm"
# swtmp and device TCTIs
echo "========================== START TEST - swtpm & device TCTI =========================="
../configure --disable-doxygen-doc --enable-unit --enable-integration --enable-tcti-swtpm --disable-tcti-mssim --enable-tcti-device
make -j check TESTS="test/unit/tcti-swtpm test/unit/tcti-device"
# swtmp and mssim TCTIs
echo "========================== START TEST - swtpm & mssim TCTI =========================="
../configure --disable-doxygen-doc --enable-unit --enable-integration --enable-tcti-swtpm --enable-tcti-mssim --disable-tcti-device
make -j check TESTS="test/unit/tcti-swtpm test/unit/tcti-mssim"
# all TCTIs
echo "========================== START TEST - swtpm & mssim & device TCTI =========================="
../configure --disable-doxygen-doc --enable-unit --enable-integration --enable-tcti-swtpm --enable-tcti-mssim --enable-tcti-device
make -j check TESTS="test/unit/tcti-swtpm test/unit/tcti-mssim test/unit/tcti-device"
fi # CC == gcc
popd
fi # TEST_TCTI_CONFIG
# back in root git directory, check for whitespace errors. We do this post CI
# so people can verify the rest of their patch works in CI before dying.
# git diff --check fails with a non-zero return code causing the shell to die
# as it has a set -e executed.
if [ -n "$BASE_REF" ]; then
echo "Running whitespace check"
git fetch origin "$BASE_REF"
git diff --check "origin/$BASE_REF"
fi
if [ "$ENABLE_COVERAGE" == "true" ]; then
bash <(curl -s https://codecov.io/bash)
fi
exit 0