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 fi
177
178 stop_test_apps
179 }
180
181 function test_ust_local_snapshot_max_size ()
182 {
183 subbuf_size=8192
184 num_cpus=`nproc`
185
186 # The minimum size limit is min(subbuf_size) * nb_streams
187 max_size=$(($subbuf_size*$num_cpus))
188
189 diag "Test local UST snapshots with max size $max_size"
190 create_lttng_session_no_output $SESSION_NAME
191
192 enable_mmap_overwrite_subbuf_ust_channel $SESSION_NAME $CHANNEL_NAME $subbuf_size
193
194 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
195 start_lttng_tracing $SESSION_NAME
196
197 snapshot_add_output $SESSION_NAME "file://$TRACE_PATH" "" $max_size
198
199 # Returns once the application has at least fired ONE tracepoint.
200 start_test_app
201
202 lttng_snapshot_record $SESSION_NAME
203
204 # Check file size
205 sum_size_tracefiles=$(find $TRACE_PATH -name "${CHANNEL_NAME}_*" \
206 -exec stat -c '%s' {} \; | awk '{s = s + $1}END{print s}')
207
208 if [ "$sum_size_tracefiles" -gt "$max_size" ]; then
209 fail "Tracefiles size sum validation"
210 diag "Tracefiles size sum: $sum_size_tracefiles Expected max: $max_size"
211 fi
212
213 pass "Tracefiles size sum validation"
214
215 stop_lttng_tracing $SESSION_NAME
216 destroy_lttng_session $SESSION_NAME
217
218 # Validate test
219 validate_trace $EVENT_NAME $TRACE_PATH/
220
221 if [ $? -eq 0 ]; then
222 # Only delete if successful
223 rm -rf $TRACE_PATH
224 fi
225
226 stop_test_apps
227 }
228
229 function test_ust_local_snapshot_large_metadata ()
230 {
231 LM_EVENT="tp:tptest1,tp:tptest2,tp:tptest3,tp:tptest4,tp:tptest5"
232 LM_PATH="$TESTDIR/utils/testapp"
233 LM_NAME="gen-ust-nevents"
234 LM_BIN="$LM_PATH/$LM_NAME/$LM_NAME"
235
236 diag "Test local UST snapshots with > 4kB metadata"
237 create_lttng_session_no_output $SESSION_NAME
238 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
239 enable_ust_lttng_event $SESSION_NAME $LM_EVENT $CHANNEL_NAME
240 start_lttng_tracing $SESSION_NAME
241 lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
242 $LM_BIN 1 1
243 ok $? "Start application to trace"
244 lttng_snapshot_record $SESSION_NAME
245 stop_lttng_tracing $SESSION_NAME
246 destroy_lttng_session $SESSION_NAME
247
248 # Validate test
249 validate_trace $LM_EVENT $TRACE_PATH/
250 if [ $? -eq 0 ]; then
251 # Only delete if successful
252 rm -rf $TRACE_PATH
253 fi
254 }
255
256 function enable_channel_per_uid_mmap_overwrite()
257 {
258 sess_name=$1
259 channel_name=$2
260
261 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --output mmap --overwrite >/dev/null 2>&1
262 ok $? "Enable channel $channel_name per UID for session $sess_name"
263 }
264
265 function test_ust_per_uid_local_snapshot ()
266 {
267 diag "Test local UST snapshots"
268 create_lttng_session_no_output $SESSION_NAME
269 enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME
270 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
271 start_lttng_tracing $SESSION_NAME
272 lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
273
274 # Returns once the application has at least fired ONE tracepoint.
275 start_test_app
276
277 lttng_snapshot_record $SESSION_NAME
278 stop_lttng_tracing $SESSION_NAME
279 destroy_lttng_session $SESSION_NAME
280
281 # Validate test
282 validate_trace $EVENT_NAME $TRACE_PATH/
283 if [ $? -eq 0 ]; then
284 # Only delete if successful
285 rm -rf $TRACE_PATH
286 fi
287
288 stop_test_apps
289 }
290
291 function test_ust_per_uid_local_snapshot_post_mortem ()
292 {
293 diag "Test local UST snapshots post-mortem"
294 create_lttng_session_no_output $SESSION_NAME
295 enable_channel_per_uid_mmap_overwrite $SESSION_NAME $CHANNEL_NAME
296 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
297 start_lttng_tracing $SESSION_NAME
298 lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
299
300 # Returns once the application has at least fired ONE tracepoint.
301 start_test_app
302 stop_test_apps
303
304 lttng_snapshot_record $SESSION_NAME
305 stop_lttng_tracing $SESSION_NAME
306 destroy_lttng_session $SESSION_NAME
307
308 # Validate test
309 validate_trace $EVENT_NAME $TRACE_PATH/
310 if [ $? -eq 0 ]; then
311 # Only delete if successful
312 rm -rf $TRACE_PATH
313 fi
314 }
315
316 function test_ust_local_snapshots ()
317 {
318 diag "Test $NR_SNAPSHOT local UST snapshots"
319 create_lttng_session_no_output $SESSION_NAME
320 enable_lttng_mmap_overwrite_ust_channel $SESSION_NAME $CHANNEL_NAME
321 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME $CHANNEL_NAME
322 start_lttng_tracing $SESSION_NAME
323 lttng_snapshot_add_output $SESSION_NAME $TRACE_PATH
324
325 # Returns once the application has at least fired ONE tracepoint.
326 start_test_app
327
328 for i in $(seq 1 $NR_SNAPSHOT); do
329 diag "Snapshot $i/$NR_SNAPSHOT"
330 rm -rf $TRACE_PATH/snapshot/* 2>/dev/null
331 lttng_snapshot_record $SESSION_NAME
332 # Validate test
333 validate_trace $EVENT_NAME $TRACE_PATH/
334 if [ $? -eq 0 ]; then
335 # Only delete if successful
336 rm -rf $TRACE_PATH
337 fi
338 done
339 stop_lttng_tracing $SESSION_NAME
340 destroy_lttng_session $SESSION_NAME
341
342 stop_test_apps
343 }
344
345 plan_tests $NUM_TESTS
346
347 print_test_banner "$TEST_DESC"
348
349 start_lttng_sessiond
350
351 tests=( test_ust_list_output
352 test_ust_local_snapshot
353 test_ust_local_snapshot_max_size
354 test_ust_per_uid_local_snapshot
355 test_ust_per_uid_local_snapshot_post_mortem
356 test_ust_local_snapshot_large_metadata
357 test_ust_local_snapshots)
358
359 for fct_test in ${tests[@]};
360 do
361 SESSION_NAME=$(randstring 16 0)
362 ${fct_test}
363 done
364
365 stop_lttng_sessiond
This page took 0.036569 seconds and 4 git commands to generate.