docs: Add supported versions and fix-backport policy
[lttng-tools.git] / tests / regression / tools / rotation / test_ust
1 #!/bin/bash
2 #
3 # Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 TEST_DESC="Rotation - User space tracing"
8
9 CURDIR=$(dirname $0)/
10 TESTDIR=$CURDIR/../../..
11 NR_USEC_WAIT=0
12 TESTAPP_PATH="$TESTDIR/utils/testapp"
13 TESTAPP_NAME="gen-ust-events"
14 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
15 SESSION_NAME="stream"
16 EVENT_NAME="tp:tptest"
17
18 TRACE_PATH=$(mktemp -d -t tmp.test_ust_rotation_trace_path.XXXXXX)
19
20 NUM_TESTS=152
21
22 source $TESTDIR/utils/utils.sh
23 source $CURDIR/rotate_utils.sh
24
25 if [ ! -x "$TESTAPP_BIN" ]; then
26 BAIL_OUT "No UST events binary detected."
27 fi
28
29 XPATH_CMD_OUTPUT="//lttng:command/lttng:output"
30 XPATH_PID="$XPATH_CMD_OUTPUT/lttng:domains/lttng:domain[./lttng:type = 'UST']/lttng:pids/lttng:pid/lttng:id"
31
32 function 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
42 function 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
65 function 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
74 function 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
83 function 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
93 function 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
103 function 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
133 function 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
146 function 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
159 function 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
193 function 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
225 function 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
258 function produce_n_events ()
259 {
260 local event_count=$1
261
262 $TESTAPP_BIN -i "$event_count" -w 0 > /dev/null 2>&1
263 }
264
265 function test_ust_local_size_uid ()
266 {
267 diag "Rotate uid local session every 2MiB"
268 local size_threshold=$((2 * 1024 * 1024))
269
270 diag "Test ust local with size-based session rotation per-uid"
271 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
272 enable_ust_lttng_channel_ok $SESSION_NAME "channel0" --buffers-uid
273 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
274 lttng_enable_rotation_size_ok $SESSION_NAME $size_threshold
275 start_lttng_tracing_ok $SESSION_NAME
276
277 # Cutoff at 100 times the expected size
278 trace_until_n_archives produce_n_events "$TRACE_PATH" 5 $((5 * 100 * size_threshold))
279
280 destroy_lttng_session_ok $SESSION_NAME
281 }
282
283 function test_ust_local_size_pid ()
284 {
285 diag "Rotate uid local session every 2MiB"
286 local size_threshold=$((2 * 1024 * 1024))
287
288 diag "Test ust local with size-based session rotation per-pid"
289 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
290 enable_ust_lttng_channel_ok $SESSION_NAME "channel0" --buffers-pid
291 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
292 lttng_enable_rotation_size_ok $SESSION_NAME $size_threshold
293 start_lttng_tracing_ok $SESSION_NAME
294
295 # Cutoff at 100 times the expected size
296 trace_until_n_archives produce_n_events "$TRACE_PATH" 3 $((3 * 100 * size_threshold))
297
298 destroy_lttng_session_ok $SESSION_NAME
299 }
300
301 plan_tests $NUM_TESTS
302
303 print_test_banner "$TEST_DESC"
304 bail_out_if_no_babeltrace
305
306 start_lttng_relayd "-o $TRACE_PATH"
307 start_lttng_sessiond
308
309 tests=( test_ust_streaming_uid test_ust_local_uid \
310 test_ust_streaming_pid test_ust_local_pid \
311 test_ust_local_timer_uid test_ust_streaming_timer_uid \
312 test_ust_local_timer_pid test_ust_streaming_timer_pid \
313 test_ust_local_size_uid test_ust_local_size_pid \
314 test_incompatible_sessions )
315
316 for fct_test in ${tests[@]};
317 do
318 SESSION_NAME=$(randstring 16 0)
319 ${fct_test}
320 clean_path $TRACE_PATH
321 done
322
323 stop_lttng_sessiond
324 stop_lttng_relayd
325
326 # Remove tmp dir
327 rm -rf $TRACE_PATH
This page took 0.036222 seconds and 5 git commands to generate.