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