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 | |
17 | TEST_DESC="UST tracer - Tracing with per UID buffers" | |
18 | ||
19 | CURDIR=$(dirname $0)/ | |
20 | TESTDIR=$CURDIR/../../.. | |
21 | NR_ITER=100 | |
22 | SESSION_NAME="buffers-uid" | |
23 | EVENT_NAME="ust_gen_nevents:tptest" | |
24 | BIN_NAME="gen-nevents" | |
25 | NUM_TESTS=58 | |
26 | ||
27 | source $TESTDIR/utils/utils.sh | |
28 | ||
29 | print_test_banner "$TEST_DESC" | |
30 | ||
31 | if [ ! -x "$CURDIR/gen-nevents" ]; then | |
32 | BAIL_OUT "No UST nevents binary detected." | |
33 | fi | |
34 | ||
35 | # MUST set TESTDIR before calling those functions | |
36 | ||
37 | function enable_channel_per_uid() | |
38 | { | |
39 | sess_name=$1 | |
40 | channel_name=$2 | |
41 | ||
42 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel --buffers-uid -u $channel_name -s $sess_name >/dev/null 2>&1 | |
43 | ok $? "Enable channel $channel_name per UID for session $sess_name" | |
44 | } | |
45 | ||
46 | function wait_apps | |
47 | { | |
48 | diag "Waiting for applications to end..." | |
49 | while [ -n "$(pidof $BIN_NAME)" ]; do | |
50 | sleep 1 | |
51 | done | |
52 | } | |
53 | ||
54 | test_after_multiple_apps() { | |
55 | local out | |
56 | local i | |
57 | ||
58 | diag "Start multiple applications AFTER tracing is started" | |
59 | ||
60 | # BEFORE application is spawned | |
61 | create_lttng_session $SESSION_NAME $TRACE_PATH | |
62 | enable_channel_per_uid $SESSION_NAME "channel0" | |
63 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME | |
64 | start_lttng_tracing $SESSION_NAME | |
65 | ||
66 | for i in `seq 1 5`; do | |
67 | ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1 | |
68 | ok $? "Start application $i for tracing" | |
69 | done | |
70 | wait_apps | |
71 | ||
72 | stop_lttng_tracing $SESSION_NAME | |
73 | destroy_lttng_session $SESSION_NAME | |
74 | ||
75 | trace_matches $EVENT_NAME $[NR_ITER * 5] $TRACE_PATH | |
76 | ||
77 | return $? | |
78 | } | |
79 | ||
80 | test_before_multiple_apps() { | |
81 | local out | |
82 | local i | |
83 | ||
84 | diag "Start multiple applications BEFORE tracing is started" | |
85 | ||
86 | for i in `seq 1 5`; do | |
87 | ./$CURDIR/$BIN_NAME $NR_ITER & >/dev/null 2>&1 | |
88 | ok $? "Start application $i for tracing" | |
89 | done | |
90 | ||
91 | # BEFORE application is spawned | |
92 | create_lttng_session $SESSION_NAME $TRACE_PATH | |
93 | enable_channel_per_uid $SESSION_NAME "channel0" | |
94 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME | |
95 | start_lttng_tracing $SESSION_NAME | |
96 | ||
97 | # At least hit one event | |
98 | sleep 2 | |
99 | ||
100 | stop_lttng_tracing $SESSION_NAME | |
101 | destroy_lttng_session $SESSION_NAME | |
102 | ||
103 | out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l) | |
104 | if [ $out -eq 0 ]; then | |
105 | fail "Trace validation" | |
106 | diag "No event(s) found. We are supposed to have at least one." | |
107 | out=1 | |
108 | else | |
109 | pass "Trace validation" | |
110 | diag "Found $out event(s). Coherent." | |
111 | out=0 | |
112 | fi | |
113 | ||
114 | wait_apps | |
115 | ||
116 | return $out | |
117 | } | |
118 | ||
119 | test_after_app() { | |
120 | local out | |
121 | ||
122 | diag "Start application AFTER tracing is started" | |
123 | ||
124 | # BEFORE application is spawned | |
125 | create_lttng_session $SESSION_NAME $TRACE_PATH | |
126 | enable_channel_per_uid $SESSION_NAME "channel0" | |
127 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME | |
128 | start_lttng_tracing $SESSION_NAME | |
129 | ||
130 | ./$CURDIR/$BIN_NAME $NR_ITER | |
131 | ok $? "Start application to trace" | |
132 | ||
133 | stop_lttng_tracing $SESSION_NAME | |
134 | destroy_lttng_session $SESSION_NAME | |
135 | ||
136 | trace_matches $EVENT_NAME $NR_ITER $TRACE_PATH | |
137 | ||
138 | return $? | |
139 | } | |
140 | ||
141 | test_before_app() { | |
142 | local out | |
143 | ||
144 | diag "Start application BEFORE tracing is started" | |
145 | ||
146 | ./$CURDIR/$BIN_NAME $NR_ITER & | |
147 | ok $? "Start application to trace" | |
148 | ||
149 | # BEFORE application is spawned | |
150 | create_lttng_session $SESSION_NAME $TRACE_PATH | |
151 | enable_channel_per_uid $SESSION_NAME "channel0" | |
152 | enable_ust_lttng_event $SESSION_NAME $EVENT_NAME | |
153 | start_lttng_tracing $SESSION_NAME | |
154 | ||
155 | # At least hit one event | |
156 | sleep 2 | |
157 | ||
158 | stop_lttng_tracing $SESSION_NAME | |
159 | destroy_lttng_session $SESSION_NAME | |
160 | ||
161 | out=$(babeltrace $TRACE_PATH | grep $EVENT_NAME | wc -l) | |
162 | if [ $out -eq 0 ]; then | |
163 | fail "Trace validation" | |
164 | diag "No event(s) found. We are supposed to have at least one." | |
165 | out=1 | |
166 | else | |
167 | pass "Trace validation" | |
168 | diag "Found $out event(s). Coherent." | |
169 | out=0 | |
170 | fi | |
171 | ||
172 | wait_apps | |
173 | ||
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 | |
184 | enable_channel_per_uid $SESSION_NAME "channel0" | |
185 | enable_channel_per_uid $SESSION_NAME "channel1" | |
186 | enable_channel_per_uid $SESSION_NAME "channel2" | |
187 | enable_channel_per_uid $SESSION_NAME "channel3" | |
188 | enable_channel_per_uid $SESSION_NAME "channel4" | |
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 | ||
202 | ./$CURDIR/$BIN_NAME $NR_ITER | |
203 | ok $? "Start application to trace" | |
204 | ||
205 | stop_lttng_tracing $SESSION_NAME | |
2edab283 | 206 | trace_matches $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 | ||
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]} | |
233 | if [ $? -ne 0 ]; then | |
234 | stop_lttng_sessiond | |
235 | exit 1 | |
236 | fi | |
237 | ||
238 | rm -rf $TRACE_PATH | |
239 | let "i++" | |
240 | done | |
241 | ||
242 | stop_lttng_sessiond |