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