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