efb9e6690a90fc3721f6e3c59747a91ae6fbeb64
[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 1000000 >/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 1000000 >/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 # BEFORE application is spawned
107 create_lttng_session $SESSION_NAME $TRACE_PATH
108 enable_metadata_per_pid $SESSION_NAME
109 enable_channel_per_pid $SESSION_NAME "channel0"
110 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
111 start_lttng_tracing $SESSION_NAME
112
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 validate_trace
119 out=$?
120
121 stop_lttng_tracing $SESSION_NAME
122 destroy_lttng_session $SESSION_NAME
123
124 return $out
125 }
126
127 test_before_app_pid() {
128 local out
129
130 diag "Start application BEFORE tracing is started"
131
132 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
133 ok $? "Start application to trace"
134
135 # BEFORE application is spawned
136 create_lttng_session $SESSION_NAME $TRACE_PATH
137 enable_metadata_per_pid $SESSION_NAME
138 enable_channel_per_pid $SESSION_NAME "channel0"
139 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME
140 start_lttng_tracing $SESSION_NAME
141
142 # At least hit one event
143 sleep 2
144 validate_trace
145 out=$?
146
147 stop_lttng_tracing $SESSION_NAME
148 destroy_lttng_session $SESSION_NAME
149
150 wait_apps
151
152 return $out
153 }
154
155 test_after_app_uid() {
156 local out
157
158 diag "Start application AFTER tracing is started"
159
160 # BEFORE application is spawned
161 create_lttng_session $SESSION_NAME $TRACE_PATH
162 enable_metadata_per_uid $SESSION_NAME
163 enable_channel_per_uid $SESSION_NAME "channel0"
164 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
165 start_lttng_tracing $SESSION_NAME
166
167 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
168 ok $? "Start application to trace"
169
170 # At least hit one event
171 sleep 2
172 validate_trace
173 out=$?
174
175 stop_lttng_tracing $SESSION_NAME
176 destroy_lttng_session $SESSION_NAME
177
178 return $out
179 }
180
181 test_before_app_uid() {
182 local out
183
184 diag "Start application BEFORE tracing is started"
185
186 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
187 ok $? "Start application to trace"
188
189 # BEFORE application is spawned
190 create_lttng_session $SESSION_NAME $TRACE_PATH
191 enable_metadata_per_uid $SESSION_NAME
192 enable_channel_per_uid $SESSION_NAME "channel0"
193 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
194 start_lttng_tracing $SESSION_NAME
195
196 # At least hit one event
197 sleep 2
198 validate_trace
199 out=$?
200
201 stop_lttng_tracing $SESSION_NAME
202 destroy_lttng_session $SESSION_NAME
203
204 wait_apps
205
206 return $out
207 }
208
209 # MUST set TESTDIR before calling those functions
210 plan_tests $NUM_TESTS
211
212 print_test_banner "$TEST_DESC"
213
214 TESTS=(
215 "test_before_app_uid"
216 "test_after_app_uid"
217 "test_before_app_pid"
218 "test_after_app_pid"
219 )
220
221 TEST_COUNT=${#TESTS[@]}
222 i=0
223
224 start_lttng_sessiond
225
226 while [ $i -lt $TEST_COUNT ]; do
227 TRACE_PATH=$(mktemp -d)
228 ${TESTS[$i]}
229 #rm -rf $TRACE_PATH
230 let "i++"
231 done
232
233 stop_lttng_sessiond
This page took 0.049778 seconds and 3 git commands to generate.