94e6fe45f3a85b94f60202aea4e660b8be025d18
[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=59
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 test_after_multiple_apps() {
49 local out
50 local i
51
52 diag "Start multiple applications AFTER tracing is started"
53
54 # BEFORE application is spawned
55 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
56 enable_channel_per_pid $SESSION_NAME "channel0"
57 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
58 start_lttng_tracing_ok $SESSION_NAME
59
60 for i in `seq 1 5`; do
61 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT >/dev/null 2>&1 &
62 ok $? "Start application $i for tracing"
63 done
64 wait
65
66 stop_lttng_tracing_ok $SESSION_NAME
67 destroy_lttng_session_ok $SESSION_NAME
68
69 trace_match_only $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
70
71 return $?
72 }
73
74 test_before_multiple_apps() {
75 local out
76 local i
77 local file_sync_after_first=$(mktemp -u)
78 local file_sync_before_last=$(mktemp -u)
79
80 diag "Start multiple applications BEFORE tracing is started"
81
82 for i in `seq 1 5`; do
83 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first}_${i} ${file_sync_before_last}_${i} >/dev/null 2>&1 &
84 ok $? "Start application $i for tracing"
85 done
86
87 # BEFORE application is spawned
88 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
89 enable_channel_per_pid $SESSION_NAME "channel0"
90 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
91 start_lttng_tracing_ok $SESSION_NAME
92
93 for i in `seq 1 5`; do
94 touch ${file_sync_before_last}_${i}
95 done
96
97 diag "Waiting for applications to end"
98 wait
99 pass "Waiting done"
100
101 stop_lttng_tracing_ok $SESSION_NAME
102 destroy_lttng_session_ok $SESSION_NAME
103
104 for i in `seq 1 5`; do
105 rm -f ${file_sync_after_first}_${i}
106 rm -f ${file_sync_before_last}_${i}
107 done
108
109 out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
110 if [ $out -eq 0 ]; then
111 fail "Trace validation"
112 diag "No event(s) found. We are supposed to have at least one."
113 out=1
114 else
115 pass "Trace validation"
116 diag "Found $out event(s). Coherent."
117 out=0
118 fi
119
120 return $out
121 }
122
123 test_after_app() {
124 local out
125
126 diag "Start application AFTER tracing is started"
127
128 # BEFORE application is spawned
129 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
130 enable_channel_per_pid $SESSION_NAME "channel0"
131 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
132 start_lttng_tracing_ok $SESSION_NAME
133
134 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
135 ok $? "Start application to trace"
136 wait
137
138 stop_lttng_tracing_ok $SESSION_NAME
139 destroy_lttng_session_ok $SESSION_NAME
140
141 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
142
143 return $?
144 }
145
146 test_before_app() {
147 local out
148 local file_sync_after_first=$(mktemp -u)
149 local file_sync_before_last=$(mktemp -u)
150
151 diag "Start application BEFORE tracing is started"
152
153
154 # BEFORE application is spawned
155 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
156 enable_channel_per_pid $SESSION_NAME "channel0"
157 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
158
159 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT ${file_sync_after_first} ${file_sync_before_last} &
160 ok $? "Start application to trace"
161
162 start_lttng_tracing_ok $SESSION_NAME
163
164 touch ${file_sync_before_last}
165
166 wait
167
168 stop_lttng_tracing_ok $SESSION_NAME
169 destroy_lttng_session_ok $SESSION_NAME
170
171 rm -f ${file_sync_after_first}
172 rm -f ${file_sync_before_last}
173
174 out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l)
175 if [ $out -eq 0 ]; then
176 fail "Trace validation"
177 diag "No event(s) found. We are supposed to have at least one."
178 out=1
179 else
180 pass "Trace validation"
181 diag "Found $out event(s). Coherent."
182 out=0
183 fi
184
185 return $out
186 }
187
188 test_multiple_channels() {
189 local out
190
191 diag "Start with multiple channels"
192
193 # BEFORE application is spawned
194 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
195 enable_channel_per_pid $SESSION_NAME "channel0"
196 enable_channel_per_pid $SESSION_NAME "channel1"
197 enable_channel_per_pid $SESSION_NAME "channel2"
198 enable_channel_per_pid $SESSION_NAME "channel3"
199 enable_channel_per_pid $SESSION_NAME "channel4"
200 # Enable event in all channels.
201 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel0 -s $SESSION_NAME -u >/dev/null 2>&1
202 ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel0"
203 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel1 -s $SESSION_NAME -u >/dev/null 2>&1
204 ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel1"
205 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel2 -s $SESSION_NAME -u >/dev/null 2>&1
206 ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel2"
207 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel3 -s $SESSION_NAME -u >/dev/null 2>&1
208 ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel3"
209 $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event $EVENT_NAME -c channel4 -s $SESSION_NAME -u >/dev/null 2>&1
210 ok $? "Enable event $EVENT_NAME for session $SESSION_NAME in channel4"
211 start_lttng_tracing_ok $SESSION_NAME
212
213 $TESTAPP_BIN $NR_ITER $NR_USEC_WAIT &
214 ok $? "Start application to trace"
215 wait
216
217 stop_lttng_tracing_ok $SESSION_NAME
218 trace_match_only $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
219 out=$?
220
221 destroy_lttng_session_ok $SESSION_NAME
222
223 return $out
224 }
225
226 # MUST set TESTDIR before calling those functions
227 plan_tests $NUM_TESTS
228
229 print_test_banner "$TEST_DESC"
230
231 TESTS=(
232 "test_before_app"
233 "test_after_app"
234 "test_after_multiple_apps"
235 "test_before_multiple_apps"
236 "test_multiple_channels"
237 )
238
239 TEST_COUNT=${#TESTS[@]}
240 i=0
241
242 start_lttng_sessiond
243
244 while [ $i -lt $TEST_COUNT ]; do
245 TRACE_PATH=$(mktemp -d)
246 ${TESTS[$i]}
247 rm -rf $TRACE_PATH
248 let "i++"
249 done
250
251 stop_lttng_sessiond
This page took 0.035938 seconds and 4 git commands to generate.