| 1 | #!/bin/bash -xeu |
| 2 | # |
| 3 | # Copyright (C) 2021 - Jonathan Rajotte <jonathan.rajotte-julien@efficios.com> |
| 4 | # |
| 5 | # This program is free software: you can redistribute it and/or modify |
| 6 | # it under the terms of the GNU General Public License as published by |
| 7 | # the Free Software Foundation, either version 3 of the License, or |
| 8 | # (at your option) any later version. |
| 9 | # |
| 10 | # This program is distributed in the hope that it will be useful, |
| 11 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | # GNU General Public License for more details. |
| 14 | # |
| 15 | # You should have received a copy of the GNU General Public License |
| 16 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | |
| 18 | # Version compare functions |
| 19 | vercomp () { |
| 20 | set +u |
| 21 | if [[ "$1" == "$2" ]]; then |
| 22 | return 0 |
| 23 | fi |
| 24 | local IFS=. |
| 25 | local i ver1=($1) ver2=($2) |
| 26 | # fill empty fields in ver1 with zeros |
| 27 | for ((i=${#ver1[@]}; i<${#ver2[@]}; i++)); do |
| 28 | ver1[i]=0 |
| 29 | done |
| 30 | for ((i=0; i<${#ver1[@]}; i++)); do |
| 31 | if [[ -z ${ver2[i]} ]]; then |
| 32 | # fill empty fields in ver2 with zeros |
| 33 | ver2[i]=0 |
| 34 | fi |
| 35 | if ((10#${ver1[i]} > 10#${ver2[i]})); then |
| 36 | return 1 |
| 37 | fi |
| 38 | if ((10#${ver1[i]} < 10#${ver2[i]})); then |
| 39 | return 2 |
| 40 | fi |
| 41 | done |
| 42 | set -u |
| 43 | return 0 |
| 44 | } |
| 45 | |
| 46 | verlte() { |
| 47 | vercomp "$1" "$2"; local res="$?" |
| 48 | [ "$res" -eq "0" ] || [ "$res" -eq "2" ] |
| 49 | } |
| 50 | |
| 51 | verlt() { |
| 52 | vercomp "$1" "$2"; local res="$?" |
| 53 | [ "$res" -eq "2" ] |
| 54 | } |
| 55 | |
| 56 | vergte() { |
| 57 | vercomp "$1" "$2"; local res="$?" |
| 58 | [ "$res" -eq "0" ] || [ "$res" -eq "1" ] |
| 59 | } |
| 60 | |
| 61 | vergt() { |
| 62 | vercomp "$1" "$2"; local res="$?" |
| 63 | [ "$res" -eq "1" ] |
| 64 | } |
| 65 | |
| 66 | verne() { |
| 67 | vercomp "$1" "$2"; local res="$?" |
| 68 | [ "$res" -ne "0" ] |
| 69 | } |
| 70 | |
| 71 | # shellcheck disable=SC2317 |
| 72 | function cleanup |
| 73 | { |
| 74 | timedatectl set-ntp true |
| 75 | # The false dates used in the tests are far in the past |
| 76 | # and it may take some time for the ntp update to actually |
| 77 | # happen. |
| 78 | # If the date is still in the past, it is possible that |
| 79 | # subsequent steps will fail (eg. TLS certificates cannot |
| 80 | # be validated). |
| 81 | while [[ "$(date +%Y)" -lt "2024" ]] ; do |
| 82 | sleep 1 |
| 83 | done |
| 84 | } |
| 85 | |
| 86 | function test_timeout |
| 87 | { |
| 88 | local TIMEOUT=0 |
| 89 | local TIMEOUT_MINUTES="${1:-90}" |
| 90 | shift 1 |
| 91 | PID='' |
| 92 | "${@}" & |
| 93 | PID="${!}" |
| 94 | while true; do |
| 95 | sleep 1m |
| 96 | if ! ps -q "${PID}" > /dev/null ; then |
| 97 | # The process ID doesn't exist anymore |
| 98 | break |
| 99 | fi |
| 100 | TIMEOUT=$((TIMEOUT+1)) |
| 101 | if [[ "${TIMEOUT}" -ge "${TIMEOUT_MINUTES}" ]]; then |
| 102 | echo "Command '${@}' timed out (${TIMEOUT} minutes) " \ |
| 103 | "attempting to get backtraces for lttng/babeltrace binaries" |
| 104 | apt-get install -y --force-yes gdb |
| 105 | # Abort all lttng-sessiond, lttng, lttng-relayd, lttng-consumerd, |
| 106 | # and babeltrace process so there are coredumps available. |
| 107 | PIDS=$(pgrep 'babeltrace*|[l]ttng*') |
| 108 | for P in ${PIDS}; do |
| 109 | OUTFILE=$(mktemp -t "backtrace-${P}.XXXXXX") |
| 110 | ps -f "${P}" | tee -a "${OUTFILE}" |
| 111 | gdb -p "${P}" --batch -ex 'thread apply all bt' 2>&1 | tee -a "${OUTFILE}" |
| 112 | mv "${OUTFILE}" /tmp/coredump/ |
| 113 | done |
| 114 | |
| 115 | # Send sigterm to make |
| 116 | kill "${PID}" |
| 117 | |
| 118 | # Cleanup, to hopefully not interfere with future tests |
| 119 | apt-get purge -y gdb |
| 120 | apt-get autoremove -y |
| 121 | fi |
| 122 | done |
| 123 | wait "${PID}" |
| 124 | return "${?}" |
| 125 | } |
| 126 | |
| 127 | trap cleanup EXIT SIGINT SIGTERM |
| 128 | |
| 129 | lttng_version="$1" |
| 130 | failed_tests=0 |
| 131 | |
| 132 | export LTTNG_ENABLE_DESTRUCTIVE_TESTS="will-break-my-system" |
| 133 | timedatectl set-ntp false |
| 134 | |
| 135 | # When make check is interrupted, the default test driver |
| 136 | # (`config/test-driver`) will still delete the log and trs |
| 137 | # files for the currently running test. |
| 138 | test_timeout 90 make --keep-going check || failed_tests=1 |
| 139 | |
| 140 | if [ -f "./tests/root_regression" ]; then |
| 141 | cd "./tests" || exit 1 |
| 142 | prove --nocolor --verbose --merge --exec '' - < root_regression || failed_tests=2 |
| 143 | cd .. |
| 144 | fi |
| 145 | |
| 146 | # This script doesn't exist in master anymore, but compatibility with old branches |
| 147 | # should be retained until lttng-tools 2.13 is no longer supported |
| 148 | if [ -f "./tests/root_destructive_tests" ]; then |
| 149 | cd "./tests" || exit 1 |
| 150 | prove --nocolor --verbose --merge --exec '' - < root_destructive_tests || failed_tests=3 |
| 151 | cd .. |
| 152 | else |
| 153 | echo 'root_destructive_tests not found' |
| 154 | fi |
| 155 | |
| 156 | if [[ "${failed_tests}" != "0" ]] ; then |
| 157 | find tests/ -iname '*.trs' -print0 -or -iname '*.log' -print0 | tar czf /tmp/coredump/logs.tgz --null -T - |
| 158 | fi |
| 159 | |
| 160 | exit $failed_tests |