Tests for the session rotation feature
[lttng-tools.git] / tests / regression / tools / rotation / test_ust
CommitLineData
e7716c6a
JD
1#!/bin/bash
2#
3# Copyright (C) - 2017 Julien Desfossez <jdesfossez@efficios.com>
4#
5# This library is free software; you can redistribute it and/or modify it under
6# the terms of the GNU Lesser General Public License as published by the Free
7# Software Foundation; version 2.1 of the License.
8#
9# This library is distributed in the hope that it will be useful, but WITHOUT
10# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
12# details.
13#
14# You should have received a copy of the GNU Lesser General Public License
15# along with this library; if not, write to the Free Software Foundation, Inc.,
16# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17TEST_DESC="Rotation - User space tracing"
18
19CURDIR=$(dirname $0)/
20TESTDIR=$CURDIR/../../..
21NR_ITER=1
22NR_USEC_WAIT=0
23TESTAPP_PATH="$TESTDIR/utils/testapp"
24TESTAPP_NAME="gen-ust-events"
25TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
26SESSION_NAME="stream"
27EVENT_NAME="tp:tptest"
28PID_RELAYD=0
29
30TRACE_PATH=$(mktemp -d)
31
32NUM_TESTS=146
33
34source $TESTDIR/utils/utils.sh
35source $CURDIR/rotate_utils.sh
36
37if [ ! -x "$TESTAPP_BIN" ]; then
38 BAIL_OUT "No UST events binary detected."
39fi
40
41function enable_channel_per_pid()
42{
43 sess_name=$1
44 channel_name=$2
45
46 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name >/dev/null 2>&1
47 ok $? "Enable channel $channel_name per PID for session $sess_name"
48}
49
50function lttng_create_session_uri
51{
52 # Create session with default path
53 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME -U net://localhost >/dev/null 2>&1
54
55 ok $? "Create session $SESSION_NAME"
56}
57
58# MUST set TESTDIR before calling those functions
59
60function rotate_ust_test ()
61{
62 local_path=$1
63 app_path=$2
64 per_pid=$3
65
66 start_lttng_tracing_ok $SESSION_NAME
67 today=$(date +%Y%m%d)
68
69 $TESTAPP_BIN 10 $NR_USEC_WAIT /dev/null 2>&1
70 rotate_session_ok $SESSION_NAME
71
72 $TESTAPP_BIN 20 $NR_USEC_WAIT /dev/null 2>&1
73 stop_lttng_tracing_ok $SESSION_NAME
74
75 # Third chunk contains no event (rotate after stop).
76 rotate_session_ok $SESSION_NAME
77
78 destroy_lttng_session_ok $SESSION_NAME
79
80 # The tests on the chunk folder rely on the date staying the same during
81 # the duration of the test, if this fail we will now why the other checks
82 # fail afterwards. There is a short window of time where an automated test
83 # could fail because of that.
84 now=$(date +%Y%m%d)
85 test $today = $now
86 ok $? "Date did not change during the test"
87
88 validate_test_chunks "${local_path}" $today $app_path ust $per_pid
89}
90
91function test_ust_streaming_uid ()
92{
93 diag "Test UST streaming with session rotation per UID"
94 lttng_create_session_uri
95 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
96
97 rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" "ust/uid/*/*/" 0
98 rm -rf ${TRACE_PATH}/${HOSTNAME}
99}
100
101function test_ust_local_uid ()
102{
103 diag "Test UST local with session rotation per UID"
104 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
105 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
106
107 rotate_ust_test "${TRACE_PATH}" "ust/uid/*/*/" 0
108 rm -rf ${TRACE_PATH}
109}
110
111function test_ust_streaming_pid ()
112{
113 diag "Test UST streaming with session rotation per PID"
114 lttng_create_session_uri
115 enable_channel_per_pid $SESSION_NAME "channel0"
116 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
117
118 rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" "ust/pid/*/" 1
119 rm -rf ${TRACE_PATH}/${HOSTNAME}
120}
121
122function test_ust_local_pid ()
123{
124 diag "Test UST local with session rotation per PID"
125 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
126 enable_channel_per_pid $SESSION_NAME "channel0"
127 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
128
129 rotate_ust_test "${TRACE_PATH}" "ust/pid/*/" 1
130 rm -rf ${TRACE_PATH}
131}
132
133function test_ust_local_timer_uid ()
134{
135 diag "Test ust local with session rotation timer per-uid"
136 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
137 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
138 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
139 start_lttng_tracing_ok $SESSION_NAME
140 # We just want the app to register, no event generated
141 $TESTAPP_BIN 0 0 /dev/null 2>&1
142
143 rotate_timer_test "${TRACE_PATH}" 0
144 rm -rf ${TRACE_PATH}
145}
146
147function test_ust_streaming_timer_uid ()
148{
149 diag "Test ust remote with session rotation timer per-uid"
150 lttng_create_session_uri
151 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
152 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
153 start_lttng_tracing_ok $SESSION_NAME
154 # We just want the app to register, no event generated
155 $TESTAPP_BIN 0 0 /dev/null 2>&1
156
157 rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" 0
158 rm -rf ${TRACE_PATH}/${HOSTNAME}
159}
160
161function test_ust_local_timer_pid ()
162{
163 diag "Test ust local with session rotation timer per-pid"
164 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
165 enable_channel_per_pid $SESSION_NAME "channel0"
166 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
167 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
168 start_lttng_tracing_ok $SESSION_NAME
169 # We just want the app to register, no event generated
170 $TESTAPP_BIN 0 0 /dev/null 2>&1
171
172 rotate_timer_test "${TRACE_PATH}" 1
173 rm -rf ${TRACE_PATH}
174}
175
176function test_ust_streaming_timer_pid ()
177{
178 diag "Test ust remote with session rotation timer per-pid"
179 lttng_create_session_uri
180 enable_channel_per_pid $SESSION_NAME "channel0"
181 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
182 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
183 start_lttng_tracing_ok $SESSION_NAME
184 # We just want the app to register, no event generated
185 $TESTAPP_BIN 0 0 /dev/null 2>&1
186
187 rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" 1
188 rm -rf ${TRACE_PATH}/${HOSTNAME}
189}
190
191function test_incompatible_sessions ()
192{
193 diag "Check incompatible session types with rotation"
194
195 diag "Live session with rotate timer"
196 # Should not be able to enable a rotation timer with a live session
197 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --live >/dev/null 2>&1
198 lttng_enable_rotation_timer_fail $SESSION_NAME 500ms
199 destroy_lttng_session_ok $SESSION_NAME
200
201 diag "Snapshot session with rotate timer"
202 # Should not be able to enable a rotation timer with a snapshot session
203 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --snapshot >/dev/null 2>&1
204 lttng_enable_rotation_timer_fail $SESSION_NAME 500ms
205 destroy_lttng_session_ok $SESSION_NAME
206
207 diag "Live session with rotate"
208 # Should not be able to rotate a live session
209 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --live >/dev/null 2>&1
210 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
211 start_lttng_tracing_ok $SESSION_NAME
212 rotate_session_fail $SESSION_NAME
213 destroy_lttng_session_ok $SESSION_NAME
214
215 diag "Snapshot session with rotate"
216 # Should not be able to rotate a snapshot session
217 $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $SESSION_NAME --snapshot >/dev/null 2>&1
218 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
219 start_lttng_tracing_ok $SESSION_NAME
220 rotate_session_fail $SESSION_NAME
221 destroy_lttng_session_ok $SESSION_NAME
222
223}
224
225plan_tests $NUM_TESTS
226
227print_test_banner "$TEST_DESC"
228
229start_lttng_relayd "-o $TRACE_PATH"
230start_lttng_sessiond
231
232tests=( test_ust_streaming_uid test_ust_local_uid \
233 test_ust_streaming_pid test_ust_local_pid \
234 test_ust_local_timer_uid test_ust_streaming_timer_uid \
235 test_ust_local_timer_pid test_ust_streaming_timer_pid \
236 test_incompatible_sessions )
237
238for fct_test in ${tests[@]};
239do
240 SESSION_NAME=$(randstring 16 0)
241 ${fct_test}
242done
243
244stop_lttng_sessiond
245stop_lttng_relayd
246
247exit $out
This page took 0.049252 seconds and 5 git commands to generate.