blob: 1cd27d76ec10743b93e4d909299d991b0593e738 [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át73e3bf22019-02-28 15:44:02 +01008ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r '.project.src_dir')
9ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r '.project.short_name')
Jan Kundrátdba63582019-06-06 13:09:30 +020010ZUUL_GERRIT_HOSTNAME=$(jq < ~/zuul-env.json -r '.project.canonical_hostname')
Jan Kundrát73e3bf22019-02-28 15:44:02 +010011
12CI_PARALLEL_JOBS=$(grep -c '^processor' /proc/cpuinfo)
13CMAKE_OPTIONS=""
14CFLAGS=""
15CXXFLAGS=""
16LDFLAGS=""
17
18if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then
19 export CC=clang
20 export CXX=clang++
21 export LD=clang
22 export CXXFLAGS="-stdlib=libc++"
Jan Kundráta46751c2020-10-19 21:50:33 +020023 # spdlog passes std::string instances, and it's built against GCC's libstdc++ on the CI
24 sed -i 's/spdlog::spdlog/spdlog::spdlog_header_only/' ${ZUUL_PROJECT_SRC_DIR}/CMakeLists.txt
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
34if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then
35 export CFLAGS="-fsanitize=address ${CFLAGS}"
36 export CXXFLAGS="-fsanitize=address ${CXXFLAGS}"
37 export LDFLAGS="-fsanitize=address ${LDFLAGS}"
38fi
39
Jan Kundrát7b7c8232019-03-13 14:04:06 +010040if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then
41 export CFLAGS="-fsanitize=thread ${CFLAGS}"
42 export CXXFLAGS="-fsanitize=thread ${CXXFLAGS}"
43 export LDFLAGS="-fsanitize=thread ${LDFLAGS}"
Jan Kundrát86840ec2021-01-27 15:38:08 +010044 export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp"
Jan Kundrát7b7c8232019-03-13 14:04:06 +010045fi
46
Jan Kundrát07a5cc52020-05-22 09:43:05 +020047if [[ ${ZUUL_JOB_NAME%%-cover?(-previous|-diff)} =~ -gcc$ ]]; then
Jan Kundrátcf5c6362020-01-16 22:54:47 +010048 # Python and ASAN (and, presumably, all other sanitizers) are tricky to use from a Python DSO,
49 # I was, e.g., getting unrelated failures from libyang's thread-local global access (ly_errno)
50 # even when correctly injecting the ASAN runtime via LD_PRELOAD. Let's just give up and only
51 # enable this when not using sanitizers.
52 # I'm still adding some code to CMakeLists.txt which makes it work locally (Jan's dev environment
53 # with GCC8 and ASAN, Gentoo).
54 CMAKE_OPTIONS="${CMAKE_OPTIONS} -DWITH_PYTHON_BINDINGS=ON"
55fi
56
Jan Kundráte6c0f5c2020-04-08 00:08:28 +020057if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then
58 export CFLAGS="${CFLAGS} --coverage"
59 export CXXFLAGS="${CXXFLAGS} --coverage"
60 export LDFLAGS="${LDFLAGS} --coverage"
61fi
62
Jan Kundrát73e3bf22019-02-28 15:44:02 +010063PREFIX=~/target
64mkdir ${PREFIX}
65BUILD_DIR=~/build
66mkdir ${BUILD_DIR}
67export PATH=${PREFIX}/bin:$PATH
68export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
Jan Kundrát0e783ac2019-10-30 12:29:17 +010069export 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 +010070
Jan Kundrát566d33c2020-04-17 14:33:37 +020071ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "tarball") | select(.project == "CzechLight/dependencies")][-1]?.url + ""')
Jan Kundrát73e3bf22019-02-28 15:44:02 +010072
73DEP_SUBMODULE_COMMIT=$(git ls-tree -l master submodules/dependencies | cut -d ' ' -f 3)
74
75if [[ -z "${ARTIFACT_URL}" ]]; then
76 # fallback to a promoted artifact
Jan Kundrátbba52522020-11-11 17:40:31 +010077 ARTIFACT_URL="https://object-store.cloud.muni.cz/swift/v1/ci-artifacts-${ZUUL_TENANT}/${ZUUL_GERRIT_HOSTNAME}/CzechLight/dependencies/${ZUUL_JOB_NAME%%+(-cover?(-previous)|-netconf-cli-no-sysrepo)}/${DEP_SUBMODULE_COMMIT}.tar.zst"
Jan Kundrát73e3bf22019-02-28 15:44:02 +010078fi
79
80ARTIFACT_FILE=$(basename ${ARTIFACT_URL})
Jan Kundrátb1cca842020-05-15 16:59:52 +020081DEP_HASH_FROM_ARTIFACT=$(echo "${ARTIFACT_FILE}" | sed -e 's/^czechlight-dependencies-//' -e 's/\.tar\.zst$//')
Jan Kundrát73e3bf22019-02-28 15:44:02 +010082if [[ "${DEP_HASH_FROM_ARTIFACT}" != "${DEP_SUBMODULE_COMMIT}" ]]; then
83 echo "Mismatched artifact: HEAD of ./submodules/dependencies does not match artifact commit ref"
84 exit 1
85fi
Jan Kundrátb1cca842020-05-15 16:59:52 +020086curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf -
Jan Kundrát73e3bf22019-02-28 15:44:02 +010087
Jan Kundrátbba52522020-11-11 17:40:31 +010088if [[ ${ZUUL_JOB_NAME} =~ .*-no-sysrepo ]]; then
89 rm -rf ${PREFIX}/include/sysrepo*
90 rm ${PREFIX}/lib*/libsysrepo*
91 rm ${PREFIX}/lib*/pkgconfig/sysrepo*
92 rm ${PREFIX}/bin/sysrepo*
93fi
94
Václav Kubernát634e24a2020-11-19 01:20:27 +010095mkdir ~/zuul-output/logs/test_netopeer_outputs
96
Jan Kundrát73e3bf22019-02-28 15:44:02 +010097cd ${BUILD_DIR}
Václav Kubernát634e24a2020-11-19 01:20:27 +010098ln -s ~/zuul-output/logs/test_netopeer_outputs test_netopeer_outputs
Jan Kundrát73e3bf22019-02-28 15:44:02 +010099cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR}
100ninja-build
101ctest -j${CI_PARALLEL_JOBS} --output-on-failure
Jan Kundrát20c17482020-04-08 00:39:05 +0200102
Jan Kundrátbba52522020-11-11 17:40:31 +0100103if [[ ! ${ZUUL_JOB_NAME} =~ .*-no-sysrepo ]]; then
104 # Normal builds should have the sysrepo and NETCONF tests
105 ctest --show-only=json-v1 | jq -r '.["tests"] | map(.name)' | grep -q test_datastore_access_netconf
106 ctest --show-only=json-v1 | jq -r '.["tests"] | map(.name)' | grep -q test_datastore_access_sysrepo
107fi
108
Jan Kundrát20c17482020-04-08 00:39:05 +0200109if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then
110 ninja-build doc
111 pushd html
112 zip -r ~/zuul-output/docs/html.zip .
113 popd
114fi
Jan Kundráte6c0f5c2020-04-08 00:08:28 +0200115
116if [[ $LDFLAGS =~ .*--coverage.* ]]; then
117 gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml
118fi