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