Tests: lttng_snapshot_add_output_ok: allow specifying output type
[lttng-tools.git] / tests / regression / tools / snapshots / ust_test
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
17 TEST_DESC="Snapshots - UST tracing"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 EVENT_NAME="tp:tptest"
22 SESSION_NAME=""
23 CHANNEL_NAME="snapchan"
24 TESTAPP_PATH="$TESTDIR/utils/testapp"
25 TESTAPP_NAME="gen-ust-events"
26 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
27 APPS_PID=
28
29 NUM_TESTS=100
30
31 TRACE_PATH=$(mktemp -d)
32
33 source $TESTDIR/utils/utils.sh
34
35 if [ ! -x "$TESTAPP_BIN" ]; then
36 BAIL_OUT "No UST events binary detected."
37 fi
38
39 # Need the number of snapshot to do.
40 if [ -z $1 ]; then
41 BAIL_OUT "A number of snapshot is needed."
42 fi
43 NR_SNAPSHOT=$1
44
45 NUM_TESTS=$(($NUM_TESTS + ($NR_SNAPSHOT * 2)))
46
47 function start_test_app()
48 {
49 local tmp_file=$(mktemp -u)
50
51 # Start application with a temporary file.
52 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
53 ret=$?
54 APPS_PID="${APPS_PID} ${!}"
55 ok $ret "Start application to trace"
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
66 function 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
74 function stop_test_apps()
75 {
76 diag "Stopping $TESTAPP_NAME"
77 for p in ${APPS_PID}; do
78 kill ${p}
79 wait ${p} 2>/dev/null
80 done
81 APPS_PID=
82 }
83
84 function 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
106 function 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
117 function 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
130 function 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
143 function 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 }
155
156 function 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
163 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
164
165 start_lttng_tracing_ok $SESSION_NAME
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
182 stop_lttng_tracing_ok $SESSION_NAME
183 destroy_lttng_session_ok $SESSION_NAME
184 }
185
186 function test_ust_local_snapshot ()
187 {
188 NR_ITER=-1
189 NR_USEC_WAIT=100
190
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
194 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
195 start_lttng_tracing_ok $SESSION_NAME
196 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
197
198 # Returns once the application has at least fired ONE tracepoint.
199 start_test_app
200
201 lttng_snapshot_record $SESSION_NAME
202 stop_lttng_tracing_ok $SESSION_NAME
203 destroy_lttng_session_ok $SESSION_NAME
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
210 fi
211
212 stop_test_apps
213 }
214
215 function 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
227 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
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
260 function 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
272 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
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
305 function test_ust_local_snapshot_max_size ()
306 {
307 NR_ITER=-1
308 NR_USEC_WAIT=100
309 page_size=`getconf PAGE_SIZE`
310 num_cpus=$(conf_proc_count)
311
312 # The minimum subbuf size is the platform PAGE_SIZE
313 subbuf_size=$(($page_size*2))
314
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
323 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
324 start_lttng_tracing_ok $SESSION_NAME
325
326 snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" "" $max_size
327
328 # Returns once the application has at least fired ONE tracepoint.
329 start_test_app
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"
340 else
341 pass "Tracefiles size sum validation"
342 fi
343
344 stop_lttng_tracing_ok $SESSION_NAME
345 destroy_lttng_session_ok $SESSION_NAME
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
355 stop_test_apps
356 }
357
358 function 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
368 enable_ust_lttng_event_ok $SESSION_NAME $LM_EVENT $CHANNEL_NAME
369 start_lttng_tracing_ok $SESSION_NAME
370 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
371 $LM_BIN 1 1
372 ok $? "Start application to trace"
373 lttng_snapshot_record $SESSION_NAME
374 stop_lttng_tracing_ok $SESSION_NAME
375 destroy_lttng_session_ok $SESSION_NAME
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
382 fi
383 }
384
385 function 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
394 function test_ust_per_uid_local_snapshot ()
395 {
396 NR_ITER=-1
397 NR_USEC_WAIT=100
398 diag "Test per-uid local UST snapshots"
399 create_lttng_session_no_output $SESSION_NAME
400 enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME
401 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
402 start_lttng_tracing_ok $SESSION_NAME
403 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
404
405 # Returns once the application has at least fired ONE tracepoint.
406 start_test_app
407
408 lttng_snapshot_record $SESSION_NAME
409 stop_lttng_tracing_ok $SESSION_NAME
410 destroy_lttng_session_ok $SESSION_NAME
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
417 fi
418
419 stop_test_apps
420 }
421
422 function test_ust_per_uid_local_snapshot_post_mortem ()
423 {
424 NR_ITER=-1
425 NR_USEC_WAIT=100
426
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
430 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
431 start_lttng_tracing_ok $SESSION_NAME
432 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
433
434 # Returns once the application has at least fired ONE tracepoint.
435 start_test_app
436 stop_test_apps
437
438 lttng_snapshot_record $SESSION_NAME
439 stop_lttng_tracing_ok $SESSION_NAME
440 destroy_lttng_session_ok $SESSION_NAME
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
447 fi
448 }
449
450 function test_ust_local_snapshots ()
451 {
452 NR_ITER=-1
453 NR_USEC_WAIT=100
454
455 diag "Test $NR_SNAPSHOT local UST snapshots"
456 create_lttng_session_no_output $SESSION_NAME
457 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
458 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
459 start_lttng_tracing_ok $SESSION_NAME
460 lttng_snapshot_add_output_ok $SESSION_NAME file://$TRACE_PATH
461
462 # Returns once the application has at least fired ONE tracepoint.
463 start_test_app
464
465 for i in $(seq 1 $NR_SNAPSHOT); do
466 diag "Snapshot $i/$NR_SNAPSHOT"
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
474 fi
475 done
476 stop_lttng_tracing_ok $SESSION_NAME
477 destroy_lttng_session_ok $SESSION_NAME
478
479 stop_test_apps
480 }
481
482 plan_tests $NUM_TESTS
483
484 print_test_banner "$TEST_DESC"
485
486 start_lttng_sessiond
487 tests=( 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
493 test_ust_local_snapshots
494 test_ust_local_snapshot_small_discard_buffers
495 test_ust_local_snapshot_small_overwrite_buffers
496 )
497
498 for fct_test in ${tests[@]};
499 do
500 SESSION_NAME=$(randstring 16 0)
501 ${fct_test}
502 done
503
504 stop_lttng_sessiond
This page took 0.041327 seconds and 5 git commands to generate.