Fix: tests: don't use pidof to wait for test apps
[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
5dca3876 66function stop_test_app()
209b934f
DG
67{
68 diag "Killing $TESTAPP_NAME"
69 PID_APP=`pidof $TESTAPP_NAME`
70 kill $PID_APP >/dev/null 2>&1
5dca3876
MD
71 diag "Waiting on $TESTAPP_NAME"
72 wait
209b934f
DG
73}
74
5e83c405
CB
75function 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
97function 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
108function 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
122function 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
ebaaaf5e
JD
152function 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
209b934f
DG
160
161 # Returns once the application has at least fired ONE tracepoint.
162 start_test_app
163
ebaaaf5e
JD
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
209b934f 176
5dca3876 177 stop_test_app
ebaaaf5e
JD
178}
179
5e83c405
CB
180function 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
209b934f
DG
198 # Returns once the application has at least fired ONE tracepoint.
199 start_test_app
5e83c405
CB
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
5dca3876 225 stop_test_app
5e83c405
CB
226}
227
a54047ec
JD
228function 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
5f4c2d80
JD
257function 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
266function 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
209b934f
DG
274
275 # Returns once the application has at least fired ONE tracepoint.
276 start_test_app
277
5f4c2d80
JD
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
209b934f 290
5dca3876 291 stop_test_app
5f4c2d80
JD
292}
293
4f03c06d
JD
294function 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
209b934f
DG
302
303 # Returns once the application has at least fired ONE tracepoint.
304 start_test_app
5dca3876 305 stop_test_app
209b934f 306
4f03c06d
JD
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
1d20c959 321function test_ust_local_snapshots ()
ebaaaf5e 322{
1d20c959 323 diag "Test $NR_SNAPSHOT local UST snapshots"
ebaaaf5e
JD
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
209b934f
DG
329
330 # Returns once the application has at least fired ONE tracepoint.
331 start_test_app
332
1d20c959
DG
333 for i in $(seq 1 $NR_SNAPSHOT); do
334 diag "Snapshot $i/$NR_SNAPSHOT"
ebaaaf5e
JD
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
209b934f 348
5dca3876 349 stop_test_app
ebaaaf5e
JD
350}
351
352plan_tests $NUM_TESTS
353
354print_test_banner "$TEST_DESC"
355
ebaaaf5e
JD
356start_lttng_sessiond
357
5e83c405
CB
358tests=( 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
1d20c959 364 test_ust_local_snapshots)
ebaaaf5e
JD
365
366for fct_test in ${tests[@]};
367do
368 SESSION_NAME=$(randstring 16 0)
369 ${fct_test}
ebaaaf5e
JD
370done
371
372stop_lttng_sessiond
This page took 0.042434 seconds and 4 git commands to generate.