Fix: keep metadata channel attr in UST session
[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
30
31source $TESTDIR/utils/utils.sh
32
b688191f
CB
33if [ ! -x "$TESTAPP_BIN" ]; then
34 BAIL_OUT "No UST events binary detected."
a788a3ed
DG
35fi
36
37# MUST set TESTDIR before calling those functions
38
39function enable_channel_per_uid()
40{
41 local sess_name=$1
42 local channel_name=$2
43
a055228d 44 $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
45 ok $? "Enable channel $channel_name per UID for session $sess_name"
46}
47
48function enable_channel_per_pid()
49{
50 local sess_name=$1
51 local channel_name=$2
52
a055228d 53 $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
54 ok $? "Enable channel $channel_name per UID for session $sess_name"
55}
56
57function 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
66function 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
75function wait_apps
76{
77 diag "Waiting for applications to end..."
b688191f 78 while [ -n "$(pidof $TESTAPP_NAME)" ]; do
a788a3ed
DG
79 sleep 1
80 done
81}
82
dd770530
DG
83function 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
a788a3ed
DG
101test_after_app_pid() {
102 local out
103
104 diag "Start application AFTER tracing is started"
105
a788a3ed
DG
106 create_lttng_session $SESSION_NAME $TRACE_PATH
107 enable_metadata_per_pid $SESSION_NAME
dd770530 108 enable_channel_per_pid $SESSION_NAME "channel0"
447e8ad9 109 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
a788a3ed
DG
110 start_lttng_tracing $SESSION_NAME
111
a055228d 112 # Start application after tracing
8a251cb8 113 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
a788a3ed
DG
114 ok $? "Start application to trace"
115
dd770530
DG
116 # At least hit one event
117 sleep 2
a055228d
MD
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.
8a251cb8
DG
122 killall -SIGSTOP -q $TESTAPP_NAME
123
124 # Give time to the consumer to write inflight data.
a055228d
MD
125 sleep 2
126
dd770530
DG
127 validate_trace
128 out=$?
129
a788a3ed
DG
130 stop_lttng_tracing $SESSION_NAME
131 destroy_lttng_session $SESSION_NAME
132
8a251cb8
DG
133 killall -SIGKILL -q $TESTAPP_NAME
134 wait_apps
135
dd770530 136 return $out
a788a3ed
DG
137}
138
139test_before_app_pid() {
140 local out
141
142 diag "Start application BEFORE tracing is started"
143
b688191f 144 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
a788a3ed
DG
145 ok $? "Start application to trace"
146
a055228d 147 # Start application before tracing
a788a3ed
DG
148 create_lttng_session $SESSION_NAME $TRACE_PATH
149 enable_metadata_per_pid $SESSION_NAME
dd770530 150 enable_channel_per_pid $SESSION_NAME "channel0"
447e8ad9 151 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
a788a3ed
DG
152 start_lttng_tracing $SESSION_NAME
153
154 # At least hit one event
155 sleep 2
a055228d
MD
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.
8a251cb8
DG
160 killall -SIGSTOP -q $TESTAPP_NAME
161
162 # Give time to the consumer to write inflight data.
a055228d
MD
163 sleep 2
164
dd770530
DG
165 validate_trace
166 out=$?
a788a3ed
DG
167
168 stop_lttng_tracing $SESSION_NAME
169 destroy_lttng_session $SESSION_NAME
170
8a251cb8 171 killall -SIGKILL -q $TESTAPP_NAME
a788a3ed
DG
172 wait_apps
173
174 return $out
175}
176
177test_after_app_uid() {
178 local out
179
180 diag "Start application AFTER tracing is started"
181
a788a3ed
DG
182 create_lttng_session $SESSION_NAME $TRACE_PATH
183 enable_metadata_per_uid $SESSION_NAME
184 enable_channel_per_uid $SESSION_NAME "channel0"
1afc6e74 185 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
a788a3ed
DG
186 start_lttng_tracing $SESSION_NAME
187
a055228d 188 # Start application after tracing
8a251cb8 189 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
a788a3ed
DG
190 ok $? "Start application to trace"
191
dd770530
DG
192 # At least hit one event
193 sleep 2
a055228d
MD
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.
8a251cb8
DG
198 killall -SIGSTOP -q $TESTAPP_NAME
199
200 # Give time to the consumer to write inflight data.
a055228d
MD
201 sleep 2
202
dd770530
DG
203 validate_trace
204 out=$?
205
a788a3ed
DG
206 stop_lttng_tracing $SESSION_NAME
207 destroy_lttng_session $SESSION_NAME
208
8a251cb8
DG
209 killall -SIGKILL -q $TESTAPP_NAME
210 wait_apps
211
dd770530 212 return $out
a788a3ed
DG
213}
214
215test_before_app_uid() {
216 local out
217
218 diag "Start application BEFORE tracing is started"
219
8a251cb8 220 # Start application before tracing
b688191f 221 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
a788a3ed
DG
222 ok $? "Start application to trace"
223
a788a3ed
DG
224 create_lttng_session $SESSION_NAME $TRACE_PATH
225 enable_metadata_per_uid $SESSION_NAME
226 enable_channel_per_uid $SESSION_NAME "channel0"
1afc6e74 227 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
a788a3ed
DG
228 start_lttng_tracing $SESSION_NAME
229
230 # At least hit one event
231 sleep 2
a055228d
MD
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.
8a251cb8
DG
236 killall -SIGSTOP -q $TESTAPP_NAME
237
238 # Give time to the consumer to write inflight data.
a055228d
MD
239 sleep 2
240
dd770530
DG
241 validate_trace
242 out=$?
a788a3ed
DG
243
244 stop_lttng_tracing $SESSION_NAME
245 destroy_lttng_session $SESSION_NAME
246
8a251cb8 247 killall -SIGKILL -q $TESTAPP_NAME
a788a3ed
DG
248 wait_apps
249
250 return $out
251}
252
253# MUST set TESTDIR before calling those functions
254plan_tests $NUM_TESTS
255
256print_test_banner "$TEST_DESC"
257
258TESTS=(
259 "test_before_app_uid"
260 "test_after_app_uid"
261 "test_before_app_pid"
262 "test_after_app_pid"
263)
264
265TEST_COUNT=${#TESTS[@]}
266i=0
267
268start_lttng_sessiond
269
270while [ $i -lt $TEST_COUNT ]; do
271 TRACE_PATH=$(mktemp -d)
272 ${TESTS[$i]}
2345b91f 273 rm -rf $TRACE_PATH
a788a3ed
DG
274 let "i++"
275done
276
277stop_lttng_sessiond
This page took 0.055782 seconds and 4 git commands to generate.