| 1 | #!/bin/bash |
| 2 | # |
| 3 | # Copyright (C) - 2012 Christian Babeux <christian.babeux@efficios.com> |
| 4 | # |
| 5 | # This program is free software; you can redistribute it and/or modify it |
| 6 | # under the terms of the GNU General Public License, version 2 only, as |
| 7 | # published by the Free Software Foundation. |
| 8 | # |
| 9 | # This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | # more details. |
| 13 | # |
| 14 | # You should have received a copy of the GNU General Public License along with |
| 15 | # this program; if not, write to the Free Software Foundation, Inc., 51 |
| 16 | # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 | |
| 18 | TEST_DESC="Health check - Thread stall" |
| 19 | |
| 20 | CURDIR=$(dirname $0)/ |
| 21 | TESTDIR=$CURDIR/../.. |
| 22 | LTTNG_BIN="lttng" |
| 23 | SESSION_NAME="health_thread_stall" |
| 24 | EVENT_NAME="bogus" |
| 25 | HEALTH_CHECK_BIN="health_check" |
| 26 | SESSIOND_PRELOAD=".libs/libhealthstall.so" |
| 27 | |
| 28 | source $TESTDIR/utils.sh |
| 29 | |
| 30 | print_test_banner "$TEST_DESC" |
| 31 | |
| 32 | if [ ! -f "$SESSIOND_PRELOAD" ]; then |
| 33 | echo -e "libhealthstall.so not available for this test. Skipping." |
| 34 | exit 0 |
| 35 | fi |
| 36 | |
| 37 | function test_thread_stall |
| 38 | { |
| 39 | test_thread_stall_name="$1" |
| 40 | test_thread_exit_code="$2" |
| 41 | |
| 42 | echo "" |
| 43 | echo -e "=== Testing health failure with ${test_thread_stall_name}" |
| 44 | |
| 45 | # Activate testpoints |
| 46 | export LTTNG_TESTPOINT_ENABLE=1 |
| 47 | |
| 48 | # Activate specific thread exit |
| 49 | export ${test_thread_stall_name}_STALL=1 |
| 50 | |
| 51 | # Spawn sessiond with preload healthexit lib |
| 52 | export LD_PRELOAD="$CURDIR/$SESSIOND_PRELOAD" |
| 53 | start_lttng_sessiond |
| 54 | |
| 55 | # Cleanup some env. var. |
| 56 | unset LD_PRELOAD |
| 57 | unset ${test_thread_stall_name}_STALL |
| 58 | |
| 59 | # Check initial health status |
| 60 | $CURDIR/$HEALTH_CHECK_BIN &> /dev/null |
| 61 | |
| 62 | echo -n "Validating that ${test_thread_stall_name} is stalled... " |
| 63 | |
| 64 | # Wait |
| 65 | sleep 25 |
| 66 | |
| 67 | # Check health status, exit code should indicate failure |
| 68 | $CURDIR/$HEALTH_CHECK_BIN &> /dev/null |
| 69 | |
| 70 | health_check_exit_code=$? |
| 71 | |
| 72 | if [ $health_check_exit_code -eq $test_thread_exit_code ]; then |
| 73 | print_ok |
| 74 | else |
| 75 | print_fail |
| 76 | echo -e "Health returned: $health_check_exit_code\n" |
| 77 | |
| 78 | stop_lttng_sessiond |
| 79 | return 1 |
| 80 | fi |
| 81 | |
| 82 | echo -n "Validating that ${test_thread_stall_name} is no longer stalled... " |
| 83 | |
| 84 | # Wait |
| 85 | sleep 40 |
| 86 | |
| 87 | # Check health status, exit code should now pass |
| 88 | $CURDIR/$HEALTH_CHECK_BIN &> /dev/null |
| 89 | |
| 90 | health_check_exit_code=$? |
| 91 | |
| 92 | if [ $health_check_exit_code -eq 0 ]; then |
| 93 | print_ok |
| 94 | stop_lttng_sessiond |
| 95 | else |
| 96 | print_fail |
| 97 | echo -e "Health returned: $health_check_exit_code\n" |
| 98 | stop_lttng_sessiond |
| 99 | return 1 |
| 100 | fi |
| 101 | |
| 102 | |
| 103 | } |
| 104 | |
| 105 | THREAD=("LTTNG_THREAD_MANAGE_CLIENTS" |
| 106 | "LTTNG_THREAD_MANAGE_APPS" |
| 107 | # This thread is a little bit tricky to stall, |
| 108 | # need to send some commands and setup an app. |
| 109 | # "LTTNG_THREAD_REG_APPS" |
| 110 | "LTTNG_THREAD_MANAGE_KERNEL") |
| 111 | |
| 112 | # Exit code value to indicate specific thread failure |
| 113 | EXIT_CODE=(1 |
| 114 | 2 |
| 115 | # 4 |
| 116 | 8) |
| 117 | |
| 118 | THREAD_COUNT=${#THREAD[@]} |
| 119 | i=0 |
| 120 | while [ "$i" -lt "$THREAD_COUNT" ]; do |
| 121 | test_thread_stall "${THREAD[$i]}" "${EXIT_CODE[$i]}" |
| 122 | |
| 123 | if [ $? -eq 1 ]; then |
| 124 | exit 1 |
| 125 | fi |
| 126 | |
| 127 | let "i++" |
| 128 | done |