test: test_periodical_metadata_flush shrink timer period, kill 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 -q $TESTAPP_NAME
123 sleep 2
124
125 validate_trace
126 out=$?
127
128 stop_lttng_tracing $SESSION_NAME
129 destroy_lttng_session $SESSION_NAME
130
131 return $out
132 }
133
134 test_before_app_pid() {
135 local out
136
137 diag "Start application BEFORE tracing is started"
138
139 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
140 ok $? "Start application to trace"
141
142 # Start application before tracing
143 create_lttng_session $SESSION_NAME $TRACE_PATH
144 enable_metadata_per_pid $SESSION_NAME
145 enable_channel_per_pid $SESSION_NAME "channel0"
146 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
147 start_lttng_tracing $SESSION_NAME
148
149 # At least hit one event
150 sleep 2
151
152 # Make sure the application does not generate any more data,
153 # thus ensuring that we are not flushing a packet concurrently
154 # with validate_trace.
155 killall -q $TESTAPP_NAME
156 sleep 2
157
158 validate_trace
159 out=$?
160
161 stop_lttng_tracing $SESSION_NAME
162 destroy_lttng_session $SESSION_NAME
163
164 wait_apps
165
166 return $out
167 }
168
169 test_after_app_uid() {
170 local out
171
172 diag "Start application AFTER tracing is started"
173
174 create_lttng_session $SESSION_NAME $TRACE_PATH
175 enable_metadata_per_uid $SESSION_NAME
176 enable_channel_per_uid $SESSION_NAME "channel0"
177 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
178 start_lttng_tracing $SESSION_NAME
179
180 # Start application after tracing
181 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
182 ok $? "Start application to trace"
183
184 # At least hit one event
185 sleep 2
186
187 # Make sure the application does not generate any more data,
188 # thus ensuring that we are not flushing a packet concurrently
189 # with validate_trace.
190 killall -q $TESTAPP_NAME
191 sleep 2
192
193 validate_trace
194 out=$?
195
196 stop_lttng_tracing $SESSION_NAME
197 destroy_lttng_session $SESSION_NAME
198
199 return $out
200 }
201
202 test_before_app_uid() {
203 local out
204
205 diag "Start application BEFORE tracing is started"
206
207 # Start application after tracing
208 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
209 ok $? "Start application to trace"
210
211 create_lttng_session $SESSION_NAME $TRACE_PATH
212 enable_metadata_per_uid $SESSION_NAME
213 enable_channel_per_uid $SESSION_NAME "channel0"
214 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
215 start_lttng_tracing $SESSION_NAME
216
217 # At least hit one event
218 sleep 2
219
220 # Make sure the application does not generate any more data,
221 # thus ensuring that we are not flushing a packet concurrently
222 # with validate_trace.
223 killall -q $TESTAPP_NAME
224 sleep 2
225
226 validate_trace
227 out=$?
228
229 stop_lttng_tracing $SESSION_NAME
230 destroy_lttng_session $SESSION_NAME
231
232 wait_apps
233
234 return $out
235 }
236
237 # MUST set TESTDIR before calling those functions
238 plan_tests $NUM_TESTS
239
240 print_test_banner "$TEST_DESC"
241
242 TESTS=(
243 "test_before_app_uid"
244 "test_after_app_uid"
245 "test_before_app_pid"
246 "test_after_app_pid"
247 )
248
249 TEST_COUNT=${#TESTS[@]}
250 i=0
251
252 start_lttng_sessiond
253
254 while [ $i -lt $TEST_COUNT ]; do
255 TRACE_PATH=$(mktemp -d)
256 ${TESTS[$i]}
257 #rm -rf $TRACE_PATH
258 let "i++"
259 done
260
261 stop_lttng_sessiond
This page took 0.051317 seconds and 4 git commands to generate.