Commit | Line | Data |
---|---|---|
6b5133f2 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 - Testpoint failure" | |
19 | ||
20 | CURDIR=$(dirname $0)/ | |
9ac429ef | 21 | TESTDIR=$CURDIR/../../.. |
6b5133f2 CB |
22 | LTTNG_BIN="lttng" |
23 | SESSION_NAME="health_tp_fail" | |
24 | EVENT_NAME="bogus" | |
25 | HEALTH_CHECK_BIN="health_check" | |
26 | SESSIOND_PRELOAD=".libs/libhealthtpfail.so" | |
33c820d6 | 27 | NUM_TESTS=9 |
6b5133f2 | 28 | |
9ac429ef | 29 | source $TESTDIR/utils/utils.sh |
6b5133f2 | 30 | |
6b5133f2 | 31 | if [ ! -f "$CURDIR/$SESSIOND_PRELOAD" ]; then |
33c820d6 | 32 | BAIL_OUT "libhealthtpfail.so not available for this test." |
6b5133f2 CB |
33 | fi |
34 | ||
35 | function test_tp_fail | |
36 | { | |
37 | test_tp_fail_name="$1" | |
1dc66576 | 38 | test_tp_error_string="$2" |
6b5133f2 | 39 | |
33c820d6 | 40 | diag "Test health failure with ${test_tp_fail_name}" |
6b5133f2 CB |
41 | |
42 | # Activate testpoints | |
43 | export LTTNG_TESTPOINT_ENABLE=1 | |
44 | ||
45 | # Activate specific testpoint failure | |
46 | export ${test_tp_fail_name}_TP_FAIL=1 | |
47 | ||
48 | # Spawn sessiond with preload healthexit lib | |
49 | export LD_PRELOAD="$CURDIR/$SESSIOND_PRELOAD" | |
50 | start_lttng_sessiond | |
51 | ||
52 | # Cleanup some env. var. | |
53 | unset LD_PRELOAD | |
54 | unset ${test_tp_fail_name}_TP_FAIL | |
55 | ||
1dc66576 MD |
56 | # Check health status |
57 | $CURDIR/$HEALTH_CHECK_BIN > ${STDOUT_PATH} 2> ${STDERR_PATH} | |
6b5133f2 | 58 | |
1dc66576 MD |
59 | out=$(grep "${test_tp_error_string}" ${STDOUT_PATH} | wc -l) |
60 | if [ $out -eq 0 ]; then | |
61 | fail "Validate thread ${test_tp_fail_name} failure" | |
62 | diag "Health returned:" | |
63 | ||
64 | diag "stdout:" | |
65 | file=${STDOUT_PATH} | |
66 | while read line ; do | |
67 | diag "$line" | |
68 | done < ${file} | |
69 | ||
70 | diag "stderr:" | |
71 | file=${STDERR_PATH} | |
72 | while read line ; do | |
73 | diag "$line" | |
74 | done < ${file} | |
6b5133f2 | 75 | |
6b5133f2 | 76 | stop_lttng_sessiond |
1dc66576 | 77 | return 1 |
6b5133f2 | 78 | else |
1dc66576 | 79 | pass "Validate thread ${test_tp_fail_name} failure" |
6b5133f2 | 80 | stop_lttng_sessiond |
6b5133f2 CB |
81 | fi |
82 | } | |
83 | ||
33c820d6 CB |
84 | plan_tests $NUM_TESTS |
85 | ||
e3bef725 CB |
86 | print_test_banner "$TEST_DESC" |
87 | ||
e547b070 MD |
88 | THREAD=("LTTNG_SESSIOND_THREAD_MANAGE_CLIENTS" |
89 | "LTTNG_SESSIOND_THREAD_MANAGE_APPS") | |
6b5133f2 | 90 | |
1dc66576 MD |
91 | ERROR_STRING=( |
92 | "Thread \"Session daemon command\" is not responding in component \"sessiond\"." | |
93 | "Thread \"Session daemon application manager\" is not responding in component \"sessiond\"." | |
94 | ) | |
95 | ||
96 | STDOUT_PATH=$(mktemp) | |
97 | STDERR_PATH=$(mktemp) | |
6b5133f2 CB |
98 | |
99 | THREAD_COUNT=${#THREAD[@]} | |
100 | i=0 | |
101 | while [ "$i" -lt "$THREAD_COUNT" ]; do | |
1dc66576 | 102 | test_tp_fail "${THREAD[$i]}" "${ERROR_STRING[$i]}" |
6b5133f2 CB |
103 | |
104 | if [ $? -eq 1 ]; then | |
105 | exit 1 | |
106 | fi | |
107 | ||
108 | let "i++" | |
109 | done | |
110 | ||
33c820d6 CB |
111 | # The manage kernel thread is only spawned if we are root |
112 | if [ "$(id -u)" == "0" ]; then | |
113 | isroot=1 | |
114 | else | |
115 | isroot=0 | |
116 | fi | |
117 | ||
e547b070 | 118 | skip $isroot "Root access is needed. Skipping LTTNG_SESSIOND_THREAD_MANAGE_KERNEL tests." "3" || |
33c820d6 | 119 | { |
e547b070 | 120 | test_tp_fail "LTTNG_SESSIOND_THREAD_MANAGE_KERNEL" "Thread \"Session daemon kernel\" is not responding in component \"sessiond\"." |
33c820d6 CB |
121 | } |
122 | ||
1dc66576 MD |
123 | rm -f ${STDOUT_PATH} |
124 | rm -f ${STDERR_PATH} | |
33c820d6 CB |
125 | |
126 | # TODO: Special case manage consumer, need to spawn consumer via commands. | |
e547b070 | 127 | #"LTTNG_SESSIOND_THREAD_MANAGE_CONSUMER" |