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 test_ust_local_snapshot
()
43 diag
"Test local UST snapshots"
44 create_lttng_session_no_output
$SESSION_NAME
45 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
46 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
47 start_lttng_tracing
$SESSION_NAME
48 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
49 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
50 ok $?
"Start application to trace"
51 lttng_snapshot_record
$SESSION_NAME
52 stop_lttng_tracing
$SESSION_NAME
53 destroy_lttng_session
$SESSION_NAME
56 validate_trace
$EVENT_NAME $TRACE_PATH/
58 # Only delete if successful
63 diag
"Killing $TESTAPP_NAME"
64 PID_APP
=`pidof $TESTAPP_NAME`
65 kill $PID_APP >/dev
/null
2>&1
68 function test_ust_local_snapshot_large_metadata
()
70 LM_EVENT
="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
71 LM_PATH
="$TESTDIR/utils/testapp"
72 LM_NAME
="gen-ust-nevents"
73 LM_BIN
="$LM_PATH/$LM_NAME/$LM_NAME"
75 diag
"Test local UST snapshots with > 4kB metadata"
76 create_lttng_session_no_output
$SESSION_NAME
77 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
78 enable_ust_lttng_event
$SESSION_NAME $LM_EVENT $CHANNEL_NAME
79 start_lttng_tracing
$SESSION_NAME
80 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
82 ok $?
"Start application to trace"
83 lttng_snapshot_record
$SESSION_NAME
84 stop_lttng_tracing
$SESSION_NAME
85 destroy_lttng_session
$SESSION_NAME
88 validate_trace
$LM_EVENT $TRACE_PATH/
90 # Only delete if successful
97 function enable_channel_per_uid_mmap_overwrite
()
102 $TESTDIR/..
/src
/bin
/lttng
/$LTTNG_BIN enable-channel
--buffers-uid -u $channel_name -s $sess_name --output mmap
--overwrite >/dev
/null
2>&1
103 ok $?
"Enable channel $channel_name per UID for session $sess_name"
106 function test_ust_per_uid_local_snapshot
()
108 diag
"Test local UST snapshots"
109 create_lttng_session_no_output
$SESSION_NAME
110 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
111 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
112 start_lttng_tracing
$SESSION_NAME
113 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
114 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
115 ok $?
"Start application to trace"
116 lttng_snapshot_record
$SESSION_NAME
117 stop_lttng_tracing
$SESSION_NAME
118 destroy_lttng_session
$SESSION_NAME
121 validate_trace
$EVENT_NAME $TRACE_PATH/
122 if [ $?
-eq 0 ]; then
123 # Only delete if successful
128 diag
"Killing $TESTAPP_NAME"
129 PID_APP
=`pidof $TESTAPP_NAME`
130 kill $PID_APP >/dev
/null
2>&1
133 function test_ust_per_uid_local_snapshot_post_mortem
()
135 diag
"Test local UST snapshots post-mortem"
136 create_lttng_session_no_output
$SESSION_NAME
137 enable_channel_per_uid_mmap_overwrite
$SESSION_NAME $CHANNEL_NAME
138 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
139 start_lttng_tracing
$SESSION_NAME
140 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
141 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
142 ok $?
"Start application to trace"
143 diag
"Killing $TESTAPP_NAME"
144 PID_APP
=`pidof $TESTAPP_NAME`
145 kill $PID_APP >/dev
/null
2>&1
146 lttng_snapshot_record
$SESSION_NAME
147 stop_lttng_tracing
$SESSION_NAME
148 destroy_lttng_session
$SESSION_NAME
151 validate_trace
$EVENT_NAME $TRACE_PATH/
152 if [ $?
-eq 0 ]; then
153 # Only delete if successful
160 function test_ust_1000_local_snapshots
()
164 diag
"Test $NB_SNAP local UST snapshots"
165 create_lttng_session_no_output
$SESSION_NAME
166 enable_lttng_mmap_overwrite_ust_channel
$SESSION_NAME $CHANNEL_NAME
167 enable_ust_lttng_event
$SESSION_NAME $EVENT_NAME $CHANNEL_NAME
168 start_lttng_tracing
$SESSION_NAME
169 lttng_snapshot_add_output
$SESSION_NAME $TRACE_PATH
170 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
171 for i
in $
(seq 1 $NB_SNAP); do
172 diag
"Snapshot $i/$NB_SNAP"
173 rm -rf $TRACE_PATH/snapshot
/* 2>/dev
/null
174 lttng_snapshot_record
$SESSION_NAME
176 validate_trace
$EVENT_NAME $TRACE_PATH/
177 if [ $?
-eq 0 ]; then
178 # Only delete if successful
184 stop_lttng_tracing
$SESSION_NAME
185 destroy_lttng_session
$SESSION_NAME
186 diag
"Killing $TESTAPP_NAME"
187 PID_APP
=`pidof $TESTAPP_NAME`
188 kill $PID_APP >/dev
/null
2>&1
191 plan_tests
$NUM_TESTS
193 print_test_banner
"$TEST_DESC"
195 if [ "$(id -u)" == "0" ]; then
203 tests
=( test_ust_local_snapshot \
204 test_ust_per_uid_local_snapshot \
205 test_ust_per_uid_local_snapshot_post_mortem \
206 test_ust_local_snapshot_large_metadata \
207 test_ust_1000_local_snapshots
)
209 for fct_test
in ${tests[@]};
211 SESSION_NAME
=$
(randstring
16 0)