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" | |
73871d43 | 27 | NUM_TESTS=11 |
5862a19a | 28 | |
9ac429ef | 29 | source $TESTDIR/utils/utils.sh |
5862a19a CB |
30 | |
31 | print_test_banner "$TEST_DESC" | |
32 | ||
a863986c | 33 | if [ ! -f "$CURDIR/$SESSIOND_PRELOAD" ]; then |
33c820d6 | 34 | BAIL_OUT "libhealthstall.so not available for this test." |
5862a19a CB |
35 | fi |
36 | ||
37 | function test_thread_stall | |
38 | { | |
39 | test_thread_stall_name="$1" | |
40 | test_thread_exit_code="$2" | |
41 | ||
33c820d6 | 42 | diag "Test health failure with ${test_thread_stall_name}" |
5862a19a CB |
43 | |
44 | # Activate testpoints | |
45 | export LTTNG_TESTPOINT_ENABLE=1 | |
46 | ||
47 | # Activate specific thread exit | |
48 | export ${test_thread_stall_name}_STALL=1 | |
49 | ||
50 | # Spawn sessiond with preload healthexit lib | |
51 | export LD_PRELOAD="$CURDIR/$SESSIOND_PRELOAD" | |
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 | |
59 | $CURDIR/$HEALTH_CHECK_BIN &> /dev/null | |
60 | ||
5862a19a CB |
61 | # Wait |
62 | sleep 25 | |
63 | ||
64 | # Check health status, exit code should indicate failure | |
65 | $CURDIR/$HEALTH_CHECK_BIN &> /dev/null | |
66 | ||
67 | health_check_exit_code=$? | |
68 | ||
69 | if [ $health_check_exit_code -eq $test_thread_exit_code ]; then | |
33c820d6 | 70 | pass "Validate that ${test_thread_stall_name} is stalled" |
5862a19a | 71 | else |
33c820d6 CB |
72 | fail "Validate that ${test_thread_stall_name} is stalled" |
73 | diag "Health returned: $health_check_exit_code" | |
5862a19a CB |
74 | |
75 | stop_lttng_sessiond | |
76 | return 1 | |
77 | fi | |
78 | ||
5862a19a CB |
79 | # Wait |
80 | sleep 40 | |
81 | ||
82 | # Check health status, exit code should now pass | |
83 | $CURDIR/$HEALTH_CHECK_BIN &> /dev/null | |
84 | ||
85 | health_check_exit_code=$? | |
86 | ||
87 | if [ $health_check_exit_code -eq 0 ]; then | |
33c820d6 | 88 | pass "Validate that ${test_thread_stall_name} is no longer stalled" |
5862a19a CB |
89 | stop_lttng_sessiond |
90 | else | |
33c820d6 CB |
91 | fail "Validate that ${test_thread_stall_name} is no longer stalled" |
92 | diag "Health returned: $health_check_exit_code\n" | |
5862a19a CB |
93 | stop_lttng_sessiond |
94 | return 1 | |
95 | fi | |
96 | ||
97 | ||
98 | } | |
99 | ||
33c820d6 CB |
100 | plan_tests $NUM_TESTS |
101 | ||
5862a19a CB |
102 | THREAD=("LTTNG_THREAD_MANAGE_CLIENTS" |
103 | "LTTNG_THREAD_MANAGE_APPS" | |
104 | # This thread is a little bit tricky to stall, | |
105 | # need to send some commands and setup an app. | |
106 | # "LTTNG_THREAD_REG_APPS" | |
33c820d6 | 107 | ) |
5862a19a CB |
108 | |
109 | # Exit code value to indicate specific thread failure | |
110 | EXIT_CODE=(1 | |
111 | 2 | |
112 | # 4 | |
33c820d6 | 113 | ) |
5862a19a CB |
114 | |
115 | THREAD_COUNT=${#THREAD[@]} | |
116 | i=0 | |
117 | while [ "$i" -lt "$THREAD_COUNT" ]; do | |
118 | test_thread_stall "${THREAD[$i]}" "${EXIT_CODE[$i]}" | |
119 | ||
120 | if [ $? -eq 1 ]; then | |
121 | exit 1 | |
122 | fi | |
123 | ||
124 | let "i++" | |
125 | done | |
33c820d6 CB |
126 | |
127 | # The manage kernel thread is only spawned if we are root | |
128 | if [ "$(id -u)" == "0" ]; then | |
129 | isroot=1 | |
130 | else | |
131 | isroot=0 | |
132 | fi | |
133 | ||
134 | skip $isroot "Root access is needed. Skipping LTTNG_THREAD_MANAGE_KERNEL tests." "3" || | |
135 | { | |
136 | test_thread_stall "LTTNG_THREAD_MANAGE_KERNEL" "8" | |
137 | } |