Tests: change buffers UID test to PID
[lttng-tools.git] / tests / regression / ust / buffers-pid / test_buffers_pid
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 PID buffers"
18
19 CURDIR=$(dirname $0)/
20 TESTDIR=$CURDIR/../../..
21 NR_ITER=100
22 NR_USEC_WAIT=100000
23 SESSION_NAME="buffers-pid"
24
25 TESTAPP_PATH="$TESTDIR/utils/testapp"
26 TESTAPP_NAME="gen-ust-events"
27 TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
28 EVENT_NAME="tp:tptest"
29 NUM_TESTS=58
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_pid()
40 {
41 sess_name=$1
42 channel_name=$2
43
44 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-pid -u $channel_name -s $sess_name >/dev/null 2>&1
45 ok $? "Enable channel $channel_name per PID for session $sess_name"
46 }
47
48 function wait_apps
49 {
50 diag "Waiting for applications to end..."
51 while [ -n "$(pidof $TESTAPP_NAME)" ]; do
52 sleep 1
53 done
54 }
55
56 test_after_multiple_apps() {
57 local out
58 local i
59
60 diag "Start multiple applications AFTER tracing is started"
61
62 # BEFORE application is spawned
63 create_lttng_session $SESSION_NAME $TRACE_PATH
64 enable_channel_per_pid $SESSION_NAME "channel0"
65 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
66 start_lttng_tracing $SESSION_NAME
67
68 for i in `seq 1 5`; do
69 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT & >/dev/null 2>&1
70 ok $? "Start application $i for tracing"
71 done
72 wait_apps
73
74 stop_lttng_tracing $SESSION_NAME
75 destroy_lttng_session $SESSION_NAME
76
77 trace_matches $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
78
79 return $?
80 }
81
82 test_before_multiple_apps() {
83 local out
84 local i
85
86 diag "Start multiple applications BEFORE tracing is started"
87
88 for i in `seq 1 5`; do
89 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT & >/dev/null 2>&1
90 ok $? "Start application $i for tracing"
91 done
92
93 # BEFORE application is spawned
94 create_lttng_session $SESSION_NAME $TRACE_PATH
95 enable_channel_per_pid $SESSION_NAME "channel0"
96 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
97 start_lttng_tracing $SESSION_NAME
98
99 # At least hit one event
100 sleep 2
101
102 stop_lttng_tracing $SESSION_NAME
103 destroy_lttng_session $SESSION_NAME
104
105 out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
106 if [ $out -eq 0 ]; then
107 fail "Trace validation"
108 diag "No event(s) found. We are supposed to have at least one."
109 out=1
110 else
111 pass "Trace validation"
112 diag "Found $out event(s). Coherent."
113 out=0
114 fi
115
116 wait_apps
117
118 return $out
119 }
120
121 test_after_app() {
122 local out
123
124 diag "Start application AFTER tracing is started"
125
126 # BEFORE application is spawned
127 create_lttng_session $SESSION_NAME $TRACE_PATH
128 enable_channel_per_pid $SESSION_NAME "channel0"
129 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
130 start_lttng_tracing $SESSION_NAME
131
132 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
133 ok $? "Start application to trace"
134
135 stop_lttng_tracing $SESSION_NAME
136 destroy_lttng_session $SESSION_NAME
137
138 trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH
139
140 return $?
141 }
142
143 test_before_app() {
144 local out
145
146 diag "Start application BEFORE tracing is started"
147
148 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
149 ok $? "Start application to trace"
150
151 # BEFORE application is spawned
152 create_lttng_session $SESSION_NAME $TRACE_PATH
153 enable_channel_per_pid $SESSION_NAME "channel0"
154 enable_ust_lttng_event $SESSION_NAME $EVENT_NAME "channel0"
155 start_lttng_tracing $SESSION_NAME
156
157 # At least hit one event
158 sleep 2
159
160 stop_lttng_tracing $SESSION_NAME
161 destroy_lttng_session $SESSION_NAME
162
163 out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
164 if [ $out -eq 0 ]; then
165 fail "Trace validation"
166 diag "No event(s) found. We are supposed to have at least one."
167 out=1
168 else
169 pass "Trace validation"
170 diag "Found $out event(s). Coherent."
171 out=0
172 fi
173
174 wait_apps
175
176 return $out
177 }
178
179 test_multiple_channels() {
180 local out
181
182 diag "Start with multiple channels"
183
184 # BEFORE application is spawned
185 create_lttng_session $SESSION_NAME $TRACE_PATH
186 enable_channel_per_pid $SESSION_NAME "channel0"
187 enable_channel_per_pid $SESSION_NAME "channel1"
188 enable_channel_per_pid $SESSION_NAME "channel2"
189 enable_channel_per_pid $SESSION_NAME "channel3"
190 enable_channel_per_pid $SESSION_NAME "channel4"
191 # Enable event in all channels.
192 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel0 -s $SESSION_NAME -u >/dev/null 2>&1
193 ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel0"
194 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel1 -s $SESSION_NAME -u >/dev/null 2>&1
195 ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel1"
196 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel2 -s $SESSION_NAME -u >/dev/null 2>&1
197 ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel2"
198 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel3 -s $SESSION_NAME -u >/dev/null 2>&1
199 ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel3"
200 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel4 -s $SESSION_NAME -u >/dev/null 2>&1
201 ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel4"
202 start_lttng_tracing $SESSION_NAME
203
204 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT
205 ok $? "Start application to trace"
206
207 stop_lttng_tracing $SESSION_NAME
208 trace_matches $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
209 out=$?
210
211 destroy_lttng_session $SESSION_NAME
212
213 return $out
214 }
215
216 # MUST set TESTDIR before calling those functions
217 plan_tests $NUM_TESTS
218
219 print_test_banner "$TEST_DESC"
220
221 TESTS=(
222 "test_before_app"
223 "test_after_app"
224 "test_after_multiple_apps"
225 "test_before_multiple_apps"
226 "test_multiple_channels"
227 )
228
229 TEST_COUNT=${#TESTS[@]}
230 i=0
231
232 start_lttng_sessiond
233
234 while [ $i -lt $TEST_COUNT ]; do
235 TRACE_PATH=$(mktemp -d)
236 ${TESTS[$i]}
237 rm -rf $TRACE_PATH
238 let "i++"
239 done
240
241 stop_lttng_sessiond
This page took 0.050704 seconds and 4 git commands to generate.