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