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