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