Tests: rotation: add a per-pid size-based rotation test
[lttng-tools.git] / tests / regression / tools / rotation / test_ust
... / ...
CommitLineData
1#!/bin/bash
2#
3# Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
4#
5# SPDX-License-Identifier: LGPL-2.1-only
6
7TEST_DESC="Rotation - User space tracing"
8
9CURDIR=$(dirname $0)/
10TESTDIR=$CURDIR/../../..
11NR_USEC_WAIT=0
12TESTAPP_PATH="$TESTDIR/utils/testapp"
13TESTAPP_NAME="gen-ust-events"
14TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
15SESSION_NAME="stream"
16EVENT_NAME="tp:tptest"
17
18TRACE_PATH=$(mktemp --tmpdir -d -t tmp.test_ust_rotation_trace_path.XXXXXX)
19
20NUM_TESTS=152
21
22source $TESTDIR/utils/utils.sh
23source $CURDIR/rotate_utils.sh
24
25if [ ! -x "$TESTAPP_BIN" ]; then
26 BAIL_OUT "No UST events binary detected."
27fi
28
29XPATH_CMD_OUTPUT="//lttng:command/lttng:output"
30XPATH_PID="$XPATH_CMD_OUTPUT/lttng:domains/lttng:domain[./lttng:type = 'UST']/lttng:pids/lttng:pid/lttng:id"
31
32function enable_channel_per_pid ()
33{
34 sess_name=$1
35 channel_name=$2
36
37 enable_ust_lttng_channel_ok $sess_name $channel_name --buffers-pid
38}
39
40# MUST set TESTDIR before calling those functions
41
42function rotate_ust_test ()
43{
44 local_path=$1
45 app_path=$2
46 per_pid=$3
47
48 start_lttng_tracing_ok $SESSION_NAME
49 today=$(date +%Y%m%d)
50
51 $TESTAPP_BIN -i 10 -w $NR_USEC_WAIT > /dev/null 2>&1
52 rotate_session_ok $SESSION_NAME
53
54 $TESTAPP_BIN -i 20 -w $NR_USEC_WAIT > /dev/null 2>&1
55 stop_lttng_tracing_ok $SESSION_NAME
56
57 # Third chunk contains no event (rotate after stop).
58 rotate_session_ok $SESSION_NAME
59
60 destroy_lttng_session_ok $SESSION_NAME
61
62 validate_test_chunks "${local_path}" $today $app_path ust
63}
64
65function test_ust_streaming_uid ()
66{
67 diag "Test UST streaming with session rotation per UID"
68 create_lttng_session_uri $SESSION_NAME net://localhost
69 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
70
71 rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*/archives" "ust/uid/*/*/" 0
72}
73
74function test_ust_local_uid ()
75{
76 diag "Test UST local with session rotation per UID"
77 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
78 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
79
80 rotate_ust_test "${TRACE_PATH}/archives" "ust/uid/*/*/" 0
81}
82
83function test_ust_streaming_pid ()
84{
85 diag "Test UST streaming with session rotation per PID"
86 create_lttng_session_uri $SESSION_NAME net://localhost
87 enable_channel_per_pid $SESSION_NAME "channel0"
88 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
89
90 rotate_ust_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*/archives" "ust/pid/*/" 1
91}
92
93function test_ust_local_pid ()
94{
95 diag "Test UST local with session rotation per PID"
96 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
97 enable_channel_per_pid $SESSION_NAME "channel0"
98 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
99
100 rotate_ust_test "${TRACE_PATH}/archives" "ust/pid/*/" 1
101}
102
103function wait_until_app_unregistration ()
104{
105 local pid=$1
106 local mi_output
107 local value=1
108
109 mi_output=$(mktemp)
110
111 while [ $value -ne 0 ]; do
112 # Extract from lttng list tracepoint the registered apps.
113 # This should give us enough guarantee since that if the app is not
114 # present it is unregistered from lttng-sessiond point of view.
115 LTTNG_BIN="lttng --mi xml" OUTPUT_DEST="$mi_output" list_lttng_notap -u
116 if ! $MI_VALIDATE "$mi_output"; then
117 return 1
118 fi
119
120 value=$("$MI_VALIDATE" "$mi_output" "$XPATH_PID" | wc -l)
121 if [ $value -ne 0 ]; then
122 diag "At least one app is still registred from lttng-sessiond point of view"
123 sleep 1
124 else
125 # No app present on listing.
126 break;
127 fi
128 done
129
130 return 0
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 -i 0 -w 0 > /dev/null 2>&1
142
143 rotate_timer_test "${TRACE_PATH}/archives" 0
144}
145
146function test_ust_streaming_timer_uid ()
147{
148 diag "Test ust remote with session rotation timer per-uid"
149 create_lttng_session_uri $SESSION_NAME net://localhost
150 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
151 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
152 start_lttng_tracing_ok $SESSION_NAME
153 # We just want the app to register, no event generated
154 $TESTAPP_BIN -i 0 -w 0 > /dev/null 2>&1
155
156 rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*/archives" 0
157}
158
159function test_ust_local_timer_pid ()
160{
161 local app_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 start_lttng_tracing_ok $SESSION_NAME
168
169 # We just want the app to register, no event generated.
170 # But we want the pid for the app since we need to validate its
171 # unregistration on lttng listing.
172 $TESTAPP_BIN -i 0 -w 0 > /dev/null 2>&1 &
173 app_pid=$!
174 wait $app_pid
175
176 wait_until_app_unregistration $app_pid
177 ok $? "App is un-registered"
178
179 # Set the rotation after that the app is done and that it was
180 # unregistered from lttng-sessiond.
181 # This is necessary since the rotate_timer_test function expects the
182 # second rotation archive to be empty. On slow machine it can take more
183 # than 500ms for the lttng-sessiond to receive and handle an app
184 # termination. This can lead to situation where the second rotation
185 # archive still have the channels for the pid for the app since that
186 # from the point of view of the lttng-sessiond/consumer the app is still
187 # "alive" and "kicking". This is a problem only for per-pid testing.
188 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
189
190 rotate_timer_test "${TRACE_PATH}/archives" 1
191}
192
193function test_ust_streaming_timer_pid ()
194{
195 diag "Test ust remote with session rotation timer per-pid"
196 create_lttng_session_uri $SESSION_NAME net://localhost
197 enable_channel_per_pid $SESSION_NAME "channel0"
198 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
199 start_lttng_tracing_ok $SESSION_NAME
200
201 # We just want the app to register, no event generated.
202 # But we want the pid for the app since we need to validate its
203 # unregistration on lttng listing.
204 $TESTAPP_BIN -i 0 -w 0 > /dev/null 2>&1 &
205 app_pid=$!
206 wait $app_pid
207
208 wait_until_app_unregistration $app_pid
209 ok $? "App is un-registered"
210
211 # Set the rotation after that the app is done and that it was
212 # unregistered from lttng-sessiond.
213 # This is necessary since the rotate_timer_test function expects the
214 # second rotation archive to be empty. On slow machine it can take more
215 # than 500ms for the lttng-sessiond to receive and handle an app
216 # termination. This can lead to situation where the second rotation
217 # archive still have the channels for the pid for the app since that
218 # from the point of view of the lttng-sessiond/consumer the app is still
219 # "alive" and "kicking". This is a problem only for per-pid testing.
220 lttng_enable_rotation_timer_ok $SESSION_NAME 500ms
221
222 rotate_timer_test "${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*/archives" 1
223}
224
225function test_incompatible_sessions ()
226{
227 diag "Check incompatible session types with rotation"
228
229 diag "Live session with rotate timer"
230 # Should not be able to enable a rotation timer with a live session
231 create_lttng_session_uri $SESSION_NAME net://localhost --live
232 lttng_enable_rotation_timer_fail $SESSION_NAME 500ms
233 destroy_lttng_session_ok $SESSION_NAME
234
235 diag "Snapshot session with rotate timer"
236 # Should not be able to enable a rotation timer with a snapshot session
237 create_lttng_session_ok $SESSION_NAME $TRACE_PATH --snapshot
238 lttng_enable_rotation_timer_fail $SESSION_NAME 500ms
239 destroy_lttng_session_ok $SESSION_NAME
240
241 diag "Live session with rotate"
242 # Should not be able to rotate a live session
243 create_lttng_session_uri $SESSION_NAME net://localhost --live
244 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
245 start_lttng_tracing_ok $SESSION_NAME
246 rotate_session_fail $SESSION_NAME
247 destroy_lttng_session_ok $SESSION_NAME
248
249 diag "Snapshot session with rotate"
250 # Should not be able to rotate a snapshot session
251 create_lttng_session_ok $SESSION_NAME $TRACE_PATH --snapshot
252 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME
253 start_lttng_tracing_ok $SESSION_NAME
254 rotate_session_fail $SESSION_NAME
255 destroy_lttng_session_ok $SESSION_NAME
256}
257
258function test_ust_local_size_uid ()
259{
260 diag "Rotate uid local session every 2MiB"
261 local size_threshold=$((2 * 1024 * 1024))
262
263 diag "Test ust local with size-based session rotation per-uid"
264 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
265 enable_ust_lttng_channel_ok $SESSION_NAME "channel0" --buffers-uid
266 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
267 lttng_enable_rotation_size_ok $SESSION_NAME $size_threshold
268 start_lttng_tracing_ok $SESSION_NAME
269
270 wait_for_archives "$TRACE_PATH" 5
271
272 destroy_lttng_session_ok $SESSION_NAME
273}
274
275function test_ust_local_size_pid ()
276{
277 diag "Rotate uid local session every 2MiB"
278 local size_threshold=$((2 * 1024 * 1024))
279
280 diag "Test ust local with size-based session rotation per-pid"
281 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
282 enable_ust_lttng_channel_ok $SESSION_NAME "channel0" --buffers-pid
283 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
284 lttng_enable_rotation_size_ok $SESSION_NAME $size_threshold
285 start_lttng_tracing_ok $SESSION_NAME
286
287 wait_for_archives "$TRACE_PATH" 3
288
289 destroy_lttng_session_ok $SESSION_NAME
290}
291
292plan_tests $NUM_TESTS
293
294print_test_banner "$TEST_DESC"
295bail_out_if_no_babeltrace
296
297start_lttng_relayd "-o $TRACE_PATH"
298start_lttng_sessiond
299
300tests=( test_ust_streaming_uid test_ust_local_uid \
301 test_ust_streaming_pid test_ust_local_pid \
302 test_ust_local_timer_uid test_ust_streaming_timer_uid \
303 test_ust_local_timer_pid test_ust_streaming_timer_pid \
304 test_ust_local_size_uid test_ust_local_size_pid \
305 test_incompatible_sessions )
306
307for fct_test in ${tests[@]};
308do
309 SESSION_NAME=$(randstring 16 0)
310 ${fct_test}
311 clean_path $TRACE_PATH
312done
313
314stop_lttng_sessiond
315stop_lttng_relayd
316
317# Remove tmp dir
318rm -rf $TRACE_PATH
This page took 0.023749 seconds and 4 git commands to generate.