a35fbf37fb9022c22946bd9c96dcd7f4a3427548
[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 PID_RELAYD=0
23 SESSION_NAME=""
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"
28 NR_ITER=2000000
29 NR_USEC_WAIT=100
30
31 NUM_TESTS=76
32
33 TRACE_PATH=$(mktemp -d)
34
35 source $TESTDIR/utils/utils.sh
36
37 if [ ! -x "$TESTAPP_BIN" ]; then
38 BAIL_OUT "No UST events binary detected."
39 fi
40
41 # Need the number of snapshot to do.
42 if [ -z $1 ]; then
43 BAIL_OUT "A number of snapshot is needed."
44 fi
45 NR_SNAPSHOT=$1
46
47 NUM_TESTS=$(($NUM_TESTS + ($NR_SNAPSHOT * 2)))
48
49 function start_test_app()
50 {
51 local tmp_file="/tmp/lttng_test_ust.42.file"
52
53 # Start application with a temporary file.
54 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $tmp_file &
55 ok $? "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 stop_test_app()
67 {
68 diag "Killing $TESTAPP_NAME"
69 PID_APP=`pidof $TESTAPP_NAME`
70 kill $PID_APP >/dev/null 2>&1
71 diag "Waiting on $TESTAPP_NAME"
72 wait
73 }
74
75 function snapshot_add_output ()
76 {
77 local sess_name=$1
78 local trace_path=$2
79 local name=$3
80 local max_size=$4
81 local extra_opt=""
82
83 if [ ! -z $name ]; then
84 extra_opt+=" -n $name "
85 fi
86
87 if [ ! -z $max_size ]; then
88 extra_opt+=" -m $max_size "
89 fi
90
91 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output \
92 -s $sess_name $extra_opt $trace_path > /dev/null 2>&1
93
94 ok $? "Added snapshot output $trace_path ($extra_opt)"
95 }
96
97 function snapshot_del_output ()
98 {
99 local sess_name=$1
100 local name=$2
101
102 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output \
103 -s $sess_name $name > /dev/null 2>&1
104
105 ok $? "Deleted snapshot output named $name"
106 }
107
108 function enable_mmap_overwrite_subbuf_ust_channel ()
109 {
110 local sess_name=$1
111 local chan_name=$2
112 local subbuf_size=$3
113
114 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name \
115 $chan_name -u --output mmap --overwrite \
116 --subbuf-size $subbuf_size > /dev/null 2>&1
117
118 ok $? "Enable channel $channel_name for session $sess_name with subbuf size $subbuf_size"
119 }
120
121
122 function test_ust_list_output ()
123 {
124 output_names=("randomname" "somesnapshot")
125
126 diag "Test UST snapshot output listing"
127 create_lttng_session_no_output $SESSION_NAME
128 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
129 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
130
131 start_lttng_tracing $SESSION_NAME
132
133 snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" ${output_names[0]}
134
135 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output \
136 -s $SESSION_NAME 2>&1 | grep ${output_names[0]} > /dev/null
137 ok $? "Snapshot named ${output_names[0]} present in list-output listing"
138
139 snapshot_del_output $SESSION_NAME ${output_names[0]}
140
141 snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" ${output_names[1]}
142
143 $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output \
144 -s $SESSION_NAME 2>&1 | grep ${output_names[1]} > /dev/null
145
146 ok $? "Snapshot named ${output_names[1]} present in list-output listing"
147
148 stop_lttng_tracing $SESSION_NAME
149 destroy_lttng_session $SESSION_NAME
150 }
151
152 function test_ust_local_snapshot ()
153 {
154 diag "Test local UST snapshots"
155 create_lttng_session_no_output $SESSION_NAME
156 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
157 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
158 start_lttng_tracing $SESSION_NAME
159 lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
160
161 # Returns once the application has at least fired ONE tracepoint.
162 start_test_app
163
164 lttng_snapshot_record $SESSION_NAME
165 stop_lttng_tracing $SESSION_NAME
166 destroy_lttng_session $SESSION_NAME
167
168 # Validate test
169 validate_trace $EVENT_NAME $TRACE_PATH/
170 if [ $? -eq 0 ]; then
171 # Only delete if successful
172 rm -rf $TRACE_PATH
173 else
174 break
175 fi
176
177 stop_test_app
178 }
179
180 function test_ust_local_snapshot_max_size ()
181 {
182 subbuf_size=8192
183 num_cpus=`nproc`
184
185 # The minimum size limit is min(subbuf_size) * nb_streams
186 max_size=$(($subbuf_size*$num_cpus))
187
188 diag "Test local UST snapshots with max size $max_size"
189 create_lttng_session_no_output $SESSION_NAME
190
191 enable_mmap_overwrite_subbuf_ust_channel $SESSION_NAME $CHANNEL_NAME $subbuf_size
192
193 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
194 start_lttng_tracing $SESSION_NAME
195
196 snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" "" $max_size
197
198 # Returns once the application has at least fired ONE tracepoint.
199 start_test_app
200
201 lttng_snapshot_record $SESSION_NAME
202
203 # Check file size
204 sum_size_tracefiles=$(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \
205 -exec stat -c '%s' {} \; | awk '{s = s + $1}END{print s}')
206
207 if [ "$sum_size_tracefiles" -gt "$max_size" ]; then
208 fail "Tracefiles size sum validation"
209 diag "Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size"
210 fi
211
212 pass "Tracefiles size sum validation"
213
214 stop_lttng_tracing $SESSION_NAME
215 destroy_lttng_session $SESSION_NAME
216
217 # Validate test
218 validate_trace $EVENT_NAME $TRACE_PATH/
219
220 if [ $? -eq 0 ]; then
221 # Only delete if successful
222 rm -rf $TRACE_PATH
223 fi
224
225 stop_test_app
226 }
227
228 function test_ust_local_snapshot_large_metadata ()
229 {
230 LM_EVENT="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
231 LM_PATH="$TESTDIR/utils/testapp"
232 LM_NAME="gen-ust-nevents"
233 LM_BIN="$LM_PATH/$LM_NAME/$LM_NAME"
234
235 diag "Test local UST snapshots with > 4kB metadata"
236 create_lttng_session_no_output $SESSION_NAME
237 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
238 enable_ust_lttng_event $SESSION_NAME $LM_EVENT $CHANNEL_NAME
239 start_lttng_tracing $SESSION_NAME
240 lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
241 $LM_BIN 1 1
242 ok $? "Start application to trace"
243 lttng_snapshot_record $SESSION_NAME
244 stop_lttng_tracing $SESSION_NAME
245 destroy_lttng_session $SESSION_NAME
246
247 # Validate test
248 validate_trace $LM_EVENT $TRACE_PATH/
249 if [ $? -eq 0 ]; then
250 # Only delete if successful
251 rm -rf $TRACE_PATH
252 else
253 break
254 fi
255 }
256
257 function enable_channel_per_uid_mmap_overwrite()
258 {
259 sess_name=$1
260 channel_name=$2
261
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"
264 }
265
266 function test_ust_per_uid_local_snapshot ()
267 {
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
274
275 # Returns once the application has at least fired ONE tracepoint.
276 start_test_app
277
278 lttng_snapshot_record $SESSION_NAME
279 stop_lttng_tracing $SESSION_NAME
280 destroy_lttng_session $SESSION_NAME
281
282 # Validate test
283 validate_trace $EVENT_NAME $TRACE_PATH/
284 if [ $? -eq 0 ]; then
285 # Only delete if successful
286 rm -rf $TRACE_PATH
287 else
288 break
289 fi
290
291 stop_test_app
292 }
293
294 function test_ust_per_uid_local_snapshot_post_mortem ()
295 {
296 diag "Test local UST snapshots post-mortem"
297 create_lttng_session_no_output $SESSION_NAME
298 enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME
299 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
300 start_lttng_tracing $SESSION_NAME
301 lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
302
303 # Returns once the application has at least fired ONE tracepoint.
304 start_test_app
305 stop_test_app
306
307 lttng_snapshot_record $SESSION_NAME
308 stop_lttng_tracing $SESSION_NAME
309 destroy_lttng_session $SESSION_NAME
310
311 # Validate test
312 validate_trace $EVENT_NAME $TRACE_PATH/
313 if [ $? -eq 0 ]; then
314 # Only delete if successful
315 rm -rf $TRACE_PATH
316 else
317 break
318 fi
319 }
320
321 function test_ust_local_snapshots ()
322 {
323 diag "Test $NR_SNAPSHOT local UST snapshots"
324 create_lttng_session_no_output $SESSION_NAME
325 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
326 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
327 start_lttng_tracing $SESSION_NAME
328 lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
329
330 # Returns once the application has at least fired ONE tracepoint.
331 start_test_app
332
333 for i in $(seq 1 $NR_SNAPSHOT); do
334 diag "Snapshot $i/$NR_SNAPSHOT"
335 rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
336 lttng_snapshot_record $SESSION_NAME
337 # Validate test
338 validate_trace $EVENT_NAME $TRACE_PATH/
339 if [ $? -eq 0 ]; then
340 # Only delete if successful
341 rm -rf $TRACE_PATH
342 else
343 break
344 fi
345 done
346 stop_lttng_tracing $SESSION_NAME
347 destroy_lttng_session $SESSION_NAME
348
349 stop_test_app
350 }
351
352 plan_tests $NUM_TESTS
353
354 print_test_banner "$TEST_DESC"
355
356 start_lttng_sessiond
357
358 tests=( test_ust_list_output
359 test_ust_local_snapshot
360 test_ust_local_snapshot_max_size
361 test_ust_per_uid_local_snapshot
362 test_ust_per_uid_local_snapshot_post_mortem
363 test_ust_local_snapshot_large_metadata
364 test_ust_local_snapshots)
365
366 for fct_test in ${tests[@]};
367 do
368 SESSION_NAME=$(randstring 16 0)
369 ${fct_test}
370 done
371
372 stop_lttng_sessiond
This page took 0.055415 seconds and 3 git commands to generate.