7cb845b229ea3de36c54a3a088c3abd2b547b3c6
[lttng-tools.git] / tests / regression / tools / health / test_thread_ok
1 #!/bin/bash
2 #
3 # Copyright (C) - 2012 Christian Babeux <christian.babeux@efficios.com>
4 # Copyright (C) - 2014 Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
5 #
6 # This program is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License, version 2 only, as
8 # published by the Free Software Foundation.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 # more details.
14 #
15 # You should have received a copy of the GNU General Public License along with
16 # this program; if not, write to the Free Software Foundation, Inc., 51
17 # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18
19 TEST_DESC="Health check - Thread OK"
20
21 CURDIR=$(dirname $0)/
22 TESTDIR=$CURDIR/../../..
23 LTTNG_BIN="lttng"
24 SESSION_NAME="health_thread_ok"
25 UST_EVENT_NAME="tp:tptest"
26 KERNEL_EVENT_NAME="sched_switch"
27 CHANNEL_NAME="testchan"
28 HEALTH_CHECK_BIN="health_check"
29 NUM_TESTS=17
30 SLEEP_TIME=30
31
32 source $TESTDIR/utils/utils.sh
33
34 function report_errors
35 {
36 # Report health errors
37 out=$(cat ${STDOUT_PATH} | wc -l)
38 if [ $out -ne 0 ]; then
39 fail "Validation failure"
40 diag "Health returned:"
41 diag "stdout:"
42 file=${STDOUT_PATH}
43 while read line ; do
44 diag "$line"
45 done < ${file}
46
47 diag "stderr:"
48 file=${STDERR_PATH}
49 while read line ; do
50 diag "$line"
51 done < ${file}
52 else
53 pass "Validation OK"
54 fi
55 }
56
57 function test_thread_ok
58 {
59 diag "Test health OK"
60
61 # Set the socket timeout to 5 so the health check delta is set to 25.
62 export LTTNG_NETWORK_SOCKET_TIMEOUT=5
63 export LTTNG_RELAYD_HEALTH="${HEALTH_PATH}/test-health"
64
65 diag "Only session daemon"
66 start_lttng_sessiond
67
68 # Check health status
69 $CURDIR/$HEALTH_CHECK_BIN > ${STDOUT_PATH} 2> ${STDERR_PATH}
70 report_errors
71
72 diag "With UST consumer daemons"
73 create_lttng_session_no_output $SESSION_NAME
74 enable_ust_lttng_event_ok $SESSION_NAME $UST_EVENT_NAME $CHANNEL_NAME
75 start_lttng_tracing_ok $SESSION_NAME
76 destroy_lttng_session_ok $SESSION_NAME
77
78 # Check health status
79 $CURDIR/$HEALTH_CHECK_BIN > ${STDOUT_PATH} 2> ${STDERR_PATH}
80 report_errors
81
82 skip $isroot "Root access is needed. Skipping kernel consumer health check test." "5" ||
83 {
84 diag "With kernel consumer daemon"
85 create_lttng_session_no_output $SESSION_NAME
86 lttng_enable_kernel_event $SESSION_NAME $KERNEL_EVENT_NAME $CHANNEL_NAME
87 start_lttng_tracing_ok $SESSION_NAME
88 destroy_lttng_session_ok $SESSION_NAME
89
90 # Check health status
91 $CURDIR/$HEALTH_CHECK_BIN > ${STDOUT_PATH} 2> ${STDERR_PATH}
92 report_errors
93 }
94
95 diag "With relay daemon"
96
97 start_lttng_relayd "-o $TRACE_PATH"
98 # Check health status
99 $CURDIR/$HEALTH_CHECK_BIN \
100 --relayd-path="${LTTNG_RELAYD_HEALTH}" \
101 > ${STDOUT_PATH} 2> ${STDERR_PATH}
102 report_errors
103
104 # Wait
105 diag "Check after running for ${SLEEP_TIME} seconds"
106 sleep ${SLEEP_TIME}
107
108 # Check health status
109 $CURDIR/$HEALTH_CHECK_BIN \
110 --relayd-path="${LTTNG_RELAYD_HEALTH}" \
111 > ${STDOUT_PATH} 2> ${STDERR_PATH}
112 report_errors
113
114 stop_lttng_relayd
115 stop_lttng_sessiond
116
117 unset LTTNG_NETWORK_SOCKET_TIMEOUT
118 unset LTTNG_RELAYD_HEALTH
119 }
120
121 plan_tests $NUM_TESTS
122
123 print_test_banner "$TEST_DESC"
124
125 STDOUT_PATH=$(mktemp)
126 STDERR_PATH=$(mktemp)
127 TRACE_PATH=$(mktemp -d)
128 HEALTH_PATH=$(mktemp -d)
129
130 # The manage kernel thread is only spawned if we are root
131 if [ "$(id -u)" == "0" ]; then
132 isroot=1
133 else
134 isroot=0
135 fi
136
137 test_thread_ok
138
139 rm -rf ${HEALTH_PATH}
140 rm -rf ${TRACE_PATH}
141 rm -f ${STDOUT_PATH}
142 rm -f ${STDERR_PATH}
This page took 0.035267 seconds and 4 git commands to generate.