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 | dbb678f | 2022-03-23 22:20:28 +0100 | [diff] [blame] | 8 | LEAF_PROJECT_NAME=CzechLight/netconf-cli |
| 9 | ZUUL_PROJECT_SRC_DIR=$HOME/$(jq < ~/zuul-env.json -r ".projects[] | select(.name == \"${LEAF_PROJECT_NAME}\").src_dir") |
| 10 | ZUUL_PROJECT_SHORT_NAME=$(jq < ~/zuul-env.json -r ".projects[] | select(.name == \"${LEAF_PROJECT_NAME}\").short_name") |
Jan Kundrát | dba6358 | 2019-06-06 13:09:30 +0200 | [diff] [blame] | 11 | ZUUL_GERRIT_HOSTNAME=$(jq < ~/zuul-env.json -r '.project.canonical_hostname') |
Jan Kundrát | dbb678f | 2022-03-23 22:20:28 +0100 | [diff] [blame] | 12 | ZUUL_JOB_NAME_NO_PROJECT=${ZUUL_JOB_NAME##${ZUUL_PROJECT_SHORT_NAME}-} |
Jan Kundrát | bb0931e | 2023-02-01 23:45:11 +0100 | [diff] [blame^] | 13 | ZUUL_SRC_COMMON_PREFIX=${ZUUL_PROJECT_SRC_DIR:0:-${#LEAF_PROJECT_NAME}} |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 14 | |
Jan Kundrát | e13caa3 | 2022-03-23 13:52:35 +0100 | [diff] [blame] | 15 | CI_PARALLEL_JOBS=$(awk -vcpu=$(getconf _NPROCESSORS_ONLN) 'BEGIN{printf "%.0f", cpu*1.3+1}') |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 16 | CMAKE_OPTIONS="" |
Jan Kundrát | bb0931e | 2023-02-01 23:45:11 +0100 | [diff] [blame^] | 17 | CFLAGS="-O2 -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" |
| 18 | CXXFLAGS="-O2 -g -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer" |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 19 | LDFLAGS="" |
| 20 | |
| 21 | if [[ $ZUUL_JOB_NAME =~ .*-clang.* ]]; then |
| 22 | export CC=clang |
| 23 | export CXX=clang++ |
| 24 | export LD=clang |
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}" |
Jan Kundrát | 86840ec | 2021-01-27 15:38:08 +0100 | [diff] [blame] | 31 | export UBSAN_OPTIONS=print_stacktrace=1:halt_on_error=1 |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 32 | fi |
| 33 | |
Jan Kundrát | bb0931e | 2023-02-01 23:45:11 +0100 | [diff] [blame^] | 34 | if [[ $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át | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 40 | fi |
| 41 | |
Jan Kundrát | 7b7c823 | 2019-03-13 14:04:06 +0100 | [diff] [blame] | 42 | if [[ $ZUUL_JOB_NAME =~ .*-tsan ]]; then |
Jan Kundrát | bb0931e | 2023-02-01 23:45:11 +0100 | [diff] [blame^] | 43 | export CFLAGS="-fsanitize=thread -Wp,-U_FORTIFY_SOURCE ${CFLAGS}" |
| 44 | export CXXFLAGS="-fsanitize=thread -Wp,-U_FORTIFY_SOURCE ${CXXFLAGS}" |
Jan Kundrát | 7b7c823 | 2019-03-13 14:04:06 +0100 | [diff] [blame] | 45 | export LDFLAGS="-fsanitize=thread ${LDFLAGS}" |
Jan Kundrát | 86840ec | 2021-01-27 15:38:08 +0100 | [diff] [blame] | 46 | export TSAN_OPTIONS="suppressions=$HOME/target/tsan.supp" |
Jan Kundrát | 7b7c823 | 2019-03-13 14:04:06 +0100 | [diff] [blame] | 47 | fi |
| 48 | |
Jan Kundrát | 07a5cc5 | 2020-05-22 09:43:05 +0200 | [diff] [blame] | 49 | if [[ ${ZUUL_JOB_NAME%%-cover?(-previous|-diff)} =~ -gcc$ ]]; then |
Jan Kundrát | cf5c636 | 2020-01-16 22:54:47 +0100 | [diff] [blame] | 50 | # 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" |
| 57 | fi |
| 58 | |
Jan Kundrát | e6c0f5c | 2020-04-08 00:08:28 +0200 | [diff] [blame] | 59 | if [[ $ZUUL_JOB_NAME =~ .*-cover.* ]]; then |
| 60 | export CFLAGS="${CFLAGS} --coverage" |
| 61 | export CXXFLAGS="${CXXFLAGS} --coverage" |
| 62 | export LDFLAGS="${LDFLAGS} --coverage" |
| 63 | fi |
| 64 | |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 65 | PREFIX=~/target |
| 66 | mkdir ${PREFIX} |
| 67 | BUILD_DIR=~/build |
| 68 | mkdir ${BUILD_DIR} |
Jan Kundrát | e13caa3 | 2022-03-23 13:52:35 +0100 | [diff] [blame] | 69 | export PATH=${PREFIX}/bin:/sbin:/usr/sbin:$PATH |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 70 | 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] | 71 | 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] | 72 | |
Jan Kundrát | 566d33c | 2020-04-17 14:33:37 +0200 | [diff] [blame] | 73 | 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] | 74 | |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 75 | if [[ -z "${ARTIFACT_URL}" ]]; then |
Jan Kundrát | e13caa3 | 2022-03-23 13:52:35 +0100 | [diff] [blame] | 76 | # 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át | 07e8f8b | 2022-03-28 13:00:06 +0200 | [diff] [blame] | 79 | 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át | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 80 | fi |
| 81 | |
Jan Kundrát | b1cca84 | 2020-05-15 16:59:52 +0200 | [diff] [blame] | 82 | curl ${ARTIFACT_URL} | unzstd --stdout | tar -C ${PREFIX} -xf - |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 83 | |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 84 | if [[ ${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* |
| 89 | fi |
| 90 | |
Václav Kubernát | 634e24a | 2020-11-19 01:20:27 +0100 | [diff] [blame] | 91 | mkdir ~/zuul-output/logs/test_netopeer_outputs |
| 92 | |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 93 | cd ${BUILD_DIR} |
Václav Kubernát | 634e24a | 2020-11-19 01:20:27 +0100 | [diff] [blame] | 94 | ln -s ~/zuul-output/logs/test_netopeer_outputs test_netopeer_outputs |
Jan Kundrát | 73e3bf2 | 2019-02-28 15:44:02 +0100 | [diff] [blame] | 95 | cmake -GNinja -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE:-Debug} -DCMAKE_INSTALL_PREFIX=${PREFIX} ${CMAKE_OPTIONS} ${ZUUL_PROJECT_SRC_DIR} |
| 96 | ninja-build |
| 97 | ctest -j${CI_PARALLEL_JOBS} --output-on-failure |
Jan Kundrát | 20c1748 | 2020-04-08 00:39:05 +0200 | [diff] [blame] | 98 | |
Jan Kundrát | bba5252 | 2020-11-11 17:40:31 +0100 | [diff] [blame] | 99 | if [[ ! ${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 |
| 103 | fi |
| 104 | |
Jan Kundrát | 20c1748 | 2020-04-08 00:39:05 +0200 | [diff] [blame] | 105 | if [[ $JOB_PERFORM_EXTRA_WORK == 1 ]]; then |
| 106 | ninja-build doc |
| 107 | pushd html |
| 108 | zip -r ~/zuul-output/docs/html.zip . |
| 109 | popd |
| 110 | fi |
Jan Kundrát | e6c0f5c | 2020-04-08 00:08:28 +0200 | [diff] [blame] | 111 | |
| 112 | if [[ $LDFLAGS =~ .*--coverage.* ]]; then |
| 113 | gcovr -j ${CI_PARALLEL_JOBS} --object-directory ${BUILD_DIR} --root ${ZUUL_PROJECT_SRC_DIR} --xml --output ${BUILD_DIR}/coverage.xml |
| 114 | fi |