blob: f8ebdf9db490ded1660963f20b27ee05f65d2337 [file] [log] [blame]
Jan Kundrátd9d26a92018-02-22 12:49:21 +01001#!/bin/bash
Jan Kundrát73e3bf22019-02-28 15:44:02 +01002
3set -eux -o pipefail
Jan Kundráte6c0f5c2020-04-08 00:08:28 +02004shopt -s failglob extglob
Jan Kundrát73e3bf22019-02-28 15:44:02 +01005
6ZUUL_JOB_NAME=$(jq < ~/zuul-env.json -r '.job')
Jan Kundrát8a914662019-02-28 18:11:55 +01007ZUUL_TENANT=$(jq < ~/zuul-env.json -r '.tenant')
Jan Kundrátdbb678f2022-03-23 22:20:28 +01008LEAF_PROJECT_NAME=CzechLight/netconf-cli
9ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r ".projects[] | select(.name == \"${LEAF_PROJECT_NAME}\").src_dir")
10ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r ".projects[] | select(.name == \"${LEAF_PROJECT_NAME}\").short_name")
Jan Kundrátdba63582019-06-06 13:09:30 +020011ZUUL_GERRIT_HOSTNAME=$(jq < ~/zuul-env.json -r '.project.canonical_hostname')
Jan Kundrátdbb678f2022-03-23 22:20:28 +010012ZUUL_JOB_NAME_NO_PROJECT=${ZUUL_JOB_NAME##${ZUUL_PROJECT_SHORT_NAME}-}
Jan Kundrátbb0931e2023-02-01 23:45:11 +010013ZUUL_SRC_COMMON_PREFIX=${ZUUL_PROJECT_SRC_DIR:0:-${#LEAF_PROJECT_NAME}}
Jan Kundrát73e3bf22019-02-28 15:44:02 +010014
Jan Kundráte13caa32022-03-23 13:52:35 +010015CI_PARALLEL_JOBS=$(awk -vcpu=$(getconf _NPROCESSORS_ONLN) 'BEGIN{printf "%.0f", cpu*1.3+1}')
Jan Kundrát73e3bf22019-02-28 15:44:02 +010016CMAKE_OPTIONS=""
Jan Kundrátbb0931e2023-02-01 23:45:11 +010017CFLAGS="-O2 -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"
18CXXFLAGS="-O2 -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer"
Jan Kundrát73e3bf22019-02-28 15:44:02 +010019LDFLAGS=""
20
21if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then
22 export CC=clang
23 export CXX=clang++
24 export LD=clang
Jan Kundrát73e3bf22019-02-28 15:44:02 +010025fi
26
27if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then
28 export CFLAGS="-fsanitize=undefined ${CFLAGS}"
29 export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}"
30 export LDFLAGS="-fsanitize=undefined ${LDFLAGS}"
Jan Kundrát86840ec2021-01-27 15:38:08 +010031 export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
Jan Kundrát73e3bf22019-02-28 15:44:02 +010032fi
33
Jan Kundrátbb0931e2023-02-01 23:45:11 +010034if [[ $ZUUL_JOB_NAME =~ .*-asan-ubsan ]]; then
35 export CFLAGS="-fsanitize=address,undefined -Wp,-U_FORTIFY_SOURCE ${CFLAGS}"
36 export CXXFLAGS="-fsanitize=address,undefined -Wp,-U_FORTIFY_SOURCE ${CXXFLAGS}"
37 export LDFLAGS="-fsanitize=address,undefined ${LDFLAGS}"
38 export ASAN_OPTIONS=intercept_tls_get_addr=0,log_to_syslog=true,handle_abort=2,strip_path_prefix=${ZUUL_SRC_COMMON_PREFIX}
39 export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1
Jan Kundrát73e3bf22019-02-28 15:44:02 +010040fi
41
Jan Kundrát7b7c8232019-03-13 14:04:06 +010042if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then
Jan Kundrátbb0931e2023-02-01 23:45:11 +010043 export CFLAGS="-fsanitize=thread -Wp,-U_FORTIFY_SOURCE ${CFLAGS}"
44 export CXXFLAGS="-fsanitize=thread -Wp,-U_FORTIFY_SOURCE ${CXXFLAGS}"
Jan Kundrát7b7c8232019-03-13 14:04:06 +010045 export LDFLAGS="-fsanitize=thread ${LDFLAGS}"
Jan Kundrát86840ec2021-01-27 15:38:08 +010046 export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp"
Jan Kundrát7b7c8232019-03-13 14:04:06 +010047fi
48
Jan Kundrát07a5cc52020-05-22 09:43:05 +020049if [[ ${ZUUL_JOB_NAME%%-cover?(-previous|-diff)} =~ -gcc$ ]]; then
Jan Kundrátcf5c6362020-01-16 22:54:47 +010050 # Python and ASAN (and, presumably, all other sanitizers) are tricky to use from a Python DSO,
51 # I was, e.g., getting unrelated failures from libyang's thread-local global access (ly_errno)
52 # even when correctly injecting the ASAN runtime via LD_PRELOAD. Let's just give up and only
53 # enable this when not using sanitizers.
54 # I'm still adding some code to CMakeLists.txt which makes it work locally (Jan's dev environment
55 # with GCC8 and ASAN, Gentoo).
56 CMAKE_OPTIONS="${CMAKE_OPTIONS} -DWITH_PYTHON_BINDINGS=ON"
57fi
58
Jan Kundráte6c0f5c2020-04-08 00:08:28 +020059if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then
60 export CFLAGS="${CFLAGS} --coverage"
61 export CXXFLAGS="${CXXFLAGS} --coverage"
62 export LDFLAGS="${LDFLAGS} --coverage"
63fi
64
Jan Kundrát73e3bf22019-02-28 15:44:02 +010065PREFIX=~/target
66mkdir ${PREFIX}
67BUILD_DIR=~/build
68mkdir ${BUILD_DIR}
Jan Kundráte13caa32022-03-23 13:52:35 +010069export PATH=${PREFIX}/bin:/sbin:/usr/sbin:$PATH
Jan Kundrát73e3bf22019-02-28 15:44:02 +010070export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
Jan Kundrát0e783ac2019-10-30 12:29:17 +010071export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH}
Jan Kundrát73e3bf22019-02-28 15:44:02 +010072
Jan Kundrát566d33c2020-04-17 14:33:37 +020073ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "tarball") | select(.project == "CzechLight/dependencies")][-1]?.url + ""')
Jan Kundrát73e3bf22019-02-28 15:44:02 +010074
Jan Kundrát73e3bf22019-02-28 15:44:02 +010075if [[ -z "${ARTIFACT_URL}" ]]; then
Jan Kundráte13caa32022-03-23 13:52:35 +010076 # nothing ahead in the pipeline -> fallback to the latest promoted artifact
77 DEPSRCDIR=$(jq < ~/zuul-env.json -e -r ".projects[] | select(.name == \"CzechLight/dependencies\").src_dir")
78 DEP_SUBMODULE_COMMIT=$(git --git-dir ${HOME}/${DEPSRCDIR}/.git rev-parse HEAD)
Jan Kundrát07e8f8b2022-03-28 13:00:06 +020079 ARTIFACT_URL="https://object-store.cloud.muni.cz/swift/v1/ci-artifacts-${ZUUL_TENANT}/${ZUUL_GERRIT_HOSTNAME}/CzechLight/dependencies/deps-${ZUUL_JOB_NAME_NO_PROJECT%%+(-cover?(-previous)|-netconf-cli-no-sysrepo)}/${DEP_SUBMODULE_COMMIT}.tar.zst"
Jan Kundrát73e3bf22019-02-28 15:44:02 +010080fi
81
Jan Kundrátb1cca842020-05-15 16:59:52 +020082curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf -
Jan Kundrát73e3bf22019-02-28 15:44:02 +010083
Jan Kundrátbba52522020-11-11 17:40:31 +010084if [[ ${ZUUL_JOB_NAME} =~ .*-no-sysrepo ]]; then
85 rm -rf ${PREFIX}/include/sysrepo*
86 rm ${PREFIX}/lib*/libsysrepo*
87 rm ${PREFIX}/lib*/pkgconfig/sysrepo*
88 rm ${PREFIX}/bin/sysrepo*
89fi
90
Václav Kubernát634e24a2020-11-19 01:20:27 +010091mkdir ~/zuul-output/logs/test_netopeer_outputs
92
Jan Kundrát73e3bf22019-02-28 15:44:02 +010093cd ${BUILD_DIR}
Václav Kubernát634e24a2020-11-19 01:20:27 +010094ln -s ~/zuul-output/logs/test_netopeer_outputs test_netopeer_outputs
Jan Kundrát73e3bf22019-02-28 15:44:02 +010095cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
96ninja-build
97ctest -j${CI_PARALLEL_JOBS} --output-on-failure
Jan Kundrát20c17482020-04-08 00:39:05 +020098
Jan Kundrátbba52522020-11-11 17:40:31 +010099if [[ ! ${ZUUL_JOB_NAME} =~ .*-no-sysrepo ]]; then
100 # Normal builds should have the sysrepo and NETCONF tests
101 ctest --show-only=json-v1 | jq -r '.["tests"] | map(.name)' | grep -q test_datastore_access_netconf
102 ctest --show-only=json-v1 | jq -r '.["tests"] | map(.name)' | grep -q test_datastore_access_sysrepo
103fi
104
Jan Kundrát20c17482020-04-08 00:39:05 +0200105if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then
106 ninja-build doc
107 pushd html
108 zip -r ~/zuul-output/docs/html.zip .
109 popd
110fi
Jan Kundráte6c0f5c2020-04-08 00:08:28 +0200111
112if [[ $LDFLAGS =~ .*--coverage.* ]]; then
113 gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml
114fi