Tests: fix health tests to use custom socket timeout
[lttng-tools.git] / tests / regression / tools / health / test_thread_stall
CommitLineData
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
18TEST_DESC="Health check - Thread stall"
19
20CURDIR=$(dirname $0)/
9ac429ef 21TESTDIR=$CURDIR/../../..
5862a19a
CB
22LTTNG_BIN="lttng"
23SESSION_NAME="health_thread_stall"
24EVENT_NAME="bogus"
25HEALTH_CHECK_BIN="health_check"
26SESSIOND_PRELOAD=".libs/libhealthstall.so"
b63a3a25 27NUM_TESTS=12
5862a19a 28
9ac429ef 29source $TESTDIR/utils/utils.sh
5862a19a 30
a863986c 31if [ ! -f "$CURDIR/$SESSIOND_PRELOAD" ]; then
33c820d6 32 BAIL_OUT "libhealthstall.so not available for this test."
5862a19a
CB
33fi
34
35function 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
59 $CURDIR/$HEALTH_CHECK_BIN &> /dev/null
60
5862a19a 61 # Wait
c2ee6c2e 62 sleep 30
5862a19a
CB
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
100plan_tests $NUM_TESTS
101
e3bef725
CB
102print_test_banner "$TEST_DESC"
103
5862a19a
CB
104THREAD=("LTTNG_THREAD_MANAGE_CLIENTS"
105 "LTTNG_THREAD_MANAGE_APPS"
106# This thread is a little bit tricky to stall,
107# need to send some commands and setup an app.
108# "LTTNG_THREAD_REG_APPS"
33c820d6 109)
5862a19a
CB
110
111# Exit code value to indicate specific thread failure
112EXIT_CODE=(1
113 2
114# 4
33c820d6 115)
5862a19a
CB
116
117THREAD_COUNT=${#THREAD[@]}
118i=0
119while [ "$i" -lt "$THREAD_COUNT" ]; do
120 test_thread_stall "${THREAD[$i]}" "${EXIT_CODE[$i]}"
121
122 if [ $? -eq 1 ]; then
123 exit 1
124 fi
125
126 let "i++"
127done
33c820d6
CB
128
129# The manage kernel thread is only spawned if we are root
130if [ "$(id -u)" == "0" ]; then
131 isroot=1
132else
133 isroot=0
134fi
135
b63a3a25 136skip $isroot "Root access is needed. Skipping LTTNG_THREAD_MANAGE_KERNEL tests." "4" ||
33c820d6
CB
137{
138 test_thread_stall "LTTNG_THREAD_MANAGE_KERNEL" "8"
139}
This page took 0.044832 seconds and 4 git commands to generate.