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