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"
34 TRACE_PATH
=$
(mktemp
-d)
36 source $TESTDIR/utils
/utils.sh
38 if [ ! -x "$TESTAPP_BIN" ]; then
39 BAIL_OUT
"No UST events binary detected."
42 # Need the number of snapshot to do.
44 BAIL_OUT
"A number of snapshot is needed."
48 NUM_TESTS
=$
(($NUM_TESTS + ($NR_SNAPSHOT * 2)))
50 function start_test_app
()
52 local tmp_file
=$
(mktemp
-u)
54 # Start application with a temporary file.
55 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
57 APPS_PID
="${APPS_PID} ${!}"
58 ok
$ret "Start application to trace"
60 # Wait for the application file to appear indicating that at least one
61 # tracepoint has been fired.
62 while [ ! -f "$tmp_file" ]; do
65 diag
"Removing test app temporary file $tmp_file"
69 function stop_test_apps
()
71 diag
"Stopping $TESTAPP_NAME"
72 for p
in ${APPS_PID}; do
79 function snapshot_add_output
()
87 if [ ! -z $name ]; then
88 extra_opt
+=" -n $name "
91 if [ ! -z $max_size ]; then
92 extra_opt
+=" -m $max_size "
95 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot add-output \
96 -s $sess_name $extra_opt $trace_path > /dev
/null
2>&1
98 ok $?
"Added snapshot output $trace_path ($extra_opt)"
101 function snapshot_del_output
()
106 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot del-output \
107 -s $sess_name $name > /dev
/null
2>&1
109 ok $?
"Deleted snapshot output named $name"
112 function enable_mmap_overwrite_subbuf_ust_channel
()
118 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
-s $sess_name \
119 $chan_name -u --output mmap
--overwrite \
120 --subbuf-size $subbuf_size > /dev
/null
2>&1
122 ok $?
"Enable channel $channel_name for session $sess_name with subbuf size $subbuf_size"
126 function test_ust_list_output
()
128 output_names
=("randomname" "somesnapshot")
130 diag
"Test UST snapshot output listing"
131 create_lttng_session_no_output
$SESSION_NAME
132 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
133 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
135 start_lttng_tracing
$SESSION_NAME
137 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" ${output_names[0]}
139 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output \
140 -s $SESSION_NAME 2>&1 |
grep ${output_names[0]} > /dev
/null
141 ok $?
"Snapshot named ${output_names[0]} present in list-output listing"
143 snapshot_del_output
$SESSION_NAME ${output_names[0]}
145 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" ${output_names[1]}
147 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN snapshot list-output \
148 -s $SESSION_NAME 2>&1 |
grep ${output_names[1]} > /dev
/null
150 ok $?
"Snapshot named ${output_names[1]} present in list-output listing"
152 stop_lttng_tracing
$SESSION_NAME
153 destroy_lttng_session
$SESSION_NAME
156 function test_ust_local_snapshot
()
158 diag
"Test local UST snapshots"
159 create_lttng_session_no_output
$SESSION_NAME
160 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
161 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
162 start_lttng_tracing
$SESSION_NAME
163 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
165 # Returns once the application has at least fired ONE tracepoint.
168 lttng_snapshot_record
$SESSION_NAME
169 stop_lttng_tracing
$SESSION_NAME
170 destroy_lttng_session
$SESSION_NAME
173 validate_trace
$EVENT_NAME $TRACE_PATH/
174 if [ $?
-eq 0 ]; then
175 # Only delete if successful
182 function test_ust_local_snapshot_max_size
()
187 # The minimum size limit is min(subbuf_size) * nb_streams
188 max_size
=$
(($subbuf_size*$num_cpus))
190 diag
"Test local UST snapshots with max size $max_size"
191 create_lttng_session_no_output
$SESSION_NAME
193 enable_mmap_overwrite_subbuf_ust_channel
$SESSION_NAME $CHANNEL_NAME $subbuf_size
195 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
196 start_lttng_tracing
$SESSION_NAME
198 snapshot_add_output
$SESSION_NAME "file://$TRACE_PATH" "" $max_size
200 # Returns once the application has at least fired ONE tracepoint.
203 lttng_snapshot_record
$SESSION_NAME
206 sum_size_tracefiles
=$
(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \
207 -exec stat
-c '%s' {} \
; |
awk '{s = s + $1}END{print s}')
209 if [ "$sum_size_tracefiles" -gt "$max_size" ]; then
210 fail
"Tracefiles size sum validation"
211 diag
"Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size"
214 pass
"Tracefiles size sum validation"
216 stop_lttng_tracing
$SESSION_NAME
217 destroy_lttng_session
$SESSION_NAME
220 validate_trace
$EVENT_NAME $TRACE_PATH/
222 if [ $?
-eq 0 ]; then
223 # Only delete if successful
230 function test_ust_local_snapshot_large_metadata
()
232 LM_EVENT
="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
233 LM_PATH
="$TESTDIR/utils/testapp"
234 LM_NAME
="gen-ust-nevents"
235 LM_BIN
="$LM_PATH/$LM_NAME/$LM_NAME"
237 diag
"Test local UST snapshots with > 4kB metadata"
238 create_lttng_session_no_output
$SESSION_NAME
239 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
240 enable_ust_lttng_event
$SESSION_NAME $LM_EVENT $CHANNEL_NAME
241 start_lttng_tracing
$SESSION_NAME
242 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
244 ok $?
"Start application to trace"
245 lttng_snapshot_record
$SESSION_NAME
246 stop_lttng_tracing
$SESSION_NAME
247 destroy_lttng_session
$SESSION_NAME
250 validate_trace
$LM_EVENT $TRACE_PATH/
251 if [ $?
-eq 0 ]; then
252 # Only delete if successful
257 function enable_channel_per_uid_mmap_overwrite
()
262 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
--buffers-uid -u $channel_name -s $sess_name --output mmap
--overwrite >/dev
/null
2>&1
263 ok $?
"Enable channel $channel_name per UID for session $sess_name"
266 function test_ust_per_uid_local_snapshot
()
268 diag
"Test local UST snapshots"
269 create_lttng_session_no_output
$SESSION_NAME
270 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
271 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
272 start_lttng_tracing
$SESSION_NAME
273 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
275 # Returns once the application has at least fired ONE tracepoint.
278 lttng_snapshot_record
$SESSION_NAME
279 stop_lttng_tracing
$SESSION_NAME
280 destroy_lttng_session
$SESSION_NAME
283 validate_trace
$EVENT_NAME $TRACE_PATH/
284 if [ $?
-eq 0 ]; then
285 # 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
317 function test_ust_local_snapshots
()
319 diag
"Test $NR_SNAPSHOT local UST snapshots"
320 create_lttng_session_no_output
$SESSION_NAME
321 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
322 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
323 start_lttng_tracing
$SESSION_NAME
324 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
326 # Returns once the application has at least fired ONE tracepoint.
329 for i
in $
(seq 1 $NR_SNAPSHOT); do
330 diag
"Snapshot $i/$NR_SNAPSHOT"
331 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
332 lttng_snapshot_record
$SESSION_NAME
334 validate_trace
$EVENT_NAME $TRACE_PATH/
335 if [ $?
-eq 0 ]; then
336 # Only delete if successful
340 stop_lttng_tracing
$SESSION_NAME
341 destroy_lttng_session
$SESSION_NAME
346 plan_tests
$NUM_TESTS
348 print_test_banner
"$TEST_DESC"
352 tests
=( test_ust_list_output
353 test_ust_local_snapshot
354 test_ust_local_snapshot_max_size
355 test_ust_per_uid_local_snapshot
356 test_ust_per_uid_local_snapshot_post_mortem
357 test_ust_local_snapshot_large_metadata
358 test_ust_local_snapshots
)
360 for fct_test
in ${tests[@]};
362 SESSION_NAME
=$
(randstring
16 0)