Commit | Line | Data |
---|---|---|
10a8a223 | 1 | #!/src/bin/bash |
d3e8f6bb DG |
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 | ||
18 | SESSIOND_BIN="lttng-sessiond" | |
f4e40ab6 | 19 | RELAYD_BIN="lttng-relayd" |
d3e8f6bb DG |
20 | LTTNG_BIN="lttng" |
21 | BABELTRACE_BIN="babeltrace" | |
22 | ||
fd4dfcec DG |
23 | # Minimal kernel version supported for session daemon tests |
24 | KERNEL_MAJOR_VERSION=2 | |
25 | KERNEL_MINOR_VERSION=6 | |
26 | KERNEL_PATCHLEVEL_VERSION=27 | |
27 | ||
29655db7 CB |
28 | source $TESTDIR/utils/tap/tap.sh |
29 | ||
fec81a7e CB |
30 | function print_ok () |
31 | { | |
32 | # Check if we are a terminal | |
33 | if [ -t 1 ]; then | |
34 | echo -e "\e[1;32mOK\e[0m" | |
35 | else | |
36 | echo -e "OK" | |
37 | fi | |
38 | } | |
39 | ||
40 | function print_fail () | |
41 | { | |
42 | # Check if we are a terminal | |
43 | if [ -t 1 ]; then | |
44 | echo -e "\e[1;31mFAIL\e[0m" | |
45 | else | |
46 | echo -e "FAIL" | |
47 | fi | |
48 | } | |
49 | ||
50 | function print_test_banner () | |
51 | { | |
52 | desc="$1" | |
29655db7 | 53 | diag "$desc" |
fec81a7e CB |
54 | } |
55 | ||
fd4dfcec DG |
56 | function validate_kernel_version () |
57 | { | |
58 | kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) | |
59 | if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then | |
60 | return 0 | |
61 | fi | |
62 | if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then | |
63 | return 0 | |
64 | fi | |
65 | if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then | |
66 | return 0 | |
67 | fi | |
68 | return 1 | |
69 | } | |
70 | ||
9ac429ef | 71 | # Generate a random string |
f4e40ab6 DG |
72 | # $1 = number of characters; defaults to 16 |
73 | # $2 = include special characters; 1 = yes, 0 = no; defaults to yes | |
9ac429ef | 74 | function randstring() |
f4e40ab6 DG |
75 | { |
76 | [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]" | |
77 | cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16} | |
78 | echo | |
79 | } | |
80 | ||
f4e40ab6 DG |
81 | function lttng_enable_kernel_event |
82 | { | |
83 | sess_name=$1 | |
84 | event_name=$2 | |
85 | ||
86 | if [ -z $event_name ]; then | |
87 | # Enable all event if no event name specified | |
29655db7 | 88 | event_name="-a" |
f4e40ab6 DG |
89 | fi |
90 | ||
907b42de | 91 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -k >/dev/null 2>&1 |
29655db7 | 92 | ok $? "Enable kernel event $event_name for session $sess_name" |
f4e40ab6 DG |
93 | } |
94 | ||
fb3268e3 | 95 | function start_lttng_relayd |
f4e40ab6 | 96 | { |
198e7caf | 97 | local opt=$1 |
173af62f | 98 | |
f4e40ab6 DG |
99 | DIR=$(readlink -f $TESTDIR) |
100 | ||
101 | if [ -z $(pidof lt-$RELAYD_BIN) ]; then | |
173af62f | 102 | $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt >/dev/null 2>&1 & |
25a818af | 103 | #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 & |
f4e40ab6 | 104 | if [ $? -eq 1 ]; then |
29655db7 | 105 | fail "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
106 | return 1 |
107 | else | |
29655db7 | 108 | pass "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
109 | fi |
110 | else | |
29655db7 | 111 | pass "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
112 | fi |
113 | } | |
114 | ||
fb3268e3 | 115 | function stop_lttng_relayd |
f4e40ab6 DG |
116 | { |
117 | PID_RELAYD=`pidof lt-$RELAYD_BIN` | |
118 | ||
f4e40ab6 | 119 | kill $PID_RELAYD >/dev/null 2>&1 |
29655db7 | 120 | |
f4e40ab6 | 121 | if [ $? -eq 1 ]; then |
29655db7 | 122 | fail "Kill lttng-relayd (pid: $PID_RELAYD)" |
f4e40ab6 DG |
123 | return 1 |
124 | else | |
125 | out=1 | |
126 | while [ -n "$out" ]; do | |
127 | out=$(pidof lt-$RELAYD_BIN) | |
128 | sleep 0.5 | |
129 | done | |
29655db7 | 130 | pass "Kill lttng-relayd (pid: $PID_RELAYD)" |
f4e40ab6 DG |
131 | return 0 |
132 | fi | |
133 | } | |
134 | ||
fb3268e3 | 135 | function start_lttng_sessiond() |
355f483d DG |
136 | { |
137 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then | |
138 | # Env variable requested no session daemon | |
139 | return | |
140 | fi | |
141 | ||
29655db7 CB |
142 | validate_kernel_version |
143 | if [ $? -ne 0 ]; then | |
144 | fail "Start session daemon" | |
145 | BAIL_OUT "*** Kernel too old for session daemon tests ***" | |
355f483d DG |
146 | fi |
147 | ||
29655db7 CB |
148 | DIR=$(readlink -f $TESTDIR) |
149 | ||
150 | if [ -z $(pidof lt-$SESSIOND_BIN) ]; then | |
151 | $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --daemonize --quiet --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" | |
152 | #$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --verbose-consumer >>/tmp/sessiond.log 2>&1 & | |
153 | status=$? | |
154 | # Wait for sessiond to bootstrap | |
155 | sleep 2 | |
156 | ok $status "Start session daemon" | |
157 | fi | |
355f483d DG |
158 | } |
159 | ||
fb3268e3 | 160 | function stop_lttng_sessiond () |
d3e8f6bb | 161 | { |
355f483d DG |
162 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
163 | # Env variable requested no session daemon | |
164 | return | |
165 | fi | |
166 | ||
d3e8f6bb DG |
167 | PID_SESSIOND=`pidof lt-$SESSIOND_BIN` |
168 | ||
d3e8f6bb | 169 | kill $PID_SESSIOND >/dev/null 2>&1 |
29655db7 | 170 | |
d3e8f6bb | 171 | if [ $? -eq 1 ]; then |
29655db7 | 172 | fail "Kill sessions daemon" |
d3e8f6bb DG |
173 | return 1 |
174 | else | |
5fa32580 DG |
175 | out=1 |
176 | while [ -n "$out" ]; do | |
177 | out=$(pidof lt-$SESSIOND_BIN) | |
178 | sleep 0.5 | |
179 | done | |
29655db7 | 180 | pass "Kill session daemon" |
d3e8f6bb DG |
181 | fi |
182 | } | |
183 | ||
184 | function create_lttng_session () | |
185 | { | |
186 | sess_name=$1 | |
187 | trace_path=$2 | |
188 | ||
10a8a223 | 189 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path >/dev/null 2>&1 |
29655db7 | 190 | ok $? "Create session $sess_name in $trace_path" |
d4018451 DG |
191 | } |
192 | ||
29655db7 | 193 | function enable_ust_lttng_channel() |
d4018451 DG |
194 | { |
195 | sess_name=$1 | |
196 | channel_name=$2 | |
197 | ||
29655db7 CB |
198 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name >/dev/null 2>&1 |
199 | ok $? "Enable channel $channel_name for session $sess_name" | |
d4018451 DG |
200 | } |
201 | ||
29655db7 | 202 | function disable_ust_lttng_channel() |
d4018451 DG |
203 | { |
204 | sess_name=$1 | |
205 | channel_name=$2 | |
206 | ||
29655db7 CB |
207 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name >/dev/null 2>&1 |
208 | ok $? "Disable channel $channel_name for session $sess_name" | |
d3e8f6bb DG |
209 | } |
210 | ||
211 | function enable_ust_lttng_event () | |
212 | { | |
213 | sess_name=$1 | |
26b53d3b | 214 | event_name="$2" |
d3e8f6bb | 215 | |
26b53d3b | 216 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u >/dev/null 2>&1 |
29655db7 | 217 | ok $? "Enable event $event_name for session $sess_name" |
26b53d3b DG |
218 | } |
219 | ||
220 | function enable_ust_lttng_event_filter() | |
221 | { | |
222 | sess_name="$1" | |
223 | event_name="$2" | |
224 | filter="$3" | |
26b53d3b | 225 | |
29655db7 CB |
226 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" >/dev/null 2>&1 |
227 | ok $? "Enable event $event_name with filtering for session $sess_name" | |
26b53d3b DG |
228 | } |
229 | ||
230 | function enable_ust_lttng_event_loglevel() | |
231 | { | |
232 | sess_name="$1" | |
233 | event_name="$2" | |
234 | loglevel="$3" | |
26b53d3b | 235 | |
29655db7 CB |
236 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel >/dev/null 2>&1 |
237 | ok $? "Enable event $event_name with loglevel $loglevel" | |
26b53d3b DG |
238 | } |
239 | ||
240 | function enable_ust_lttng_event_loglevel_only() | |
241 | { | |
242 | sess_name="$1" | |
243 | event_name="$2" | |
244 | loglevel="$3" | |
26b53d3b | 245 | |
29655db7 CB |
246 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel >/dev/null 2>&1 |
247 | ok $? "Enable event $event_name with loglevel-only $loglevel" | |
26b53d3b DG |
248 | } |
249 | ||
250 | function disable_ust_lttng_event () | |
251 | { | |
907b42de DG |
252 | sess_name="$1" |
253 | event_name="$2" | |
26b53d3b | 254 | |
907b42de | 255 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -u >/dev/null 2>&1 |
29655db7 | 256 | ok $? "Disable event $event_name for session $sess_name" |
d3e8f6bb DG |
257 | } |
258 | ||
fb3268e3 | 259 | function start_lttng_tracing () |
d3e8f6bb DG |
260 | { |
261 | sess_name=$1 | |
262 | ||
10a8a223 | 263 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >/dev/null 2>&1 |
29655db7 | 264 | ok $? "Start tracing for session $sess_name" |
d3e8f6bb DG |
265 | } |
266 | ||
fb3268e3 | 267 | function stop_lttng_tracing () |
d3e8f6bb DG |
268 | { |
269 | sess_name=$1 | |
270 | ||
10a8a223 | 271 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >/dev/null 2>&1 |
29655db7 | 272 | ok $? "Stop lttng tracing for session $sess_name" |
d3e8f6bb DG |
273 | } |
274 | ||
275 | function destroy_lttng_session () | |
276 | { | |
277 | sess_name=$1 | |
278 | ||
29655db7 | 279 | |
10a8a223 | 280 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >/dev/null 2>&1 |
29655db7 | 281 | ok $? "Destroy lttng session $sess_name" |
d3e8f6bb DG |
282 | } |
283 | ||
284 | function trace_matches () | |
285 | { | |
286 | event_name=$1 | |
287 | nr_iter=$2 | |
288 | trace_path=$3 | |
289 | ||
317eef93 | 290 | which $BABELTRACE_BIN >/dev/null |
29655db7 | 291 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" |
d3e8f6bb DG |
292 | |
293 | count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) | |
29655db7 | 294 | |
d3e8f6bb | 295 | if [ "$count" -ne "$nr_iter" ]; then |
29655db7 CB |
296 | fail "Trace match" |
297 | diag "$count events found in trace" | |
d3e8f6bb | 298 | else |
29655db7 | 299 | pass "Trace match" |
d3e8f6bb DG |
300 | fi |
301 | } | |
f4e40ab6 DG |
302 | |
303 | function validate_trace | |
304 | { | |
305 | event_name=$1 | |
306 | trace_path=$2 | |
307 | ||
308 | which $BABELTRACE_BIN >/dev/null | |
29655db7 CB |
309 | if [ $? -ne 0 ]; then |
310 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
f4e40ab6 DG |
311 | fi |
312 | ||
f4e40ab6 | 313 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $event_name | wc -l) |
29655db7 CB |
314 | if [ "$traced" -ne 0 ]; then |
315 | pass "Validate trace for event $event_name" | |
f4e40ab6 | 316 | else |
29655db7 CB |
317 | fail "Validate trace for event $event_name" |
318 | diag "Found $traced occurences of $event_name" | |
f4e40ab6 DG |
319 | fi |
320 | } |