Jan Kundrát | d9d26a9 | 2018-02-22 12:49:21 +0100 | [diff] [blame] | 1 | #!/bin/bash |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 2 | |
| 3 | set -eux -o pipefail |
Jan Kundrát | e6c0f5c | 2020-04-08 00:08:28 +0200 | [diff] [blame] | 4 | shopt -s failglob extglob |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 5 | |
| 6 | ZUUL_JOB_NAME=$(jq < ~/zuul-env.json -r '.job') |
Jan Kundrát | 8a91466 | 2019-02-28 18:11:55 +0100 | [diff] [blame] | 7 | ZUUL_TENANT=$(jq < ~/zuul-env.json -r '.tenant') |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 8 | ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r '.project.src_dir') |
| 9 | ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r '.project.short_name') |
Jan Kundrát | dba6358 | 2019-06-06 13:09:30 +0200 | [diff] [blame] | 10 | ZUUL_GERRIT_HOSTNAME=$(jq < ~/zuul-env.json -r '.project.canonical_hostname') |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 11 | |
| 12 | CI_PARALLEL_JOBS=$(grep -c '^processor' /proc/cpuinfo) |
| 13 | CMAKE_OPTIONS="" |
| 14 | CFLAGS="" |
| 15 | CXXFLAGS="" |
| 16 | LDFLAGS="" |
| 17 | |
| 18 | if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then |
| 19 | export CC=clang |
| 20 | export CXX=clang++ |
| 21 | export LD=clang |
| 22 | export CXXFLAGS="-stdlib=libc++" |
Jan Kundrát | a46751c | 2020-10-19 21:50:33 +0200 | [diff] [blame] | 23 | # 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át | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 25 | fi |
| 26 | |
| 27 | if [[ $ZUUL_JOB_NAME =~ .*-ubsan ]]; then |
| 28 | export CFLAGS="-fsanitize=undefined ${CFLAGS}" |
| 29 | export CXXFLAGS="-fsanitize=undefined ${CXXFLAGS}" |
| 30 | export LDFLAGS="-fsanitize=undefined ${LDFLAGS}" |
| 31 | fi |
| 32 | |
| 33 | if [[ $ZUUL_JOB_NAME =~ .*-asan ]]; then |
| 34 | export CFLAGS="-fsanitize=address ${CFLAGS}" |
| 35 | export CXXFLAGS="-fsanitize=address ${CXXFLAGS}" |
| 36 | export LDFLAGS="-fsanitize=address ${LDFLAGS}" |
| 37 | fi |
| 38 | |
Jan Kundrát | 7b7c823 | 2019-03-13 14:04:06 +0100 | [diff] [blame] | 39 | if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then |
| 40 | export CFLAGS="-fsanitize=thread ${CFLAGS}" |
| 41 | export CXXFLAGS="-fsanitize=thread ${CXXFLAGS}" |
| 42 | export LDFLAGS="-fsanitize=thread ${LDFLAGS}" |
Václav Kubernát | 654303f | 2020-07-31 13:16:54 +0200 | [diff] [blame] | 43 | export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp:detect_deadlocks=0" |
Jan Kundrát | 7b7c823 | 2019-03-13 14:04:06 +0100 | [diff] [blame] | 44 | fi |
| 45 | |
Jan Kundrát | 07a5cc5 | 2020-05-22 09:43:05 +0200 | [diff] [blame] | 46 | if [[ ${ZUUL_JOB_NAME%%-cover?(-previous|-diff)} =~ -gcc$ ]]; then |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 47 | # Python and ASAN (and, presumably, all other sanitizers) are tricky to use from a Python DSO, |
| 48 | # I was, e.g., getting unrelated failures from libyang's thread-local global access (ly_errno) |
| 49 | # even when correctly injecting the ASAN runtime via LD_PRELOAD. Let's just give up and only |
| 50 | # enable this when not using sanitizers. |
| 51 | # I'm still adding some code to CMakeLists.txt which makes it work locally (Jan's dev environment |
| 52 | # with GCC8 and ASAN, Gentoo). |
| 53 | CMAKE_OPTIONS="${CMAKE_OPTIONS} -DWITH_PYTHON_BINDINGS=ON" |
| 54 | fi |
| 55 | |
Jan Kundrát | e6c0f5c | 2020-04-08 00:08:28 +0200 | [diff] [blame] | 56 | if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then |
| 57 | export CFLAGS="${CFLAGS} --coverage" |
| 58 | export CXXFLAGS="${CXXFLAGS} --coverage" |
| 59 | export LDFLAGS="${LDFLAGS} --coverage" |
| 60 | fi |
| 61 | |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 62 | PREFIX=~/target |
| 63 | mkdir ${PREFIX} |
| 64 | BUILD_DIR=~/build |
| 65 | mkdir ${BUILD_DIR} |
| 66 | export PATH=${PREFIX}/bin:$PATH |
| 67 | export LD_LIBRARY_PATH=${PREFIX}/lib64:${PREFIX}/lib${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH} |
Jan Kundrát | 0e783ac | 2019-10-30 12:29:17 +0100 | [diff] [blame] | 68 | export PKG_CONFIG_PATH=${PREFIX}/lib64/pkgconfig:${PREFIX}/lib/pkgconfig:${PREFIX}/share/pkgconfig${PKG_CONFIG_PATH:+:$PKG_CONFIG_PATH} |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 69 | |
Jan Kundrát | 566d33c | 2020-04-17 14:33:37 +0200 | [diff] [blame] | 70 | ARTIFACT_URL=$(jq < ~/zuul-env.json -r '[.artifacts[]? | select(.name == "tarball") | select(.project == "CzechLight/dependencies")][-1]?.url + ""') |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 71 | |
| 72 | DEP_SUBMODULE_COMMIT=$(git ls-tree -l master submodules/dependencies | cut -d ' ' -f 3) |
| 73 | |
| 74 | if [[ -z "${ARTIFACT_URL}" ]]; then |
| 75 | # fallback to a promoted artifact |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 76 | 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át | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 77 | fi |
| 78 | |
| 79 | ARTIFACT_FILE=$(basename ${ARTIFACT_URL}) |
Jan Kundrát | b1cca84 | 2020-05-15 16:59:52 +0200 | [diff] [blame] | 80 | DEP_HASH_FROM_ARTIFACT=$(echo "${ARTIFACT_FILE}" | sed -e 's/^czechlight-dependencies-//' -e 's/\.tar\.zst$//') |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 81 | if [[ "${DEP_HASH_FROM_ARTIFACT}" != "${DEP_SUBMODULE_COMMIT}" ]]; then |
| 82 | echo "Mismatched artifact: HEAD of ./submodules/dependencies does not match artifact commit ref" |
| 83 | exit 1 |
| 84 | fi |
Jan Kundrát | b1cca84 | 2020-05-15 16:59:52 +0200 | [diff] [blame] | 85 | curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf - |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 86 | |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 87 | if [[ ${ZUUL_JOB_NAME} =~ .*-no-sysrepo ]]; then |
| 88 | rm -rf ${PREFIX}/include/sysrepo* |
| 89 | rm ${PREFIX}/lib*/libsysrepo* |
| 90 | rm ${PREFIX}/lib*/pkgconfig/sysrepo* |
| 91 | rm ${PREFIX}/bin/sysrepo* |
| 92 | fi |
| 93 | |
Václav Kubernát | 634e24a | 2020-11-19 01:20:27 +0100 | [diff] [blame] | 94 | mkdir ~/zuul-output/logs/test_netopeer_outputs |
| 95 | |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 96 | cd ${BUILD_DIR} |
Václav Kubernát | 634e24a | 2020-11-19 01:20:27 +0100 | [diff] [blame] | 97 | ln -s ~/zuul-output/logs/test_netopeer_outputs test_netopeer_outputs |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 98 | cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR} |
| 99 | ninja-build |
| 100 | ctest -j${CI_PARALLEL_JOBS} --output-on-failure |
Jan Kundrát | 20c1748 | 2020-04-08 00:39:05 +0200 | [diff] [blame] | 101 | |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 102 | if [[ ! ${ZUUL_JOB_NAME} =~ .*-no-sysrepo ]]; then |
| 103 | # Normal builds should have the sysrepo and NETCONF tests |
| 104 | ctest --show-only=json-v1 | jq -r '.["tests"] | map(.name)' | grep -q test_datastore_access_netconf |
| 105 | ctest --show-only=json-v1 | jq -r '.["tests"] | map(.name)' | grep -q test_datastore_access_sysrepo |
| 106 | fi |
| 107 | |
Jan Kundrát | 20c1748 | 2020-04-08 00:39:05 +0200 | [diff] [blame] | 108 | if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then |
| 109 | ninja-build doc |
| 110 | pushd html |
| 111 | zip -r ~/zuul-output/docs/html.zip . |
| 112 | popd |
| 113 | fi |
Jan Kundrát | e6c0f5c | 2020-04-08 00:08:28 +0200 | [diff] [blame] | 114 | |
| 115 | if [[ $LDFLAGS =~ .*--coverage.* ]]; then |
| 116 | gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml |
| 117 | fi |