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