Tests: utils: regroup xml utils to utils.sh
[lttng-tools.git] / tests / regression / tools / snapshots / ust_test
CommitLineData
ebaaaf5e
JD
1#!/bin/bash
2#
9d16b343 3# Copyright (C) 2013 Julien Desfossez <jdesfossez@efficios.com>
ebaaaf5e 4#
9d16b343
MJ
5# SPDX-License-Identifier: LGPL-2.1-only
6
ebaaaf5e
JD
7TEST_DESC="Snapshots - UST tracing"
8
9CURDIR=$(dirname $0)/
10TESTDIR=$CURDIR/../../..
11EVENT_NAME="tp:tptest"
ebaaaf5e
JD
12SESSION_NAME=""
13CHANNEL_NAME="snapchan"
14TESTAPP_PATH="$TESTDIR/utils/testapp"
15TESTAPP_NAME="gen-ust-events"
16TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
0fc2834c 17APPS_PID=
ebaaaf5e 18
bd666153 19NUM_TESTS=105
ebaaaf5e 20
33e55711 21TRACE_PATH=$(mktemp --tmpdir -d tmp.test_snapshots_ust_trace_path.XXXXXX)
ebaaaf5e
JD
22
23source $TESTDIR/utils/utils.sh
24
25if [ ! -x "$TESTAPP_BIN" ]; then
ce83431d 26 BAIL_OUT "No UST events binary detected"
ebaaaf5e
JD
27fi
28
1d20c959
DG
29# Need the number of snapshot to do.
30if [ -z $1 ]; then
ce83431d 31 BAIL_OUT "A number of snapshot is needed"
1d20c959
DG
32fi
33NR_SNAPSHOT=$1
34
bd666153 35NUM_TESTS=$(($NUM_TESTS + ($NR_SNAPSHOT * 3)))
1d20c959 36
209b934f
DG
37function start_test_app()
38{
33e55711 39 local tmp_file=$(mktemp --tmpdir -u "tmp.${FUNCNAME[0]}_tmp_file.XXXXXX")
209b934f
DG
40
41 # Start application with a temporary file.
6c4a91d6 42 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $tmp_file &
0fc2834c
MD
43 ret=$?
44 APPS_PID="${APPS_PID} ${!}"
45 ok $ret "Start application to trace"
209b934f
DG
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
ae779dd6
MD
56function 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
0fc2834c 64function stop_test_apps()
209b934f 65{
0fc2834c
MD
66 diag "Stopping $TESTAPP_NAME"
67 for p in ${APPS_PID}; do
68 kill ${p}
5402fe87 69 wait ${p} 2>/dev/null
0fc2834c 70 done
c7613334 71 APPS_PID=
209b934f
DG
72}
73
5e83c405
CB
74function 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
96function 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
107function 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
ae779dd6
MD
120function 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
133function 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}
5e83c405
CB
145
146function 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
c4926bb5 153 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
5e83c405 154
e563bbdb 155 start_lttng_tracing_ok $SESSION_NAME
5e83c405
CB
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
96340a01 172 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 173 destroy_lttng_session_ok $SESSION_NAME
5e83c405
CB
174}
175
ebaaaf5e
JD
176function test_ust_local_snapshot ()
177{
18c9d47c 178 NR_ITER=-1
ae779dd6
MD
179 NR_USEC_WAIT=100
180
ebaaaf5e
JD
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
c4926bb5 184 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 185 start_lttng_tracing_ok $SESSION_NAME
9f0e230a 186 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
209b934f
DG
187
188 # Returns once the application has at least fired ONE tracepoint.
189 start_test_app
190
ebaaaf5e 191 lttng_snapshot_record $SESSION_NAME
96340a01 192 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 193 destroy_lttng_session_ok $SESSION_NAME
ebaaaf5e
JD
194
195 # Validate test
bd666153 196 validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0
ebaaaf5e
JD
197 validate_trace $EVENT_NAME $TRACE_PATH/
198 if [ $? -eq 0 ]; then
199 # Only delete if successful
200 rm -rf $TRACE_PATH
ebaaaf5e 201 fi
209b934f 202
0fc2834c 203 stop_test_apps
ebaaaf5e
JD
204}
205
ae779dd6
MD
206function 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
9f0e230a 218 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
ae779dd6
MD
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
ce83431d 241 fail "First snapshot event do not match"
ae779dd6 242 else
ce83431d 243 pass "First snapshot event match"
ae779dd6
MD
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
251function 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
9f0e230a 263 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
ae779dd6
MD
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
ce83431d 286 pass "First snapshot event do not match"
ae779dd6 287 else
ce83431d 288 fail "First snapshot event match"
ae779dd6
MD
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
5e83c405
CB
296function test_ust_local_snapshot_max_size ()
297{
18c9d47c 298 NR_ITER=-1
ae779dd6 299 NR_USEC_WAIT=100
034a7848 300 page_size=`getconf PAGE_SIZE`
1901f874 301 num_cpus=$(conf_proc_count)
5e83c405 302
034a7848
MJ
303 # The minimum subbuf size is the platform PAGE_SIZE
304 subbuf_size=$(($page_size*2))
305
5e83c405
CB
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
c4926bb5 314 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 315 start_lttng_tracing_ok $SESSION_NAME
5e83c405
CB
316
317 snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" "" $max_size
318
209b934f
DG
319 # Returns once the application has at least fired ONE tracepoint.
320 start_test_app
5e83c405
CB
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"
b67cdb8c
JG
331 else
332 pass "Tracefiles size sum validation"
5e83c405
CB
333 fi
334
96340a01 335 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 336 destroy_lttng_session_ok $SESSION_NAME
5e83c405
CB
337
338 # Validate test
bd666153 339 validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0
5e83c405
CB
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
0fc2834c 347 stop_test_apps
5e83c405
CB
348}
349
a54047ec
JD
350function 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
c4926bb5 360 enable_ust_lttng_event_ok $SESSION_NAME $LM_EVENT $CHANNEL_NAME
e563bbdb 361 start_lttng_tracing_ok $SESSION_NAME
9f0e230a 362 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
8db430e7 363 $LM_BIN --iter 1 --wait 1
a54047ec
JD
364 ok $? "Start application to trace"
365 lttng_snapshot_record $SESSION_NAME
96340a01 366 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 367 destroy_lttng_session_ok $SESSION_NAME
a54047ec
JD
368
369 # Validate test
bd666153 370 validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0
a54047ec
JD
371 validate_trace $LM_EVENT $TRACE_PATH/
372 if [ $? -eq 0 ]; then
373 # Only delete if successful
374 rm -rf $TRACE_PATH
a54047ec
JD
375 fi
376}
377
5f4c2d80
JD
378function 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
387function test_ust_per_uid_local_snapshot ()
388{
18c9d47c
JR
389 NR_ITER=-1
390 NR_USEC_WAIT=100
891d74dd 391 diag "Test per-uid local UST snapshots"
5f4c2d80
JD
392 create_lttng_session_no_output $SESSION_NAME
393 enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME
c4926bb5 394 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 395 start_lttng_tracing_ok $SESSION_NAME
9f0e230a 396 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
209b934f
DG
397
398 # Returns once the application has at least fired ONE tracepoint.
399 start_test_app
400
5f4c2d80 401 lttng_snapshot_record $SESSION_NAME
96340a01 402 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 403 destroy_lttng_session_ok $SESSION_NAME
5f4c2d80
JD
404
405 # Validate test
bd666153 406 validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0
5f4c2d80
JD
407 validate_trace $EVENT_NAME $TRACE_PATH/
408 if [ $? -eq 0 ]; then
409 # Only delete if successful
410 rm -rf $TRACE_PATH
5f4c2d80 411 fi
209b934f 412
0fc2834c 413 stop_test_apps
5f4c2d80
JD
414}
415
4f03c06d
JD
416function test_ust_per_uid_local_snapshot_post_mortem ()
417{
18c9d47c 418 NR_ITER=-1
ae779dd6
MD
419 NR_USEC_WAIT=100
420
4f03c06d
JD
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
c4926bb5 424 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 425 start_lttng_tracing_ok $SESSION_NAME
9f0e230a 426 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
209b934f
DG
427
428 # Returns once the application has at least fired ONE tracepoint.
429 start_test_app
0fc2834c 430 stop_test_apps
209b934f 431
4f03c06d 432 lttng_snapshot_record $SESSION_NAME
96340a01 433 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 434 destroy_lttng_session_ok $SESSION_NAME
4f03c06d
JD
435
436 # Validate test
bd666153 437 validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" 0
4f03c06d
JD
438 validate_trace $EVENT_NAME $TRACE_PATH/
439 if [ $? -eq 0 ]; then
440 # Only delete if successful
441 rm -rf $TRACE_PATH
4f03c06d
JD
442 fi
443}
444
1d20c959 445function test_ust_local_snapshots ()
ebaaaf5e 446{
18c9d47c 447 NR_ITER=-1
ae779dd6
MD
448 NR_USEC_WAIT=100
449
1d20c959 450 diag "Test $NR_SNAPSHOT local UST snapshots"
ebaaaf5e
JD
451 create_lttng_session_no_output $SESSION_NAME
452 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
c4926bb5 453 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
e563bbdb 454 start_lttng_tracing_ok $SESSION_NAME
9f0e230a 455 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
209b934f
DG
456
457 # Returns once the application has at least fired ONE tracepoint.
458 start_test_app
459
1d20c959
DG
460 for i in $(seq 1 $NR_SNAPSHOT); do
461 diag "Snapshot $i/$NR_SNAPSHOT"
ebaaaf5e
JD
462 rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
463 lttng_snapshot_record $SESSION_NAME
464 # Validate test
bd666153 465 validate_trace_path_ust_uid_snapshot "$TRACE_PATH" "" "snapshot-1" $((i - 1))
ebaaaf5e
JD
466 validate_trace $EVENT_NAME $TRACE_PATH/
467 if [ $? -eq 0 ]; then
468 # Only delete if successful
469 rm -rf $TRACE_PATH
ebaaaf5e
JD
470 fi
471 done
96340a01 472 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 473 destroy_lttng_session_ok $SESSION_NAME
209b934f 474
0fc2834c 475 stop_test_apps
ebaaaf5e
JD
476}
477
478plan_tests $NUM_TESTS
479
480print_test_banner "$TEST_DESC"
481
ebaaaf5e 482start_lttng_sessiond
5e83c405
CB
483tests=( 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
ae779dd6
MD
489 test_ust_local_snapshots
490 test_ust_local_snapshot_small_discard_buffers
491 test_ust_local_snapshot_small_overwrite_buffers
492)
ebaaaf5e
JD
493
494for fct_test in ${tests[@]};
495do
496 SESSION_NAME=$(randstring 16 0)
497 ${fct_test}
ebaaaf5e
JD
498done
499
500stop_lttng_sessiond
This page took 0.06596 seconds and 4 git commands to generate.