Commit | Line | Data |
---|---|---|
9e32c5c0 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 exit" | |
19 | ||
20 | CURDIR=$(dirname $0)/ | |
9ac429ef | 21 | TESTDIR=$CURDIR/../../.. |
9e32c5c0 CB |
22 | LTTNG_BIN="lttng" |
23 | SESSION_NAME="health_thread_exit" | |
24 | EVENT_NAME="bogus" | |
25 | HEALTH_CHECK_BIN="health_check" | |
26 | SESSIOND_PRELOAD=".libs/libhealthexit.so" | |
33c820d6 | 27 | NUM_TESTS=12 |
9e32c5c0 | 28 | |
9ac429ef | 29 | source $TESTDIR/utils/utils.sh |
9e32c5c0 | 30 | |
a863986c | 31 | if [ ! -f "$CURDIR/$SESSIOND_PRELOAD" ]; then |
33c820d6 | 32 | BAIL_OUT "libhealthexit.so not available for this test." |
9e32c5c0 CB |
33 | fi |
34 | ||
35 | function test_thread_exit | |
36 | { | |
37 | test_thread_exit_name="$1" | |
1dc66576 | 38 | test_thread_error_string="$2" |
9e32c5c0 | 39 | |
33c820d6 | 40 | diag "Test health failure with ${test_thread_exit_name}" |
9e32c5c0 CB |
41 | |
42 | # Activate testpoints | |
43 | export LTTNG_TESTPOINT_ENABLE=1 | |
44 | ||
45 | # Activate specific thread exit | |
46 | export ${test_thread_exit_name}_EXIT=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 | |
9e32c5c0 CB |
52 | start_lttng_sessiond |
53 | ||
54 | # Cleanup some env. var. | |
55 | unset LD_PRELOAD | |
56 | unset ${test_thread_exit_name}_EXIT | |
57 | ||
58 | # Check initial health status | |
1dc66576 | 59 | $CURDIR/$HEALTH_CHECK_BIN > /dev/null |
9e32c5c0 | 60 | |
9e32c5c0 | 61 | # Wait |
c2ee6c2e | 62 | sleep 30 |
9e32c5c0 | 63 | |
1dc66576 MD |
64 | # Check health status |
65 | $CURDIR/$HEALTH_CHECK_BIN > ${STDOUT_PATH} 2> ${STDERR_PATH} | |
9e32c5c0 | 66 | |
1dc66576 MD |
67 | out=$(grep "${test_thread_error_string}" ${STDOUT_PATH} | wc -l) |
68 | if [ $out -eq 0 ]; then | |
33c820d6 | 69 | fail "Validate thread ${test_thread_exit_name} failure" |
1dc66576 MD |
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} | |
9e32c5c0 CB |
82 | |
83 | stop_lttng_sessiond | |
84 | return 1 | |
1dc66576 MD |
85 | else |
86 | pass "Validate thread ${test_thread_exit_name} failure" | |
87 | stop_lttng_sessiond | |
9e32c5c0 CB |
88 | fi |
89 | } | |
e3bef725 | 90 | |
33c820d6 | 91 | plan_tests $NUM_TESTS |
9e32c5c0 | 92 | |
e3bef725 CB |
93 | print_test_banner "$TEST_DESC" |
94 | ||
9e32c5c0 CB |
95 | THREAD=("LTTNG_THREAD_MANAGE_CLIENTS" |
96 | "LTTNG_THREAD_MANAGE_APPS" | |
33c820d6 | 97 | "LTTNG_THREAD_REG_APPS") |
9e32c5c0 | 98 | |
1dc66576 MD |
99 | ERROR_STRING=( |
100 | "Thread \"Session daemon command\" is not responding in component \"sessiond\"." | |
101 | "Thread \"Session daemon application manager\" is not responding in component \"sessiond\"." | |
102 | "Thread \"Session daemon application registration\" is not responding in component \"sessiond\"." | |
103 | ) | |
104 | ||
105 | STDOUT_PATH=$(mktemp) | |
106 | STDERR_PATH=$(mktemp) | |
9e32c5c0 CB |
107 | |
108 | THREAD_COUNT=${#THREAD[@]} | |
109 | i=0 | |
110 | while [ "$i" -lt "$THREAD_COUNT" ]; do | |
1dc66576 | 111 | test_thread_exit "${THREAD[$i]}" "${ERROR_STRING[$i]}" |
9e32c5c0 CB |
112 | |
113 | if [ $? -eq 1 ]; then | |
114 | exit 1 | |
115 | fi | |
116 | ||
117 | let "i++" | |
118 | done | |
119 | ||
33c820d6 CB |
120 | # The manage kernel thread is only spawned if we are root |
121 | if [ "$(id -u)" == "0" ]; then | |
122 | isroot=1 | |
123 | else | |
124 | isroot=0 | |
125 | fi | |
126 | ||
127 | skip $isroot "Root access is needed. Skipping LTTNG_THREAD_MANAGE_KERNEL tests." "3" || | |
128 | { | |
1dc66576 | 129 | test_thread_exit "LTTNG_THREAD_MANAGE_KERNEL" "Thread \"Session daemon kernel\" is not responding in component \"sessiond\"." |
33c820d6 CB |
130 | } |
131 | ||
1dc66576 MD |
132 | rm -f ${STDOUT_PATH} |
133 | rm -f ${STDERR_PATH} | |
33c820d6 CB |
134 | |
135 | # TODO: Special case manage consumer, need to spawn consumer via commands. | |
9e32c5c0 | 136 | #"LTTNG_THREAD_MANAGE_CONSUMER" |