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