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" | |
19356f3a | 19 | RUNAS_BIN="lttng-runas" |
f7613992 | 20 | CONSUMERD_BIN="lttng-consumerd" |
f4e40ab6 | 21 | RELAYD_BIN="lttng-relayd" |
d3e8f6bb DG |
22 | LTTNG_BIN="lttng" |
23 | BABELTRACE_BIN="babeltrace" | |
2cf48300 JR |
24 | OUTPUT_DEST=/dev/null |
25 | ERROR_OUTPUT_DEST=/dev/null | |
d3e8f6bb | 26 | |
fd4dfcec DG |
27 | # Minimal kernel version supported for session daemon tests |
28 | KERNEL_MAJOR_VERSION=2 | |
29 | KERNEL_MINOR_VERSION=6 | |
30 | KERNEL_PATCHLEVEL_VERSION=27 | |
31 | ||
629b9335 MD |
32 | # We set the default UST register timeout to "wait forever", so that |
33 | # basic tests don't have to worry about hitting timeouts on busy | |
34 | # systems. Specialized tests should test those corner-cases. | |
35 | export LTTNG_UST_REGISTER_TIMEOUT=-1 | |
36 | ||
fd7fe1a8 JR |
37 | # We set the default lttng-sessiond path to /bin/true to prevent the spawning |
38 | # of a daemonized sessiond. This is necessary since 'lttng create' will spawn | |
39 | # its own sessiond if none is running. It also ensures that 'lttng create' | |
40 | # fails when no sessiond is running. | |
41 | export LTTNG_SESSIOND_PATH="/bin/true" | |
42 | ||
29655db7 CB |
43 | source $TESTDIR/utils/tap/tap.sh |
44 | ||
fec81a7e CB |
45 | function print_ok () |
46 | { | |
47 | # Check if we are a terminal | |
48 | if [ -t 1 ]; then | |
49 | echo -e "\e[1;32mOK\e[0m" | |
50 | else | |
51 | echo -e "OK" | |
52 | fi | |
53 | } | |
54 | ||
55 | function print_fail () | |
56 | { | |
57 | # Check if we are a terminal | |
58 | if [ -t 1 ]; then | |
59 | echo -e "\e[1;31mFAIL\e[0m" | |
60 | else | |
61 | echo -e "FAIL" | |
62 | fi | |
63 | } | |
64 | ||
65 | function print_test_banner () | |
66 | { | |
7d0ad314 | 67 | local desc="$1" |
29655db7 | 68 | diag "$desc" |
fec81a7e CB |
69 | } |
70 | ||
fd4dfcec DG |
71 | function validate_kernel_version () |
72 | { | |
7d0ad314 | 73 | local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) |
fd4dfcec DG |
74 | if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then |
75 | return 0 | |
76 | fi | |
77 | if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then | |
78 | return 0 | |
79 | fi | |
80 | if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then | |
81 | return 0 | |
82 | fi | |
83 | return 1 | |
84 | } | |
85 | ||
9ac429ef | 86 | # Generate a random string |
f4e40ab6 DG |
87 | # $1 = number of characters; defaults to 16 |
88 | # $2 = include special characters; 1 = yes, 0 = no; defaults to yes | |
9ac429ef | 89 | function randstring() |
f4e40ab6 DG |
90 | { |
91 | [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]" | |
b89c3a68 | 92 | cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null |
f4e40ab6 DG |
93 | echo |
94 | } | |
95 | ||
9e136324 JG |
96 | # Return the number of _configured_ CPUs. |
97 | function conf_proc_count() | |
98 | { | |
99 | getconf _NPROCESSORS_CONF | |
100 | if [ $? -ne 0 ]; then | |
101 | diag "Failed to get the number of configured CPUs" | |
102 | fi | |
103 | echo | |
104 | } | |
105 | ||
4a180d9f | 106 | function enable_kernel_lttng_event |
f4e40ab6 | 107 | { |
4a180d9f MD |
108 | local expected_to_fail="$1" |
109 | local sess_name="$2" | |
110 | local event_name="$3" | |
111 | local channel_name="$4" | |
f4e40ab6 | 112 | |
4a180d9f | 113 | if [ -z "$event_name" ]; then |
f4e40ab6 | 114 | # Enable all event if no event name specified |
29655db7 | 115 | event_name="-a" |
f4e40ab6 DG |
116 | fi |
117 | ||
4a180d9f | 118 | if [ -z "$channel_name" ]; then |
07b86b52 JD |
119 | # default channel if none specified |
120 | chan="" | |
121 | else | |
122 | chan="-c $channel_name" | |
123 | fi | |
124 | ||
2cf48300 | 125 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
4a180d9f MD |
126 | ret=$? |
127 | if [[ $expected_to_fail -eq "1" ]]; then | |
128 | test $ret -ne "0" | |
129 | ok $? "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected" | |
130 | else | |
131 | ok $ret "Enable kernel event $event_name for session $sess_name" | |
132 | fi | |
133 | } | |
134 | ||
135 | function enable_kernel_lttng_event_ok () | |
136 | { | |
137 | enable_kernel_lttng_event 0 "$@" | |
138 | } | |
139 | ||
140 | function enable_kernel_lttng_event_fail () | |
141 | { | |
142 | enable_kernel_lttng_event 1 "$@" | |
143 | } | |
144 | ||
145 | # Old interface | |
146 | function lttng_enable_kernel_event | |
147 | { | |
148 | enable_kernel_lttng_event_ok "$@" | |
f4e40ab6 DG |
149 | } |
150 | ||
8cfcd41c MD |
151 | function lttng_enable_kernel_syscall() |
152 | { | |
153 | local expected_to_fail=$1 | |
154 | local sess_name=$2 | |
155 | local syscall_name=$3 | |
156 | local channel_name=$4 | |
157 | ||
158 | if [ -z $syscall_name ]; then | |
159 | # Enable all event if no syscall name specified | |
160 | syscall_name="-a" | |
161 | fi | |
162 | ||
163 | if [ -z $channel_name ]; then | |
164 | # default channel if none specified | |
165 | chan="" | |
166 | else | |
167 | chan="-c $channel_name" | |
168 | fi | |
169 | ||
2cf48300 | 170 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
8cfcd41c MD |
171 | ret=$? |
172 | if [[ $expected_to_fail -eq "1" ]]; then | |
173 | test $ret -ne "0" | |
174 | ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected" | |
175 | else | |
176 | ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name" | |
177 | fi | |
178 | } | |
179 | ||
180 | function lttng_enable_kernel_syscall_ok() | |
181 | { | |
421b83dc | 182 | lttng_enable_kernel_syscall 0 "$@" |
8cfcd41c MD |
183 | } |
184 | ||
185 | function lttng_enable_kernel_syscall_fail() | |
186 | { | |
421b83dc | 187 | lttng_enable_kernel_syscall 1 "$@" |
8cfcd41c MD |
188 | } |
189 | ||
190 | function lttng_disable_kernel_syscall() | |
191 | { | |
192 | local expected_to_fail=$1 | |
193 | local sess_name=$2 | |
194 | local syscall_name=$3 | |
195 | local channel_name=$4 | |
196 | ||
197 | if [ -z $syscall_name ]; then | |
198 | # Enable all event if no syscall name specified | |
199 | syscall_name="-a" | |
200 | fi | |
201 | ||
202 | if [ -z $channel_name ]; then | |
203 | # default channel if none specified | |
204 | chan="" | |
205 | else | |
206 | chan="-c $channel_name" | |
207 | fi | |
208 | ||
2cf48300 | 209 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event --syscall "$syscall_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
8cfcd41c MD |
210 | |
211 | ret=$? | |
212 | if [[ $expected_to_fail -eq "1" ]]; then | |
213 | test $ret -ne "0" | |
34ab15c5 | 214 | ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected" |
8cfcd41c MD |
215 | else |
216 | ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name" | |
217 | fi | |
218 | } | |
219 | ||
220 | function lttng_disable_kernel_syscall_ok() | |
221 | { | |
421b83dc | 222 | lttng_disable_kernel_syscall 0 "$@" |
8cfcd41c MD |
223 | } |
224 | ||
225 | function lttng_disable_kernel_syscall_fail() | |
226 | { | |
421b83dc | 227 | lttng_disable_kernel_syscall 1 "$@" |
8cfcd41c MD |
228 | } |
229 | ||
d96f6315 MD |
230 | function lttng_enable_kernel_channel() |
231 | { | |
232 | local expected_to_fail=$1 | |
233 | local sess_name=$2 | |
234 | local channel_name=$3 | |
235 | ||
2cf48300 | 236 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
d96f6315 MD |
237 | ret=$? |
238 | if [[ $expected_to_fail -eq "1" ]]; then | |
239 | test "$ret" -ne "0" | |
34ab15c5 | 240 | ok $? "Enable channel $channel_name for session $sess_name failed as expected" |
d96f6315 MD |
241 | else |
242 | ok $ret "Enable channel $channel_name for session $sess_name" | |
243 | fi | |
244 | } | |
245 | ||
246 | function lttng_enable_kernel_channel_ok() | |
247 | { | |
421b83dc | 248 | lttng_enable_kernel_channel 0 "$@" |
d96f6315 MD |
249 | } |
250 | ||
251 | function lttng_enable_kernel_channel_fail() | |
252 | { | |
421b83dc | 253 | lttng_enable_kernel_channel 1 "$@" |
d96f6315 MD |
254 | } |
255 | ||
256 | function lttng_disable_kernel_channel() | |
257 | { | |
258 | local expected_to_fail=$1 | |
259 | local sess_name=$2 | |
260 | local channel_name=$3 | |
261 | ||
2cf48300 | 262 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
d96f6315 MD |
263 | ret=$? |
264 | if [[ $expected_to_fail -eq "1" ]]; then | |
265 | test "$ret" -ne "0" | |
34ab15c5 | 266 | ok $? "Disable channel $channel_name for session $sess_name failed as expected" |
d96f6315 | 267 | else |
34ab15c5 | 268 | ok $ret "Disable channel $channel_name for session $sess_name" |
d96f6315 MD |
269 | fi |
270 | } | |
271 | ||
272 | function lttng_disable_kernel_channel_ok() | |
273 | { | |
421b83dc | 274 | lttng_disable_kernel_channel 0 "$@" |
d96f6315 MD |
275 | } |
276 | ||
277 | function lttng_disable_kernel_channel_fail() | |
278 | { | |
421b83dc | 279 | lttng_disable_kernel_channel 1 "$@" |
d96f6315 MD |
280 | } |
281 | ||
05aa48da | 282 | function start_lttng_relayd_opt() |
f4e40ab6 | 283 | { |
05aa48da MD |
284 | local withtap=$1 |
285 | local opt=$2 | |
173af62f | 286 | |
f4e40ab6 DG |
287 | DIR=$(readlink -f $TESTDIR) |
288 | ||
db7b260c | 289 | if [ -z $(pgrep --full lt-$RELAYD_BIN) ]; then |
2cf48300 | 290 | $DIR/../src/bin/lttng-relayd/$RELAYD_BIN -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
25a818af | 291 | #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 & |
f4e40ab6 | 292 | if [ $? -eq 1 ]; then |
05aa48da MD |
293 | if [ $withtap -eq "1" ]; then |
294 | fail "Start lttng-relayd (opt: $opt)" | |
295 | fi | |
f4e40ab6 DG |
296 | return 1 |
297 | else | |
05aa48da MD |
298 | if [ $withtap -eq "1" ]; then |
299 | pass "Start lttng-relayd (opt: $opt)" | |
300 | fi | |
f4e40ab6 DG |
301 | fi |
302 | else | |
29655db7 | 303 | pass "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
304 | fi |
305 | } | |
306 | ||
05aa48da | 307 | function start_lttng_relayd() |
f4e40ab6 | 308 | { |
05aa48da MD |
309 | start_lttng_relayd_opt 1 "$@" |
310 | } | |
311 | ||
312 | function start_lttng_relayd_notap() | |
313 | { | |
314 | start_lttng_relayd_opt 0 "$@" | |
315 | } | |
316 | ||
317 | function stop_lttng_relayd_opt() | |
318 | { | |
319 | local withtap=$1 | |
320 | ||
db7b260c | 321 | PID_RELAYD=`pgrep --full lt-$RELAYD_BIN` |
f4e40ab6 | 322 | |
05aa48da MD |
323 | if [ $withtap -eq "1" ]; then |
324 | diag "Killing lttng-relayd (pid: $PID_RELAYD)" | |
325 | fi | |
2cf48300 | 326 | kill $PID_RELAYD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
1fb23888 | 327 | retval=$? |
29655db7 | 328 | |
05aa48da MD |
329 | if [ $? -eq 1 ]; then |
330 | if [ $withtap -eq "1" ]; then | |
331 | fail "Kill relay daemon" | |
332 | fi | |
333 | return 1 | |
334 | else | |
f4e40ab6 DG |
335 | out=1 |
336 | while [ -n "$out" ]; do | |
db7b260c | 337 | out=$(pgrep --full lt-$RELAYD_BIN) |
f4e40ab6 DG |
338 | sleep 0.5 |
339 | done | |
05aa48da MD |
340 | if [ $withtap -eq "1" ]; then |
341 | pass "Kill relay daemon" | |
342 | fi | |
1fb23888 MD |
343 | fi |
344 | return $retval | |
345 | } | |
346 | ||
05aa48da | 347 | function stop_lttng_relayd() |
1fb23888 | 348 | { |
05aa48da MD |
349 | stop_lttng_relayd_opt 1 "$@" |
350 | } | |
1fb23888 | 351 | |
05aa48da MD |
352 | function stop_lttng_relayd_notap() |
353 | { | |
354 | stop_lttng_relayd_opt 0 "$@" | |
f4e40ab6 DG |
355 | } |
356 | ||
05aa48da MD |
357 | #First arg: show tap output |
358 | #Second argument: load path for automatic loading | |
359 | function start_lttng_sessiond_opt() | |
355f483d | 360 | { |
05aa48da MD |
361 | local withtap=$1 |
362 | local load_path=$2 | |
8d51ddbc | 363 | |
355f483d DG |
364 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
365 | # Env variable requested no session daemon | |
366 | return | |
367 | fi | |
368 | ||
29655db7 CB |
369 | validate_kernel_version |
370 | if [ $? -ne 0 ]; then | |
371 | fail "Start session daemon" | |
372 | BAIL_OUT "*** Kernel too old for session daemon tests ***" | |
355f483d DG |
373 | fi |
374 | ||
29655db7 | 375 | DIR=$(readlink -f $TESTDIR) |
d3d97763 JG |
376 | : ${LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/config/} |
377 | export LTTNG_SESSION_CONFIG_XSD_PATH | |
29655db7 | 378 | |
db7b260c | 379 | if [ -z $(pgrep --full lt-$SESSIOND_BIN) ]; then |
8d51ddbc | 380 | # Have a load path ? |
05aa48da | 381 | if [ -n "$load_path" ]; then |
e4f8013b | 382 | $DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN --load "$load_path" --background --consumerd32-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" --consumerd64-path="$DIR/../src/bin/lttng-consumerd/lttng-consumerd" |
8d51ddbc JRJ |
383 | else |
384 | $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" | |
385 | fi | |
0fc2834c | 386 | #$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" --verbose-consumer >>/tmp/sessiond.log 2>&1 |
29655db7 | 387 | status=$? |
05aa48da MD |
388 | if [ $withtap -eq "1" ]; then |
389 | ok $status "Start session daemon" | |
390 | fi | |
29655db7 | 391 | fi |
355f483d DG |
392 | } |
393 | ||
05aa48da MD |
394 | function start_lttng_sessiond() |
395 | { | |
396 | start_lttng_sessiond_opt 1 "$@" | |
397 | } | |
398 | ||
399 | function start_lttng_sessiond_notap() | |
d3e8f6bb | 400 | { |
05aa48da MD |
401 | start_lttng_sessiond_opt 0 "$@" |
402 | } | |
403 | ||
404 | function stop_lttng_sessiond_opt() | |
405 | { | |
406 | local withtap=$1 | |
4c80129b JR |
407 | local signal=$2 |
408 | local kill_opt="" | |
05aa48da | 409 | |
355f483d DG |
410 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
411 | # Env variable requested no session daemon | |
412 | return | |
413 | fi | |
414 | ||
19356f3a | 415 | PID_SESSIOND="$(pgrep --full lt-$SESSIOND_BIN) $(pgrep --full $RUNAS_BIN)" |
d3e8f6bb | 416 | |
4c80129b JR |
417 | if [ -n "$2" ]; then |
418 | kill_opt="$kill_opt -s $signal" | |
419 | fi | |
8490897a MD |
420 | if [ $withtap -eq "1" ]; then |
421 | diag "Killing lt-$SESSIOND_BIN pids: $(echo $PID_SESSIOND | tr '\n' ' ')" | |
422 | fi | |
4c80129b | 423 | kill $kill_opt $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 424 | |
d3e8f6bb | 425 | if [ $? -eq 1 ]; then |
05aa48da MD |
426 | if [ $withtap -eq "1" ]; then |
427 | fail "Kill sessions daemon" | |
428 | fi | |
d3e8f6bb | 429 | else |
5fa32580 DG |
430 | out=1 |
431 | while [ -n "$out" ]; do | |
db7b260c | 432 | out=$(pgrep --full lt-$SESSIOND_BIN) |
5fa32580 DG |
433 | sleep 0.5 |
434 | done | |
f7613992 MD |
435 | out=1 |
436 | while [ -n "$out" ]; do | |
db7b260c | 437 | out=$(pgrep --full $CONSUMERD_BIN) |
f7613992 MD |
438 | sleep 0.5 |
439 | done | |
05aa48da MD |
440 | if [ $withtap -eq "1" ]; then |
441 | pass "Kill session daemon" | |
442 | fi | |
d3e8f6bb DG |
443 | fi |
444 | } | |
445 | ||
05aa48da MD |
446 | function stop_lttng_sessiond() |
447 | { | |
448 | stop_lttng_sessiond_opt 1 "$@" | |
449 | } | |
450 | ||
451 | function stop_lttng_sessiond_notap() | |
452 | { | |
453 | stop_lttng_sessiond_opt 0 "$@" | |
454 | } | |
455 | ||
8490897a MD |
456 | function sigstop_lttng_sessiond_opt() |
457 | { | |
458 | local withtap=$1 | |
459 | local signal=SIGSTOP | |
460 | local kill_opt="" | |
461 | ||
462 | if [ -n $TEST_NO_SESSIOND ] && [ "$TEST_NO_SESSIOND" == "1" ]; then | |
463 | # Env variable requested no session daemon | |
464 | return | |
465 | fi | |
466 | ||
19356f3a | 467 | PID_SESSIOND="$(pgrep --full lt-$SESSIOND_BIN) $(pgrep --full $RUNAS_BIN)" |
8490897a MD |
468 | |
469 | kill_opt="$kill_opt -s $signal" | |
470 | ||
471 | if [ $withtap -eq "1" ]; then | |
472 | diag "Sending SIGSTOP to lt-$SESSIOND_BIN pids: $(echo $PID_SESSIOND | tr '\n' ' ')" | |
473 | fi | |
474 | kill $kill_opt $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
475 | ||
476 | if [ $? -eq 1 ]; then | |
477 | if [ $withtap -eq "1" ]; then | |
478 | fail "Sending SIGSTOP to session daemon" | |
479 | fi | |
480 | else | |
481 | out=1 | |
482 | while [ $out -ne 0 ]; do | |
483 | pid=$(pgrep --full lt-$SESSIOND_BIN) | |
484 | ||
485 | # Wait until state becomes stopped for session | |
486 | # daemon(s). | |
487 | out=0 | |
488 | for sessiond_pid in $pid; do | |
489 | state=$(ps -p $sessiond_pid -o state= ) | |
490 | if [[ -n "$state" && "$state" != "T" ]]; then | |
491 | out=1 | |
492 | fi | |
493 | done | |
494 | sleep 0.5 | |
495 | done | |
496 | if [ $withtap -eq "1" ]; then | |
497 | pass "Sending SIGSTOP to session daemon" | |
498 | fi | |
499 | fi | |
500 | } | |
501 | ||
502 | function sigstop_lttng_sessiond() | |
503 | { | |
504 | sigstop_lttng_sessiond_opt 1 "$@" | |
505 | } | |
506 | ||
507 | function sigstop_lttng_sessiond_notap() | |
508 | { | |
509 | sigstop_lttng_sessiond_opt 0 "$@" | |
510 | } | |
511 | ||
4c80129b JR |
512 | function stop_lttng_consumerd_opt() |
513 | { | |
514 | local withtap=$1 | |
515 | local signal=$2 | |
516 | local kill_opt="" | |
517 | ||
db7b260c | 518 | PID_CONSUMERD=`pgrep --full $CONSUMERD_BIN` |
4c80129b JR |
519 | |
520 | if [ -n "$2" ]; then | |
521 | kill_opt="$kill_opt -s $signal" | |
522 | fi | |
523 | ||
524 | if [ $withtap -eq "1" ]; then | |
8490897a | 525 | diag "Killing $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')" |
4c80129b JR |
526 | fi |
527 | kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
528 | retval=$? | |
529 | set +x | |
530 | ||
531 | if [ $? -eq 1 ]; then | |
532 | if [ $withtap -eq "1" ]; then | |
533 | fail "Kill consumer daemon" | |
534 | fi | |
535 | return 1 | |
536 | else | |
537 | out=1 | |
538 | while [ $out -ne 0 ]; do | |
db7b260c | 539 | pid=$(pgrep --full $CONSUMERD_BIN) |
4c80129b JR |
540 | |
541 | # If consumerds are still present check their status. | |
542 | # A zombie status qualifies the consumerd as *killed* | |
543 | out=0 | |
544 | for consumer_pid in $pid; do | |
545 | state=$(ps -p $consumer_pid -o state= ) | |
546 | if [[ -n "$state" && "$state" != "Z" ]]; then | |
547 | out=1 | |
548 | fi | |
549 | done | |
550 | sleep 0.5 | |
551 | done | |
552 | if [ $withtap -eq "1" ]; then | |
553 | pass "Kill consumer daemon" | |
554 | fi | |
555 | fi | |
556 | return $retval | |
557 | } | |
558 | ||
559 | function stop_lttng_consumerd() | |
560 | { | |
561 | stop_lttng_consumerd_opt 1 "$@" | |
562 | } | |
563 | ||
564 | function stop_lttng_consumerd_notap() | |
565 | { | |
566 | stop_lttng_consumerd_opt 0 "$@" | |
567 | } | |
568 | ||
8490897a MD |
569 | function sigstop_lttng_consumerd_opt() |
570 | { | |
571 | local withtap=$1 | |
572 | local signal=SIGSTOP | |
573 | local kill_opt="" | |
574 | ||
575 | PID_CONSUMERD=`pgrep --full $CONSUMERD_BIN` | |
576 | ||
577 | kill_opt="$kill_opt -s $signal" | |
578 | ||
579 | if [ $withtap -eq "1" ]; then | |
580 | diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')" | |
581 | fi | |
582 | kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
583 | retval=$? | |
584 | set +x | |
585 | ||
586 | if [ $? -eq 1 ]; then | |
587 | if [ $withtap -eq "1" ]; then | |
588 | fail "Sending SIGSTOP to consumer daemon" | |
589 | fi | |
590 | return 1 | |
591 | else | |
592 | out=1 | |
593 | while [ $out -ne 0 ]; do | |
594 | pid=$(pgrep --full $CONSUMERD_BIN) | |
595 | ||
596 | # Wait until state becomes stopped for all | |
597 | # consumers. | |
598 | out=0 | |
599 | for consumer_pid in $pid; do | |
600 | state=$(ps -p $consumer_pid -o state= ) | |
601 | if [[ -n "$state" && "$state" != "T" ]]; then | |
602 | out=1 | |
603 | fi | |
604 | done | |
605 | sleep 0.5 | |
606 | done | |
607 | if [ $withtap -eq "1" ]; then | |
608 | pass "Sending SIGSTOP to consumer daemon" | |
609 | fi | |
610 | fi | |
611 | return $retval | |
612 | } | |
613 | ||
614 | function sigstop_lttng_consumerd() | |
615 | { | |
616 | sigstop_lttng_consumerd_opt 1 "$@" | |
617 | } | |
618 | ||
619 | function sigstop_lttng_consumerd_notap() | |
620 | { | |
621 | sigstop_lttng_consumerd_opt 0 "$@" | |
622 | } | |
623 | ||
873c2aae JRJ |
624 | function list_lttng_with_opts () |
625 | { | |
7d0ad314 | 626 | local opts=$1 |
2cf48300 | 627 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
873c2aae JRJ |
628 | ok $? "Lttng-tool list command with option $opts" |
629 | } | |
630 | ||
07b86b52 JD |
631 | function create_lttng_session_no_output () |
632 | { | |
7d0ad314 | 633 | local sess_name=$1 |
07b86b52 | 634 | |
2cf48300 | 635 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
07b86b52 JD |
636 | ok $? "Create session $sess_name in no-output mode" |
637 | } | |
638 | ||
d3e8f6bb DG |
639 | function create_lttng_session () |
640 | { | |
bf6ae429 JR |
641 | local expected_to_fail=$1 |
642 | local sess_name=$2 | |
643 | local trace_path=$3 | |
4c80129b | 644 | local opt=$4 |
d3e8f6bb | 645 | |
4c80129b | 646 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path $opt > $OUTPUT_DEST |
873c2aae | 647 | ret=$? |
bf6ae429 | 648 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 649 | test "$ret" -ne "0" |
34ab15c5 | 650 | ok $? "Create session $sess_name in $trace_path failed as expected" |
873c2aae JRJ |
651 | else |
652 | ok $ret "Create session $sess_name in $trace_path" | |
653 | fi | |
d4018451 DG |
654 | } |
655 | ||
bf6ae429 JR |
656 | function create_lttng_session_ok () |
657 | { | |
658 | create_lttng_session 0 "$@" | |
659 | } | |
660 | ||
661 | function create_lttng_session_fail () | |
662 | { | |
663 | create_lttng_session 1 "$@" | |
664 | } | |
665 | ||
666 | ||
827caf52 | 667 | function enable_ust_lttng_channel () |
d4018451 | 668 | { |
34ab15c5 | 669 | local expected_to_fail=$1 |
827caf52 JR |
670 | local sess_name=$2 |
671 | local channel_name=$3 | |
4c80129b | 672 | local opt=$4 |
d4018451 | 673 | |
4c80129b | 674 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
312dabc3 | 675 | ret=$? |
34ab15c5 | 676 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 677 | test "$ret" -ne "0" |
34ab15c5 | 678 | ok $? "Enable channel $channel_name for session $sess_name failed as expected" |
312dabc3 JRJ |
679 | else |
680 | ok $ret "Enable channel $channel_name for session $sess_name" | |
681 | fi | |
d4018451 DG |
682 | } |
683 | ||
827caf52 JR |
684 | function enable_ust_lttng_channel_ok () |
685 | { | |
686 | enable_ust_lttng_channel 0 "$@" | |
687 | } | |
688 | ||
689 | function enable_ust_lttng_channel_fail () | |
690 | { | |
691 | enable_ust_lttng_channel 1 "$@" | |
692 | } | |
693 | ||
29655db7 | 694 | function disable_ust_lttng_channel() |
d4018451 | 695 | { |
7d0ad314 JRJ |
696 | local sess_name=$1 |
697 | local channel_name=$2 | |
d4018451 | 698 | |
2cf48300 | 699 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 700 | ok $? "Disable channel $channel_name for session $sess_name" |
d3e8f6bb DG |
701 | } |
702 | ||
07b86b52 JD |
703 | function enable_lttng_mmap_overwrite_kernel_channel() |
704 | { | |
7d0ad314 JRJ |
705 | local sess_name=$1 |
706 | local channel_name=$2 | |
07b86b52 | 707 | |
2cf48300 | 708 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
07b86b52 JD |
709 | ok $? "Enable channel $channel_name for session $sess_name" |
710 | } | |
711 | ||
ebaaaf5e JD |
712 | function enable_lttng_mmap_overwrite_ust_channel() |
713 | { | |
7d0ad314 JRJ |
714 | local sess_name=$1 |
715 | local channel_name=$2 | |
ebaaaf5e | 716 | |
2cf48300 | 717 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -u --output mmap --overwrite 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
ebaaaf5e JD |
718 | ok $? "Enable channel $channel_name for session $sess_name" |
719 | } | |
720 | ||
d3e8f6bb DG |
721 | function enable_ust_lttng_event () |
722 | { | |
c4926bb5 JR |
723 | local expected_to_fail=$1 |
724 | local sess_name=$2 | |
725 | local event_name="$3" | |
726 | local channel_name=$4 | |
ebaaaf5e JD |
727 | |
728 | if [ -z $channel_name ]; then | |
729 | # default channel if none specified | |
730 | chan="" | |
731 | else | |
732 | chan="-c $channel_name" | |
733 | fi | |
d3e8f6bb | 734 | |
2cf48300 | 735 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 736 | ret=$? |
c4926bb5 | 737 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 738 | test $ret -ne "0" |
34ab15c5 | 739 | ok $? "Enable ust event $event_name for session $session_name failed as expected" |
01513c3e | 740 | else |
34ab15c5 | 741 | ok $ret "Enable ust event $event_name for session $sess_name" |
01513c3e | 742 | fi |
26b53d3b DG |
743 | } |
744 | ||
c4926bb5 JR |
745 | function enable_ust_lttng_event_ok () |
746 | { | |
747 | enable_ust_lttng_event 0 "$@" | |
748 | } | |
749 | ||
750 | function enable_ust_lttng_event_fail () | |
751 | { | |
752 | enable_ust_lttng_event 1 "$@" | |
753 | } | |
754 | ||
37175ce4 DG |
755 | function enable_jul_lttng_event() |
756 | { | |
757 | sess_name=$1 | |
758 | event_name="$2" | |
759 | channel_name=$3 | |
760 | ||
761 | if [ -z $channel_name ]; then | |
762 | # default channel if none specified | |
763 | chan="" | |
764 | else | |
765 | chan="-c $channel_name" | |
766 | fi | |
767 | ||
2cf48300 | 768 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
37175ce4 DG |
769 | ok $? "Enable JUL event $event_name for session $sess_name" |
770 | } | |
771 | ||
b2064f54 DG |
772 | function enable_jul_lttng_event_loglevel() |
773 | { | |
7d0ad314 JRJ |
774 | local sess_name=$1 |
775 | local event_name="$2" | |
776 | local loglevel=$3 | |
777 | local channel_name=$4 | |
b2064f54 DG |
778 | |
779 | if [ -z $channel_name ]; then | |
780 | # default channel if none specified | |
781 | chan="" | |
782 | else | |
783 | chan="-c $channel_name" | |
784 | fi | |
785 | ||
2cf48300 | 786 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
b2064f54 DG |
787 | ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel" |
788 | } | |
789 | ||
504d4ace DG |
790 | function enable_log4j_lttng_event() |
791 | { | |
792 | sess_name=$1 | |
793 | event_name="$2" | |
794 | channel_name=$3 | |
795 | ||
796 | if [ -z $channel_name ]; then | |
797 | # default channel if none specified | |
798 | chan="" | |
799 | else | |
800 | chan="-c $channel_name" | |
801 | fi | |
802 | ||
2cf48300 | 803 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
504d4ace DG |
804 | ok $? "Enable LOG4J event $event_name for session $sess_name" |
805 | } | |
806 | ||
807 | function enable_log4j_lttng_event_loglevel() | |
808 | { | |
809 | local sess_name=$1 | |
810 | local event_name="$2" | |
811 | local loglevel=$3 | |
812 | local channel_name=$4 | |
813 | ||
814 | if [ -z $channel_name ]; then | |
815 | # default channel if none specified | |
816 | chan="" | |
817 | else | |
818 | chan="-c $channel_name" | |
819 | fi | |
820 | ||
2cf48300 | 821 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
504d4ace DG |
822 | ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel" |
823 | } | |
824 | ||
0e115563 DG |
825 | function enable_python_lttng_event() |
826 | { | |
827 | sess_name=$1 | |
828 | event_name="$2" | |
829 | channel_name=$3 | |
830 | ||
831 | if [ -z $channel_name ]; then | |
832 | # default channel if none specified | |
833 | chan="" | |
834 | else | |
835 | chan="-c $channel_name" | |
836 | fi | |
837 | ||
2cf48300 | 838 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
0e115563 DG |
839 | ok $? "Enable Python event $event_name for session $sess_name" |
840 | } | |
841 | ||
842 | function enable_python_lttng_event_loglevel() | |
843 | { | |
844 | local sess_name=$1 | |
845 | local event_name="$2" | |
846 | local loglevel=$3 | |
847 | local channel_name=$4 | |
848 | ||
849 | if [ -z $channel_name ]; then | |
850 | # default channel if none specified | |
851 | chan="" | |
852 | else | |
853 | chan="-c $channel_name" | |
854 | fi | |
855 | ||
2cf48300 | 856 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
0e115563 DG |
857 | ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel" |
858 | } | |
859 | ||
26b53d3b DG |
860 | function enable_ust_lttng_event_filter() |
861 | { | |
7d0ad314 JRJ |
862 | local sess_name="$1" |
863 | local event_name="$2" | |
864 | local filter="$3" | |
26b53d3b | 865 | |
2cf48300 | 866 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 867 | ok $? "Enable event $event_name with filtering for session $sess_name" |
26b53d3b DG |
868 | } |
869 | ||
870 | function enable_ust_lttng_event_loglevel() | |
871 | { | |
7d0ad314 JRJ |
872 | local sess_name="$1" |
873 | local event_name="$2" | |
874 | local loglevel="$3" | |
26b53d3b | 875 | |
2cf48300 | 876 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 877 | ok $? "Enable event $event_name with loglevel $loglevel" |
26b53d3b DG |
878 | } |
879 | ||
880 | function enable_ust_lttng_event_loglevel_only() | |
881 | { | |
7d0ad314 JRJ |
882 | local sess_name="$1" |
883 | local event_name="$2" | |
884 | local loglevel="$3" | |
26b53d3b | 885 | |
2cf48300 | 886 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 887 | ok $? "Enable event $event_name with loglevel-only $loglevel" |
26b53d3b DG |
888 | } |
889 | ||
890 | function disable_ust_lttng_event () | |
891 | { | |
7d0ad314 JRJ |
892 | local sess_name="$1" |
893 | local event_name="$2" | |
01513c3e | 894 | local channel_name="$3" |
26b53d3b | 895 | |
01513c3e JRJ |
896 | if [ -z $channel_name ]; then |
897 | # default channel if none specified | |
898 | chan="" | |
899 | else | |
900 | chan="-c $channel_name" | |
901 | fi | |
902 | ||
2cf48300 | 903 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 904 | ok $? "Disable event $event_name for session $sess_name" |
d3e8f6bb DG |
905 | } |
906 | ||
1d842d5a DG |
907 | function disable_jul_lttng_event () |
908 | { | |
909 | local sess_name="$1" | |
910 | local event_name="$2" | |
911 | ||
912 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1 | |
913 | ok $? "Disable JUL event $event_name for session $sess_name" | |
914 | } | |
915 | ||
504d4ace DG |
916 | function disable_log4j_lttng_event () |
917 | { | |
918 | local sess_name="$1" | |
919 | local event_name="$2" | |
920 | ||
921 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1 | |
922 | ok $? "Disable LOG4J event $event_name for session $sess_name" | |
923 | } | |
924 | ||
0e115563 DG |
925 | function disable_python_lttng_event () |
926 | { | |
927 | local sess_name="$1" | |
928 | local event_name="$2" | |
929 | ||
2cf48300 | 930 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
0e115563 DG |
931 | ok $? "Disable Python event $event_name for session $sess_name" |
932 | } | |
933 | ||
fb3268e3 | 934 | function start_lttng_tracing () |
d3e8f6bb | 935 | { |
e563bbdb JR |
936 | local expected_to_fail=$1 |
937 | local sess_name=$2 | |
d3e8f6bb | 938 | |
2cf48300 | 939 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 940 | ret=$? |
e563bbdb | 941 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 942 | test "$ret" -ne "0" |
34ab15c5 | 943 | ok $? "Start tracing for session $sess_name failed as expected" |
01513c3e JRJ |
944 | else |
945 | ok $ret "Start tracing for session $sess_name" | |
946 | fi | |
d3e8f6bb DG |
947 | } |
948 | ||
e563bbdb JR |
949 | function start_lttng_tracing_ok () |
950 | { | |
951 | start_lttng_tracing 0 "$@" | |
952 | } | |
953 | ||
954 | function start_lttng_tracing_fail () | |
955 | { | |
956 | start_lttng_tracing 1 "$@" | |
957 | } | |
958 | ||
fb3268e3 | 959 | function stop_lttng_tracing () |
d3e8f6bb | 960 | { |
96340a01 JR |
961 | local expected_to_fail=$1 |
962 | local sess_name=$2 | |
d3e8f6bb | 963 | |
2cf48300 | 964 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 965 | ret=$? |
96340a01 | 966 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 967 | test "$ret" -ne "0" |
34ab15c5 | 968 | ok $? "Stop lttng tracing for session $sess_name failed as expected" |
01513c3e JRJ |
969 | else |
970 | ok $ret "Stop lttng tracing for session $sess_name" | |
971 | fi | |
d3e8f6bb DG |
972 | } |
973 | ||
96340a01 JR |
974 | function stop_lttng_tracing_ok () |
975 | { | |
976 | stop_lttng_tracing 0 "$@" | |
977 | } | |
978 | ||
979 | function stop_lttng_tracing_fail () | |
980 | { | |
981 | stop_lttng_tracing 1 "$@" | |
982 | } | |
983 | ||
d3e8f6bb DG |
984 | function destroy_lttng_session () |
985 | { | |
67b4c664 JR |
986 | local expected_to_fail=$1 |
987 | local sess_name=$2 | |
d3e8f6bb | 988 | |
2cf48300 | 989 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 990 | ret=$? |
96340a01 | 991 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 992 | test "$ret" -ne "0" |
34ab15c5 | 993 | ok $? "Destroy session $sess_name failed as expected" |
01513c3e JRJ |
994 | else |
995 | ok $ret "Destroy session $sess_name" | |
996 | fi | |
d3e8f6bb DG |
997 | } |
998 | ||
67b4c664 JR |
999 | function destroy_lttng_session_ok () |
1000 | { | |
1001 | destroy_lttng_session 0 "$@" | |
1002 | ||
1003 | } | |
1004 | ||
1005 | function destroy_lttng_session_fail () | |
1006 | { | |
1007 | destroy_lttng_session 1 "$@" | |
1008 | } | |
1009 | ||
1010 | ||
873c2aae JRJ |
1011 | function destroy_lttng_sessions () |
1012 | { | |
2cf48300 | 1013 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
873c2aae JRJ |
1014 | ok $? "Destroy all lttng sessions" |
1015 | } | |
1016 | ||
07b86b52 JD |
1017 | function lttng_snapshot_add_output () |
1018 | { | |
b5633831 JR |
1019 | local expected_to_fail=$1 |
1020 | local sess_name=$2 | |
1021 | local trace_path=$3 | |
07b86b52 | 1022 | |
2cf48300 | 1023 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1024 | ret=$? |
b5633831 | 1025 | if [[ $expected_to_fail -eq 1 ]]; then |
01513c3e | 1026 | test "$ret" -ne "0" |
34ab15c5 | 1027 | ok $? "Added snapshot output file://$trace_path failed as expected" |
01513c3e JRJ |
1028 | else |
1029 | ok $ret "Added snapshot output file://$trace_path" | |
1030 | fi | |
07b86b52 JD |
1031 | } |
1032 | ||
b5633831 JR |
1033 | function lttng_snapshot_add_output_ok () |
1034 | { | |
1035 | lttng_snapshot_add_output 0 "$@" | |
1036 | } | |
1037 | ||
1038 | function lttng_snapshot_add_output_fail () | |
1039 | { | |
1040 | lttng_snapshot_add_output 1 "$@" | |
1041 | } | |
1042 | ||
26402e0c DG |
1043 | function lttng_snapshot_del_output () |
1044 | { | |
31580dc7 JR |
1045 | local expected_to_fail=$1 |
1046 | local sess_name=$2 | |
1047 | local id=$3 | |
26402e0c | 1048 | |
2cf48300 | 1049 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1050 | ret=$? |
31580dc7 | 1051 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1052 | test "$ret" -ne "0" |
34ab15c5 | 1053 | ok $? "Deleted snapshot output id $id failed as expected" |
01513c3e JRJ |
1054 | else |
1055 | ok $ret "Deleted snapshot output id $id" | |
1056 | fi | |
26402e0c DG |
1057 | } |
1058 | ||
31580dc7 JR |
1059 | function lttng_snapshot_del_output_ok () |
1060 | { | |
1061 | lttng_snapshot_del_output 0 "$@" | |
1062 | } | |
1063 | ||
1064 | function lttng_snapshot_del_output_fail () | |
1065 | { | |
1066 | lttng_snapshot_del_output 1 "$@" | |
1067 | } | |
1068 | ||
07b86b52 JD |
1069 | function lttng_snapshot_record () |
1070 | { | |
7d0ad314 JRJ |
1071 | local sess_name=$1 |
1072 | local trace_path=$2 | |
07b86b52 | 1073 | |
2cf48300 | 1074 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
07b86b52 JD |
1075 | ok $? "Snapshot recorded" |
1076 | } | |
1077 | ||
01513c3e JRJ |
1078 | function lttng_snapshot_list () |
1079 | { | |
1080 | local sess_name=$1 | |
2cf48300 | 1081 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e JRJ |
1082 | ok $? "Snapshot list" |
1083 | } | |
1084 | ||
e02b109b DG |
1085 | function lttng_save() |
1086 | { | |
1087 | local sess_name=$1 | |
1088 | local opts=$2 | |
1089 | ||
2cf48300 | 1090 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
34ab15c5 | 1091 | ok $? "Session saved" |
e02b109b DG |
1092 | } |
1093 | ||
1094 | function lttng_load() | |
1095 | { | |
1096 | local opts=$1 | |
1097 | ||
2cf48300 | 1098 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
34ab15c5 | 1099 | ok $? "Load command with opts: $opts" |
e02b109b DG |
1100 | } |
1101 | ||
e83a8bdb JR |
1102 | function lttng_track() |
1103 | { | |
1104 | local expected_to_fail=$1 | |
1105 | local opts=$2 | |
1106 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST | |
1107 | ret=$? | |
1108 | if [[ $expected_to_fail -eq "1" ]]; then | |
1109 | test $ret -ne "0" | |
1110 | ok $? "Track command failed as expected with opts: $opts" | |
1111 | else | |
34ab15c5 | 1112 | ok $ret "Track command with opts: $opts" |
e83a8bdb JR |
1113 | fi |
1114 | } | |
1115 | ||
1116 | function lttng_track_ok() | |
1117 | { | |
1118 | lttng_track 0 "$@" | |
1119 | } | |
1120 | ||
1121 | function lttng_track_fail() | |
1122 | { | |
1123 | lttng_track 1 "$@" | |
1124 | } | |
1125 | ||
1126 | function lttng_untrack() | |
1127 | { | |
1128 | local expected_to_fail=$1 | |
1129 | local opts=$2 | |
1130 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST | |
1131 | ret=$? | |
1132 | if [[ $expected_to_fail -eq "1" ]]; then | |
1133 | test $ret -ne "0" | |
1134 | ok $? "Untrack command failed as expected with opts: $opts" | |
1135 | else | |
34ab15c5 | 1136 | ok $ret "Untrack command with opts: $opts" |
e83a8bdb JR |
1137 | fi |
1138 | } | |
1139 | ||
1140 | function lttng_untrack_ok() | |
1141 | { | |
1142 | lttng_untrack 0 "$@" | |
1143 | } | |
1144 | ||
1145 | function lttng_untrack_fail() | |
1146 | { | |
1147 | lttng_untrack 1 "$@" | |
1148 | } | |
1149 | ||
8dcef147 JR |
1150 | function add_context_lttng() |
1151 | { | |
1152 | local expected_to_fail="$1" | |
1153 | local domain="$2" | |
1154 | local session_name="$3" | |
1155 | local channel_name="$4" | |
1156 | local type="$5" | |
1157 | ||
1158 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1159 | ret=$? | |
1160 | if [[ $expected_to_fail -eq "1" ]]; then | |
1161 | test $ret -ne "0" | |
1162 | ok $? "Add context command failed as expected for type: $type" | |
1163 | else | |
1164 | ok $ret "Add context command for type: $type" | |
1165 | fi | |
1166 | } | |
1167 | ||
1168 | function add_context_ust_ok() | |
1169 | { | |
1170 | add_context_lttng 0 -u "$@" | |
1171 | } | |
1172 | ||
1173 | function add_context_ust_fail() | |
1174 | { | |
1175 | add_context_lttng 1 -u "$@" | |
1176 | } | |
1177 | ||
1178 | function add_context_kernel_ok() | |
1179 | { | |
1180 | add_context_lttng 0 -k "$@" | |
1181 | } | |
1182 | ||
1183 | function add_context_kernel_fail() | |
1184 | { | |
1185 | add_context_lttng 1 -k "$@" | |
1186 | } | |
1187 | ||
d3e8f6bb DG |
1188 | function trace_matches () |
1189 | { | |
7d0ad314 JRJ |
1190 | local event_name=$1 |
1191 | local nr_iter=$2 | |
1192 | local trace_path=$3 | |
d3e8f6bb | 1193 | |
317eef93 | 1194 | which $BABELTRACE_BIN >/dev/null |
29655db7 | 1195 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" |
d3e8f6bb | 1196 | |
7d0ad314 | 1197 | local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) |
29655db7 | 1198 | |
d3e8f6bb | 1199 | if [ "$count" -ne "$nr_iter" ]; then |
29655db7 CB |
1200 | fail "Trace match" |
1201 | diag "$count events found in trace" | |
d3e8f6bb | 1202 | else |
29655db7 | 1203 | pass "Trace match" |
d3e8f6bb DG |
1204 | fi |
1205 | } | |
f4e40ab6 | 1206 | |
d53addeb DG |
1207 | function trace_match_only() |
1208 | { | |
1209 | local event_name=$1 | |
1210 | local nr_iter=$2 | |
1211 | local trace_path=$3 | |
1212 | ||
1213 | which $BABELTRACE_BIN >/dev/null | |
1214 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" | |
1215 | ||
1216 | local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) | |
1217 | local total=$($BABELTRACE_BIN $trace_path | wc -l) | |
1218 | ||
1219 | if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then | |
1220 | pass "Trace match with $total event $event_name" | |
1221 | else | |
1222 | fail "Trace match" | |
1223 | diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count" | |
1224 | fi | |
1225 | } | |
1226 | ||
f4e40ab6 DG |
1227 | function validate_trace |
1228 | { | |
7d0ad314 JRJ |
1229 | local event_name=$1 |
1230 | local trace_path=$2 | |
f4e40ab6 DG |
1231 | |
1232 | which $BABELTRACE_BIN >/dev/null | |
29655db7 CB |
1233 | if [ $? -ne 0 ]; then |
1234 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
f4e40ab6 DG |
1235 | fi |
1236 | ||
07b86b52 JD |
1237 | OLDIFS=$IFS |
1238 | IFS="," | |
1239 | for i in $event_name; do | |
1240 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) | |
1241 | if [ "$traced" -ne 0 ]; then | |
ebaaaf5e | 1242 | pass "Validate trace for event $i, $traced events" |
07b86b52 JD |
1243 | else |
1244 | fail "Validate trace for event $i" | |
1245 | diag "Found $traced occurences of $i" | |
1246 | fi | |
1247 | done | |
1248 | ret=$? | |
1249 | IFS=$OLDIFS | |
1250 | return $ret | |
f4e40ab6 | 1251 | } |
8cfcd41c MD |
1252 | |
1253 | function validate_trace_exp() | |
1254 | { | |
1255 | local event_exp=$1 | |
1256 | local trace_path=$2 | |
1257 | ||
1258 | which $BABELTRACE_BIN >/dev/null | |
1259 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation" | |
1260 | ||
1261 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l) | |
1262 | if [ "$traced" -ne 0 ]; then | |
1263 | pass "Validate trace for expression '${event_exp}', $traced events" | |
1264 | else | |
1265 | fail "Validate trace for expression '${event_exp}'" | |
1266 | diag "Found $traced occurences of '${event_exp}'" | |
1267 | fi | |
1268 | ret=$? | |
1269 | return $ret | |
1270 | } | |
1271 | ||
1272 | function validate_trace_only_exp() | |
1273 | { | |
1274 | local event_exp=$1 | |
1275 | local trace_path=$2 | |
1276 | ||
1277 | which $BABELTRACE_BIN >/dev/null | |
1278 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" | |
1279 | ||
1280 | local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l) | |
1281 | local total=$($BABELTRACE_BIN $trace_path | wc -l) | |
1282 | ||
1283 | if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then | |
1284 | pass "Trace match with $total for expression '${event_exp}" | |
1285 | else | |
1286 | fail "Trace match" | |
1287 | diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected" | |
1288 | fi | |
1289 | ret=$? | |
1290 | return $ret | |
1291 | } | |
1292 | ||
1293 | function validate_trace_empty() | |
1294 | { | |
1295 | local trace_path=$1 | |
1296 | ||
1297 | which $BABELTRACE_BIN >/dev/null | |
1298 | if [ $? -ne 0 ]; then | |
1299 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
1300 | fi | |
1301 | ||
1302 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l) | |
1303 | if [ "$traced" -eq 0 ]; then | |
1304 | pass "Validate empty trace" | |
1305 | else | |
1306 | fail "Validate empty trace" | |
1307 | diag "Found $traced events in trace" | |
1308 | fi | |
1309 | ret=$? | |
1310 | return $ret | |
1311 | } | |
801236b0 JD |
1312 | |
1313 | function metadata_regenerate () | |
1314 | { | |
1315 | local expected_to_fail=$1 | |
1316 | local sess_name=$2 | |
1317 | ||
1318 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN metadata regenerate -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1319 | ret=$? | |
1320 | if [[ $expected_to_fail -eq "1" ]]; then | |
1321 | test "$ret" -ne "0" | |
1322 | ok $? "Expected fail on regenerate $sess_name" | |
1323 | else | |
1324 | ok $ret "Metadata regenerate $sess_name" | |
1325 | fi | |
1326 | } | |
1327 | ||
1328 | function metadata_regenerate_ok () | |
1329 | { | |
1330 | metadata_regenerate 0 "$@" | |
1331 | } | |
1332 | ||
1333 | function metadata_regenerate_fail () | |
1334 | { | |
1335 | metadata_regenerate 1 "$@" | |
1336 | } | |
512eb148 JD |
1337 | |
1338 | function destructive_tests_enabled () | |
1339 | { | |
1340 | if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then | |
1341 | return 0 | |
1342 | else | |
1343 | return 1 | |
1344 | fi | |
1345 | } |