Tests: lttng-ust-getcpu-override-test cache and error-check sysconf()
[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=$(mktemp -u)
31 APPS_PID=
32
33 source $TESTDIR/utils/utils.sh
34
35 if [ ! -x "$TESTAPP_BIN" ]; then
36 BAIL_OUT "No UST events binary detected."
37 fi
38
39 # MUST set TESTDIR before calling those functions
40
41 function enable_channel_per_uid()
42 {
43 local sess_name=$1
44 local channel_name=$2
45
46 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name --switch-timer 100000 >/dev/null 2>&1
47 ok $? "Enable channel $channel_name per UID for session $sess_name"
48 }
49
50 function enable_channel_per_pid()
51 {
52 local sess_name=$1
53 local channel_name=$2
54
55 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name --switch-timer 100000 >/dev/null 2>&1
56 ok $? "Enable channel $channel_name per UID for session $sess_name"
57 }
58
59 function 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
68 function 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
77 function 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
95 function 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
106 function start_trace_app()
107 {
108 # Start application with a temporary file.
109 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT $APP_TMP_FILE &
110 ret=$?
111 APPS_PID="${APPS_PID} ${!}"
112 ok $ret "Start application to trace"
113 }
114
115 function start_check_trace_app()
116 {
117 start_trace_app
118 check_app_tmp_file
119 }
120
121
122 function wait_trace_apps()
123 {
124 for p in ${APPS_PID}; do
125 wait ${p} 2>/dev/null
126 done
127 APPS_PID=
128 }
129
130 test_after_app_pid() {
131 local out
132
133 APPS_PID=
134
135 diag "Start application AFTER tracing is started"
136
137 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
138 enable_metadata_per_pid $SESSION_NAME
139 enable_channel_per_pid $SESSION_NAME "channel0"
140 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
141 start_lttng_tracing_ok $SESSION_NAME
142
143 # Start application after tracing
144 start_check_trace_app
145 # After this point we are sure that at least one event has been hit.
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.
150 for p in ${APPS_PID}; do
151 kill -s SIGSTOP ${p}
152 done
153
154 # Give time to the consumer to write inflight data.
155 sleep 2
156
157 validate_trace
158 out=$?
159
160 for p in ${APPS_PID}; do
161 kill -s SIGKILL ${p}
162 wait ${p} 2>/dev/null
163 done
164 stop_lttng_tracing_ok $SESSION_NAME
165 destroy_lttng_session_ok $SESSION_NAME
166
167 wait_trace_apps
168
169 return $out
170 }
171
172 test_before_app_pid() {
173 local out
174 local tmp_file="/tmp/lttng_test_ust.42.file"
175
176 APPS_PID=
177
178 diag "Start application BEFORE tracing is started"
179
180 start_trace_app
181
182 # Start application before tracing
183 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
184 enable_metadata_per_pid $SESSION_NAME
185 enable_channel_per_pid $SESSION_NAME "channel0"
186 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
187 start_lttng_tracing_ok $SESSION_NAME
188
189 check_app_tmp_file
190 # Let the application at least perform a flush!
191 sleep 2
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.
196 for p in ${APPS_PID}; do
197 kill -s SIGSTOP ${p}
198 done
199
200 # Give time to the consumer to write inflight data.
201 sleep 2
202
203 validate_trace
204 out=$?
205
206 for p in ${APPS_PID}; do
207 kill -s SIGKILL ${p}
208 wait ${p} 2>/dev/null
209 done
210
211 stop_lttng_tracing_ok $SESSION_NAME
212 destroy_lttng_session_ok $SESSION_NAME
213
214 wait_trace_apps
215
216 return $out
217 }
218
219 test_after_app_uid() {
220 local out
221
222 APPS_PID=
223
224 diag "Start application AFTER tracing is started"
225
226 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
227 enable_metadata_per_uid $SESSION_NAME
228 enable_channel_per_uid $SESSION_NAME "channel0"
229 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
230 start_lttng_tracing_ok $SESSION_NAME
231
232 # Start application after tracing
233 start_check_trace_app
234 # After this point we are sure that at least one event has been hit.
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.
239 for p in ${APPS_PID}; do
240 kill -s SIGSTOP ${p}
241 done
242
243
244 # Give time to the consumer to write inflight data.
245 sleep 2
246
247 validate_trace
248 out=$?
249
250 for p in ${APPS_PID}; do
251 kill -s SIGKILL ${p}
252 wait ${p} 2>/dev/null
253 done
254 stop_lttng_tracing_ok $SESSION_NAME
255 destroy_lttng_session_ok $SESSION_NAME
256
257 wait_trace_apps
258
259 return $out
260 }
261
262 test_before_app_uid() {
263 local out
264
265 APPS_PID=
266
267 diag "Start application BEFORE tracing is started"
268
269 # Start application before tracing
270 start_trace_app
271
272 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
273 enable_metadata_per_uid $SESSION_NAME
274 enable_channel_per_uid $SESSION_NAME "channel0"
275 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
276 start_lttng_tracing_ok $SESSION_NAME
277
278 check_app_tmp_file
279 # Let the application at least perform a flush!
280 sleep 2
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.
285 for p in ${APPS_PID}; do
286 kill -s SIGSTOP ${p}
287 done
288
289 # Give time to the consumer to write inflight data.
290 sleep 2
291
292 validate_trace
293 out=$?
294
295 for p in ${APPS_PID}; do
296 kill -s SIGKILL ${p}
297 wait ${p} 2>/dev/null
298 done
299 stop_lttng_tracing_ok $SESSION_NAME
300 destroy_lttng_session_ok $SESSION_NAME
301
302 wait_trace_apps
303
304 return $out
305 }
306
307 # MUST set TESTDIR before calling those functions
308 plan_tests $NUM_TESTS
309
310 print_test_banner "$TEST_DESC"
311
312 TESTS=(
313 "test_before_app_uid"
314 "test_after_app_uid"
315 "test_before_app_pid"
316 "test_after_app_pid"
317 )
318
319 TEST_COUNT=${#TESTS[@]}
320 i=0
321
322 start_lttng_sessiond
323
324 while [ $i -lt $TEST_COUNT ]; do
325 TRACE_PATH=$(mktemp -d)
326 ${TESTS[$i]}
327 rm -rf $TRACE_PATH
328 let "i++"
329 done
330
331 stop_lttng_sessiond
This page took 0.059071 seconds and 4 git commands to generate.