Gen-ust-events: use options instead of arguments
[lttng-tools.git] / tests / regression / ust / buffers-pid / test_buffers_pid
CommitLineData
7972aab2
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
f5481aa9 17TEST_DESC="UST tracer - Tracing with per PID buffers"
7972aab2
DG
18
19CURDIR=$(dirname $0)/
20TESTDIR=$CURDIR/../../..
21NR_ITER=100
b6a8c35e 22NR_USEC_WAIT=100000
f5481aa9 23SESSION_NAME="buffers-pid"
b6a8c35e
CB
24
25TESTAPP_PATH="$TESTDIR/utils/testapp"
26TESTAPP_NAME="gen-ust-events"
27TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
28EVENT_NAME="tp:tptest"
5dca3876 29NUM_TESTS=59
7972aab2
DG
30
31source $TESTDIR/utils/utils.sh
32
b6a8c35e
CB
33if [ ! -x "$TESTAPP_BIN" ]; then
34 BAIL_OUT "No UST events binary detected."
7972aab2
DG
35fi
36
37# MUST set TESTDIR before calling those functions
38
f5481aa9 39function enable_channel_per_pid()
7972aab2
DG
40{
41 sess_name=$1
42 channel_name=$2
43
f5481aa9
DG
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"
7972aab2
DG
46}
47
7972aab2
DG
48test_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
bf6ae429 55 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
f5481aa9 56 enable_channel_per_pid $SESSION_NAME "channel0"
c4926bb5 57 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
e563bbdb 58 start_lttng_tracing_ok $SESSION_NAME
7972aab2
DG
59
60 for i in `seq 1 5`; do
a4c30524 61 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT >/dev/null 2>&1 &
7972aab2
DG
62 ok $? "Start application $i for tracing"
63 done
c7613334 64 wait
7972aab2 65
96340a01 66 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 67 destroy_lttng_session_ok $SESSION_NAME
7972aab2 68
d53addeb 69 trace_match_only $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
7972aab2
DG
70
71 return $?
72}
73
74test_before_multiple_apps() {
75 local out
76 local i
5fcaccbc
MD
77 local file_sync_after_first=$(mktemp -u)
78 local file_sync_before_last=$(mktemp -u)
7972aab2
DG
79
80 diag "Start multiple applications BEFORE tracing is started"
81
82 for i in `seq 1 5`; do
a4c30524
JR
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 &
7972aab2
DG
86 ok $? "Start application $i for tracing"
87 done
88
89 # BEFORE application is spawned
bf6ae429 90 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
f5481aa9 91 enable_channel_per_pid $SESSION_NAME "channel0"
c4926bb5 92 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
e563bbdb 93 start_lttng_tracing_ok $SESSION_NAME
7972aab2 94
5fcaccbc
MD
95 for i in `seq 1 5`; do
96 touch ${file_sync_before_last}_${i}
97 done
98
5dca3876
MD
99 diag "Waiting for applications to end"
100 wait
101 pass "Waiting done"
7972aab2 102
96340a01 103 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 104 destroy_lttng_session_ok $SESSION_NAME
7972aab2 105
5fcaccbc
MD
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
7972aab2
DG
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
7972aab2
DG
122 return $out
123}
124
125test_after_app() {
126 local out
127
128 diag "Start application AFTER tracing is started"
129
130 # BEFORE application is spawned
bf6ae429 131 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
f5481aa9 132 enable_channel_per_pid $SESSION_NAME "channel0"
c4926bb5 133 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
e563bbdb 134 start_lttng_tracing_ok $SESSION_NAME
7972aab2 135
a4c30524 136 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
7972aab2 137 ok $? "Start application to trace"
c7613334 138 wait
7972aab2 139
96340a01 140 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 141 destroy_lttng_session_ok $SESSION_NAME
7972aab2 142
d53addeb 143 trace_match_only $EVENT_NAME $NR_ITER $TRACE_PATH
7972aab2
DG
144
145 return $?
146}
147
148test_before_app() {
149 local out
5fcaccbc
MD
150 local file_sync_after_first=$(mktemp -u)
151 local file_sync_before_last=$(mktemp -u)
7972aab2
DG
152
153 diag "Start application BEFORE tracing is started"
154
7972aab2
DG
155
156 # BEFORE application is spawned
bf6ae429 157 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
f5481aa9 158 enable_channel_per_pid $SESSION_NAME "channel0"
c4926bb5 159 enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME "channel0"
f8ccb5c8 160
a4c30524
JR
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} &
f8ccb5c8
CB
164 ok $? "Start application to trace"
165
e563bbdb 166 start_lttng_tracing_ok $SESSION_NAME
7972aab2 167
5fcaccbc
MD
168 touch ${file_sync_before_last}
169
c7613334 170 wait
7972aab2 171
96340a01 172 stop_lttng_tracing_ok $SESSION_NAME
67b4c664 173 destroy_lttng_session_ok $SESSION_NAME
7972aab2 174
5fcaccbc
MD
175 rm -f ${file_sync_after_first}
176 rm -f ${file_sync_before_last}
177
7972aab2
DG
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
7972aab2
DG
189 return $out
190}
191
192test_multiple_channels() {
193 local out
194
195 diag "Start with multiple channels"
196
197 # BEFORE application is spawned
bf6ae429 198 create_lttng_session_ok $SESSION_NAME $TRACE_PATH
f5481aa9
DG
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"
7972aab2
DG
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"
e563bbdb 215 start_lttng_tracing_ok $SESSION_NAME
7972aab2 216
a4c30524 217 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT &
7972aab2 218 ok $? "Start application to trace"
c7613334 219 wait
7972aab2 220
96340a01 221 stop_lttng_tracing_ok $SESSION_NAME
d53addeb 222 trace_match_only $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH
7972aab2
DG
223 out=$?
224
67b4c664 225 destroy_lttng_session_ok $SESSION_NAME
7972aab2
DG
226
227 return $out
228}
229
230# MUST set TESTDIR before calling those functions
231plan_tests $NUM_TESTS
232
e3bef725
CB
233print_test_banner "$TEST_DESC"
234
7972aab2
DG
235TESTS=(
236 "test_before_app"
237 "test_after_app"
238 "test_after_multiple_apps"
239 "test_before_multiple_apps"
240 "test_multiple_channels"
241)
242
243TEST_COUNT=${#TESTS[@]}
244i=0
245
246start_lttng_sessiond
247
248while [ $i -lt $TEST_COUNT ]; do
249 TRACE_PATH=$(mktemp -d)
250 ${TESTS[$i]}
7972aab2
DG
251 rm -rf $TRACE_PATH
252 let "i++"
253done
254
255stop_lttng_sessiond
This page took 0.089745 seconds and 5 git commands to generate.