2018-08-03 15:21:03 +02:00
#!/usr/bin/env bash
#
2022-12-24 23:49:50 +00:00
# Copyright (c) 2018-2022 The Bitcoin Core developers
2018-08-03 15:21:03 +02:00
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
2018-08-07 11:50:05 +02:00
export LC_ALL = C.UTF-8
2018-08-03 15:21:03 +02:00
2019-12-17 22:02:48 -05:00
if [ [ $QEMU_USER_CMD = = qemu-s390* ] ] ; then
export LC_ALL = C
fi
2019-11-29 21:46:49 +02:00
2020-04-22 10:24:29 -04:00
# Create folders that are mounted into the docker
2019-10-10 19:03:51 -04:00
mkdir -p " ${ CCACHE_DIR } "
2019-01-05 20:20:42 +01:00
mkdir -p " ${ PREVIOUS_RELEASES_DIR } "
2019-01-16 11:49:01 -05:00
2019-12-05 10:46:55 +00:00
export ASAN_OPTIONS = "detect_stack_use_after_return=1:check_initialization_order=1:strict_init_order=1"
2019-11-20 19:40:22 -05: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 14:10:57 -05: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 10:17:00 +01: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)
2023-01-09 10:22:18 +01:00
CI_CONTAINER_CAP = "--cap-add SYS_PTRACE"
2018-08-03 15:21:03 +02:00
fi
2019-11-22 13:58:53 -05:00
export P_CI_DIR = " $PWD "
2023-01-09 11:56:57 +01:00
export BINS_SCRATCH_DIR = " ${ BASE_SCRATCH_DIR } /bins/ "
2019-11-22 13:58:53 -05:00
2020-04-09 02:59:37 +03:00
if [ -z " $DANGER_RUN_CI_ON_HOST " ] ; then
2023-01-09 10:22:18 +01:00
echo " Creating $CI_IMAGE_NAME_TAG container to run in "
2022-10-06 15:06:29 -04:00
LOCAL_UID = $( id -u)
LOCAL_GID = $( id -g)
# the name isn't important, so long as we use the same UID
LOCAL_USER = nonroot
2023-01-27 12:42:46 +01:00
DOCKER_BUILDKIT = 1 ${ CI_RETRY_EXE } docker build \
--file " ${ BASE_ROOT_DIR } /ci/test_imagefile " \
--build-arg " CI_IMAGE_NAME_TAG= ${ CI_IMAGE_NAME_TAG } " \
--build-arg " FILE_ENV= ${ FILE_ENV } " \
--tag= " ${ CONTAINER_NAME } " \
" ${ BASE_ROOT_DIR } "
2023-02-03 11:41:17 +01:00
docker volume create " ${ CONTAINER_NAME } _ccache " || true
docker volume create " ${ CONTAINER_NAME } _depends " || true
docker volume create " ${ CONTAINER_NAME } _previous_releases " || true
2019-08-11 11:57:21 -04:00
2021-03-25 11:14:35 +01: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 14:13:39 +02:00
# shellcheck disable=SC2086
2023-01-09 10:22:18 +01:00
CI_CONTAINER_ID = $( docker run $CI_CONTAINER_CAP --rm --interactive --detach --tty \
2019-11-20 19:40:22 -05:00
--mount type = bind,src= $BASE_ROOT_DIR ,dst= /ro_base,readonly \
2023-02-03 11:41:17 +01:00
--mount " type=volume,src= ${ CONTAINER_NAME } _ccache,dst= $CCACHE_DIR " \
--mount " type=volume,src= ${ CONTAINER_NAME } _depends,dst= $DEPENDS_DIR " \
--mount " type=volume,src= ${ CONTAINER_NAME } _previous_releases,dst= $PREVIOUS_RELEASES_DIR " \
2019-11-20 19:40:22 -05:00
-w $BASE_ROOT_DIR \
2019-11-09 09:20:41 -05:00
--env-file /tmp/env \
2020-02-05 08:43:10 +08:00
--name $CONTAINER_NAME \
2023-01-27 12:42:46 +01:00
$CONTAINER_NAME )
2023-01-09 10:42:19 +01:00
export CI_CONTAINER_ID
2022-10-06 15:06:29 -04:00
# Create a non-root user inside the container which matches the local user.
#
# This prevents the root user in the container modifying the local file system permissions
# on the mounted directories
2023-01-09 10:22:18 +01:00
docker exec " $CI_CONTAINER_ID " useradd -u " $LOCAL_UID " -o -m " $LOCAL_USER "
docker exec " $CI_CONTAINER_ID " groupmod -o -g " $LOCAL_GID " " $LOCAL_USER "
docker exec " $CI_CONTAINER_ID " chown -R " $LOCAL_USER " :" $LOCAL_USER " " ${ BASE_ROOT_DIR } "
export CI_EXEC_CMD_PREFIX_ROOT = " docker exec -u 0 $CI_CONTAINER_ID "
export CI_EXEC_CMD_PREFIX = " docker exec -u $LOCAL_UID $CI_CONTAINER_ID "
2019-08-11 11:57:21 -04:00
else
echo "Running on host system without docker wrapper"
2023-01-27 12:42:46 +01:00
" ${ BASE_ROOT_DIR } /ci/test/01_base_install.sh "
2019-08-11 11:57:21 -04:00
fi
2020-05-30 07:56:56 -04:00
2022-01-31 12:09:37 +01:00
CI_EXEC ( ) {
2023-01-09 10:22:18 +01:00
$CI_EXEC_CMD_PREFIX bash -c " export PATH= ${ BINS_SCRATCH_DIR } :\$PATH && cd \" $P_CI_DIR \" && $* "
2020-05-30 07:56:56 -04:00
}
2022-10-06 15:06:29 -04:00
CI_EXEC_ROOT ( ) {
2023-01-09 10:22:18 +01:00
$CI_EXEC_CMD_PREFIX_ROOT bash -c " export PATH= ${ BINS_SCRATCH_DIR } :\$PATH && cd \" $P_CI_DIR \" && $* "
2022-10-06 15:06:29 -04:00
}
2022-01-31 12:09:37 +01:00
export -f CI_EXEC
2022-10-06 15:06:29 -04:00
export -f CI_EXEC_ROOT
2019-08-11 11:57:21 -04:00
2023-01-09 11:56:57 +01:00
CI_EXEC mkdir -p " ${ BINS_SCRATCH_DIR } "
2022-10-03 12:57:50 +02:00
if [ -n " $PIP_PACKAGES " ] ; then
if [ " $CI_OS_NAME " = = "macos" ] ; then
sudo -H pip3 install --upgrade pip
# shellcheck disable=SC2086
2022-10-25 09:48:35 +01:00
IN_GETOPT_BIN = " $( brew --prefix gnu-getopt) /bin/getopt " ${ CI_RETRY_EXE } pip3 install --user $PIP_PACKAGES
2022-10-03 12:57:50 +02:00
else
2021-11-07 14:13:39 +02:00
# shellcheck disable=SC2086
2022-10-03 12:57:50 +02:00
${ CI_RETRY_EXE } CI_EXEC pip3 install --user $PIP_PACKAGES
2021-04-13 12:40:15 +08:00
fi
2019-10-14 23:00:49 +02:00
fi
2018-08-03 15:21:03 +02:00
2020-11-08 11:28:24 +01:00
if [ " $CI_OS_NAME " = = "macos" ] ; then
2019-12-17 15:22:41 -05:00
top -l 1 -s 0 | awk ' /PhysMem/ {print}'
echo " Number of CPUs: $( sysctl -n hw.logicalcpu) "
else
2022-01-31 12:09:37 +01:00
CI_EXEC free -m -h
CI_EXEC echo "Number of CPUs \(nproc\):" \$ \( nproc\)
CI_EXEC echo " $( lscpu | grep Endian) "
2019-12-17 15:22:41 -05:00
fi
2022-01-31 12:09:37 +01:00
CI_EXEC echo "Free disk space:"
CI_EXEC df -h
2019-12-17 15:22:41 -05:00
2022-01-02 12:01:32 +02: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 12:09:37 +01:00
CI_EXEC git clone --depth= 1 https://github.com/bitcoin-core/qa-assets " ${ DIR_QA_ASSETS } "
2021-06-30 11:58:58 +02:00
fi
2022-01-02 12:01:32 +02:00
elif [ " $RUN_UNIT_TESTS " = "true" ] || [ " $RUN_UNIT_TESTS_SEQUENTIAL " = "true" ] ; then
2021-06-30 11:58:58 +02:00
export DIR_UNIT_TEST_DATA = ${ DIR_QA_ASSETS } /unit_test_data/
2022-01-02 12:01:32 +02:00
if [ ! -d " $DIR_UNIT_TEST_DATA " ] ; then
2022-01-31 12:09:37 +01: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 12:01:32 +02:00
fi
2019-11-09 09:13:30 -05:00
fi
2022-01-31 12:09:37 +01:00
CI_EXEC mkdir -p " ${ BASE_SCRATCH_DIR } /sanitizer-output/ "
2019-11-09 09:16:16 -05:00
2020-06-01 08:12:33 +00:00
if [ [ ${ USE_MEMORY_SANITIZER } = = "true" ] ] ; then
2022-11-25 14:13:29 +01:00
CI_EXEC_ROOT "update-alternatives --install /usr/bin/clang++ clang++ \$(which clang++-12) 100"
CI_EXEC_ROOT "update-alternatives --install /usr/bin/clang clang \$(which clang-12) 100"
2022-01-31 12:09:37 +01: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 11:22:53 +02: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 12:09:37 +01:00
CI_EXEC " cd ${ BASE_SCRATCH_DIR } /msan/build/ && make $MAKEJOBS cxx "
2020-06-01 08:12:33 +00:00
fi
2022-04-11 20:45:22 +01:00
if [ [ " ${ RUN_TIDY } " = = "true" ] ] ; then
2022-04-29 15:07:11 +02:00
export DIR_IWYU = " ${ BASE_SCRATCH_DIR } /iwyu "
if [ ! -d " ${ DIR_IWYU } " ] ; then
CI_EXEC " mkdir -p ${ DIR_IWYU } /build/ "
2023-03-22 15:21:39 +00:00
CI_EXEC " git clone --depth=1 https://github.com/include-what-you-use/include-what-you-use -b clang_15 ${ DIR_IWYU } /include-what-you-use "
CI_EXEC " cd ${ DIR_IWYU } /build && cmake -G 'Unix Makefiles' -DCMAKE_PREFIX_PATH=/usr/lib/llvm-15 ../include-what-you-use "
2022-10-06 15:06:29 -04:00
CI_EXEC_ROOT " cd ${ DIR_IWYU } /build && make install $MAKEJOBS "
2022-04-29 15:07:11 +02:00
fi
2022-04-11 20:45:22 +01:00
fi
2020-04-09 02:59:37 +03:00
if [ -z " $DANGER_RUN_CI_ON_HOST " ] ; then
2019-11-20 19:40:22 -05:00
echo " Create $BASE_ROOT_DIR "
2022-01-31 12:09:37 +01:00
CI_EXEC rsync -a /ro_base/ " $BASE_ROOT_DIR "
2019-11-09 09:20:41 -05:00
fi
2019-09-30 17:26:22 -04:00
if [ " $USE_BUSY_BOX " = "true" ] ; then
echo "Setup to use BusyBox utils"
# tar excluded for now because it requires passing in the exact archive type 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
2023-01-09 12:19:24 +01:00
CI_EXEC for util in \$ \( busybox --list \| grep -v " ^ar $" \| grep -v " ^tar $" \) \; do ln -s \$ \( command -v busybox\) " ${ BINS_SCRATCH_DIR } /\$util " \; done
2019-09-30 17:26:22 -04:00
# Print BusyBox version
2022-01-31 12:09:37 +01:00
CI_EXEC patch --help
2019-09-30 17:26:22 -04:00
fi