Tests: remove declaration already present in utils.sh
[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 SESSION_NAME="health_thread_ok"
24 UST_EVENT_NAME="tp:tptest"
25 KERNEL_EVENT_NAME="sched_switch"
26 CHANNEL_NAME="testchan"
27 HEALTH_CHECK_BIN="health_check"
28 NUM_TESTS=17
29 SLEEP_TIME=30
30
31 source $TESTDIR/utils/utils.sh
32
33 function lttng_create_session_uri
34 {
35 # Create session with default path
36 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME \
37 -U net://localhost >/dev/null 2>&1
38 ok $? "Create session with default path"
39 }
40
41 function report_errors
42 {
43 # Report health errors
44 out=$(cat ${STDOUT_PATH} | wc -l)
45 if [ $out -ne 0 ]; then
46 fail "Validation failure"
47 diag "Health returned:"
48 diag "stdout:"
49 file=${STDOUT_PATH}
50 while read line ; do
51 diag "$line"
52 done < ${file}
53
54 diag "stderr:"
55 file=${STDERR_PATH}
56 while read line ; do
57 diag "$line"
58 done < ${file}
59 else
60 pass "Validation OK"
61 fi
62 }
63
64 function test_thread_ok
65 {
66 diag "Test health OK"
67
68 # Set the socket timeout to 5 so the health check delta is set to 25.
69 export LTTNG_NETWORK_SOCKET_TIMEOUT=5
70 export LTTNG_RELAYD_HEALTH="${HEALTH_PATH}/test-health"
71
72 diag "Only session daemon"
73 start_lttng_sessiond
74
75 # Check health status
76 $CURDIR/$HEALTH_CHECK_BIN > ${STDOUT_PATH} 2> ${STDERR_PATH}
77 report_errors
78
79 diag "With UST consumer daemons"
80 create_lttng_session_no_output $SESSION_NAME
81 enable_ust_lttng_event_ok $SESSION_NAME $UST_EVENT_NAME $CHANNEL_NAME
82 start_lttng_tracing_ok $SESSION_NAME
83 destroy_lttng_session_ok $SESSION_NAME
84
85 # Check health status
86 $CURDIR/$HEALTH_CHECK_BIN > ${STDOUT_PATH} 2> ${STDERR_PATH}
87 report_errors
88
89 skip $isroot "Root access is needed. Skipping kernel consumer health check test." "5" ||
90 {
91 diag "With kernel consumer daemon"
92 create_lttng_session_no_output $SESSION_NAME
93 lttng_enable_kernel_event $SESSION_NAME $KERNEL_EVENT_NAME $CHANNEL_NAME
94 start_lttng_tracing_ok $SESSION_NAME
95 destroy_lttng_session_ok $SESSION_NAME
96
97 # Check health status
98 $CURDIR/$HEALTH_CHECK_BIN > ${STDOUT_PATH} 2> ${STDERR_PATH}
99 report_errors
100 }
101
102 diag "With relay daemon"
103
104 start_lttng_relayd "-o $TRACE_PATH"
105 # Check health status
106 $CURDIR/$HEALTH_CHECK_BIN \
107 --relayd-path="${LTTNG_RELAYD_HEALTH}" \
108 > ${STDOUT_PATH} 2> ${STDERR_PATH}
109 report_errors
110
111 # Wait
112 diag "Check after running for ${SLEEP_TIME} seconds"
113 sleep ${SLEEP_TIME}
114
115 # Check health status
116 $CURDIR/$HEALTH_CHECK_BIN \
117 --relayd-path="${LTTNG_RELAYD_HEALTH}" \
118 > ${STDOUT_PATH} 2> ${STDERR_PATH}
119 report_errors
120
121 stop_lttng_relayd
122 stop_lttng_sessiond
123
124 unset LTTNG_NETWORK_SOCKET_TIMEOUT
125 unset LTTNG_RELAYD_HEALTH
126 }
127
128 plan_tests $NUM_TESTS
129
130 print_test_banner "$TEST_DESC"
131
132 STDOUT_PATH=$(mktemp)
133 STDERR_PATH=$(mktemp)
134 TRACE_PATH=$(mktemp -d)
135 HEALTH_PATH=$(mktemp -d)
136
137 # The manage kernel thread is only spawned if we are root
138 if [ "$(id -u)" == "0" ]; then
139 isroot=1
140 else
141 isroot=0
142 fi
143
144 test_thread_ok
145
146 rm -rf ${HEALTH_PATH}
147 rm -rf ${TRACE_PATH}
148 rm -f ${STDOUT_PATH}
149 rm -f ${STDERR_PATH}
This page took 0.033216 seconds and 5 git commands to generate.