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" | |
f7613992 | 19 | CONSUMERD_BIN="lttng-consumerd" |
f4e40ab6 | 20 | RELAYD_BIN="lttng-relayd" |
d3e8f6bb DG |
21 | LTTNG_BIN="lttng" |
22 | BABELTRACE_BIN="babeltrace" | |
873c2aae | 23 | OUTPUT_DEST=/dev/null 2>&1 |
d3e8f6bb | 24 | |
fd4dfcec DG |
25 | # Minimal kernel version supported for session daemon tests |
26 | KERNEL_MAJOR_VERSION=2 | |
27 | KERNEL_MINOR_VERSION=6 | |
28 | KERNEL_PATCHLEVEL_VERSION=27 | |
29 | ||
29655db7 CB |
30 | source $TESTDIR/utils/tap/tap.sh |
31 | ||
fec81a7e CB |
32 | function print_ok () |
33 | { | |
34 | # Check if we are a terminal | |
35 | if [ -t 1 ]; then | |
36 | echo -e "\e[1;32mOK\e[0m" | |
37 | else | |
38 | echo -e "OK" | |
39 | fi | |
40 | } | |
41 | ||
42 | function print_fail () | |
43 | { | |
44 | # Check if we are a terminal | |
45 | if [ -t 1 ]; then | |
46 | echo -e "\e[1;31mFAIL\e[0m" | |
47 | else | |
48 | echo -e "FAIL" | |
49 | fi | |
50 | } | |
51 | ||
52 | function print_test_banner () | |
53 | { | |
54 | desc="$1" | |
29655db7 | 55 | diag "$desc" |
fec81a7e CB |
56 | } |
57 | ||
fd4dfcec DG |
58 | function validate_kernel_version () |
59 | { | |
60 | kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) | |
61 | if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then | |
62 | return 0 | |
63 | fi | |
64 | if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then | |
65 | return 0 | |
66 | fi | |
67 | if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then | |
68 | return 0 | |
69 | fi | |
70 | return 1 | |
71 | } | |
72 | ||
9ac429ef | 73 | # Generate a random string |
f4e40ab6 DG |
74 | # $1 = number of characters; defaults to 16 |
75 | # $2 = include special characters; 1 = yes, 0 = no; defaults to yes | |
9ac429ef | 76 | function randstring() |
f4e40ab6 DG |
77 | { |
78 | [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]" | |
79 | cat /dev/urandom | tr -cd "$CHAR" | head -c ${1:-16} | |
80 | echo | |
81 | } | |
82 | ||
f4e40ab6 DG |
83 | function lttng_enable_kernel_event |
84 | { | |
85 | sess_name=$1 | |
86 | event_name=$2 | |
07b86b52 | 87 | channel_name=$3 |
f4e40ab6 DG |
88 | |
89 | if [ -z $event_name ]; then | |
90 | # Enable all event if no event name specified | |
29655db7 | 91 | event_name="-a" |
f4e40ab6 DG |
92 | fi |
93 | ||
07b86b52 JD |
94 | if [ -z $channel_name ]; then |
95 | # default channel if none specified | |
96 | chan="" | |
97 | else | |
98 | chan="-c $channel_name" | |
99 | fi | |
100 | ||
873c2aae | 101 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k >$OUTPUT_DEST |
29655db7 | 102 | ok $? "Enable kernel event $event_name for session $sess_name" |
f4e40ab6 DG |
103 | } |
104 | ||
fb3268e3 | 105 | function start_lttng_relayd |
f4e40ab6 | 106 | { |
198e7caf | 107 | local opt=$1 |
173af62f | 108 | |
f4e40ab6 DG |
109 | DIR=$(readlink -f $TESTDIR) |
110 | ||
111 | if [ -z $(pidof lt-$RELAYD_BIN) ]; then | |
873c2aae | 112 | $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt >$OUTPUT_DEST |
25a818af | 113 | #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 & |
f4e40ab6 | 114 | if [ $? -eq 1 ]; then |
29655db7 | 115 | fail "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
116 | return 1 |
117 | else | |
29655db7 | 118 | pass "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
119 | fi |
120 | else | |
29655db7 | 121 | pass "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
122 | fi |
123 | } | |
124 | ||
1fb23888 | 125 | function stop_lttng_relayd_nocheck |
f4e40ab6 DG |
126 | { |
127 | PID_RELAYD=`pidof lt-$RELAYD_BIN` | |
128 | ||
1fb23888 | 129 | diag "Killing lttng-relayd (pid: $PID_RELAYD)" |
873c2aae | 130 | kill $PID_RELAYD >$OUTPUT_DEST |
1fb23888 | 131 | retval=$? |
29655db7 | 132 | |
1fb23888 | 133 | if [ $retval -eq 1 ]; then |
f4e40ab6 DG |
134 | out=1 |
135 | while [ -n "$out" ]; do | |
136 | out=$(pidof lt-$RELAYD_BIN) | |
137 | sleep 0.5 | |
138 | done | |
1fb23888 MD |
139 | fi |
140 | return $retval | |
141 | } | |
142 | ||
143 | function stop_lttng_relayd | |
144 | { | |
145 | stop_lttng_relayd_nocheck | |
146 | ||
147 | if [ $? -eq 1 ]; then | |
148 | fail "Killed lttng-relayd (pid: $PID_RELAYD)" | |
149 | return 1 | |
150 | else | |
151 | pass "Killed lttng-relayd (pid: $PID_RELAYD)" | |
f4e40ab6 DG |
152 | return 0 |
153 | fi | |
154 | } | |
155 | ||
fb3268e3 | 156 | function start_lttng_sessiond() |
355f483d DG |
157 | { |
158 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then | |
159 | # Env variable requested no session daemon | |
160 | return | |
161 | fi | |
162 | ||
29655db7 CB |
163 | validate_kernel_version |
164 | if [ $? -ne 0 ]; then | |
165 | fail "Start session daemon" | |
166 | BAIL_OUT "*** Kernel too old for session daemon tests ***" | |
355f483d DG |
167 | fi |
168 | ||
29655db7 | 169 | DIR=$(readlink -f $TESTDIR) |
d3d97763 JG |
170 | : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/} |
171 | export LTTNG_SESSION_CONFIG_XSD_PATH | |
29655db7 CB |
172 | |
173 | if [ -z $(pidof lt-$SESSIOND_BIN) ]; then | |
d7b63d8c | 174 | $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" |
29655db7 CB |
175 | #$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 & |
176 | status=$? | |
29655db7 CB |
177 | ok $status "Start session daemon" |
178 | fi | |
355f483d DG |
179 | } |
180 | ||
fb3268e3 | 181 | function stop_lttng_sessiond () |
d3e8f6bb | 182 | { |
355f483d DG |
183 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
184 | # Env variable requested no session daemon | |
185 | return | |
186 | fi | |
187 | ||
d3e8f6bb DG |
188 | PID_SESSIOND=`pidof lt-$SESSIOND_BIN` |
189 | ||
873c2aae | 190 | kill $PID_SESSIOND >$OUTPUT_DEST |
29655db7 | 191 | |
d3e8f6bb | 192 | if [ $? -eq 1 ]; then |
29655db7 | 193 | fail "Kill sessions daemon" |
d3e8f6bb DG |
194 | return 1 |
195 | else | |
5fa32580 DG |
196 | out=1 |
197 | while [ -n "$out" ]; do | |
198 | out=$(pidof lt-$SESSIOND_BIN) | |
199 | sleep 0.5 | |
200 | done | |
f7613992 MD |
201 | out=1 |
202 | while [ -n "$out" ]; do | |
203 | out=$(pidof $CONSUMERD_BIN) | |
204 | sleep 0.5 | |
205 | done | |
29655db7 | 206 | pass "Kill session daemon" |
d3e8f6bb DG |
207 | fi |
208 | } | |
209 | ||
873c2aae JRJ |
210 | function list_lttng_with_opts () |
211 | { | |
212 | opts=$1 | |
213 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN $opts >$OUTPUT_DEST | |
214 | ok $? "Lttng-tool list command with option $opts" | |
215 | } | |
216 | ||
07b86b52 JD |
217 | function create_lttng_session_no_output () |
218 | { | |
219 | sess_name=$1 | |
220 | ||
873c2aae | 221 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output >$OUTPUT_DEST |
07b86b52 JD |
222 | ok $? "Create session $sess_name in no-output mode" |
223 | } | |
224 | ||
d3e8f6bb DG |
225 | function create_lttng_session () |
226 | { | |
227 | sess_name=$1 | |
228 | trace_path=$2 | |
873c2aae | 229 | expected_to_fail=$3 |
d3e8f6bb | 230 | |
873c2aae JRJ |
231 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path > $OUTPUT_DEST |
232 | ret=$? | |
233 | if [[ $expected_to_fail && $ret ]]; then | |
234 | ok 0 "Expected fail on session creation $sess_name in $trace_path" | |
235 | else | |
236 | ok $ret "Create session $sess_name in $trace_path" | |
237 | fi | |
d4018451 DG |
238 | } |
239 | ||
29655db7 | 240 | function enable_ust_lttng_channel() |
d4018451 DG |
241 | { |
242 | sess_name=$1 | |
243 | channel_name=$2 | |
244 | ||
873c2aae | 245 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name >$OUTPUT_DEST |
29655db7 | 246 | ok $? "Enable channel $channel_name for session $sess_name" |
d4018451 DG |
247 | } |
248 | ||
29655db7 | 249 | function disable_ust_lttng_channel() |
d4018451 DG |
250 | { |
251 | sess_name=$1 | |
252 | channel_name=$2 | |
253 | ||
873c2aae | 254 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name >$OUTPUT_DEST |
29655db7 | 255 | ok $? "Disable channel $channel_name for session $sess_name" |
d3e8f6bb DG |
256 | } |
257 | ||
07b86b52 JD |
258 | function enable_lttng_mmap_overwrite_kernel_channel() |
259 | { | |
260 | sess_name=$1 | |
261 | channel_name=$2 | |
262 | ||
873c2aae | 263 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite >$OUTPUT_DEST |
07b86b52 JD |
264 | ok $? "Enable channel $channel_name for session $sess_name" |
265 | } | |
266 | ||
ebaaaf5e JD |
267 | function enable_lttng_mmap_overwrite_ust_channel() |
268 | { | |
269 | sess_name=$1 | |
270 | channel_name=$2 | |
271 | ||
873c2aae | 272 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite >$OUTPUT_DEST |
ebaaaf5e JD |
273 | ok $? "Enable channel $channel_name for session $sess_name" |
274 | } | |
275 | ||
d3e8f6bb DG |
276 | function enable_ust_lttng_event () |
277 | { | |
278 | sess_name=$1 | |
26b53d3b | 279 | event_name="$2" |
ebaaaf5e JD |
280 | channel_name=$3 |
281 | ||
282 | if [ -z $channel_name ]; then | |
283 | # default channel if none specified | |
284 | chan="" | |
285 | else | |
286 | chan="-c $channel_name" | |
287 | fi | |
d3e8f6bb | 288 | |
873c2aae | 289 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u >$OUTPUT_DEST |
29655db7 | 290 | ok $? "Enable event $event_name for session $sess_name" |
26b53d3b DG |
291 | } |
292 | ||
37175ce4 DG |
293 | function enable_jul_lttng_event() |
294 | { | |
295 | sess_name=$1 | |
296 | event_name="$2" | |
297 | channel_name=$3 | |
298 | ||
299 | if [ -z $channel_name ]; then | |
300 | # default channel if none specified | |
301 | chan="" | |
302 | else | |
303 | chan="-c $channel_name" | |
304 | fi | |
305 | ||
873c2aae | 306 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j >$OUTPUT_DEST |
37175ce4 DG |
307 | ok $? "Enable JUL event $event_name for session $sess_name" |
308 | } | |
309 | ||
b2064f54 DG |
310 | function enable_jul_lttng_event_loglevel() |
311 | { | |
312 | sess_name=$1 | |
313 | event_name="$2" | |
314 | loglevel=$3 | |
315 | channel_name=$4 | |
316 | ||
317 | if [ -z $channel_name ]; then | |
318 | # default channel if none specified | |
319 | chan="" | |
320 | else | |
321 | chan="-c $channel_name" | |
322 | fi | |
323 | ||
873c2aae | 324 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j >$OUTPUT_DEST |
b2064f54 DG |
325 | ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel" |
326 | } | |
327 | ||
26b53d3b DG |
328 | function enable_ust_lttng_event_filter() |
329 | { | |
330 | sess_name="$1" | |
331 | event_name="$2" | |
332 | filter="$3" | |
26b53d3b | 333 | |
873c2aae | 334 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" >$OUTPUT_DEST |
29655db7 | 335 | ok $? "Enable event $event_name with filtering for session $sess_name" |
26b53d3b DG |
336 | } |
337 | ||
338 | function enable_ust_lttng_event_loglevel() | |
339 | { | |
340 | sess_name="$1" | |
341 | event_name="$2" | |
342 | loglevel="$3" | |
26b53d3b | 343 | |
873c2aae | 344 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel >$OUTPUT_DEST |
29655db7 | 345 | ok $? "Enable event $event_name with loglevel $loglevel" |
26b53d3b DG |
346 | } |
347 | ||
348 | function enable_ust_lttng_event_loglevel_only() | |
349 | { | |
350 | sess_name="$1" | |
351 | event_name="$2" | |
352 | loglevel="$3" | |
26b53d3b | 353 | |
873c2aae | 354 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel >$OUTPUT_DEST |
29655db7 | 355 | ok $? "Enable event $event_name with loglevel-only $loglevel" |
26b53d3b DG |
356 | } |
357 | ||
358 | function disable_ust_lttng_event () | |
359 | { | |
907b42de DG |
360 | sess_name="$1" |
361 | event_name="$2" | |
26b53d3b | 362 | |
873c2aae | 363 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -u >$OUTPUT_DEST |
29655db7 | 364 | ok $? "Disable event $event_name for session $sess_name" |
d3e8f6bb DG |
365 | } |
366 | ||
1d842d5a DG |
367 | function disable_jul_lttng_event () |
368 | { | |
369 | local sess_name="$1" | |
370 | local event_name="$2" | |
371 | ||
372 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1 | |
373 | ok $? "Disable JUL event $event_name for session $sess_name" | |
374 | } | |
375 | ||
fb3268e3 | 376 | function start_lttng_tracing () |
d3e8f6bb DG |
377 | { |
378 | sess_name=$1 | |
379 | ||
873c2aae | 380 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name >$OUTPUT_DEST |
29655db7 | 381 | ok $? "Start tracing for session $sess_name" |
d3e8f6bb DG |
382 | } |
383 | ||
fb3268e3 | 384 | function stop_lttng_tracing () |
d3e8f6bb DG |
385 | { |
386 | sess_name=$1 | |
387 | ||
873c2aae | 388 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name >$OUTPUT_DEST |
29655db7 | 389 | ok $? "Stop lttng tracing for session $sess_name" |
d3e8f6bb DG |
390 | } |
391 | ||
392 | function destroy_lttng_session () | |
393 | { | |
394 | sess_name=$1 | |
395 | ||
873c2aae | 396 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name >$OUTPUT_DEST |
29655db7 | 397 | ok $? "Destroy lttng session $sess_name" |
d3e8f6bb DG |
398 | } |
399 | ||
873c2aae JRJ |
400 | function destroy_lttng_sessions () |
401 | { | |
402 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all >$OUTPUT_DEST | |
403 | ok $? "Destroy all lttng sessions" | |
404 | } | |
405 | ||
07b86b52 JD |
406 | function lttng_snapshot_add_output () |
407 | { | |
408 | sess_name=$1 | |
409 | trace_path=$2 | |
410 | ||
873c2aae | 411 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path >$OUTPUT_DEST |
07b86b52 JD |
412 | ok $? "Added snapshot output file://$trace_path" |
413 | } | |
414 | ||
26402e0c DG |
415 | function lttng_snapshot_del_output () |
416 | { | |
417 | local sess_name=$1 | |
418 | local id=$2 | |
419 | ||
873c2aae | 420 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id >$OUTPUT_DEST |
26402e0c DG |
421 | ok $? "Deleted snapshot output id $id" |
422 | } | |
423 | ||
07b86b52 JD |
424 | function lttng_snapshot_record () |
425 | { | |
426 | sess_name=$1 | |
427 | trace_path=$2 | |
428 | ||
873c2aae | 429 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name >$OUTPUT_DEST |
07b86b52 JD |
430 | ok $? "Snapshot recorded" |
431 | } | |
432 | ||
e02b109b DG |
433 | function lttng_save() |
434 | { | |
435 | local sess_name=$1 | |
436 | local opts=$2 | |
437 | ||
873c2aae | 438 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts >$OUTPUT_DEST |
e02b109b DG |
439 | ok $? "Session successfully saved" |
440 | } | |
441 | ||
442 | function lttng_load() | |
443 | { | |
444 | local opts=$1 | |
445 | ||
873c2aae | 446 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts >$OUTPUT_DEST |
e02b109b DG |
447 | ok $? "Load command successful" |
448 | } | |
449 | ||
d3e8f6bb DG |
450 | function trace_matches () |
451 | { | |
452 | event_name=$1 | |
453 | nr_iter=$2 | |
454 | trace_path=$3 | |
455 | ||
317eef93 | 456 | which $BABELTRACE_BIN >/dev/null |
29655db7 | 457 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" |
d3e8f6bb DG |
458 | |
459 | count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) | |
29655db7 | 460 | |
d3e8f6bb | 461 | if [ "$count" -ne "$nr_iter" ]; then |
29655db7 CB |
462 | fail "Trace match" |
463 | diag "$count events found in trace" | |
d3e8f6bb | 464 | else |
29655db7 | 465 | pass "Trace match" |
d3e8f6bb DG |
466 | fi |
467 | } | |
f4e40ab6 DG |
468 | |
469 | function validate_trace | |
470 | { | |
471 | event_name=$1 | |
472 | trace_path=$2 | |
473 | ||
474 | which $BABELTRACE_BIN >/dev/null | |
29655db7 CB |
475 | if [ $? -ne 0 ]; then |
476 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
f4e40ab6 DG |
477 | fi |
478 | ||
07b86b52 JD |
479 | OLDIFS=$IFS |
480 | IFS="," | |
481 | for i in $event_name; do | |
482 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) | |
483 | if [ "$traced" -ne 0 ]; then | |
ebaaaf5e | 484 | pass "Validate trace for event $i, $traced events" |
07b86b52 JD |
485 | else |
486 | fail "Validate trace for event $i" | |
487 | diag "Found $traced occurences of $i" | |
488 | fi | |
489 | done | |
490 | ret=$? | |
491 | IFS=$OLDIFS | |
492 | return $ret | |
f4e40ab6 | 493 | } |