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