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