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"
31 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 function snapshot_add_output
()
49 if [ ! -z $name ]; then
50 extra_opt
+=" -n $name "
53 if [ ! -z $max_size ]; then
54 extra_opt
+=" -m $max_size "
57 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output \
58 -s $sess_name $extra_opt $trace_path > /dev
/null
2>&1
60 ok $?
"Added snapshot output $trace_path ($extra_opt)"
63 function snapshot_del_output
()
68 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output \
69 -s $sess_name $name > /dev
/null
2>&1
71 ok $?
"Deleted snapshot output named $name"
74 function enable_mmap_overwrite_subbuf_ust_channel
()
80 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name \
81 $chan_name -u --output mmap
--overwrite \
82 --subbuf-size $subbuf_size > /dev
/null
2>&1
84 ok $?
"Enable channel $channel_name for session $sess_name with subbuf size $subbuf_size"
88 function test_ust_list_output
()
90 output_names
=("randomname" "somesnapshot")
92 diag
"Test UST snapshot output listing"
93 create_lttng_session_no_output
$SESSION_NAME
94 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
95 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
97 start_lttng_tracing
$SESSION_NAME
99 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" ${output_names[0]}
101 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output \
102 -s $SESSION_NAME 2>&1 |
grep ${output_names[0]} > /dev
/null
103 ok $?
"Snapshot named ${output_names[0]} present in list-output listing"
105 snapshot_del_output
$SESSION_NAME ${output_names[0]}
107 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" ${output_names[1]}
109 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output \
110 -s $SESSION_NAME 2>&1 |
grep ${output_names[1]} > /dev
/null
112 ok $?
"Snapshot named ${output_names[1]} present in list-output listing"
114 stop_lttng_tracing
$SESSION_NAME
115 destroy_lttng_session
$SESSION_NAME
118 function test_ust_local_snapshot
()
120 diag
"Test local UST snapshots"
121 create_lttng_session_no_output
$SESSION_NAME
122 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
123 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
124 start_lttng_tracing
$SESSION_NAME
125 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
126 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
127 ok $?
"Start application to trace"
128 lttng_snapshot_record
$SESSION_NAME
129 stop_lttng_tracing
$SESSION_NAME
130 destroy_lttng_session
$SESSION_NAME
133 validate_trace
$EVENT_NAME $TRACE_PATH/
134 if [ $?
-eq 0 ]; then
135 # Only delete if successful
140 diag
"Killing $TESTAPP_NAME"
141 PID_APP
=`pidof $TESTAPP_NAME`
142 kill $PID_APP >/dev
/null
2>&1
145 function test_ust_local_snapshot_max_size
()
150 # The minimum size limit is min(subbuf_size) * nb_streams
151 max_size
=$
(($subbuf_size*$num_cpus))
153 diag
"Test local UST snapshots with max size $max_size"
154 create_lttng_session_no_output
$SESSION_NAME
156 enable_mmap_overwrite_subbuf_ust_channel
$SESSION_NAME $CHANNEL_NAME $subbuf_size
158 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
159 start_lttng_tracing
$SESSION_NAME
161 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" "" $max_size
163 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
164 ok $?
"Start application to trace"
166 lttng_snapshot_record
$SESSION_NAME
169 sum_size_tracefiles
=$
(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \
170 -exec stat
-c '%s' {} \
; |
awk '{s = s + $1}END{print s}')
172 if [ "$sum_size_tracefiles" -gt "$max_size" ]; then
173 fail
"Tracefiles size sum validation"
174 diag
"Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size"
177 pass
"Tracefiles size sum validation"
179 stop_lttng_tracing
$SESSION_NAME
180 destroy_lttng_session
$SESSION_NAME
183 validate_trace
$EVENT_NAME $TRACE_PATH/
185 if [ $?
-eq 0 ]; then
186 # Only delete if successful
190 diag
"Killing $TESTAPP_NAME"
191 PID_APP
=`pidof $TESTAPP_NAME`
192 kill $PID_APP >/dev
/null
2>&1
195 function test_ust_local_snapshot_large_metadata
()
197 LM_EVENT
="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
198 LM_PATH
="$TESTDIR/utils/testapp"
199 LM_NAME
="gen-ust-nevents"
200 LM_BIN
="$LM_PATH/$LM_NAME/$LM_NAME"
202 diag
"Test local UST snapshots with > 4kB metadata"
203 create_lttng_session_no_output
$SESSION_NAME
204 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
205 enable_ust_lttng_event
$SESSION_NAME $LM_EVENT $CHANNEL_NAME
206 start_lttng_tracing
$SESSION_NAME
207 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
209 ok $?
"Start application to trace"
210 lttng_snapshot_record
$SESSION_NAME
211 stop_lttng_tracing
$SESSION_NAME
212 destroy_lttng_session
$SESSION_NAME
215 validate_trace
$LM_EVENT $TRACE_PATH/
216 if [ $?
-eq 0 ]; then
217 # Only delete if successful
224 function enable_channel_per_uid_mmap_overwrite
()
229 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
--buffers-uid -u $channel_name -s $sess_name --output mmap
--overwrite >/dev
/null
2>&1
230 ok $?
"Enable channel $channel_name per UID for session $sess_name"
233 function test_ust_per_uid_local_snapshot
()
235 diag
"Test local UST snapshots"
236 create_lttng_session_no_output
$SESSION_NAME
237 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
238 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
239 start_lttng_tracing
$SESSION_NAME
240 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
241 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
242 ok $?
"Start application to trace"
243 lttng_snapshot_record
$SESSION_NAME
244 stop_lttng_tracing
$SESSION_NAME
245 destroy_lttng_session
$SESSION_NAME
248 validate_trace
$EVENT_NAME $TRACE_PATH/
249 if [ $?
-eq 0 ]; then
250 # Only delete if successful
255 diag
"Killing $TESTAPP_NAME"
256 PID_APP
=`pidof $TESTAPP_NAME`
257 kill $PID_APP >/dev
/null
2>&1
260 function test_ust_per_uid_local_snapshot_post_mortem
()
262 diag
"Test local UST snapshots post-mortem"
263 create_lttng_session_no_output
$SESSION_NAME
264 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
265 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
266 start_lttng_tracing
$SESSION_NAME
267 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
268 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
269 ok $?
"Start application to trace"
270 diag
"Killing $TESTAPP_NAME"
271 PID_APP
=`pidof $TESTAPP_NAME`
272 kill $PID_APP >/dev
/null
2>&1
273 lttng_snapshot_record
$SESSION_NAME
274 stop_lttng_tracing
$SESSION_NAME
275 destroy_lttng_session
$SESSION_NAME
278 validate_trace
$EVENT_NAME $TRACE_PATH/
279 if [ $?
-eq 0 ]; then
280 # Only delete if successful
287 function test_ust_1000_local_snapshots
()
291 diag
"Test $NB_SNAP local UST snapshots"
292 create_lttng_session_no_output
$SESSION_NAME
293 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
294 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
295 start_lttng_tracing
$SESSION_NAME
296 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
297 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
298 for i
in $
(seq 1 $NB_SNAP); do
299 diag
"Snapshot $i/$NB_SNAP"
300 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
301 lttng_snapshot_record
$SESSION_NAME
303 validate_trace
$EVENT_NAME $TRACE_PATH/
304 if [ $?
-eq 0 ]; then
305 # Only delete if successful
311 stop_lttng_tracing
$SESSION_NAME
312 destroy_lttng_session
$SESSION_NAME
313 diag
"Killing $TESTAPP_NAME"
314 PID_APP
=`pidof $TESTAPP_NAME`
315 kill $PID_APP >/dev
/null
2>&1
318 plan_tests
$NUM_TESTS
320 print_test_banner
"$TEST_DESC"
322 if [ "$(id -u)" == "0" ]; then
330 tests
=( test_ust_list_output
331 test_ust_local_snapshot
332 test_ust_local_snapshot_max_size
333 test_ust_per_uid_local_snapshot
334 test_ust_per_uid_local_snapshot_post_mortem
335 test_ust_local_snapshot_large_metadata
336 test_ust_1000_local_snapshots
)
338 for fct_test
in ${tests[@]};
340 SESSION_NAME
=$
(randstring
16 0)