Fix: correctly close metadata on sessiond thread shutdown
[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
b688191f 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.
122 killall -q $TESTAPP_NAME
123 sleep 2
124
dd770530
DG
125 validate_trace
126 out=$?
127
a788a3ed
DG
128 stop_lttng_tracing $SESSION_NAME
129 destroy_lttng_session $SESSION_NAME
130
dd770530 131 return $out
a788a3ed
DG
132}
133
134test_before_app_pid() {
135 local out
136
137 diag "Start application BEFORE tracing is started"
138
b688191f 139 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
a788a3ed
DG
140 ok $? "Start application to trace"
141
a055228d 142 # Start application before tracing
a788a3ed
DG
143 create_lttng_session $SESSION_NAME $TRACE_PATH
144 enable_metadata_per_pid $SESSION_NAME
dd770530 145 enable_channel_per_pid $SESSION_NAME "channel0"
447e8ad9 146 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
a788a3ed
DG
147 start_lttng_tracing $SESSION_NAME
148
149 # At least hit one event
150 sleep 2
a055228d
MD
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
dd770530
DG
158 validate_trace
159 out=$?
a788a3ed
DG
160
161 stop_lttng_tracing $SESSION_NAME
162 destroy_lttng_session $SESSION_NAME
163
a788a3ed
DG
164 wait_apps
165
166 return $out
167}
168
169test_after_app_uid() {
170 local out
171
172 diag "Start application AFTER tracing is started"
173
a788a3ed
DG
174 create_lttng_session $SESSION_NAME $TRACE_PATH
175 enable_metadata_per_uid $SESSION_NAME
176 enable_channel_per_uid $SESSION_NAME "channel0"
1afc6e74 177 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
a788a3ed
DG
178 start_lttng_tracing $SESSION_NAME
179
a055228d 180 # Start application after tracing
b688191f 181 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
a788a3ed
DG
182 ok $? "Start application to trace"
183
dd770530
DG
184 # At least hit one event
185 sleep 2
a055228d
MD
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
dd770530
DG
193 validate_trace
194 out=$?
195
a788a3ed
DG
196 stop_lttng_tracing $SESSION_NAME
197 destroy_lttng_session $SESSION_NAME
198
dd770530 199 return $out
a788a3ed
DG
200}
201
202test_before_app_uid() {
203 local out
204
205 diag "Start application BEFORE tracing is started"
206
a055228d 207 # Start application after tracing
b688191f 208 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
a788a3ed
DG
209 ok $? "Start application to trace"
210
a788a3ed
DG
211 create_lttng_session $SESSION_NAME $TRACE_PATH
212 enable_metadata_per_uid $SESSION_NAME
213 enable_channel_per_uid $SESSION_NAME "channel0"
1afc6e74 214 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
a788a3ed
DG
215 start_lttng_tracing $SESSION_NAME
216
217 # At least hit one event
218 sleep 2
a055228d
MD
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
dd770530
DG
226 validate_trace
227 out=$?
a788a3ed
DG
228
229 stop_lttng_tracing $SESSION_NAME
230 destroy_lttng_session $SESSION_NAME
231
a788a3ed
DG
232 wait_apps
233
234 return $out
235}
236
237# MUST set TESTDIR before calling those functions
238plan_tests $NUM_TESTS
239
240print_test_banner "$TEST_DESC"
241
242TESTS=(
243 "test_before_app_uid"
244 "test_after_app_uid"
245 "test_before_app_pid"
246 "test_after_app_pid"
247)
248
249TEST_COUNT=${#TESTS[@]}
250i=0
251
252start_lttng_sessiond
253
254while [ $i -lt $TEST_COUNT ]; do
255 TRACE_PATH=$(mktemp -d)
256 ${TESTS[$i]}
2345b91f 257 rm -rf $TRACE_PATH
a788a3ed
DG
258 let "i++"
259done
260
261stop_lttng_sessiond
This page took 0.052129 seconds and 4 git commands to generate.