test: snapshot after regenerate metadata
[lttng-tools.git] / tests / regression / tools / snapshots / ust_test
1 #!/bin/bash
2 #
3 # Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
4 #
5 # SPDX-License-Identifier: LGPL-2.1-only
6
7 TEST_DESC="Snapshots - UST tracing"
8
9 CURDIR=$(dirname $0)/
10 TESTDIR=$CURDIR/../../..
11 EVENT_NAME="tp:tptest"
12 SESSION_NAME=""
13 CHANNEL_NAME="snapchan"
14 TESTAPP_PATH="$TESTDIR/utils/testapp"
15 TESTAPP_NAME="gen-ust-events"
16 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
17 APPS_PID=
18
19 NUM_TESTS=105
20
21 TRACE_PATH=$(mktemp -d)
22
23 source $TESTDIR/utils/utils.sh
24
25 if [ ! -x "$TESTAPP_BIN" ]; then
26 BAIL_OUT "No UST events binary detected."
27 fi
28
29 # Need the number of snapshot to do.
30 if [ -z $1 ]; then
31 BAIL_OUT "A number of snapshot is needed."
32 fi
33 NR_SNAPSHOT=$1
34
35 NUM_TESTS=$(($NUM_TESTS + ($NR_SNAPSHOT * 3)))
36
37 function start_test_app()
38 {
39 local tmp_file=$(mktemp -u)
40
41 # Start application with a temporary file.
42 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file &
43 ret=$?
44 APPS_PID="${APPS_PID} ${!}"
45 ok $ret "Start application to trace"
46
47 # Wait for the application file to appear indicating that at least one
48 # tracepoint has been fired.
49 while [ ! -f "$tmp_file" ]; do
50 sleep 0.5
51 done
52 diag "Removing test app temporary file $tmp_file"
53 rm -f $tmp_file
54 }
55
56 function wait_test_apps()
57 {
58 diag "Waiting for $TESTAPP_NAME"
59 for p in ${APPS_PID}; do
60 wait ${p} 2>/dev/null
61 done
62 }
63
64 function stop_test_apps()
65 {
66 diag "Stopping $TESTAPP_NAME"
67 for p in ${APPS_PID}; do
68 kill ${p}
69 wait ${p} 2>/dev/null
70 done
71 APPS_PID=
72 }
73
74 function snapshot_add_output ()
75 {
76 local sess_name=$1
77 local trace_path=$2
78 local name=$3
79 local max_size=$4
80 local extra_opt=""
81
82 if [ ! -z $name ]; then
83 extra_opt+=" -n $name "
84 fi
85
86 if [ ! -z $max_size ]; then
87 extra_opt+=" -m $max_size "
88 fi
89
90 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output \
91 -s $sess_name $extra_opt $trace_path > /dev/null 2>&1
92
93 ok $? "Added snapshot output $trace_path ($extra_opt)"
94 }
95
96 function snapshot_del_output ()
97 {
98 local sess_name=$1
99 local name=$2
100
101 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output \
102 -s $sess_name $name > /dev/null 2>&1
103
104 ok $? "Deleted snapshot output named $name"
105 }
106
107 function enable_mmap_overwrite_subbuf_ust_channel ()
108 {
109 local sess_name=$1
110 local chan_name=$2
111 local subbuf_size=$3
112
113 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name \
114 $chan_name -u --output mmap --overwrite \
115 --subbuf-size $subbuf_size > /dev/null 2>&1
116
117 ok $? "Enable channel $channel_name for session $sess_name with subbuf size $subbuf_size"
118 }
119
120 function enable_mmap_small_discard_ust_channel ()
121 {
122 local sess_name=$1
123 local chan_name=$2
124
125 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name \
126 $chan_name -u --output mmap --discard \
127 --subbuf-size $(getconf PAGE_SIZE) --num-subbuf 2 \
128 > /dev/null 2>&1
129
130 ok $? "Enable channel $channel_name for session $sess_name with small discard buffers"
131 }
132
133 function enable_mmap_small_overwrite_ust_channel ()
134 {
135 local sess_name=$1
136 local chan_name=$2
137
138 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name \
139 $chan_name -u --output mmap --overwrite \
140 --subbuf-size $(getconf PAGE_SIZE) --num-subbuf 2 \
141 > /dev/null 2>&1
142
143 ok $? "Enable channel $channel_name for session $sess_name with small discard buffers"
144 }
145
146 function test_ust_list_output ()
147 {
148 output_names=("randomname" "somesnapshot")
149
150 diag "Test UST snapshot output listing"
151 create_lttng_session_no_output $SESSION_NAME
152 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
153 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
154
155 start_lttng_tracing_ok $SESSION_NAME
156
157 snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" ${output_names[0]}
158
159 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output \
160 -s $SESSION_NAME 2>&1 | grep ${output_names[0]} > /dev/null
161 ok $? "Snapshot named ${output_names[0]} present in list-output listing"
162
163 snapshot_del_output $SESSION_NAME ${output_names[0]}
164
165 snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" ${output_names[1]}
166
167 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output \
168 -s $SESSION_NAME 2>&1 | grep ${output_names[1]} > /dev/null
169
170 ok $? "Snapshot named ${output_names[1]} present in list-output listing"
171
172 stop_lttng_tracing_ok $SESSION_NAME
173 destroy_lttng_session_ok $SESSION_NAME
174 }
175
176 function test_ust_local_snapshot ()
177 {
178 NR_ITER=-1
179 NR_USEC_WAIT=100
180
181 diag "Test local UST snapshots"
182 create_lttng_session_no_output $SESSION_NAME
183 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
184 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
185 start_lttng_tracing_ok $SESSION_NAME
186 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
187
188 # Returns once the application has at least fired ONE tracepoint.
189 start_test_app
190
191 lttng_snapshot_record $SESSION_NAME
192 stop_lttng_tracing_ok $SESSION_NAME
193 destroy_lttng_session_ok $SESSION_NAME
194
195 # Validate test
196 validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0
197 validate_trace $EVENT_NAME $TRACE_PATH/
198 if [ $? -eq 0 ]; then
199 # Only delete if successful
200 rm -rf $TRACE_PATH
201 fi
202
203 stop_test_apps
204 }
205
206 function test_ust_local_snapshot_small_discard_buffers ()
207 {
208 NR_ITER=10000
209 NR_USEC_WAIT=0
210 OLDCPUSET=$(taskset -p $$)
211
212 diag "Test local UST snapshots with small discard buffers"
213 taskset -p 0x1 $$ 1>/dev/null 2>&1 # CPU 0 only
214 create_lttng_session_no_output $SESSION_NAME
215 enable_mmap_small_discard_ust_channel $SESSION_NAME $CHANNEL_NAME
216 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
217 start_lttng_tracing_ok $SESSION_NAME
218 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
219
220 # Run test apps, wait for them to complete.
221 start_test_app
222 wait_test_apps
223
224 # Take first snapshot, remember first line.
225 lttng_snapshot_record $SESSION_NAME
226 FIRST_LINE="$(trace_first_line $TRACE_PATH/)"
227 diag "First line (1st snapshot): $FIRST_LINE"
228 rm -rf $TRACE_PATH/
229
230 # Run test apps, wait for them to complete.
231 start_test_app
232 wait_test_apps
233
234 # Take second snapshot, remember first line.
235 lttng_snapshot_record $SESSION_NAME
236 FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
237 diag "First line (2nd snapshot): $FIRST_LINE_2"
238 rm -rf $TRACE_PATH/
239
240 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
241 fail "First snapshot event do not match."
242 else
243 pass "First snapshot event match."
244 fi
245
246 stop_lttng_tracing_ok $SESSION_NAME
247 destroy_lttng_session_ok $SESSION_NAME
248 taskset -p $OLDCPUSET $$ 1>/dev/null 2>&1
249 }
250
251 function test_ust_local_snapshot_small_overwrite_buffers ()
252 {
253 NR_ITER=10000
254 NR_USEC_WAIT=0
255 OLDCPUSET=$(taskset -p $$)
256
257 diag "Test local UST snapshots with small overwrite buffers"
258 taskset -p 0x1 $$ 1>/dev/null 2>&1 # CPU 0 only
259 create_lttng_session_no_output $SESSION_NAME
260 enable_mmap_small_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
261 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
262 start_lttng_tracing_ok $SESSION_NAME
263 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
264
265 # Run test apps, wait for them to complete.
266 start_test_app
267 wait_test_apps
268
269 # Take first snapshot, remember first line.
270 lttng_snapshot_record $SESSION_NAME
271 FIRST_LINE="$(trace_first_line $TRACE_PATH/)"
272 diag "First line (1st snapshot): $FIRST_LINE"
273 rm -rf $TRACE_PATH/
274
275 # Run test apps, wait for them to complete.
276 start_test_app
277 wait_test_apps
278
279 # Take second snapshot, remember first line.
280 lttng_snapshot_record $SESSION_NAME
281 FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
282 diag "First line (2nd snapshot): $FIRST_LINE_2"
283 rm -rf $TRACE_PATH/
284
285 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
286 pass "First snapshot event do not match."
287 else
288 fail "First snapshot event match."
289 fi
290
291 stop_lttng_tracing_ok $SESSION_NAME
292 destroy_lttng_session_ok $SESSION_NAME
293 taskset -p $OLDCPUSET $$ 1>/dev/null 2>&1
294 }
295
296 function test_ust_local_snapshot_max_size ()
297 {
298 NR_ITER=-1
299 NR_USEC_WAIT=100
300 page_size=`getconf PAGE_SIZE`
301 num_cpus=$(conf_proc_count)
302
303 # The minimum subbuf size is the platform PAGE_SIZE
304 subbuf_size=$(($page_size*2))
305
306 # The minimum size limit is min(subbuf_size) * nb_streams
307 max_size=$(($subbuf_size*$num_cpus))
308
309 diag "Test local UST snapshots with max size $max_size"
310 create_lttng_session_no_output $SESSION_NAME
311
312 enable_mmap_overwrite_subbuf_ust_channel $SESSION_NAME $CHANNEL_NAME $subbuf_size
313
314 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
315 start_lttng_tracing_ok $SESSION_NAME
316
317 snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" "" $max_size
318
319 # Returns once the application has at least fired ONE tracepoint.
320 start_test_app
321
322 lttng_snapshot_record $SESSION_NAME
323
324 # Check file size
325 sum_size_tracefiles=$(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \
326 -exec stat -c '%s' {} \; | awk '{s = s + $1}END{print s}')
327
328 if [ "$sum_size_tracefiles" -gt "$max_size" ]; then
329 fail "Tracefiles size sum validation"
330 diag "Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size"
331 else
332 pass "Tracefiles size sum validation"
333 fi
334
335 stop_lttng_tracing_ok $SESSION_NAME
336 destroy_lttng_session_ok $SESSION_NAME
337
338 # Validate test
339 validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0
340 validate_trace $EVENT_NAME $TRACE_PATH/
341
342 if [ $? -eq 0 ]; then
343 # Only delete if successful
344 rm -rf $TRACE_PATH
345 fi
346
347 stop_test_apps
348 }
349
350 function test_ust_local_snapshot_large_metadata ()
351 {
352 LM_EVENT="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
353 LM_PATH="$TESTDIR/utils/testapp"
354 LM_NAME="gen-ust-nevents"
355 LM_BIN="$LM_PATH/$LM_NAME/$LM_NAME"
356
357 diag "Test local UST snapshots with > 4kB metadata"
358 create_lttng_session_no_output $SESSION_NAME
359 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
360 enable_ust_lttng_event_ok $SESSION_NAME $LM_EVENT $CHANNEL_NAME
361 start_lttng_tracing_ok $SESSION_NAME
362 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
363 $LM_BIN --iter 1 --wait 1
364 ok $? "Start application to trace"
365 lttng_snapshot_record $SESSION_NAME
366 stop_lttng_tracing_ok $SESSION_NAME
367 destroy_lttng_session_ok $SESSION_NAME
368
369 # Validate test
370 validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0
371 validate_trace $LM_EVENT $TRACE_PATH/
372 if [ $? -eq 0 ]; then
373 # Only delete if successful
374 rm -rf $TRACE_PATH
375 fi
376 }
377
378 function enable_channel_per_uid_mmap_overwrite()
379 {
380 sess_name=$1
381 channel_name=$2
382
383 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --output mmap --overwrite >/dev/null 2>&1
384 ok $? "Enable channel $channel_name per UID for session $sess_name"
385 }
386
387 function test_ust_per_uid_local_snapshot ()
388 {
389 NR_ITER=-1
390 NR_USEC_WAIT=100
391 diag "Test per-uid local UST snapshots"
392 create_lttng_session_no_output $SESSION_NAME
393 enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME
394 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
395 start_lttng_tracing_ok $SESSION_NAME
396 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
397
398 # Returns once the application has at least fired ONE tracepoint.
399 start_test_app
400
401 lttng_snapshot_record $SESSION_NAME
402 stop_lttng_tracing_ok $SESSION_NAME
403 destroy_lttng_session_ok $SESSION_NAME
404
405 # Validate test
406 validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0
407 validate_trace $EVENT_NAME $TRACE_PATH/
408 if [ $? -eq 0 ]; then
409 # Only delete if successful
410 rm -rf $TRACE_PATH
411 fi
412
413 stop_test_apps
414 }
415
416 function test_ust_per_uid_local_snapshot_post_mortem ()
417 {
418 NR_ITER=-1
419 NR_USEC_WAIT=100
420
421 diag "Test local UST snapshots post-mortem"
422 create_lttng_session_no_output $SESSION_NAME
423 enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME
424 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
425 start_lttng_tracing_ok $SESSION_NAME
426 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
427
428 # Returns once the application has at least fired ONE tracepoint.
429 start_test_app
430 stop_test_apps
431
432 lttng_snapshot_record $SESSION_NAME
433 stop_lttng_tracing_ok $SESSION_NAME
434 destroy_lttng_session_ok $SESSION_NAME
435
436 # Validate test
437 validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0
438 validate_trace $EVENT_NAME $TRACE_PATH/
439 if [ $? -eq 0 ]; then
440 # Only delete if successful
441 rm -rf $TRACE_PATH
442 fi
443 }
444
445 function test_ust_local_snapshots ()
446 {
447 NR_ITER=-1
448 NR_USEC_WAIT=100
449
450 diag "Test $NR_SNAPSHOT local UST snapshots"
451 create_lttng_session_no_output $SESSION_NAME
452 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
453 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
454 start_lttng_tracing_ok $SESSION_NAME
455 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
456
457 # Returns once the application has at least fired ONE tracepoint.
458 start_test_app
459
460 for i in $(seq 1 $NR_SNAPSHOT); do
461 diag "Snapshot $i/$NR_SNAPSHOT"
462 rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
463 lttng_snapshot_record $SESSION_NAME
464 # Validate test
465 validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" $((i - 1))
466 validate_trace $EVENT_NAME $TRACE_PATH/
467 if [ $? -eq 0 ]; then
468 # Only delete if successful
469 rm -rf $TRACE_PATH
470 fi
471 done
472 stop_lttng_tracing_ok $SESSION_NAME
473 destroy_lttng_session_ok $SESSION_NAME
474
475 stop_test_apps
476 }
477
478 plan_tests $NUM_TESTS
479
480 print_test_banner "$TEST_DESC"
481
482 start_lttng_sessiond
483 tests=( test_ust_list_output
484 test_ust_local_snapshot
485 test_ust_local_snapshot_max_size
486 test_ust_per_uid_local_snapshot
487 test_ust_per_uid_local_snapshot_post_mortem
488 test_ust_local_snapshot_large_metadata
489 test_ust_local_snapshots
490 test_ust_local_snapshot_small_discard_buffers
491 test_ust_local_snapshot_small_overwrite_buffers
492 )
493
494 for fct_test in ${tests[@]};
495 do
496 SESSION_NAME=$(randstring 16 0)
497 ${fct_test}
498 done
499
500 stop_lttng_sessiond
This page took 0.099372 seconds and 4 git commands to generate.