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