3 # Copyright (C) 2017 Julien Desfossez <jdesfossez@efficios.com>
5 # SPDX-License-Identifier: LGPL-2.1-only
7 TEST_DESC
="Rotation - User space tracing"
10 TESTDIR
=$CURDIR/..
/..
/..
12 TESTAPP_PATH
="$TESTDIR/utils/testapp"
13 TESTAPP_NAME
="gen-ust-events"
14 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
16 EVENT_NAME
="tp:tptest"
18 TRACE_PATH
=$
(mktemp
-d -t tmp.test_ust_rotation_trace_path.XXXXXX
)
22 source $TESTDIR/utils
/utils.sh
23 source $CURDIR/rotate_utils.sh
25 if [ ! -x "$TESTAPP_BIN" ]; then
26 BAIL_OUT
"No UST events binary detected."
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"
32 function enable_channel_per_pid
()
37 enable_ust_lttng_channel_ok
$sess_name $channel_name --buffers-pid
40 # MUST set TESTDIR before calling those functions
42 function rotate_ust_test
()
48 start_lttng_tracing_ok
$SESSION_NAME
51 $TESTAPP_BIN -i 10 -w $NR_USEC_WAIT > /dev
/null
2>&1
52 rotate_session_ok
$SESSION_NAME
54 $TESTAPP_BIN -i 20 -w $NR_USEC_WAIT > /dev
/null
2>&1
55 stop_lttng_tracing_ok
$SESSION_NAME
57 # Third chunk contains no event (rotate after stop).
58 rotate_session_ok
$SESSION_NAME
60 destroy_lttng_session_ok
$SESSION_NAME
62 validate_test_chunks
"${local_path}" $today $app_path ust
65 function test_ust_streaming_uid
()
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
71 rotate_ust_test
"${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*/archives" "ust/uid/*/*/" 0
74 function test_ust_local_uid
()
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
80 rotate_ust_test
"${TRACE_PATH}/archives" "ust/uid/*/*/" 0
83 function test_ust_streaming_pid
()
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"
90 rotate_ust_test
"${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*/archives" "ust/pid/*/" 1
93 function test_ust_local_pid
()
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"
100 rotate_ust_test
"${TRACE_PATH}/archives" "ust/pid/*/" 1
103 function wait_until_app_unregistration
()
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
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"
125 # No app present on listing.
133 function test_ust_local_timer_uid
()
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
143 rotate_timer_test
"${TRACE_PATH}/archives" 0
146 function test_ust_streaming_timer_uid
()
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
156 rotate_timer_test
"${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*/archives" 0
159 function test_ust_local_timer_pid
()
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
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 &
176 wait_until_app_unregistration
$app_pid
177 ok $?
"App is un-registered"
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
190 rotate_timer_test
"${TRACE_PATH}/archives" 1
193 function test_ust_streaming_timer_pid
()
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
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 &
208 wait_until_app_unregistration
$app_pid
209 ok $?
"App is un-registered"
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
222 rotate_timer_test
"${TRACE_PATH}/${HOSTNAME}/${SESSION_NAME}*/archives" 1
225 function test_incompatible_sessions
()
227 diag
"Check incompatible session types with rotation"
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
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
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
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
258 function produce_n_events
()
262 $TESTAPP_BIN -i "$event_count" -w 0 > /dev
/null
2>&1
265 function test_ust_local_size_uid
()
267 diag
"Rotate uid local session every 2MiB"
268 local size_threshold
=$
((2 * 1024 * 1024))
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
277 # Cutoff at 100 times the expected size
278 trace_until_n_archives produce_n_events
"$TRACE_PATH" 5 $
((5 * 100 * size_threshold
))
280 destroy_lttng_session_ok
$SESSION_NAME
283 function test_ust_local_size_pid
()
285 diag
"Rotate uid local session every 2MiB"
286 local size_threshold
=$
((2 * 1024 * 1024))
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
295 # Cutoff at 100 times the expected size
296 trace_until_n_archives produce_n_events
"$TRACE_PATH" 3 $
((3 * 100 * size_threshold
))
298 destroy_lttng_session_ok
$SESSION_NAME
301 plan_tests
$NUM_TESTS
303 print_test_banner
"$TEST_DESC"
304 bail_out_if_no_babeltrace
306 start_lttng_relayd
"-o $TRACE_PATH"
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
)
316 for fct_test
in ${tests[@]};
318 SESSION_NAME
=$
(randstring
16 0)
320 clean_path
$TRACE_PATH