3 # Copyright (C) - 2013 Julien Desfossez <jdesfossez@efficios.com>
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.
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
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"
20 TESTDIR
=$CURDIR/..
/..
/..
21 EVENT_NAME
="tp:tptest"
24 CHANNEL_NAME
="snapchan"
25 TESTAPP_PATH
="$TESTDIR/utils/testapp"
26 TESTAPP_NAME
="gen-ust-events"
27 TESTAPP_BIN
="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
33 TRACE_PATH
=$
(mktemp
-d)
35 source $TESTDIR/utils
/utils.sh
37 if [ ! -x "$TESTAPP_BIN" ]; then
38 BAIL_OUT
"No UST events binary detected."
41 # Need the number of snapshot to do.
43 BAIL_OUT
"A number of snapshot is needed."
47 NUM_TESTS
=$
(($NUM_TESTS + ($NR_SNAPSHOT * 2)))
49 function start_test_app
()
51 local tmp_file
="/tmp/lttng_test_ust.42.file"
53 # Start application with a temporary file.
54 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
55 ok $?
"Start application to trace"
57 # Wait for the application file to appear indicating that at least one
58 # tracepoint has been fired.
59 while [ ! -f "$tmp_file" ]; do
62 diag
"Removing test app temporary file $tmp_file"
66 function kill_test_app
()
68 diag
"Killing $TESTAPP_NAME"
69 PID_APP
=`pidof $TESTAPP_NAME`
70 kill $PID_APP >/dev
/null
2>&1
73 function snapshot_add_output
()
81 if [ ! -z $name ]; then
82 extra_opt
+=" -n $name "
85 if [ ! -z $max_size ]; then
86 extra_opt
+=" -m $max_size "
89 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output \
90 -s $sess_name $extra_opt $trace_path > /dev
/null
2>&1
92 ok $?
"Added snapshot output $trace_path ($extra_opt)"
95 function snapshot_del_output
()
100 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output \
101 -s $sess_name $name > /dev
/null
2>&1
103 ok $?
"Deleted snapshot output named $name"
106 function enable_mmap_overwrite_subbuf_ust_channel
()
112 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name \
113 $chan_name -u --output mmap
--overwrite \
114 --subbuf-size $subbuf_size > /dev
/null
2>&1
116 ok $?
"Enable channel $channel_name for session $sess_name with subbuf size $subbuf_size"
120 function test_ust_list_output
()
122 output_names
=("randomname" "somesnapshot")
124 diag
"Test UST snapshot output listing"
125 create_lttng_session_no_output
$SESSION_NAME
126 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
127 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
129 start_lttng_tracing
$SESSION_NAME
131 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" ${output_names[0]}
133 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output \
134 -s $SESSION_NAME 2>&1 |
grep ${output_names[0]} > /dev
/null
135 ok $?
"Snapshot named ${output_names[0]} present in list-output listing"
137 snapshot_del_output
$SESSION_NAME ${output_names[0]}
139 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" ${output_names[1]}
141 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output \
142 -s $SESSION_NAME 2>&1 |
grep ${output_names[1]} > /dev
/null
144 ok $?
"Snapshot named ${output_names[1]} present in list-output listing"
146 stop_lttng_tracing
$SESSION_NAME
147 destroy_lttng_session
$SESSION_NAME
150 function test_ust_local_snapshot
()
152 diag
"Test local UST snapshots"
153 create_lttng_session_no_output
$SESSION_NAME
154 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
155 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
156 start_lttng_tracing
$SESSION_NAME
157 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
159 # Returns once the application has at least fired ONE tracepoint.
162 lttng_snapshot_record
$SESSION_NAME
163 stop_lttng_tracing
$SESSION_NAME
164 destroy_lttng_session
$SESSION_NAME
167 validate_trace
$EVENT_NAME $TRACE_PATH/
168 if [ $?
-eq 0 ]; then
169 # Only delete if successful
178 function test_ust_local_snapshot_max_size
()
183 # The minimum size limit is min(subbuf_size) * nb_streams
184 max_size
=$
(($subbuf_size*$num_cpus))
186 diag
"Test local UST snapshots with max size $max_size"
187 create_lttng_session_no_output
$SESSION_NAME
189 enable_mmap_overwrite_subbuf_ust_channel
$SESSION_NAME $CHANNEL_NAME $subbuf_size
191 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
192 start_lttng_tracing
$SESSION_NAME
194 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" "" $max_size
196 # Returns once the application has at least fired ONE tracepoint.
199 lttng_snapshot_record
$SESSION_NAME
202 sum_size_tracefiles
=$
(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \
203 -exec stat
-c '%s' {} \
; |
awk '{s = s + $1}END{print s}')
205 if [ "$sum_size_tracefiles" -gt "$max_size" ]; then
206 fail
"Tracefiles size sum validation"
207 diag
"Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size"
210 pass
"Tracefiles size sum validation"
212 stop_lttng_tracing
$SESSION_NAME
213 destroy_lttng_session
$SESSION_NAME
216 validate_trace
$EVENT_NAME $TRACE_PATH/
218 if [ $?
-eq 0 ]; then
219 # Only delete if successful
226 function test_ust_local_snapshot_large_metadata
()
228 LM_EVENT
="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
229 LM_PATH
="$TESTDIR/utils/testapp"
230 LM_NAME
="gen-ust-nevents"
231 LM_BIN
="$LM_PATH/$LM_NAME/$LM_NAME"
233 diag
"Test local UST snapshots with > 4kB metadata"
234 create_lttng_session_no_output
$SESSION_NAME
235 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
236 enable_ust_lttng_event
$SESSION_NAME $LM_EVENT $CHANNEL_NAME
237 start_lttng_tracing
$SESSION_NAME
238 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
240 ok $?
"Start application to trace"
241 lttng_snapshot_record
$SESSION_NAME
242 stop_lttng_tracing
$SESSION_NAME
243 destroy_lttng_session
$SESSION_NAME
246 validate_trace
$LM_EVENT $TRACE_PATH/
247 if [ $?
-eq 0 ]; then
248 # Only delete if successful
255 function enable_channel_per_uid_mmap_overwrite
()
260 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
--buffers-uid -u $channel_name -s $sess_name --output mmap
--overwrite >/dev
/null
2>&1
261 ok $?
"Enable channel $channel_name per UID for session $sess_name"
264 function test_ust_per_uid_local_snapshot
()
266 diag
"Test local UST snapshots"
267 create_lttng_session_no_output
$SESSION_NAME
268 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
269 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
270 start_lttng_tracing
$SESSION_NAME
271 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
273 # Returns once the application has at least fired ONE tracepoint.
276 lttng_snapshot_record
$SESSION_NAME
277 stop_lttng_tracing
$SESSION_NAME
278 destroy_lttng_session
$SESSION_NAME
281 validate_trace
$EVENT_NAME $TRACE_PATH/
282 if [ $?
-eq 0 ]; then
283 # Only delete if successful
292 function test_ust_per_uid_local_snapshot_post_mortem
()
294 diag
"Test local UST snapshots post-mortem"
295 create_lttng_session_no_output
$SESSION_NAME
296 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
297 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
298 start_lttng_tracing
$SESSION_NAME
299 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
301 # Returns once the application has at least fired ONE tracepoint.
305 lttng_snapshot_record
$SESSION_NAME
306 stop_lttng_tracing
$SESSION_NAME
307 destroy_lttng_session
$SESSION_NAME
310 validate_trace
$EVENT_NAME $TRACE_PATH/
311 if [ $?
-eq 0 ]; then
312 # Only delete if successful
319 function test_ust_local_snapshots
()
321 diag
"Test $NR_SNAPSHOT local UST snapshots"
322 create_lttng_session_no_output
$SESSION_NAME
323 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
324 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
325 start_lttng_tracing
$SESSION_NAME
326 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
328 # Returns once the application has at least fired ONE tracepoint.
331 for i
in $
(seq 1 $NR_SNAPSHOT); do
332 diag
"Snapshot $i/$NR_SNAPSHOT"
333 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
334 lttng_snapshot_record
$SESSION_NAME
336 validate_trace
$EVENT_NAME $TRACE_PATH/
337 if [ $?
-eq 0 ]; then
338 # Only delete if successful
344 stop_lttng_tracing
$SESSION_NAME
345 destroy_lttng_session
$SESSION_NAME
350 plan_tests
$NUM_TESTS
352 print_test_banner
"$TEST_DESC"
356 tests
=( test_ust_list_output
357 test_ust_local_snapshot
358 test_ust_local_snapshot_max_size
359 test_ust_per_uid_local_snapshot
360 test_ust_per_uid_local_snapshot_post_mortem
361 test_ust_local_snapshot_large_metadata
362 test_ust_local_snapshots
)
364 for fct_test
in ${tests[@]};
366 SESSION_NAME
=$
(randstring
16 0)