2018-08-03 09:21:03 -04:00
#!/usr/bin/env bash
#
2021-12-30 14:36:57 -03:00
# Copyright (c) 2018-2021 The Bitcoin Core developers
2018-08-03 09:21:03 -04:00
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
2018-08-07 05:50:05 -04:00
export LC_ALL = C.UTF-8
2018-08-03 09:21:03 -04:00
2019-12-18 00:02:48 -03:00
if [ [ $QEMU_USER_CMD = = qemu-s390* ] ] ; then
export LC_ALL = C
fi
2019-11-29 16:46:49 -03:00
2020-11-08 07:28:24 -03:00
if [ " $CI_OS_NAME " = = "macos" ] ; then
2021-06-27 14:40:08 -04:00
sudo -H pip3 install --upgrade pip
2021-11-07 09:13:39 -03:00
# shellcheck disable=SC2086
2020-11-08 05:48:29 -03:00
IN_GETOPT_BIN = "/usr/local/opt/gnu-getopt/bin/getopt" ${ CI_RETRY_EXE } pip3 install --user $PIP_PACKAGES
2019-10-14 18:00:49 -03:00
fi
2020-04-22 10:24:29 -04:00
# Create folders that are mounted into the docker
2019-10-10 20:03:51 -03:00
mkdir -p " ${ CCACHE_DIR } "
2019-01-05 16:20:42 -03:00
mkdir -p " ${ PREVIOUS_RELEASES_DIR } "
2019-01-16 13:49:01 -03:00
2019-12-05 07:46:55 -03:00
export ASAN_OPTIONS = "detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1"
2019-11-20 21:40:22 -03:00
export LSAN_OPTIONS = " suppressions= ${ BASE_ROOT_DIR } /test/sanitizer_suppressions/lsan "
2020-05-30 07:56:31 -04:00
export TSAN_OPTIONS = " suppressions= ${ BASE_ROOT_DIR } /test/sanitizer_suppressions/tsan:halt_on_error=1:log_path= ${ BASE_SCRATCH_DIR } /sanitizer-output/tsan "
2019-11-20 16:10:57 -03:00
export UBSAN_OPTIONS = " suppressions= ${ BASE_ROOT_DIR } /test/sanitizer_suppressions/ubsan:print_stacktrace=1:halt_on_error=1:report_error_type=1 "
2020-05-19 07:12:22 -04:00
env | grep -E '^(BITCOIN_CONFIG|BASE_|QEMU_|CCACHE_|LC_ALL|BOOST_TEST_RANDOM|DEBIAN_FRONTEND|CONFIG_SHELL|(ASAN|LSAN|TSAN|UBSAN)_OPTIONS|PREVIOUS_RELEASES_DIR)' | tee /tmp/env
2020-11-09 06:17:00 -03:00
if [ [ $BITCOIN_CONFIG = *--with-sanitizers= *address* ] ] ; then # If ran with (ASan + LSan), Docker needs access to ptrace (https://github.com/google/sanitizers/issues/764)
2018-12-28 11:28:00 -03:00
DOCKER_ADMIN = "--cap-add SYS_PTRACE"
2018-08-03 09:21:03 -04:00
fi
2019-11-22 15:58:53 -03:00
export P_CI_DIR = " $PWD "
2020-04-08 19:59:37 -04:00
if [ -z " $DANGER_RUN_CI_ON_HOST " ] ; then
2019-08-11 11:57:21 -04:00
echo " Creating $DOCKER_NAME_TAG container to run in "
${ CI_RETRY_EXE } docker pull " $DOCKER_NAME_TAG "
2021-03-25 07:14:35 -03:00
if [ -n " ${ RESTART_CI_DOCKER_BEFORE_RUN } " ] ; then
echo "Restart docker before run to stop and clear all containers started with --rm"
systemctl restart docker
fi
2021-11-07 09:13:39 -03:00
# shellcheck disable=SC2086
2021-03-25 07:14:35 -03:00
DOCKER_ID = $( docker run $DOCKER_ADMIN --rm --interactive --detach --tty \
2019-11-20 21:40:22 -03:00
--mount type = bind,src= $BASE_ROOT_DIR ,dst= /ro_base,readonly \
2019-11-09 11:20:41 -03:00
--mount type = bind,src= $CCACHE_DIR ,dst= $CCACHE_DIR \
2019-11-20 21:40:22 -03:00
--mount type = bind,src= $DEPENDS_DIR ,dst= $DEPENDS_DIR \
2019-01-05 16:20:42 -03:00
--mount type = bind,src= $PREVIOUS_RELEASES_DIR ,dst= $PREVIOUS_RELEASES_DIR \
2019-11-20 21:40:22 -03:00
-w $BASE_ROOT_DIR \
2019-11-09 11:20:41 -03:00
--env-file /tmp/env \
2020-02-04 21:43:10 -03:00
--name $CONTAINER_NAME \
2019-11-09 11:20:41 -03:00
$DOCKER_NAME_TAG )
2020-05-30 07:56:56 -04:00
export DOCKER_CI_CMD_PREFIX = " docker exec $DOCKER_ID "
2019-08-11 11:57:21 -04:00
else
echo "Running on host system without docker wrapper"
fi
2020-05-30 07:56:56 -04:00
2022-01-31 08:09:37 -03:00
CI_EXEC ( ) {
2021-11-07 09:13:39 -03:00
$DOCKER_CI_CMD_PREFIX bash -c " export PATH= $BASE_SCRATCH_DIR /bins/:\$PATH && cd \" $P_CI_DIR \" && $* "
2020-05-30 07:56:56 -04:00
}
2022-01-31 08:09:37 -03:00
export -f CI_EXEC
2019-08-11 11:57:21 -04:00
2019-10-10 20:04:49 -03:00
if [ -n " $DPKG_ADD_ARCH " ] ; then
2022-01-31 08:09:37 -03:00
CI_EXEC dpkg --add-architecture " $DPKG_ADD_ARCH "
2019-10-10 20:04:49 -03:00
fi
2019-10-14 18:00:49 -03:00
2022-01-31 07:19:23 -03:00
if [ [ $DOCKER_NAME_TAG = = *centos* ] ] ; then
2022-01-31 08:09:37 -03:00
${ CI_RETRY_EXE } CI_EXEC dnf -y install epel-release
${ CI_RETRY_EXE } CI_EXEC dnf -y --allowerasing install " $DOCKER_PACKAGES " " $PACKAGES "
2020-03-26 09:30:02 -03:00
elif [ " $CI_USE_APT_INSTALL " != "no" ] ; then
2022-01-31 08:09:37 -03:00
${ CI_RETRY_EXE } CI_EXEC apt-get update
${ CI_RETRY_EXE } CI_EXEC apt-get install --no-install-recommends --no-upgrade -y " $PACKAGES " " $DOCKER_PACKAGES "
2021-04-13 00:40:15 -04:00
if [ -n " $PIP_PACKAGES " ] ; then
2021-11-07 09:13:39 -03:00
# shellcheck disable=SC2086
2021-04-13 00:40:15 -04:00
${ CI_RETRY_EXE } pip3 install --user $PIP_PACKAGES
fi
2019-10-14 18:00:49 -03:00
fi
2018-08-03 09:21:03 -04:00
2020-11-08 07:28:24 -03:00
if [ " $CI_OS_NAME " = = "macos" ] ; then
2019-12-17 17:22:41 -03:00
top -l 1 -s 0 | awk ' /PhysMem/ {print}'
echo " Number of CPUs: $( sysctl -n hw.logicalcpu) "
else
2022-01-31 08:09:37 -03:00
CI_EXEC free -m -h
CI_EXEC echo "Number of CPUs \(nproc\):" \$ \( nproc\)
CI_EXEC echo " $( lscpu | grep Endian) "
2019-12-17 17:22:41 -03:00
fi
2022-01-31 08:09:37 -03:00
CI_EXEC echo "Free disk space:"
CI_EXEC df -h
2019-12-17 17:22:41 -03:00
2022-01-02 07:01:32 -03:00
if [ " $RUN_FUZZ_TESTS " = "true" ] ; then
export DIR_FUZZ_IN = ${ DIR_QA_ASSETS } /fuzz_seed_corpus/
if [ ! -d " $DIR_FUZZ_IN " ] ; then
2022-01-31 08:09:37 -03:00
CI_EXEC git clone --depth= 1 https://github.com/bitcoin-core/qa-assets " ${ DIR_QA_ASSETS } "
2021-06-30 05:58:58 -04:00
fi
2022-01-02 07:01:32 -03:00
elif [ " $RUN_UNIT_TESTS " = "true" ] || [ " $RUN_UNIT_TESTS_SEQUENTIAL " = "true" ] ; then
2021-06-30 05:58:58 -04:00
export DIR_UNIT_TEST_DATA = ${ DIR_QA_ASSETS } /unit_test_data/
2022-01-02 07:01:32 -03:00
if [ ! -d " $DIR_UNIT_TEST_DATA " ] ; then
2022-01-31 08:09:37 -03:00
CI_EXEC mkdir -p " $DIR_UNIT_TEST_DATA "
CI_EXEC curl --location --fail https://github.com/bitcoin-core/qa-assets/raw/main/unit_test_data/script_assets_test.json -o " ${ DIR_UNIT_TEST_DATA } /script_assets_test.json "
2022-01-02 07:01:32 -03:00
fi
2019-11-09 11:13:30 -03:00
fi
2022-01-31 08:09:37 -03:00
CI_EXEC mkdir -p " ${ BASE_SCRATCH_DIR } /sanitizer-output/ "
2019-11-09 11:16:16 -03:00
2020-06-01 04:12:33 -04:00
if [ [ ${ USE_MEMORY_SANITIZER } = = "true" ] ] ; then
2021-09-17 06:22:53 -03:00
CI_EXEC "update-alternatives --install /usr/bin/clang++ clang++ \$(which clang++-12) 100"
CI_EXEC "update-alternatives --install /usr/bin/clang clang \$(which clang-12) 100"
2022-01-31 08:09:37 -03:00
CI_EXEC " mkdir -p ${ BASE_SCRATCH_DIR } /msan/build/ "
CI_EXEC " git clone --depth=1 https://github.com/llvm/llvm-project -b llvmorg-12.0.0 ${ BASE_SCRATCH_DIR } /msan/llvm-project "
2021-09-17 06:22:53 -03:00
CI_EXEC " cd ${ BASE_SCRATCH_DIR } /msan/build/ && cmake -DLLVM_ENABLE_PROJECTS='libcxx;libcxxabi' -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER=MemoryWithOrigins -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DLLVM_TARGETS_TO_BUILD=X86 ../llvm-project/llvm/ "
2022-01-31 08:09:37 -03:00
CI_EXEC " cd ${ BASE_SCRATCH_DIR } /msan/build/ && make $MAKEJOBS cxx "
2020-06-01 04:12:33 -04:00
fi
2020-04-08 19:59:37 -04:00
if [ -z " $DANGER_RUN_CI_ON_HOST " ] ; then
2019-11-20 21:40:22 -03:00
echo " Create $BASE_ROOT_DIR "
2022-01-31 08:09:37 -03:00
CI_EXEC rsync -a /ro_base/ " $BASE_ROOT_DIR "
2019-11-09 11:20:41 -03:00
fi
2019-09-30 18:26:22 -03:00
if [ " $USE_BUSY_BOX " = "true" ] ; then
echo "Setup to use BusyBox utils"
2022-01-31 08:09:37 -03:00
CI_EXEC mkdir -p " ${ BASE_SCRATCH_DIR } /bins/ "
2019-09-30 18:26:22 -03:00
# tar excluded for now because it requires passing in the exact archive type in ./depends (fixed in later BusyBox version)
# find excluded for now because it does not recognize the -delete option in ./depends (fixed in later BusyBox version)
# ar excluded for now because it does not recognize the -q option in ./depends (unknown if fixed)
# shellcheck disable=SC1010
2022-01-31 08:09:37 -03:00
CI_EXEC for util in \$ \( busybox --list \| grep -v " ^ar $" \| grep -v " ^tar $" \| grep -v " ^find $" \) \; do ln -s \$ \( command -v busybox\) " ${ BASE_SCRATCH_DIR } /bins/\$util " \; done
2019-09-30 18:26:22 -03:00
# Print BusyBox version
2022-01-31 08:09:37 -03:00
CI_EXEC patch --help
2019-09-30 18:26:22 -03:00
fi