Commit | Line | Data |
---|---|---|
5862a19a CB |
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)/ | |
9ac429ef | 21 | TESTDIR=$CURDIR/../../.. |
5862a19a CB |
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" | |
b63a3a25 | 27 | NUM_TESTS=12 |
5862a19a | 28 | |
9ac429ef | 29 | source $TESTDIR/utils/utils.sh |
5862a19a | 30 | |
a863986c | 31 | if [ ! -f "$CURDIR/$SESSIOND_PRELOAD" ]; then |
33c820d6 | 32 | BAIL_OUT "libhealthstall.so not available for this test." |
5862a19a CB |
33 | fi |
34 | ||
35 | function test_thread_stall | |
36 | { | |
37 | test_thread_stall_name="$1" | |
38 | test_thread_exit_code="$2" | |
39 | ||
33c820d6 | 40 | diag "Test health failure with ${test_thread_stall_name}" |
5862a19a CB |
41 | |
42 | # Activate testpoints | |
43 | export LTTNG_TESTPOINT_ENABLE=1 | |
44 | ||
45 | # Activate specific thread exit | |
46 | export ${test_thread_stall_name}_STALL=1 | |
47 | ||
48 | # Spawn sessiond with preload healthexit lib | |
49 | export LD_PRELOAD="$CURDIR/$SESSIOND_PRELOAD" | |
c2ee6c2e DG |
50 | # Set the socket timeout to 5 so the health check delta is set to 25. |
51 | export LTTNG_NETWORK_SOCKET_TIMEOUT=5 | |
5862a19a CB |
52 | start_lttng_sessiond |
53 | ||
54 | # Cleanup some env. var. | |
55 | unset LD_PRELOAD | |
56 | unset ${test_thread_stall_name}_STALL | |
57 | ||
58 | # Check initial health status | |
1dc66576 | 59 | $CURDIR/$HEALTH_CHECK_BIN > /dev/null |
5862a19a | 60 | |
5862a19a | 61 | # Wait |
c2ee6c2e | 62 | sleep 30 |
5862a19a | 63 | |
1dc66576 MD |
64 | # Check health status, should indicate failure |
65 | $CURDIR/$HEALTH_CHECK_BIN > ${STDOUT_PATH} 2> ${STDERR_PATH} | |
66 | ||
67 | out=$(grep "${test_thread_error_string}" ${STDOUT_PATH} | wc -l) | |
68 | if [ $out -eq 0 ]; then | |
69 | fail "Validate thread ${test_thread_stall_name} is stalled" | |
70 | diag "Health returned:" | |
71 | diag "stdout:" | |
72 | file=${STDOUT_PATH} | |
73 | while read line ; do | |
74 | diag "$line" | |
75 | done < ${file} | |
76 | ||
77 | diag "stderr:" | |
78 | file=${STDERR_PATH} | |
79 | while read line ; do | |
80 | diag "$line" | |
81 | done < ${file} | |
5862a19a CB |
82 | |
83 | stop_lttng_sessiond | |
84 | return 1 | |
1dc66576 MD |
85 | else |
86 | pass "Validate thread ${test_thread_stall_name} is stalled" | |
5862a19a CB |
87 | fi |
88 | ||
5862a19a CB |
89 | # Wait |
90 | sleep 40 | |
91 | ||
1dc66576 MD |
92 | # Check health status, should now pass |
93 | $CURDIR/$HEALTH_CHECK_BIN > ${STDOUT_PATH} 2> ${STDERR_PATH} | |
94 | ||
95 | out=$(grep "${test_thread_error_string}" ${STDOUT_PATH} | wc -l) | |
96 | if [ $out -ne 0 ]; then | |
97 | fail "Validate thread ${test_thread_stall_name} is not longer stalled" | |
98 | diag "Health returned:" | |
99 | diag "stdout:" | |
100 | file=${STDOUT_PATH} | |
101 | while read line ; do | |
102 | diag "$line" | |
103 | done < ${file} | |
104 | ||
105 | diag "stderr:" | |
106 | file=${STDERR_PATH} | |
107 | while read line ; do | |
108 | diag "$line" | |
109 | done < ${file} | |
5862a19a | 110 | |
5862a19a | 111 | stop_lttng_sessiond |
1dc66576 | 112 | return 1 |
5862a19a | 113 | else |
1dc66576 | 114 | pass "Validate thread ${test_thread_stall_name} is not longer stalled" |
5862a19a | 115 | stop_lttng_sessiond |
5862a19a | 116 | fi |
5862a19a CB |
117 | } |
118 | ||
33c820d6 CB |
119 | plan_tests $NUM_TESTS |
120 | ||
e3bef725 CB |
121 | print_test_banner "$TEST_DESC" |
122 | ||
71ddb4ed MD |
123 | THREAD=("LTTNG_SESSIOND_THREAD_MANAGE_CLIENTS" |
124 | "LTTNG_SESSIOND_THREAD_MANAGE_APPS" | |
5862a19a CB |
125 | # This thread is a little bit tricky to stall, |
126 | # need to send some commands and setup an app. | |
71ddb4ed | 127 | # "LTTNG_SESSIOND_THREAD_REG_APPS" |
33c820d6 | 128 | ) |
5862a19a | 129 | |
1dc66576 MD |
130 | ERROR_STRING=( |
131 | "Thread \"Session daemon command\" is not responding in component \"sessiond\"." | |
132 | "Thread \"Session daemon application manager\" is not responding in component \"sessiond\"." | |
133 | "Thread \"Session daemon application registration\" is not responding in component \"sessiond\"." | |
33c820d6 | 134 | ) |
5862a19a | 135 | |
1dc66576 MD |
136 | STDOUT_PATH=$(mktemp) |
137 | STDERR_PATH=$(mktemp) | |
138 | ||
5862a19a CB |
139 | THREAD_COUNT=${#THREAD[@]} |
140 | i=0 | |
141 | while [ "$i" -lt "$THREAD_COUNT" ]; do | |
1dc66576 | 142 | test_thread_stall "${THREAD[$i]}" "${ERROR_STRING[$i]}" |
5862a19a CB |
143 | |
144 | if [ $? -eq 1 ]; then | |
145 | exit 1 | |
146 | fi | |
147 | ||
148 | let "i++" | |
149 | done | |
33c820d6 CB |
150 | |
151 | # The manage kernel thread is only spawned if we are root | |
152 | if [ "$(id -u)" == "0" ]; then | |
153 | isroot=1 | |
154 | else | |
155 | isroot=0 | |
156 | fi | |
157 | ||
71ddb4ed | 158 | skip $isroot "Root access is needed. Skipping LTTNG_SESSIOND_THREAD_MANAGE_KERNEL tests." "4" || |
33c820d6 | 159 | { |
71ddb4ed | 160 | test_thread_stall "LTTNG_SESSIOND_THREAD_MANAGE_KERNEL" "Thread \"Session daemon kernel\" is not responding in component \"sessiond\"." |
33c820d6 | 161 | } |
1dc66576 MD |
162 | |
163 | rm -f ${STDOUT_PATH} | |
164 | rm -f ${STDERR_PATH} |