trigger: introduce refcounting
[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=100
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 * 2)))
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 $EVENT_NAME $TRACE_PATH/
197 if [ $? -eq 0 ]; then
198 # Only delete if successful
199 rm -rf $TRACE_PATH
200 fi
201
202 stop_test_apps
203 }
204
205 function test_ust_local_snapshot_small_discard_buffers ()
206 {
207 NR_ITER=10000
208 NR_USEC_WAIT=0
209 OLDCPUSET=$(taskset -p $$)
210
211 diag "Test local UST snapshots with small discard buffers"
212 taskset -p 0x1 $$ 1>/dev/null 2>&1 # CPU 0 only
213 create_lttng_session_no_output $SESSION_NAME
214 enable_mmap_small_discard_ust_channel $SESSION_NAME $CHANNEL_NAME
215 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
216 start_lttng_tracing_ok $SESSION_NAME
217 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
218
219 # Run test apps, wait for them to complete.
220 start_test_app
221 wait_test_apps
222
223 # Take first snapshot, remember first line.
224 lttng_snapshot_record $SESSION_NAME
225 FIRST_LINE="$(trace_first_line $TRACE_PATH/)"
226 diag "First line (1st snapshot): $FIRST_LINE"
227 rm -rf $TRACE_PATH/
228
229 # Run test apps, wait for them to complete.
230 start_test_app
231 wait_test_apps
232
233 # Take second snapshot, remember first line.
234 lttng_snapshot_record $SESSION_NAME
235 FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
236 diag "First line (2nd snapshot): $FIRST_LINE_2"
237 rm -rf $TRACE_PATH/
238
239 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
240 fail "First snapshot event do not match."
241 else
242 pass "First snapshot event match."
243 fi
244
245 stop_lttng_tracing_ok $SESSION_NAME
246 destroy_lttng_session_ok $SESSION_NAME
247 taskset -p $OLDCPUSET $$ 1>/dev/null 2>&1
248 }
249
250 function test_ust_local_snapshot_small_overwrite_buffers ()
251 {
252 NR_ITER=10000
253 NR_USEC_WAIT=0
254 OLDCPUSET=$(taskset -p $$)
255
256 diag "Test local UST snapshots with small overwrite buffers"
257 taskset -p 0x1 $$ 1>/dev/null 2>&1 # CPU 0 only
258 create_lttng_session_no_output $SESSION_NAME
259 enable_mmap_small_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
260 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
261 start_lttng_tracing_ok $SESSION_NAME
262 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
263
264 # Run test apps, wait for them to complete.
265 start_test_app
266 wait_test_apps
267
268 # Take first snapshot, remember first line.
269 lttng_snapshot_record $SESSION_NAME
270 FIRST_LINE="$(trace_first_line $TRACE_PATH/)"
271 diag "First line (1st snapshot): $FIRST_LINE"
272 rm -rf $TRACE_PATH/
273
274 # Run test apps, wait for them to complete.
275 start_test_app
276 wait_test_apps
277
278 # Take second snapshot, remember first line.
279 lttng_snapshot_record $SESSION_NAME
280 FIRST_LINE_2="$(trace_first_line $TRACE_PATH/)"
281 diag "First line (2nd snapshot): $FIRST_LINE_2"
282 rm -rf $TRACE_PATH/
283
284 if [ x"$FIRST_LINE" != x"$FIRST_LINE_2" ]; then
285 pass "First snapshot event do not match."
286 else
287 fail "First snapshot event match."
288 fi
289
290 stop_lttng_tracing_ok $SESSION_NAME
291 destroy_lttng_session_ok $SESSION_NAME
292 taskset -p $OLDCPUSET $$ 1>/dev/null 2>&1
293 }
294
295 function test_ust_local_snapshot_max_size ()
296 {
297 NR_ITER=-1
298 NR_USEC_WAIT=100
299 page_size=`getconf PAGE_SIZE`
300 num_cpus=$(conf_proc_count)
301
302 # The minimum subbuf size is the platform PAGE_SIZE
303 subbuf_size=$(($page_size*2))
304
305 # The minimum size limit is min(subbuf_size) * nb_streams
306 max_size=$(($subbuf_size*$num_cpus))
307
308 diag "Test local UST snapshots with max size $max_size"
309 create_lttng_session_no_output $SESSION_NAME
310
311 enable_mmap_overwrite_subbuf_ust_channel $SESSION_NAME $CHANNEL_NAME $subbuf_size
312
313 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
314 start_lttng_tracing_ok $SESSION_NAME
315
316 snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" "" $max_size
317
318 # Returns once the application has at least fired ONE tracepoint.
319 start_test_app
320
321 lttng_snapshot_record $SESSION_NAME
322
323 # Check file size
324 sum_size_tracefiles=$(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \
325 -exec stat -c '%s' {} \; | awk '{s = s + $1}END{print s}')
326
327 if [ "$sum_size_tracefiles" -gt "$max_size" ]; then
328 fail "Tracefiles size sum validation"
329 diag "Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size"
330 else
331 pass "Tracefiles size sum validation"
332 fi
333
334 stop_lttng_tracing_ok $SESSION_NAME
335 destroy_lttng_session_ok $SESSION_NAME
336
337 # Validate test
338 validate_trace $EVENT_NAME $TRACE_PATH/
339
340 if [ $? -eq 0 ]; then
341 # Only delete if successful
342 rm -rf $TRACE_PATH
343 fi
344
345 stop_test_apps
346 }
347
348 function test_ust_local_snapshot_large_metadata ()
349 {
350 LM_EVENT="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
351 LM_PATH="$TESTDIR/utils/testapp"
352 LM_NAME="gen-ust-nevents"
353 LM_BIN="$LM_PATH/$LM_NAME/$LM_NAME"
354
355 diag "Test local UST snapshots with > 4kB metadata"
356 create_lttng_session_no_output $SESSION_NAME
357 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
358 enable_ust_lttng_event_ok $SESSION_NAME $LM_EVENT $CHANNEL_NAME
359 start_lttng_tracing_ok $SESSION_NAME
360 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
361 $LM_BIN --iter 1 --wait 1
362 ok $? "Start application to trace"
363 lttng_snapshot_record $SESSION_NAME
364 stop_lttng_tracing_ok $SESSION_NAME
365 destroy_lttng_session_ok $SESSION_NAME
366
367 # Validate test
368 validate_trace $LM_EVENT $TRACE_PATH/
369 if [ $? -eq 0 ]; then
370 # Only delete if successful
371 rm -rf $TRACE_PATH
372 fi
373 }
374
375 function enable_channel_per_uid_mmap_overwrite()
376 {
377 sess_name=$1
378 channel_name=$2
379
380 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --output mmap --overwrite >/dev/null 2>&1
381 ok $? "Enable channel $channel_name per UID for session $sess_name"
382 }
383
384 function test_ust_per_uid_local_snapshot ()
385 {
386 NR_ITER=-1
387 NR_USEC_WAIT=100
388 diag "Test per-uid local UST snapshots"
389 create_lttng_session_no_output $SESSION_NAME
390 enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME
391 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
392 start_lttng_tracing_ok $SESSION_NAME
393 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
394
395 # Returns once the application has at least fired ONE tracepoint.
396 start_test_app
397
398 lttng_snapshot_record $SESSION_NAME
399 stop_lttng_tracing_ok $SESSION_NAME
400 destroy_lttng_session_ok $SESSION_NAME
401
402 # Validate test
403 validate_trace $EVENT_NAME $TRACE_PATH/
404 if [ $? -eq 0 ]; then
405 # Only delete if successful
406 rm -rf $TRACE_PATH
407 fi
408
409 stop_test_apps
410 }
411
412 function test_ust_per_uid_local_snapshot_post_mortem ()
413 {
414 NR_ITER=-1
415 NR_USEC_WAIT=100
416
417 diag "Test local UST snapshots post-mortem"
418 create_lttng_session_no_output $SESSION_NAME
419 enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME
420 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
421 start_lttng_tracing_ok $SESSION_NAME
422 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
423
424 # Returns once the application has at least fired ONE tracepoint.
425 start_test_app
426 stop_test_apps
427
428 lttng_snapshot_record $SESSION_NAME
429 stop_lttng_tracing_ok $SESSION_NAME
430 destroy_lttng_session_ok $SESSION_NAME
431
432 # Validate test
433 validate_trace $EVENT_NAME $TRACE_PATH/
434 if [ $? -eq 0 ]; then
435 # Only delete if successful
436 rm -rf $TRACE_PATH
437 fi
438 }
439
440 function test_ust_local_snapshots ()
441 {
442 NR_ITER=-1
443 NR_USEC_WAIT=100
444
445 diag "Test $NR_SNAPSHOT local UST snapshots"
446 create_lttng_session_no_output $SESSION_NAME
447 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
448 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
449 start_lttng_tracing_ok $SESSION_NAME
450 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
451
452 # Returns once the application has at least fired ONE tracepoint.
453 start_test_app
454
455 for i in $(seq 1 $NR_SNAPSHOT); do
456 diag "Snapshot $i/$NR_SNAPSHOT"
457 rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
458 lttng_snapshot_record $SESSION_NAME
459 # Validate test
460 validate_trace $EVENT_NAME $TRACE_PATH/
461 if [ $? -eq 0 ]; then
462 # Only delete if successful
463 rm -rf $TRACE_PATH
464 fi
465 done
466 stop_lttng_tracing_ok $SESSION_NAME
467 destroy_lttng_session_ok $SESSION_NAME
468
469 stop_test_apps
470 }
471
472 plan_tests $NUM_TESTS
473
474 print_test_banner "$TEST_DESC"
475
476 start_lttng_sessiond
477 tests=( test_ust_list_output
478 test_ust_local_snapshot
479 test_ust_local_snapshot_max_size
480 test_ust_per_uid_local_snapshot
481 test_ust_per_uid_local_snapshot_post_mortem
482 test_ust_local_snapshot_large_metadata
483 test_ust_local_snapshots
484 test_ust_local_snapshot_small_discard_buffers
485 test_ust_local_snapshot_small_overwrite_buffers
486 )
487
488 for fct_test in ${tests[@]};
489 do
490 SESSION_NAME=$(randstring 16 0)
491 ${fct_test}
492 done
493
494 stop_lttng_sessiond
This page took 0.047826 seconds and 5 git commands to generate.