Gen-ust-events: use options instead of arguments
[lttng-tools.git] / tests / regression / ust / periodical-metadata-flush / test_periodical_metadata_flush
CommitLineData
a788a3ed
DG
1#!/bin/bash
2#
3# Copyright (C) - 2012 David Goulet <dgoulet@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="UST tracer - Tracing with per UID buffers and periodical flush"
18
19CURDIR=$(dirname $0)/
20TESTDIR=$CURDIR/../../..
21NR_ITER=100
b688191f
CB
22NR_USEC_WAIT=100000
23TESTAPP_PATH="$TESTDIR/utils/testapp"
24TESTAPP_NAME="gen-ust-events"
25TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
a788a3ed 26SESSION_NAME="periodical-flush"
b688191f 27EVENT_NAME="tp:tptest"
a788a3ed
DG
28BIN_NAME="gen-nevents"
29NUM_TESTS=38
5fcaccbc 30APP_TMP_FILE=$(mktemp -u)
c7613334 31APPS_PID=
a788a3ed
DG
32
33source $TESTDIR/utils/utils.sh
34
b688191f
CB
35if [ ! -x "$TESTAPP_BIN" ]; then
36 BAIL_OUT "No UST events binary detected."
a788a3ed
DG
37fi
38
39# MUST set TESTDIR before calling those functions
40
41function enable_channel_per_uid()
42{
43 local sess_name=$1
44 local channel_name=$2
45
a055228d 46 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --switch-timer 100000 >/dev/null 2>&1
dd770530
DG
47 ok $? "Enable channel $channel_name per UID for session $sess_name"
48}
49
50function enable_channel_per_pid()
51{
52 local sess_name=$1
53 local channel_name=$2
54
a055228d 55 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name --switch-timer 100000 >/dev/null 2>&1
a788a3ed
DG
56 ok $? "Enable channel $channel_name per UID for session $sess_name"
57}
58
59function enable_metadata_per_uid()
60{
61 local sess_name=$1
62 local channel_name="metadata"
63
64 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --switch-timer 200000 >/dev/null 2>&1
65 ok $? "Enable channel $channel_name per UID for session $sess_name"
66}
67
68function enable_metadata_per_pid()
69{
70 local sess_name=$1
71 local channel_name="metadata"
72
73 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name --switch-timer 200000 >/dev/null 2>&1
74 ok $? "Enable channel $channel_name per PID for session $sess_name"
75}
76
dd770530
DG
77function validate_trace()
78{
79 local out
80
81 out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
82 if [ $out -eq 0 ]; then
83 fail "Trace validation"
84 diag "No event(s) found. We are supposed to have at least one."
85 out=1
86 else
87 pass "Trace validation"
88 diag "Found $out event(s). Coherent."
89 out=0
90 fi
91
92 return $out
93}
94
8c93562f
DG
95function check_app_tmp_file()
96{
97 # Wait for the application file to appear indicating that at least one
98 # tracepoint has been fired.
99 while [ ! -f "$APP_TMP_FILE" ]; do
100 sleep 0.5
101 done
102 diag "Removing test app temporary file $APP_TMP_FILE"
103 rm -f $APP_TMP_FILE
104}
105
106function start_trace_app()
107{
108 # Start application with a temporary file.
a4c30524 109 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT --sync-after-first-event $APP_TMP_FILE &
c7613334
MD
110 ret=$?
111 APPS_PID="${APPS_PID} ${!}"
112 ok $ret "Start application to trace"
8c93562f
DG
113}
114
115function start_check_trace_app()
116{
117 start_trace_app
118 check_app_tmp_file
119}
120
c7613334
MD
121
122function wait_trace_apps()
123{
124 for p in ${APPS_PID}; do
125 wait ${p} 2>/dev/null
126 done
127 APPS_PID=
128}
129
a788a3ed
DG
130test_after_app_pid() {
131 local out
132
c7613334
MD
133 APPS_PID=
134
a788a3ed
DG
135 diag "Start application AFTER tracing is started"
136
bf6ae429 137 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
a788a3ed 138 enable_metadata_per_pid $SESSION_NAME
dd770530 139 enable_channel_per_pid $SESSION_NAME "channel0"
c4926bb5 140 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
e563bbdb 141 start_lttng_tracing_ok $SESSION_NAME
a788a3ed 142
a055228d 143 # Start application after tracing
8c93562f
DG
144 start_check_trace_app
145 # After this point we are sure that at least one event has been hit.
a055228d
MD
146
147 # Make sure the application does not generate any more data,
148 # thus ensuring that we are not flushing a packet concurrently
149 # with validate_trace.
c7613334
MD
150 for p in ${APPS_PID}; do
151 kill -s SIGSTOP ${p}
152 done
8a251cb8
DG
153
154 # Give time to the consumer to write inflight data.
a055228d
MD
155 sleep 2
156
dd770530
DG
157 validate_trace
158 out=$?
159
c7613334
MD
160 for p in ${APPS_PID}; do
161 kill -s SIGKILL ${p}
162 wait ${p} 2>/dev/null
163 done
96340a01 164 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 165 destroy_lttng_session_ok $SESSION_NAME
a788a3ed 166
c7613334 167 wait_trace_apps
8a251cb8 168
dd770530 169 return $out
a788a3ed
DG
170}
171
172test_before_app_pid() {
173 local out
8c93562f 174 local tmp_file="/tmp/lttng_test_ust.42.file"
a788a3ed 175
c7613334
MD
176 APPS_PID=
177
a788a3ed
DG
178 diag "Start application BEFORE tracing is started"
179
8c93562f 180 start_trace_app
a788a3ed 181
a055228d 182 # Start application before tracing
bf6ae429 183 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
a788a3ed 184 enable_metadata_per_pid $SESSION_NAME
dd770530 185 enable_channel_per_pid $SESSION_NAME "channel0"
c4926bb5 186 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
e563bbdb 187 start_lttng_tracing_ok $SESSION_NAME
a788a3ed 188
8c93562f
DG
189 check_app_tmp_file
190 # Let the application at least perform a flush!
a788a3ed 191 sleep 2
a055228d
MD
192
193 # Make sure the application does not generate any more data,
194 # thus ensuring that we are not flushing a packet concurrently
195 # with validate_trace.
c7613334
MD
196 for p in ${APPS_PID}; do
197 kill -s SIGSTOP ${p}
198 done
8a251cb8
DG
199
200 # Give time to the consumer to write inflight data.
a055228d
MD
201 sleep 2
202
dd770530
DG
203 validate_trace
204 out=$?
a788a3ed 205
c7613334
MD
206 for p in ${APPS_PID}; do
207 kill -s SIGKILL ${p}
208 wait ${p} 2>/dev/null
209 done
210
96340a01 211 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 212 destroy_lttng_session_ok $SESSION_NAME
a788a3ed 213
c7613334 214 wait_trace_apps
a788a3ed
DG
215
216 return $out
217}
218
219test_after_app_uid() {
220 local out
221
c7613334
MD
222 APPS_PID=
223
a788a3ed
DG
224 diag "Start application AFTER tracing is started"
225
bf6ae429 226 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
a788a3ed
DG
227 enable_metadata_per_uid $SESSION_NAME
228 enable_channel_per_uid $SESSION_NAME "channel0"
c4926bb5 229 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
e563bbdb 230 start_lttng_tracing_ok $SESSION_NAME
a788a3ed 231
a055228d 232 # Start application after tracing
8c93562f
DG
233 start_check_trace_app
234 # After this point we are sure that at least one event has been hit.
a055228d
MD
235
236 # Make sure the application does not generate any more data,
237 # thus ensuring that we are not flushing a packet concurrently
238 # with validate_trace.
c7613334
MD
239 for p in ${APPS_PID}; do
240 kill -s SIGSTOP ${p}
241 done
242
8a251cb8
DG
243
244 # Give time to the consumer to write inflight data.
a055228d
MD
245 sleep 2
246
dd770530
DG
247 validate_trace
248 out=$?
249
c7613334
MD
250 for p in ${APPS_PID}; do
251 kill -s SIGKILL ${p}
252 wait ${p} 2>/dev/null
253 done
96340a01 254 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 255 destroy_lttng_session_ok $SESSION_NAME
a788a3ed 256
c7613334 257 wait_trace_apps
8a251cb8 258
dd770530 259 return $out
a788a3ed
DG
260}
261
262test_before_app_uid() {
263 local out
264
c7613334
MD
265 APPS_PID=
266
a788a3ed
DG
267 diag "Start application BEFORE tracing is started"
268
8a251cb8 269 # Start application before tracing
8c93562f 270 start_trace_app
a788a3ed 271
bf6ae429 272 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
a788a3ed
DG
273 enable_metadata_per_uid $SESSION_NAME
274 enable_channel_per_uid $SESSION_NAME "channel0"
c4926bb5 275 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
e563bbdb 276 start_lttng_tracing_ok $SESSION_NAME
a788a3ed 277
8c93562f
DG
278 check_app_tmp_file
279 # Let the application at least perform a flush!
a788a3ed 280 sleep 2
a055228d
MD
281
282 # Make sure the application does not generate any more data,
283 # thus ensuring that we are not flushing a packet concurrently
284 # with validate_trace.
c7613334
MD
285 for p in ${APPS_PID}; do
286 kill -s SIGSTOP ${p}
287 done
8a251cb8
DG
288
289 # Give time to the consumer to write inflight data.
a055228d
MD
290 sleep 2
291
dd770530
DG
292 validate_trace
293 out=$?
a788a3ed 294
c7613334
MD
295 for p in ${APPS_PID}; do
296 kill -s SIGKILL ${p}
297 wait ${p} 2>/dev/null
298 done
96340a01 299 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 300 destroy_lttng_session_ok $SESSION_NAME
a788a3ed 301
c7613334 302 wait_trace_apps
a788a3ed
DG
303
304 return $out
305}
306
307# MUST set TESTDIR before calling those functions
308plan_tests $NUM_TESTS
309
310print_test_banner "$TEST_DESC"
311
312TESTS=(
313 "test_before_app_uid"
314 "test_after_app_uid"
315 "test_before_app_pid"
316 "test_after_app_pid"
317)
318
319TEST_COUNT=${#TESTS[@]}
320i=0
321
322start_lttng_sessiond
323
324while [ $i -lt $TEST_COUNT ]; do
325 TRACE_PATH=$(mktemp -d)
326 ${TESTS[$i]}
2345b91f 327 rm -rf $TRACE_PATH
a788a3ed
DG
328 let "i++"
329done
330
331stop_lttng_sessiond
This page took 0.096702 seconds and 5 git commands to generate.