Tests: Clean trace_path after each subtest
[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/../../..
e7716c6a
JD
21NR_USEC_WAIT=0
22TESTAPP_PATH="$TESTDIR/utils/testapp"
23TESTAPP_NAME="gen-ust-events"
24TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
25SESSION_NAME="stream"
26EVENT_NAME="tp:tptest"
e7716c6a
JD
27
28TRACE_PATH=$(mktemp -d)
29
308a8946 30NUM_TESTS=150
e7716c6a
JD
31
32source $TESTDIR/utils/utils.sh
33source $CURDIR/rotate_utils.sh
34
35if [ ! -x "$TESTAPP_BIN" ]; then
36 BAIL_OUT "No UST events binary detected."
37fi
38
d09115ee 39function enable_channel_per_pid ()
e7716c6a
JD
40{
41 sess_name=$1
42 channel_name=$2
43
da0e4484 44 enable_ust_lttng_channel_ok $sess_name $channel_name --buffers-pid
e7716c6a
JD
45}
46
e7716c6a
JD
47# MUST set TESTDIR before calling those functions
48
49function rotate_ust_test ()
50{
51 local_path=$1
52 app_path=$2
53 per_pid=$3
54
55 start_lttng_tracing_ok $SESSION_NAME
56 today=$(date +%Y%m%d)
57
58 $TESTAPP_BIN 10 $NR_USEC_WAIT /dev/null 2>&1
59 rotate_session_ok $SESSION_NAME
60
61 $TESTAPP_BIN 20 $NR_USEC_WAIT /dev/null 2>&1
62 stop_lttng_tracing_ok $SESSION_NAME
63
64 # Third chunk contains no event (rotate after stop).
65 rotate_session_ok $SESSION_NAME
66
67 destroy_lttng_session_ok $SESSION_NAME
68
69 # The tests on the chunk folder rely on the date staying the same during
70 # the duration of the test, if this fail we will now why the other checks
71 # fail afterwards. There is a short window of time where an automated test
72 # could fail because of that.
73 now=$(date +%Y%m%d)
74 test $today = $now
75 ok $? "Date did not change during the test"
76
77 validate_test_chunks "${local_path}" $today $app_path ust $per_pid
78}
79
80function test_ust_streaming_uid ()
81{
82 diag "Test UST streaming with session rotation per UID"
f0d43d3d 83 create_lttng_session_uri $SESSION_NAME net://localhost
e7716c6a
JD
84 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
85
86 rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" "ust/uid/*/*/" 0
e7716c6a
JD
87}
88
89function test_ust_local_uid ()
90{
91 diag "Test UST local with session rotation per UID"
92 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
93 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
94
95 rotate_ust_test "${TRACE_PATH}" "ust/uid/*/*/" 0
e7716c6a
JD
96}
97
98function test_ust_streaming_pid ()
99{
100 diag "Test UST streaming with session rotation per PID"
f0d43d3d 101 create_lttng_session_uri $SESSION_NAME net://localhost
e7716c6a
JD
102 enable_channel_per_pid $SESSION_NAME "channel0"
103 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
104
105 rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" "ust/pid/*/" 1
e7716c6a
JD
106}
107
108function test_ust_local_pid ()
109{
110 diag "Test UST local with session rotation per PID"
111 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
112 enable_channel_per_pid $SESSION_NAME "channel0"
113 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
114
115 rotate_ust_test "${TRACE_PATH}" "ust/pid/*/" 1
e7716c6a
JD
116}
117
118function test_ust_local_timer_uid ()
119{
120 diag "Test ust local with session rotation timer per-uid"
121 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
122 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
123 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
124 start_lttng_tracing_ok $SESSION_NAME
125 # We just want the app to register, no event generated
126 $TESTAPP_BIN 0 0 /dev/null 2>&1
127
128 rotate_timer_test "${TRACE_PATH}" 0
e7716c6a
JD
129}
130
131function test_ust_streaming_timer_uid ()
132{
133 diag "Test ust remote with session rotation timer per-uid"
f0d43d3d 134 create_lttng_session_uri $SESSION_NAME net://localhost
e7716c6a
JD
135 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
136 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
137 start_lttng_tracing_ok $SESSION_NAME
138 # We just want the app to register, no event generated
139 $TESTAPP_BIN 0 0 /dev/null 2>&1
140
141 rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" 0
e7716c6a
JD
142}
143
144function test_ust_local_timer_pid ()
145{
146 diag "Test ust local with session rotation timer per-pid"
147 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
148 enable_channel_per_pid $SESSION_NAME "channel0"
149 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
150 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
151 start_lttng_tracing_ok $SESSION_NAME
152 # We just want the app to register, no event generated
153 $TESTAPP_BIN 0 0 /dev/null 2>&1
154
155 rotate_timer_test "${TRACE_PATH}" 1
e7716c6a
JD
156}
157
158function test_ust_streaming_timer_pid ()
159{
160 diag "Test ust remote with session rotation timer per-pid"
f0d43d3d 161 create_lttng_session_uri $SESSION_NAME net://localhost
e7716c6a
JD
162 enable_channel_per_pid $SESSION_NAME "channel0"
163 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
164 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
165 start_lttng_tracing_ok $SESSION_NAME
166 # We just want the app to register, no event generated
167 $TESTAPP_BIN 0 0 /dev/null 2>&1
168
169 rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*" 1
e7716c6a
JD
170}
171
172function test_incompatible_sessions ()
173{
174 diag "Check incompatible session types with rotation"
175
176 diag "Live session with rotate timer"
177 # Should not be able to enable a rotation timer with a live session
308a8946 178 create_lttng_session_uri $SESSION_NAME net://localhost --live
e7716c6a
JD
179 lttng_enable_rotation_timer_fail $SESSION_NAME 500ms
180 destroy_lttng_session_ok $SESSION_NAME
181
182 diag "Snapshot session with rotate timer"
183 # Should not be able to enable a rotation timer with a snapshot session
308a8946 184 create_lttng_session_ok $SESSION_NAME $TRACE_PATH --snapshot
e7716c6a
JD
185 lttng_enable_rotation_timer_fail $SESSION_NAME 500ms
186 destroy_lttng_session_ok $SESSION_NAME
187
188 diag "Live session with rotate"
189 # Should not be able to rotate a live session
308a8946 190 create_lttng_session_uri $SESSION_NAME net://localhost --live
e7716c6a
JD
191 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
192 start_lttng_tracing_ok $SESSION_NAME
193 rotate_session_fail $SESSION_NAME
194 destroy_lttng_session_ok $SESSION_NAME
195
196 diag "Snapshot session with rotate"
197 # Should not be able to rotate a snapshot session
308a8946 198 create_lttng_session_ok $SESSION_NAME $TRACE_PATH --snapshot
e7716c6a
JD
199 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
200 start_lttng_tracing_ok $SESSION_NAME
201 rotate_session_fail $SESSION_NAME
202 destroy_lttng_session_ok $SESSION_NAME
e7716c6a
JD
203}
204
205plan_tests $NUM_TESTS
206
207print_test_banner "$TEST_DESC"
208
209start_lttng_relayd "-o $TRACE_PATH"
210start_lttng_sessiond
211
212tests=( test_ust_streaming_uid test_ust_local_uid \
213 test_ust_streaming_pid test_ust_local_pid \
214 test_ust_local_timer_uid test_ust_streaming_timer_uid \
215 test_ust_local_timer_pid test_ust_streaming_timer_pid \
216 test_incompatible_sessions )
217
218for fct_test in ${tests[@]};
219do
220 SESSION_NAME=$(randstring 16 0)
221 ${fct_test}
8f2d0517 222 clean_path $TRACE_PATH
e7716c6a
JD
223done
224
225stop_lttng_sessiond
226stop_lttng_relayd
9dc506ae
JR
227
228# Remove tmp dir
229rm -rf $TRACE_PATH
This page took 0.031865 seconds and 4 git commands to generate.