Commit | Line | Data |
---|---|---|
d3e8f6bb DG |
1 | # Copyright (C) - 2012 David Goulet <dgoulet@efficios.com> |
2 | # | |
3 | # This library is free software; you can redistribute it and/or modify it under | |
4 | # the terms of the GNU Lesser General Public License as published by the Free | |
5 | # Software Foundation; version 2.1 of the License. | |
6 | # | |
7 | # This library is distributed in the hope that it will be useful, but WITHOUT | |
8 | # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | |
9 | # FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more | |
10 | # details. | |
11 | # | |
12 | # You should have received a copy of the GNU Lesser General Public License | |
13 | # along with this library; if not, write to the Free Software Foundation, Inc., | |
14 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA | |
15 | ||
16 | SESSIOND_BIN="lttng-sessiond" | |
725f658e | 17 | SESSIOND_MATCH=".*lttng-sess.*" |
19356f3a | 18 | RUNAS_BIN="lttng-runas" |
725f658e | 19 | RUNAS_MATCH=".*lttng-runas.*" |
f7613992 | 20 | CONSUMERD_BIN="lttng-consumerd" |
725f658e | 21 | CONSUMERD_MATCH=".*lttng-consumerd.*" |
f4e40ab6 | 22 | RELAYD_BIN="lttng-relayd" |
725f658e | 23 | RELAYD_MATCH=".*lttng-relayd.*" |
d3e8f6bb DG |
24 | LTTNG_BIN="lttng" |
25 | BABELTRACE_BIN="babeltrace" | |
2cf48300 JR |
26 | OUTPUT_DEST=/dev/null |
27 | ERROR_OUTPUT_DEST=/dev/null | |
d3e8f6bb | 28 | |
fd4dfcec DG |
29 | # Minimal kernel version supported for session daemon tests |
30 | KERNEL_MAJOR_VERSION=2 | |
31 | KERNEL_MINOR_VERSION=6 | |
32 | KERNEL_PATCHLEVEL_VERSION=27 | |
33 | ||
651b8bb3 JG |
34 | # We set the default UST register timeout and network and app socket timeout to |
35 | # "wait forever", so that basic tests don't have to worry about hitting | |
36 | # timeouts on busy systems. Specialized tests should test those corner-cases. | |
629b9335 | 37 | export LTTNG_UST_REGISTER_TIMEOUT=-1 |
651b8bb3 JG |
38 | export LTTNG_NETWORK_SOCKET_TIMEOUT=-1 |
39 | export LTTNG_APP_SOCKET_TIMEOUT=-1 | |
629b9335 | 40 | |
fd7fe1a8 JR |
41 | # We set the default lttng-sessiond path to /bin/true to prevent the spawning |
42 | # of a daemonized sessiond. This is necessary since 'lttng create' will spawn | |
43 | # its own sessiond if none is running. It also ensures that 'lttng create' | |
44 | # fails when no sessiond is running. | |
45 | export LTTNG_SESSIOND_PATH="/bin/true" | |
46 | ||
29655db7 CB |
47 | source $TESTDIR/utils/tap/tap.sh |
48 | ||
c70fe895 | 49 | if [ -z ${LTTNG_TEST_TEARDOWN_TIMEOUT+x} ]; then |
74a6c3f5 MD |
50 | LTTNG_TEST_TEARDOWN_TIMEOUT=60 |
51 | fi | |
52 | ||
1c362dc7 JR |
53 | function full_cleanup () |
54 | { | |
74a6c3f5 MD |
55 | # Try to kill daemons gracefully |
56 | stop_lttng_relayd_notap SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT | |
57 | stop_lttng_sessiond_notap SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT | |
58 | ||
59 | # If daemons are still present, forcibly kill them | |
60 | stop_lttng_relayd_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT | |
61 | stop_lttng_sessiond_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT | |
62 | stop_lttng_consumerd_notap SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT | |
1c362dc7 JR |
63 | |
64 | # Disable trap for SIGTERM since the following kill to the | |
65 | # pidgroup will be SIGTERM. Otherwise it loops. | |
66 | # The '-' before the pid number ($$) indicates 'kill' to signal the | |
67 | # whole process group. | |
68 | trap - SIGTERM && kill -- -$$ | |
ef001e78 | 69 | exit 1 |
1c362dc7 JR |
70 | } |
71 | ||
ad7b9fd5 MD |
72 | function null_pipes () |
73 | { | |
74 | exec 0>/dev/null | |
75 | exec 1>/dev/null | |
76 | exec 2>/dev/null | |
77 | } | |
1c362dc7 JR |
78 | |
79 | trap full_cleanup SIGINT SIGTERM | |
80 | ||
ad7b9fd5 MD |
81 | # perl prove closes its child pipes before giving it a chance to run its |
82 | # signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught | |
83 | # to allow those trap handlers to proceed. | |
84 | ||
85 | trap null_pipes SIGPIPE | |
86 | ||
fec81a7e CB |
87 | function print_ok () |
88 | { | |
89 | # Check if we are a terminal | |
90 | if [ -t 1 ]; then | |
91 | echo -e "\e[1;32mOK\e[0m" | |
92 | else | |
93 | echo -e "OK" | |
94 | fi | |
95 | } | |
96 | ||
97 | function print_fail () | |
98 | { | |
99 | # Check if we are a terminal | |
100 | if [ -t 1 ]; then | |
101 | echo -e "\e[1;31mFAIL\e[0m" | |
102 | else | |
103 | echo -e "FAIL" | |
104 | fi | |
105 | } | |
106 | ||
107 | function print_test_banner () | |
108 | { | |
7d0ad314 | 109 | local desc="$1" |
29655db7 | 110 | diag "$desc" |
fec81a7e CB |
111 | } |
112 | ||
fd4dfcec DG |
113 | function validate_kernel_version () |
114 | { | |
7d0ad314 | 115 | local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) |
fd4dfcec DG |
116 | if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then |
117 | return 0 | |
118 | fi | |
119 | if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then | |
120 | return 0 | |
121 | fi | |
122 | if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then | |
123 | return 0 | |
124 | fi | |
125 | return 1 | |
126 | } | |
127 | ||
9ac429ef | 128 | # Generate a random string |
f4e40ab6 DG |
129 | # $1 = number of characters; defaults to 16 |
130 | # $2 = include special characters; 1 = yes, 0 = no; defaults to yes | |
9ac429ef | 131 | function randstring() |
f4e40ab6 DG |
132 | { |
133 | [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]" | |
b89c3a68 | 134 | cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null |
f4e40ab6 DG |
135 | echo |
136 | } | |
137 | ||
9e136324 JG |
138 | # Return the number of _configured_ CPUs. |
139 | function conf_proc_count() | |
140 | { | |
141 | getconf _NPROCESSORS_CONF | |
142 | if [ $? -ne 0 ]; then | |
143 | diag "Failed to get the number of configured CPUs" | |
144 | fi | |
145 | echo | |
146 | } | |
147 | ||
f637036a JR |
148 | # Check if base lttng-modules are present. |
149 | # Bail out on failure | |
150 | function validate_lttng_modules_present () | |
151 | { | |
152 | modprobe -n lttng-tracer 2>/dev/null | |
153 | if [ $? -ne 0 ]; then | |
154 | BAIL_OUT "LTTng modules not detected." | |
155 | fi | |
156 | } | |
157 | ||
4a180d9f | 158 | function enable_kernel_lttng_event |
f4e40ab6 | 159 | { |
60c78fd5 JR |
160 | local withtap="$1" |
161 | local expected_to_fail="$2" | |
162 | local sess_name="$3" | |
163 | local event_name="$4" | |
164 | local channel_name="$5" | |
f4e40ab6 | 165 | |
4a180d9f | 166 | if [ -z "$event_name" ]; then |
f4e40ab6 | 167 | # Enable all event if no event name specified |
29655db7 | 168 | event_name="-a" |
f4e40ab6 DG |
169 | fi |
170 | ||
4a180d9f | 171 | if [ -z "$channel_name" ]; then |
07b86b52 JD |
172 | # default channel if none specified |
173 | chan="" | |
174 | else | |
175 | chan="-c $channel_name" | |
176 | fi | |
177 | ||
2cf48300 | 178 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -k 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
4a180d9f MD |
179 | ret=$? |
180 | if [[ $expected_to_fail -eq "1" ]]; then | |
181 | test $ret -ne "0" | |
60c78fd5 JR |
182 | ret=$? |
183 | if [ $withtap -eq "1" ]; then | |
184 | ok $ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected" | |
185 | fi | |
4a180d9f | 186 | else |
60c78fd5 JR |
187 | if [ $withtap -eq "1" ]; then |
188 | ok $ret "Enable kernel event $event_name for session $sess_name" | |
189 | fi | |
4a180d9f MD |
190 | fi |
191 | } | |
192 | ||
193 | function enable_kernel_lttng_event_ok () | |
194 | { | |
60c78fd5 | 195 | enable_kernel_lttng_event 1 0 "$@" |
4a180d9f MD |
196 | } |
197 | ||
198 | function enable_kernel_lttng_event_fail () | |
199 | { | |
60c78fd5 JR |
200 | enable_kernel_lttng_event 1 1 "$@" |
201 | } | |
202 | ||
203 | function enable_kernel_lttng_event_notap () | |
204 | { | |
205 | enable_kernel_lttng_event 0 0 "$@" | |
4a180d9f MD |
206 | } |
207 | ||
208 | # Old interface | |
209 | function lttng_enable_kernel_event | |
210 | { | |
211 | enable_kernel_lttng_event_ok "$@" | |
f4e40ab6 DG |
212 | } |
213 | ||
8cfcd41c MD |
214 | function lttng_enable_kernel_syscall() |
215 | { | |
216 | local expected_to_fail=$1 | |
217 | local sess_name=$2 | |
218 | local syscall_name=$3 | |
219 | local channel_name=$4 | |
220 | ||
221 | if [ -z $syscall_name ]; then | |
222 | # Enable all event if no syscall name specified | |
223 | syscall_name="-a" | |
224 | fi | |
225 | ||
226 | if [ -z $channel_name ]; then | |
227 | # default channel if none specified | |
228 | chan="" | |
229 | else | |
230 | chan="-c $channel_name" | |
231 | fi | |
232 | ||
2cf48300 | 233 | $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 |
234 | ret=$? |
235 | if [[ $expected_to_fail -eq "1" ]]; then | |
236 | test $ret -ne "0" | |
237 | ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected" | |
238 | else | |
239 | ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name" | |
240 | fi | |
241 | } | |
242 | ||
243 | function lttng_enable_kernel_syscall_ok() | |
244 | { | |
421b83dc | 245 | lttng_enable_kernel_syscall 0 "$@" |
8cfcd41c MD |
246 | } |
247 | ||
248 | function lttng_enable_kernel_syscall_fail() | |
249 | { | |
421b83dc | 250 | lttng_enable_kernel_syscall 1 "$@" |
8cfcd41c MD |
251 | } |
252 | ||
253 | function lttng_disable_kernel_syscall() | |
254 | { | |
255 | local expected_to_fail=$1 | |
256 | local sess_name=$2 | |
257 | local syscall_name=$3 | |
258 | local channel_name=$4 | |
259 | ||
260 | if [ -z $syscall_name ]; then | |
261 | # Enable all event if no syscall name specified | |
262 | syscall_name="-a" | |
263 | fi | |
264 | ||
265 | if [ -z $channel_name ]; then | |
266 | # default channel if none specified | |
267 | chan="" | |
268 | else | |
269 | chan="-c $channel_name" | |
270 | fi | |
271 | ||
2cf48300 | 272 | $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 |
273 | |
274 | ret=$? | |
275 | if [[ $expected_to_fail -eq "1" ]]; then | |
276 | test $ret -ne "0" | |
34ab15c5 | 277 | ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected" |
8cfcd41c MD |
278 | else |
279 | ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name" | |
280 | fi | |
281 | } | |
282 | ||
283 | function lttng_disable_kernel_syscall_ok() | |
284 | { | |
421b83dc | 285 | lttng_disable_kernel_syscall 0 "$@" |
8cfcd41c MD |
286 | } |
287 | ||
288 | function lttng_disable_kernel_syscall_fail() | |
289 | { | |
421b83dc | 290 | lttng_disable_kernel_syscall 1 "$@" |
8cfcd41c MD |
291 | } |
292 | ||
d96f6315 MD |
293 | function lttng_enable_kernel_channel() |
294 | { | |
60c78fd5 JR |
295 | local withtap=$1 |
296 | local expected_to_fail=$2 | |
297 | local sess_name=$3 | |
298 | local channel_name=$4 | |
299 | local opt=$5 | |
d96f6315 | 300 | |
60c78fd5 | 301 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -k $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
d96f6315 MD |
302 | ret=$? |
303 | if [[ $expected_to_fail -eq "1" ]]; then | |
304 | test "$ret" -ne "0" | |
60c78fd5 JR |
305 | ret=$? |
306 | if [ $withtap -eq "1" ]; then | |
307 | ok $ret "Enable channel $channel_name for session $sess_name failed as expected" | |
308 | fi | |
d96f6315 | 309 | else |
60c78fd5 JR |
310 | if [ $withtap -eq "1" ]; then |
311 | ok $ret "Enable channel $channel_name for session $sess_name" | |
312 | fi | |
d96f6315 MD |
313 | fi |
314 | } | |
315 | ||
316 | function lttng_enable_kernel_channel_ok() | |
317 | { | |
60c78fd5 | 318 | lttng_enable_kernel_channel 1 0 "$@" |
d96f6315 MD |
319 | } |
320 | ||
321 | function lttng_enable_kernel_channel_fail() | |
322 | { | |
60c78fd5 JR |
323 | lttng_enable_kernel_channel 1 1 "$@" |
324 | } | |
325 | ||
326 | function lttng_enable_kernel_channel_notap() | |
327 | { | |
328 | lttng_enable_kernel_channel 0 0 "$@" | |
329 | } | |
330 | ||
331 | function enable_kernel_lttng_channel_ok() | |
332 | { | |
333 | lttng_enable_kernel_channel 1 0 "$@" | |
d96f6315 MD |
334 | } |
335 | ||
336 | function lttng_disable_kernel_channel() | |
337 | { | |
338 | local expected_to_fail=$1 | |
339 | local sess_name=$2 | |
340 | local channel_name=$3 | |
341 | ||
2cf48300 | 342 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -k $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
d96f6315 MD |
343 | ret=$? |
344 | if [[ $expected_to_fail -eq "1" ]]; then | |
345 | test "$ret" -ne "0" | |
34ab15c5 | 346 | ok $? "Disable channel $channel_name for session $sess_name failed as expected" |
d96f6315 | 347 | else |
34ab15c5 | 348 | ok $ret "Disable channel $channel_name for session $sess_name" |
d96f6315 MD |
349 | fi |
350 | } | |
351 | ||
352 | function lttng_disable_kernel_channel_ok() | |
353 | { | |
421b83dc | 354 | lttng_disable_kernel_channel 0 "$@" |
d96f6315 MD |
355 | } |
356 | ||
357 | function lttng_disable_kernel_channel_fail() | |
358 | { | |
421b83dc | 359 | lttng_disable_kernel_channel 1 "$@" |
d96f6315 MD |
360 | } |
361 | ||
05aa48da | 362 | function start_lttng_relayd_opt() |
f4e40ab6 | 363 | { |
05aa48da MD |
364 | local withtap=$1 |
365 | local opt=$2 | |
173af62f | 366 | |
74a6c3f5 | 367 | DIR=$(readlink -f "$TESTDIR") |
f4e40ab6 | 368 | |
74a6c3f5 MD |
369 | if [ -z "$(pgrep "$RELAYD_MATCH")" ]; then |
370 | # shellcheck disable=SC2086 | |
371 | "$DIR/../src/bin/lttng-relayd/$RELAYD_BIN" -b $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
372 | #"$DIR/../src/bin/lttng-relayd/$RELAYD_BIN" $opt -vvv >>/tmp/relayd.log 2>&1 & | |
f4e40ab6 | 373 | if [ $? -eq 1 ]; then |
74a6c3f5 | 374 | if [ "$withtap" -eq "1" ]; then |
05aa48da MD |
375 | fail "Start lttng-relayd (opt: $opt)" |
376 | fi | |
f4e40ab6 DG |
377 | return 1 |
378 | else | |
74a6c3f5 | 379 | if [ "$withtap" -eq "1" ]; then |
05aa48da MD |
380 | pass "Start lttng-relayd (opt: $opt)" |
381 | fi | |
f4e40ab6 DG |
382 | fi |
383 | else | |
29655db7 | 384 | pass "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
385 | fi |
386 | } | |
387 | ||
05aa48da | 388 | function start_lttng_relayd() |
f4e40ab6 | 389 | { |
05aa48da MD |
390 | start_lttng_relayd_opt 1 "$@" |
391 | } | |
392 | ||
393 | function start_lttng_relayd_notap() | |
394 | { | |
395 | start_lttng_relayd_opt 0 "$@" | |
396 | } | |
397 | ||
398 | function stop_lttng_relayd_opt() | |
399 | { | |
400 | local withtap=$1 | |
74a6c3f5 | 401 | local signal=$2 |
05aa48da | 402 | |
74a6c3f5 MD |
403 | if [ -z "$signal" ]; then |
404 | signal="SIGTERM" | |
05aa48da | 405 | fi |
29655db7 | 406 | |
74a6c3f5 MD |
407 | local timeout_s=$3 |
408 | local dtimeleft_s= | |
409 | ||
410 | # Multiply time by 2 to simplify integer arithmetic | |
411 | if [ -n "$timeout_s" ]; then | |
412 | dtimeleft_s=$((timeout_s * 2)) | |
413 | fi | |
414 | ||
415 | local retval=0 | |
416 | local pids= | |
417 | ||
418 | pids=$(pgrep "$RELAYD_MATCH") | |
419 | if [ -z "$pids" ]; then | |
420 | if [ "$withtap" -eq "1" ]; then | |
421 | pass "No relay daemon to kill" | |
422 | fi | |
423 | return 0 | |
424 | fi | |
425 | ||
426 | diag "Killing (signal $signal) lttng-relayd (pid: $pids)" | |
427 | ||
428 | # shellcheck disable=SC2086 | |
429 | if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then | |
430 | retval=1 | |
431 | if [ "$withtap" -eq "1" ]; then | |
05aa48da MD |
432 | fail "Kill relay daemon" |
433 | fi | |
05aa48da | 434 | else |
f4e40ab6 DG |
435 | out=1 |
436 | while [ -n "$out" ]; do | |
74a6c3f5 MD |
437 | out=$(pgrep "$RELAYD_MATCH") |
438 | if [ -n "$dtimeleft_s" ]; then | |
439 | if [ $dtimeleft_s -lt 0 ]; then | |
440 | out= | |
441 | retval=1 | |
442 | fi | |
443 | dtimeleft_s=$((dtimeleft_s - 1)) | |
444 | fi | |
f4e40ab6 DG |
445 | sleep 0.5 |
446 | done | |
74a6c3f5 MD |
447 | if [ "$withtap" -eq "1" ]; then |
448 | if [ "$retval" -eq "0" ]; then | |
449 | pass "Wait after kill relay daemon" | |
450 | else | |
451 | fail "Wait after kill relay daemon" | |
452 | fi | |
05aa48da | 453 | fi |
1fb23888 MD |
454 | fi |
455 | return $retval | |
456 | } | |
457 | ||
05aa48da | 458 | function stop_lttng_relayd() |
1fb23888 | 459 | { |
05aa48da MD |
460 | stop_lttng_relayd_opt 1 "$@" |
461 | } | |
1fb23888 | 462 | |
05aa48da MD |
463 | function stop_lttng_relayd_notap() |
464 | { | |
465 | stop_lttng_relayd_opt 0 "$@" | |
f4e40ab6 DG |
466 | } |
467 | ||
05aa48da MD |
468 | #First arg: show tap output |
469 | #Second argument: load path for automatic loading | |
470 | function start_lttng_sessiond_opt() | |
355f483d | 471 | { |
05aa48da MD |
472 | local withtap=$1 |
473 | local load_path=$2 | |
8d51ddbc | 474 | |
39c98949 | 475 | local env_vars="" |
85cfac2f | 476 | local consumerd="" |
85cfac2f | 477 | |
74a6c3f5 MD |
478 | local long_bit_value= |
479 | long_bit_value=$(getconf LONG_BIT) | |
480 | ||
481 | if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then | |
355f483d DG |
482 | # Env variable requested no session daemon |
483 | return | |
484 | fi | |
485 | ||
74a6c3f5 | 486 | DIR=$(readlink -f "$TESTDIR") |
85cfac2f JR |
487 | |
488 | # Get long_bit value for 32/64 consumerd | |
489 | case "$long_bit_value" in | |
490 | 32) | |
491 | consumerd="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd" | |
492 | ;; | |
493 | 64) | |
494 | consumerd="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd" | |
495 | ;; | |
496 | *) | |
497 | return | |
498 | ;; | |
499 | esac | |
500 | ||
39c98949 JR |
501 | # Check for env. variable. Allow the use of LD_PRELOAD etc. |
502 | if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then | |
74a6c3f5 | 503 | env_vars="${LTTNG_SESSIOND_ENV_VARS} " |
39c98949 | 504 | fi |
74a6c3f5 | 505 | env_vars="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN" |
39c98949 | 506 | |
74a6c3f5 | 507 | if ! validate_kernel_version; then |
29655db7 CB |
508 | fail "Start session daemon" |
509 | BAIL_OUT "*** Kernel too old for session daemon tests ***" | |
355f483d DG |
510 | fi |
511 | ||
74a6c3f5 | 512 | : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/config/"}" |
d3d97763 | 513 | export LTTNG_SESSION_CONFIG_XSD_PATH |
29655db7 | 514 | |
74a6c3f5 | 515 | if [ -z "$(pgrep "${SESSIOND_MATCH}")" ]; then |
8d51ddbc | 516 | # Have a load path ? |
05aa48da | 517 | if [ -n "$load_path" ]; then |
74a6c3f5 MD |
518 | # shellcheck disable=SC2086 |
519 | env $env_vars --load "$load_path" --background "$consumerd" | |
8d51ddbc | 520 | else |
74a6c3f5 MD |
521 | # shellcheck disable=SC2086 |
522 | env $env_vars --background "$consumerd" | |
8d51ddbc | 523 | fi |
0fc2834c | 524 | #$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 | 525 | status=$? |
74a6c3f5 | 526 | if [ "$withtap" -eq "1" ]; then |
05aa48da MD |
527 | ok $status "Start session daemon" |
528 | fi | |
29655db7 | 529 | fi |
355f483d DG |
530 | } |
531 | ||
05aa48da MD |
532 | function start_lttng_sessiond() |
533 | { | |
534 | start_lttng_sessiond_opt 1 "$@" | |
535 | } | |
536 | ||
537 | function start_lttng_sessiond_notap() | |
d3e8f6bb | 538 | { |
05aa48da MD |
539 | start_lttng_sessiond_opt 0 "$@" |
540 | } | |
541 | ||
542 | function stop_lttng_sessiond_opt() | |
543 | { | |
544 | local withtap=$1 | |
4c80129b | 545 | local signal=$2 |
05aa48da | 546 | |
74a6c3f5 MD |
547 | if [ -z "$signal" ]; then |
548 | signal=SIGTERM | |
549 | fi | |
550 | ||
551 | local timeout_s=$3 | |
552 | local dtimeleft_s= | |
553 | ||
554 | # Multiply time by 2 to simplify integer arithmetic | |
555 | if [ -n "$timeout_s" ]; then | |
556 | dtimeleft_s=$((timeout_s * 2)) | |
557 | fi | |
558 | ||
559 | if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then | |
355f483d | 560 | # Env variable requested no session daemon |
74a6c3f5 | 561 | return 0 |
355f483d DG |
562 | fi |
563 | ||
74a6c3f5 | 564 | local retval=0 |
d3e8f6bb | 565 | |
74a6c3f5 MD |
566 | local runas_pids= |
567 | runas_pids=$(pgrep "$RUNAS_MATCH") | |
568 | ||
569 | local pids= | |
570 | pids=$(pgrep "$SESSIOND_MATCH") | |
571 | ||
572 | if [ -n "$runas_pids" ]; then | |
573 | pids="$pids $runas_pids" | |
4c80129b | 574 | fi |
74a6c3f5 MD |
575 | |
576 | if [ -z "$pids" ]; then | |
577 | if [ "$withtap" -eq "1" ]; then | |
578 | pass "No session daemon to kill" | |
579 | fi | |
580 | return 0 | |
8490897a | 581 | fi |
29655db7 | 582 | |
74a6c3f5 MD |
583 | diag "Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')" |
584 | ||
585 | # shellcheck disable=SC2086 | |
586 | if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then | |
587 | retval=1 | |
588 | if [ "$withtap" -eq "1" ]; then | |
05aa48da MD |
589 | fail "Kill sessions daemon" |
590 | fi | |
d3e8f6bb | 591 | else |
5fa32580 DG |
592 | out=1 |
593 | while [ -n "$out" ]; do | |
74a6c3f5 MD |
594 | out=$(pgrep "${SESSIOND_MATCH}") |
595 | if [ -n "$dtimeleft_s" ]; then | |
596 | if [ $dtimeleft_s -lt 0 ]; then | |
597 | out= | |
598 | retval=1 | |
599 | fi | |
600 | dtimeleft_s=$((dtimeleft_s - 1)) | |
601 | fi | |
5fa32580 DG |
602 | sleep 0.5 |
603 | done | |
f7613992 MD |
604 | out=1 |
605 | while [ -n "$out" ]; do | |
74a6c3f5 MD |
606 | out=$(pgrep "$CONSUMERD_MATCH") |
607 | if [ -n "$dtimeleft_s" ]; then | |
608 | if [ $dtimeleft_s -lt 0 ]; then | |
609 | out= | |
610 | retval=1 | |
611 | fi | |
612 | dtimeleft_s=$((dtimeleft_s - 1)) | |
613 | fi | |
f7613992 MD |
614 | sleep 0.5 |
615 | done | |
1c362dc7 | 616 | |
74a6c3f5 MD |
617 | if [ "$withtap" -eq "1" ]; then |
618 | if [ "$retval" -eq "0" ]; then | |
619 | pass "Wait after kill session daemon" | |
620 | else | |
621 | fail "Wait after kill session daemon" | |
622 | fi | |
05aa48da | 623 | fi |
d3e8f6bb | 624 | fi |
74a6c3f5 MD |
625 | if [ "$signal" = "SIGKILL" ]; then |
626 | if [ "$(id -u)" -eq "0" ]; then | |
627 | local modules= | |
628 | modules="$(lsmod | grep ^lttng | awk '{print $1}')" | |
629 | ||
630 | if [ -n "$modules" ]; then | |
631 | diag "Unloading all LTTng modules" | |
632 | modprobe -r "$modules" | |
633 | fi | |
634 | fi | |
635 | fi | |
636 | ||
637 | return $retval | |
d3e8f6bb DG |
638 | } |
639 | ||
05aa48da MD |
640 | function stop_lttng_sessiond() |
641 | { | |
642 | stop_lttng_sessiond_opt 1 "$@" | |
643 | } | |
644 | ||
645 | function stop_lttng_sessiond_notap() | |
646 | { | |
647 | stop_lttng_sessiond_opt 0 "$@" | |
648 | } | |
649 | ||
8490897a MD |
650 | function sigstop_lttng_sessiond_opt() |
651 | { | |
652 | local withtap=$1 | |
653 | local signal=SIGSTOP | |
8490897a | 654 | |
74a6c3f5 | 655 | if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
8490897a MD |
656 | # Env variable requested no session daemon |
657 | return | |
658 | fi | |
659 | ||
74a6c3f5 | 660 | PID_SESSIOND="$(pgrep "${SESSIOND_MATCH}") $(pgrep "$RUNAS_MATCH")" |
8490897a | 661 | |
74a6c3f5 MD |
662 | if [ "$withtap" -eq "1" ]; then |
663 | diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$PID_SESSIOND" | tr '\n' ' ')" | |
8490897a | 664 | fi |
8490897a | 665 | |
74a6c3f5 MD |
666 | # shellcheck disable=SC2086 |
667 | if ! kill -s $signal $PID_SESSIOND 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then | |
668 | if [ "$withtap" -eq "1" ]; then | |
8490897a MD |
669 | fail "Sending SIGSTOP to session daemon" |
670 | fi | |
671 | else | |
672 | out=1 | |
673 | while [ $out -ne 0 ]; do | |
74a6c3f5 | 674 | pid="$(pgrep "$SESSIOND_MATCH")" |
8490897a MD |
675 | |
676 | # Wait until state becomes stopped for session | |
677 | # daemon(s). | |
678 | out=0 | |
679 | for sessiond_pid in $pid; do | |
74a6c3f5 | 680 | state="$(ps -p "$sessiond_pid" -o state= )" |
8490897a MD |
681 | if [[ -n "$state" && "$state" != "T" ]]; then |
682 | out=1 | |
683 | fi | |
684 | done | |
685 | sleep 0.5 | |
686 | done | |
74a6c3f5 | 687 | if [ "$withtap" -eq "1" ]; then |
8490897a MD |
688 | pass "Sending SIGSTOP to session daemon" |
689 | fi | |
690 | fi | |
691 | } | |
692 | ||
693 | function sigstop_lttng_sessiond() | |
694 | { | |
695 | sigstop_lttng_sessiond_opt 1 "$@" | |
696 | } | |
697 | ||
698 | function sigstop_lttng_sessiond_notap() | |
699 | { | |
700 | sigstop_lttng_sessiond_opt 0 "$@" | |
701 | } | |
702 | ||
4c80129b JR |
703 | function stop_lttng_consumerd_opt() |
704 | { | |
705 | local withtap=$1 | |
706 | local signal=$2 | |
4c80129b | 707 | |
74a6c3f5 MD |
708 | if [ -z "$signal" ]; then |
709 | signal=SIGTERM | |
710 | fi | |
711 | ||
712 | local timeout_s=$3 | |
713 | local dtimeleft_s= | |
4c80129b | 714 | |
74a6c3f5 MD |
715 | # Multiply time by 2 to simplify integer arithmetic |
716 | if [ -n "$timeout_s" ]; then | |
717 | dtimeleft_s=$((timeout_s * 2)) | |
4c80129b JR |
718 | fi |
719 | ||
74a6c3f5 MD |
720 | local retval=0 |
721 | ||
722 | PID_CONSUMERD="$(pgrep "$CONSUMERD_MATCH")" | |
723 | ||
724 | if [ -z "$PID_CONSUMERD" ]; then | |
725 | if [ "$withtap" -eq "1" ]; then | |
726 | pass "No consumer daemon to kill" | |
727 | fi | |
728 | return 0 | |
4c80129b | 729 | fi |
51dc0abb | 730 | |
74a6c3f5 | 731 | diag "Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')" |
4c80129b | 732 | |
74a6c3f5 MD |
733 | # shellcheck disable=SC2086 |
734 | if ! kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then | |
735 | retval=1 | |
736 | if [ "$withtap" -eq "1" ]; then | |
4c80129b JR |
737 | fail "Kill consumer daemon" |
738 | fi | |
4c80129b JR |
739 | else |
740 | out=1 | |
741 | while [ $out -ne 0 ]; do | |
74a6c3f5 | 742 | pid="$(pgrep "$CONSUMERD_MATCH")" |
4c80129b JR |
743 | |
744 | # If consumerds are still present check their status. | |
745 | # A zombie status qualifies the consumerd as *killed* | |
746 | out=0 | |
747 | for consumer_pid in $pid; do | |
74a6c3f5 | 748 | state="$(ps -p "$consumer_pid" -o state= )" |
4c80129b JR |
749 | if [[ -n "$state" && "$state" != "Z" ]]; then |
750 | out=1 | |
751 | fi | |
752 | done | |
74a6c3f5 MD |
753 | if [ -n "$dtimeleft_s" ]; then |
754 | if [ $dtimeleft_s -lt 0 ]; then | |
755 | out=0 | |
756 | retval=1 | |
757 | fi | |
758 | dtimeleft_s=$((dtimeleft_s - 1)) | |
759 | fi | |
4c80129b JR |
760 | sleep 0.5 |
761 | done | |
74a6c3f5 MD |
762 | if [ "$withtap" -eq "1" ]; then |
763 | if [ "$retval" -eq "0" ]; then | |
764 | pass "Wait after kill consumer daemon" | |
765 | else | |
766 | fail "Wait after kill consumer daemon" | |
767 | fi | |
4c80129b JR |
768 | fi |
769 | fi | |
74a6c3f5 | 770 | |
4c80129b JR |
771 | return $retval |
772 | } | |
773 | ||
774 | function stop_lttng_consumerd() | |
775 | { | |
776 | stop_lttng_consumerd_opt 1 "$@" | |
777 | } | |
778 | ||
779 | function stop_lttng_consumerd_notap() | |
780 | { | |
781 | stop_lttng_consumerd_opt 0 "$@" | |
782 | } | |
783 | ||
8490897a MD |
784 | function sigstop_lttng_consumerd_opt() |
785 | { | |
786 | local withtap=$1 | |
787 | local signal=SIGSTOP | |
8490897a | 788 | |
74a6c3f5 | 789 | PID_CONSUMERD="$(pgrep "$CONSUMERD_MATCH")" |
8490897a | 790 | |
74a6c3f5 | 791 | diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$PID_CONSUMERD" | tr '\n' ' ')" |
8490897a | 792 | |
74a6c3f5 MD |
793 | # shellcheck disable=SC2086 |
794 | kill -s $signal $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
8490897a | 795 | retval=$? |
8490897a | 796 | |
74a6c3f5 MD |
797 | if [ $retval -eq 1 ]; then |
798 | if [ "$withtap" -eq "1" ]; then | |
8490897a MD |
799 | fail "Sending SIGSTOP to consumer daemon" |
800 | fi | |
801 | return 1 | |
802 | else | |
803 | out=1 | |
804 | while [ $out -ne 0 ]; do | |
74a6c3f5 | 805 | pid="$(pgrep "$CONSUMERD_MATCH")" |
8490897a MD |
806 | |
807 | # Wait until state becomes stopped for all | |
808 | # consumers. | |
809 | out=0 | |
810 | for consumer_pid in $pid; do | |
74a6c3f5 | 811 | state="$(ps -p "$consumer_pid" -o state= )" |
8490897a MD |
812 | if [[ -n "$state" && "$state" != "T" ]]; then |
813 | out=1 | |
814 | fi | |
815 | done | |
816 | sleep 0.5 | |
817 | done | |
74a6c3f5 | 818 | if [ "$withtap" -eq "1" ]; then |
8490897a MD |
819 | pass "Sending SIGSTOP to consumer daemon" |
820 | fi | |
821 | fi | |
822 | return $retval | |
823 | } | |
824 | ||
825 | function sigstop_lttng_consumerd() | |
826 | { | |
827 | sigstop_lttng_consumerd_opt 1 "$@" | |
828 | } | |
829 | ||
830 | function sigstop_lttng_consumerd_notap() | |
831 | { | |
832 | sigstop_lttng_consumerd_opt 0 "$@" | |
833 | } | |
834 | ||
873c2aae JRJ |
835 | function list_lttng_with_opts () |
836 | { | |
7d0ad314 | 837 | local opts=$1 |
2cf48300 | 838 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN list $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
873c2aae JRJ |
839 | ok $? "Lttng-tool list command with option $opts" |
840 | } | |
841 | ||
07b86b52 JD |
842 | function create_lttng_session_no_output () |
843 | { | |
7d0ad314 | 844 | local sess_name=$1 |
07b86b52 | 845 | |
2cf48300 | 846 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name --no-output 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
07b86b52 JD |
847 | ok $? "Create session $sess_name in no-output mode" |
848 | } | |
849 | ||
d3e8f6bb DG |
850 | function create_lttng_session () |
851 | { | |
dc890bff JR |
852 | local withtap=$1 |
853 | local expected_to_fail=$2 | |
854 | local sess_name=$3 | |
855 | local trace_path=$4 | |
856 | local opt=$5 | |
d3e8f6bb | 857 | |
4c80129b | 858 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -o $trace_path $opt > $OUTPUT_DEST |
873c2aae | 859 | ret=$? |
dc890bff | 860 | if [ $expected_to_fail -eq "1" ]; then |
01513c3e | 861 | test "$ret" -ne "0" |
dc890bff JR |
862 | ret=$? |
863 | if [ $withtap -eq "1" ]; then | |
864 | ok $ret "Create session $sess_name in $trace_path failed as expected" | |
865 | fi | |
873c2aae | 866 | else |
dc890bff JR |
867 | if [ $withtap -eq "1" ]; then |
868 | ok $ret "Create session $sess_name in $trace_path" | |
869 | fi | |
873c2aae | 870 | fi |
dc890bff | 871 | return $ret |
d4018451 DG |
872 | } |
873 | ||
bf6ae429 JR |
874 | function create_lttng_session_ok () |
875 | { | |
dc890bff | 876 | create_lttng_session 1 0 "$@" |
bf6ae429 JR |
877 | } |
878 | ||
879 | function create_lttng_session_fail () | |
880 | { | |
dc890bff JR |
881 | create_lttng_session 1 1 "$@" |
882 | } | |
883 | ||
884 | function create_lttng_session_notap () | |
885 | { | |
886 | create_lttng_session 0 0 "$@" | |
bf6ae429 JR |
887 | } |
888 | ||
889 | ||
827caf52 | 890 | function enable_ust_lttng_channel () |
d4018451 | 891 | { |
dc890bff JR |
892 | local withtap=$1 |
893 | local expected_to_fail=$2 | |
894 | local sess_name=$3 | |
895 | local channel_name=$4 | |
896 | local opt=$5 | |
d4018451 | 897 | |
4c80129b | 898 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -u $channel_name -s $sess_name $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
312dabc3 | 899 | ret=$? |
34ab15c5 | 900 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 901 | test "$ret" -ne "0" |
dc890bff JR |
902 | ret=$? |
903 | if [ $withtap -eq "1" ]; then | |
904 | ok $ret "Enable channel $channel_name for session $sess_name failed as expected" | |
905 | fi | |
312dabc3 | 906 | else |
dc890bff JR |
907 | if [ $withtap -eq "1" ]; then |
908 | ok $ret "Enable channel $channel_name for session $sess_name" | |
909 | fi | |
312dabc3 | 910 | fi |
dc890bff | 911 | return $ret |
d4018451 DG |
912 | } |
913 | ||
827caf52 JR |
914 | function enable_ust_lttng_channel_ok () |
915 | { | |
dc890bff | 916 | enable_ust_lttng_channel 1 0 "$@" |
827caf52 JR |
917 | } |
918 | ||
919 | function enable_ust_lttng_channel_fail () | |
920 | { | |
dc890bff JR |
921 | enable_ust_lttng_channel 1 1 "$@" |
922 | } | |
923 | ||
924 | function enable_ust_lttng_channel_notap () | |
925 | { | |
926 | enable_ust_lttng_channel 0 0 "$@" | |
827caf52 JR |
927 | } |
928 | ||
29655db7 | 929 | function disable_ust_lttng_channel() |
d4018451 | 930 | { |
7d0ad314 JRJ |
931 | local sess_name=$1 |
932 | local channel_name=$2 | |
d4018451 | 933 | |
2cf48300 | 934 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-channel -u $channel_name -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 935 | ok $? "Disable channel $channel_name for session $sess_name" |
d3e8f6bb DG |
936 | } |
937 | ||
07b86b52 JD |
938 | function enable_lttng_mmap_overwrite_kernel_channel() |
939 | { | |
7d0ad314 JRJ |
940 | local sess_name=$1 |
941 | local channel_name=$2 | |
07b86b52 | 942 | |
2cf48300 | 943 | $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 |
944 | ok $? "Enable channel $channel_name for session $sess_name" |
945 | } | |
946 | ||
086e6add MD |
947 | function enable_lttng_mmap_discard_small_kernel_channel() |
948 | { | |
949 | local sess_name=$1 | |
950 | local channel_name=$2 | |
951 | ||
952 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --discard --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
953 | ok $? "Enable small discard channel $channel_name for session $sess_name" | |
954 | } | |
955 | ||
956 | function enable_lttng_mmap_overwrite_small_kernel_channel() | |
957 | { | |
958 | local sess_name=$1 | |
959 | local channel_name=$2 | |
960 | ||
961 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-channel -s $sess_name $channel_name -k --output mmap --overwrite --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
962 | ok $? "Enable small discard channel $channel_name for session $sess_name" | |
963 | } | |
964 | ||
ebaaaf5e JD |
965 | function enable_lttng_mmap_overwrite_ust_channel() |
966 | { | |
7d0ad314 JRJ |
967 | local sess_name=$1 |
968 | local channel_name=$2 | |
ebaaaf5e | 969 | |
2cf48300 | 970 | $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 |
971 | ok $? "Enable channel $channel_name for session $sess_name" |
972 | } | |
973 | ||
d3e8f6bb DG |
974 | function enable_ust_lttng_event () |
975 | { | |
dc890bff JR |
976 | local withtap=$1 |
977 | local expected_to_fail=$2 | |
978 | local sess_name=$3 | |
979 | local event_name="$4" | |
980 | local channel_name=$5 | |
ebaaaf5e JD |
981 | |
982 | if [ -z $channel_name ]; then | |
983 | # default channel if none specified | |
984 | chan="" | |
985 | else | |
986 | chan="-c $channel_name" | |
987 | fi | |
d3e8f6bb | 988 | |
2cf48300 | 989 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 990 | ret=$? |
c4926bb5 | 991 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 992 | test $ret -ne "0" |
dc890bff JR |
993 | ret=$? |
994 | if [[ $withtap -eq "1" ]]; then | |
995 | ok $ret "Enable ust event $event_name for session $session_name failed as expected" | |
996 | fi | |
01513c3e | 997 | else |
dc890bff JR |
998 | if [[ $withtap -eq "1" ]]; then |
999 | ok $ret "Enable ust event $event_name for session $sess_name" | |
1000 | fi | |
01513c3e | 1001 | fi |
dc890bff | 1002 | return $ret |
26b53d3b DG |
1003 | } |
1004 | ||
c4926bb5 JR |
1005 | function enable_ust_lttng_event_ok () |
1006 | { | |
dc890bff | 1007 | enable_ust_lttng_event 1 0 "$@" |
c4926bb5 JR |
1008 | } |
1009 | ||
1010 | function enable_ust_lttng_event_fail () | |
1011 | { | |
dc890bff JR |
1012 | enable_ust_lttng_event 1 1 "$@" |
1013 | } | |
1014 | ||
1015 | function enable_ust_lttng_event_notap () | |
1016 | { | |
1017 | enable_ust_lttng_event 0 0 "$@" | |
c4926bb5 JR |
1018 | } |
1019 | ||
37175ce4 DG |
1020 | function enable_jul_lttng_event() |
1021 | { | |
1022 | sess_name=$1 | |
1023 | event_name="$2" | |
1024 | channel_name=$3 | |
1025 | ||
1026 | if [ -z $channel_name ]; then | |
1027 | # default channel if none specified | |
1028 | chan="" | |
1029 | else | |
1030 | chan="-c $channel_name" | |
1031 | fi | |
1032 | ||
2cf48300 | 1033 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -j 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
37175ce4 DG |
1034 | ok $? "Enable JUL event $event_name for session $sess_name" |
1035 | } | |
1036 | ||
b2064f54 DG |
1037 | function enable_jul_lttng_event_loglevel() |
1038 | { | |
7d0ad314 JRJ |
1039 | local sess_name=$1 |
1040 | local event_name="$2" | |
1041 | local loglevel=$3 | |
1042 | local channel_name=$4 | |
b2064f54 DG |
1043 | |
1044 | if [ -z $channel_name ]; then | |
1045 | # default channel if none specified | |
1046 | chan="" | |
1047 | else | |
1048 | chan="-c $channel_name" | |
1049 | fi | |
1050 | ||
2cf48300 | 1051 | $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 |
1052 | ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel" |
1053 | } | |
1054 | ||
504d4ace DG |
1055 | function enable_log4j_lttng_event() |
1056 | { | |
1057 | sess_name=$1 | |
1058 | event_name="$2" | |
1059 | channel_name=$3 | |
1060 | ||
1061 | if [ -z $channel_name ]; then | |
1062 | # default channel if none specified | |
1063 | chan="" | |
1064 | else | |
1065 | chan="-c $channel_name" | |
1066 | fi | |
1067 | ||
2cf48300 | 1068 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -l 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
504d4ace DG |
1069 | ok $? "Enable LOG4J event $event_name for session $sess_name" |
1070 | } | |
1071 | ||
1072 | function enable_log4j_lttng_event_loglevel() | |
1073 | { | |
1074 | local sess_name=$1 | |
1075 | local event_name="$2" | |
1076 | local loglevel=$3 | |
1077 | local channel_name=$4 | |
1078 | ||
1079 | if [ -z $channel_name ]; then | |
1080 | # default channel if none specified | |
1081 | chan="" | |
1082 | else | |
1083 | chan="-c $channel_name" | |
1084 | fi | |
1085 | ||
2cf48300 | 1086 | $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 |
1087 | ok $? "Enable LOG4J event $event_name for session $sess_name with loglevel $loglevel" |
1088 | } | |
1089 | ||
0e115563 DG |
1090 | function enable_python_lttng_event() |
1091 | { | |
1092 | sess_name=$1 | |
1093 | event_name="$2" | |
1094 | channel_name=$3 | |
1095 | ||
1096 | if [ -z $channel_name ]; then | |
1097 | # default channel if none specified | |
1098 | chan="" | |
1099 | else | |
1100 | chan="-c $channel_name" | |
1101 | fi | |
1102 | ||
2cf48300 | 1103 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" $chan -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
0e115563 DG |
1104 | ok $? "Enable Python event $event_name for session $sess_name" |
1105 | } | |
1106 | ||
1107 | function enable_python_lttng_event_loglevel() | |
1108 | { | |
1109 | local sess_name=$1 | |
1110 | local event_name="$2" | |
1111 | local loglevel=$3 | |
1112 | local channel_name=$4 | |
1113 | ||
1114 | if [ -z $channel_name ]; then | |
1115 | # default channel if none specified | |
1116 | chan="" | |
1117 | else | |
1118 | chan="-c $channel_name" | |
1119 | fi | |
1120 | ||
2cf48300 | 1121 | $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 |
1122 | ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel" |
1123 | } | |
1124 | ||
26b53d3b DG |
1125 | function enable_ust_lttng_event_filter() |
1126 | { | |
7d0ad314 JRJ |
1127 | local sess_name="$1" |
1128 | local event_name="$2" | |
1129 | local filter="$3" | |
26b53d3b | 1130 | |
2cf48300 | 1131 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --filter "$filter" 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 1132 | ok $? "Enable event $event_name with filtering for session $sess_name" |
26b53d3b DG |
1133 | } |
1134 | ||
1135 | function enable_ust_lttng_event_loglevel() | |
1136 | { | |
7d0ad314 JRJ |
1137 | local sess_name="$1" |
1138 | local event_name="$2" | |
1139 | local loglevel="$3" | |
26b53d3b | 1140 | |
2cf48300 | 1141 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-event "$event_name" -s $sess_name -u --loglevel $loglevel 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 1142 | ok $? "Enable event $event_name with loglevel $loglevel" |
26b53d3b DG |
1143 | } |
1144 | ||
1145 | function enable_ust_lttng_event_loglevel_only() | |
1146 | { | |
7d0ad314 JRJ |
1147 | local sess_name="$1" |
1148 | local event_name="$2" | |
1149 | local loglevel="$3" | |
26b53d3b | 1150 | |
2cf48300 | 1151 | $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 | 1152 | ok $? "Enable event $event_name with loglevel-only $loglevel" |
26b53d3b DG |
1153 | } |
1154 | ||
1155 | function disable_ust_lttng_event () | |
1156 | { | |
7d0ad314 JRJ |
1157 | local sess_name="$1" |
1158 | local event_name="$2" | |
01513c3e | 1159 | local channel_name="$3" |
26b53d3b | 1160 | |
01513c3e JRJ |
1161 | if [ -z $channel_name ]; then |
1162 | # default channel if none specified | |
1163 | chan="" | |
1164 | else | |
1165 | chan="-c $channel_name" | |
1166 | fi | |
1167 | ||
2cf48300 | 1168 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name $chan -u 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
29655db7 | 1169 | ok $? "Disable event $event_name for session $sess_name" |
d3e8f6bb DG |
1170 | } |
1171 | ||
1d842d5a DG |
1172 | function disable_jul_lttng_event () |
1173 | { | |
1174 | local sess_name="$1" | |
1175 | local event_name="$2" | |
1176 | ||
1177 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1 | |
1178 | ok $? "Disable JUL event $event_name for session $sess_name" | |
1179 | } | |
1180 | ||
504d4ace DG |
1181 | function disable_log4j_lttng_event () |
1182 | { | |
1183 | local sess_name="$1" | |
1184 | local event_name="$2" | |
1185 | ||
1186 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -l >/dev/null 2>&1 | |
1187 | ok $? "Disable LOG4J event $event_name for session $sess_name" | |
1188 | } | |
1189 | ||
0e115563 DG |
1190 | function disable_python_lttng_event () |
1191 | { | |
1192 | local sess_name="$1" | |
1193 | local event_name="$2" | |
1194 | ||
2cf48300 | 1195 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -p 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
0e115563 DG |
1196 | ok $? "Disable Python event $event_name for session $sess_name" |
1197 | } | |
1198 | ||
fb3268e3 | 1199 | function start_lttng_tracing () |
d3e8f6bb | 1200 | { |
e563bbdb JR |
1201 | local expected_to_fail=$1 |
1202 | local sess_name=$2 | |
d3e8f6bb | 1203 | |
2cf48300 | 1204 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1205 | ret=$? |
e563bbdb | 1206 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1207 | test "$ret" -ne "0" |
34ab15c5 | 1208 | ok $? "Start tracing for session $sess_name failed as expected" |
01513c3e JRJ |
1209 | else |
1210 | ok $ret "Start tracing for session $sess_name" | |
1211 | fi | |
d3e8f6bb DG |
1212 | } |
1213 | ||
e563bbdb JR |
1214 | function start_lttng_tracing_ok () |
1215 | { | |
1216 | start_lttng_tracing 0 "$@" | |
1217 | } | |
1218 | ||
1219 | function start_lttng_tracing_fail () | |
1220 | { | |
1221 | start_lttng_tracing 1 "$@" | |
1222 | } | |
1223 | ||
fb3268e3 | 1224 | function stop_lttng_tracing () |
d3e8f6bb | 1225 | { |
96340a01 JR |
1226 | local expected_to_fail=$1 |
1227 | local sess_name=$2 | |
d3e8f6bb | 1228 | |
2cf48300 | 1229 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1230 | ret=$? |
96340a01 | 1231 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1232 | test "$ret" -ne "0" |
34ab15c5 | 1233 | ok $? "Stop lttng tracing for session $sess_name failed as expected" |
01513c3e JRJ |
1234 | else |
1235 | ok $ret "Stop lttng tracing for session $sess_name" | |
1236 | fi | |
d3e8f6bb DG |
1237 | } |
1238 | ||
96340a01 JR |
1239 | function stop_lttng_tracing_ok () |
1240 | { | |
1241 | stop_lttng_tracing 0 "$@" | |
1242 | } | |
1243 | ||
1244 | function stop_lttng_tracing_fail () | |
1245 | { | |
1246 | stop_lttng_tracing 1 "$@" | |
1247 | } | |
1248 | ||
d3e8f6bb DG |
1249 | function destroy_lttng_session () |
1250 | { | |
60c78fd5 JR |
1251 | local withtap=$1 |
1252 | local expected_to_fail=$2 | |
1253 | local sess_name=$3 | |
d3e8f6bb | 1254 | |
2cf48300 | 1255 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1256 | ret=$? |
96340a01 | 1257 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1258 | test "$ret" -ne "0" |
60c78fd5 JR |
1259 | ret=$? |
1260 | if [ $withtap -eq "1" ]; then | |
1261 | ok $ret "Destroy session $sess_name failed as expected" | |
1262 | fi | |
01513c3e | 1263 | else |
60c78fd5 JR |
1264 | if [ $withtap -eq "1" ]; then |
1265 | ok $ret "Destroy session $sess_name" | |
1266 | fi | |
01513c3e | 1267 | fi |
d3e8f6bb DG |
1268 | } |
1269 | ||
67b4c664 JR |
1270 | function destroy_lttng_session_ok () |
1271 | { | |
60c78fd5 | 1272 | destroy_lttng_session 1 0 "$@" |
67b4c664 JR |
1273 | |
1274 | } | |
1275 | ||
1276 | function destroy_lttng_session_fail () | |
1277 | { | |
60c78fd5 | 1278 | destroy_lttng_session 1 1 "$@" |
67b4c664 JR |
1279 | } |
1280 | ||
60c78fd5 JR |
1281 | function destroy_lttng_session_notap () |
1282 | { | |
1283 | destroy_lttng_session 0 0 "$@" | |
1284 | } | |
67b4c664 | 1285 | |
873c2aae JRJ |
1286 | function destroy_lttng_sessions () |
1287 | { | |
2cf48300 | 1288 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN destroy --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
873c2aae JRJ |
1289 | ok $? "Destroy all lttng sessions" |
1290 | } | |
1291 | ||
07b86b52 JD |
1292 | function lttng_snapshot_add_output () |
1293 | { | |
b5633831 JR |
1294 | local expected_to_fail=$1 |
1295 | local sess_name=$2 | |
1296 | local trace_path=$3 | |
07b86b52 | 1297 | |
2cf48300 | 1298 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot add-output -s $sess_name file://$trace_path 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1299 | ret=$? |
b5633831 | 1300 | if [[ $expected_to_fail -eq 1 ]]; then |
01513c3e | 1301 | test "$ret" -ne "0" |
34ab15c5 | 1302 | ok $? "Added snapshot output file://$trace_path failed as expected" |
01513c3e JRJ |
1303 | else |
1304 | ok $ret "Added snapshot output file://$trace_path" | |
1305 | fi | |
07b86b52 JD |
1306 | } |
1307 | ||
b5633831 JR |
1308 | function lttng_snapshot_add_output_ok () |
1309 | { | |
1310 | lttng_snapshot_add_output 0 "$@" | |
1311 | } | |
1312 | ||
1313 | function lttng_snapshot_add_output_fail () | |
1314 | { | |
1315 | lttng_snapshot_add_output 1 "$@" | |
1316 | } | |
1317 | ||
26402e0c DG |
1318 | function lttng_snapshot_del_output () |
1319 | { | |
31580dc7 JR |
1320 | local expected_to_fail=$1 |
1321 | local sess_name=$2 | |
1322 | local id=$3 | |
26402e0c | 1323 | |
2cf48300 | 1324 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot del-output -s $sess_name $id 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e | 1325 | ret=$? |
31580dc7 | 1326 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1327 | test "$ret" -ne "0" |
34ab15c5 | 1328 | ok $? "Deleted snapshot output id $id failed as expected" |
01513c3e JRJ |
1329 | else |
1330 | ok $ret "Deleted snapshot output id $id" | |
1331 | fi | |
26402e0c DG |
1332 | } |
1333 | ||
31580dc7 JR |
1334 | function lttng_snapshot_del_output_ok () |
1335 | { | |
1336 | lttng_snapshot_del_output 0 "$@" | |
1337 | } | |
1338 | ||
1339 | function lttng_snapshot_del_output_fail () | |
1340 | { | |
1341 | lttng_snapshot_del_output 1 "$@" | |
1342 | } | |
1343 | ||
07b86b52 JD |
1344 | function lttng_snapshot_record () |
1345 | { | |
7d0ad314 JRJ |
1346 | local sess_name=$1 |
1347 | local trace_path=$2 | |
07b86b52 | 1348 | |
2cf48300 | 1349 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot record -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
07b86b52 JD |
1350 | ok $? "Snapshot recorded" |
1351 | } | |
1352 | ||
01513c3e JRJ |
1353 | function lttng_snapshot_list () |
1354 | { | |
1355 | local sess_name=$1 | |
2cf48300 | 1356 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN snapshot list-output -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
01513c3e JRJ |
1357 | ok $? "Snapshot list" |
1358 | } | |
1359 | ||
e02b109b DG |
1360 | function lttng_save() |
1361 | { | |
1362 | local sess_name=$1 | |
1363 | local opts=$2 | |
1364 | ||
2cf48300 | 1365 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN save $sess_name $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
34ab15c5 | 1366 | ok $? "Session saved" |
e02b109b DG |
1367 | } |
1368 | ||
1369 | function lttng_load() | |
1370 | { | |
192ac418 JR |
1371 | local expected_to_fail=$1 |
1372 | local opts=$2 | |
e02b109b | 1373 | |
2cf48300 | 1374 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN load $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
192ac418 JR |
1375 | ret=$? |
1376 | if [[ $expected_to_fail -eq "1" ]]; then | |
1377 | test $ret -ne "0" | |
1378 | ok $? "Load command failed as expected with opts: $opts" | |
1379 | else | |
1380 | ok $ret "Load command with opts: $opts" | |
1381 | fi | |
1382 | } | |
1383 | ||
1384 | function lttng_load_ok() | |
1385 | { | |
1386 | lttng_load 0 "$@" | |
1387 | } | |
1388 | ||
1389 | function lttng_load_fail() | |
1390 | { | |
1391 | lttng_load 1 "$@" | |
e02b109b DG |
1392 | } |
1393 | ||
e83a8bdb JR |
1394 | function lttng_track() |
1395 | { | |
1396 | local expected_to_fail=$1 | |
1397 | local opts=$2 | |
1398 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST | |
1399 | ret=$? | |
1400 | if [[ $expected_to_fail -eq "1" ]]; then | |
1401 | test $ret -ne "0" | |
1402 | ok $? "Track command failed as expected with opts: $opts" | |
1403 | else | |
34ab15c5 | 1404 | ok $ret "Track command with opts: $opts" |
e83a8bdb JR |
1405 | fi |
1406 | } | |
1407 | ||
1408 | function lttng_track_ok() | |
1409 | { | |
1410 | lttng_track 0 "$@" | |
1411 | } | |
1412 | ||
1413 | function lttng_track_fail() | |
1414 | { | |
1415 | lttng_track 1 "$@" | |
1416 | } | |
1417 | ||
1418 | function lttng_untrack() | |
1419 | { | |
1420 | local expected_to_fail=$1 | |
1421 | local opts=$2 | |
1422 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST | |
1423 | ret=$? | |
1424 | if [[ $expected_to_fail -eq "1" ]]; then | |
1425 | test $ret -ne "0" | |
1426 | ok $? "Untrack command failed as expected with opts: $opts" | |
1427 | else | |
34ab15c5 | 1428 | ok $ret "Untrack command with opts: $opts" |
e83a8bdb JR |
1429 | fi |
1430 | } | |
1431 | ||
1432 | function lttng_untrack_ok() | |
1433 | { | |
1434 | lttng_untrack 0 "$@" | |
1435 | } | |
1436 | ||
1437 | function lttng_untrack_fail() | |
1438 | { | |
1439 | lttng_untrack 1 "$@" | |
1440 | } | |
1441 | ||
8dcef147 JR |
1442 | function add_context_lttng() |
1443 | { | |
1444 | local expected_to_fail="$1" | |
1445 | local domain="$2" | |
1446 | local session_name="$3" | |
1447 | local channel_name="$4" | |
1448 | local type="$5" | |
1449 | ||
1450 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context -s $session_name -c $channel_name -t $type $domain 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1451 | ret=$? | |
1452 | if [[ $expected_to_fail -eq "1" ]]; then | |
1453 | test $ret -ne "0" | |
1454 | ok $? "Add context command failed as expected for type: $type" | |
1455 | else | |
1456 | ok $ret "Add context command for type: $type" | |
1457 | fi | |
1458 | } | |
1459 | ||
1460 | function add_context_ust_ok() | |
1461 | { | |
1462 | add_context_lttng 0 -u "$@" | |
1463 | } | |
1464 | ||
1465 | function add_context_ust_fail() | |
1466 | { | |
1467 | add_context_lttng 1 -u "$@" | |
1468 | } | |
1469 | ||
1470 | function add_context_kernel_ok() | |
1471 | { | |
1472 | add_context_lttng 0 -k "$@" | |
1473 | } | |
1474 | ||
1475 | function add_context_kernel_fail() | |
1476 | { | |
1477 | add_context_lttng 1 -k "$@" | |
1478 | } | |
1479 | ||
d3e8f6bb DG |
1480 | function trace_matches () |
1481 | { | |
7d0ad314 JRJ |
1482 | local event_name=$1 |
1483 | local nr_iter=$2 | |
1484 | local trace_path=$3 | |
d3e8f6bb | 1485 | |
317eef93 | 1486 | which $BABELTRACE_BIN >/dev/null |
29655db7 | 1487 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" |
d3e8f6bb | 1488 | |
7d0ad314 | 1489 | local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) |
29655db7 | 1490 | |
d3e8f6bb | 1491 | if [ "$count" -ne "$nr_iter" ]; then |
29655db7 | 1492 | fail "Trace match" |
af91abc9 | 1493 | diag "$count matching events found in trace" |
d3e8f6bb | 1494 | else |
29655db7 | 1495 | pass "Trace match" |
d3e8f6bb DG |
1496 | fi |
1497 | } | |
f4e40ab6 | 1498 | |
d53addeb DG |
1499 | function trace_match_only() |
1500 | { | |
1501 | local event_name=$1 | |
1502 | local nr_iter=$2 | |
1503 | local trace_path=$3 | |
1504 | ||
1505 | which $BABELTRACE_BIN >/dev/null | |
1506 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" | |
1507 | ||
1508 | local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) | |
1509 | local total=$($BABELTRACE_BIN $trace_path | wc -l) | |
1510 | ||
1511 | if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then | |
1512 | pass "Trace match with $total event $event_name" | |
1513 | else | |
1514 | fail "Trace match" | |
1515 | diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count" | |
1516 | fi | |
1517 | } | |
1518 | ||
f4e40ab6 DG |
1519 | function validate_trace |
1520 | { | |
7d0ad314 JRJ |
1521 | local event_name=$1 |
1522 | local trace_path=$2 | |
f4e40ab6 DG |
1523 | |
1524 | which $BABELTRACE_BIN >/dev/null | |
29655db7 CB |
1525 | if [ $? -ne 0 ]; then |
1526 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
f4e40ab6 DG |
1527 | fi |
1528 | ||
07b86b52 JD |
1529 | OLDIFS=$IFS |
1530 | IFS="," | |
1531 | for i in $event_name; do | |
1532 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) | |
1533 | if [ "$traced" -ne 0 ]; then | |
ebaaaf5e | 1534 | pass "Validate trace for event $i, $traced events" |
07b86b52 JD |
1535 | else |
1536 | fail "Validate trace for event $i" | |
1537 | diag "Found $traced occurences of $i" | |
1538 | fi | |
1539 | done | |
1540 | ret=$? | |
1541 | IFS=$OLDIFS | |
1542 | return $ret | |
f4e40ab6 | 1543 | } |
8cfcd41c | 1544 | |
54cd6107 JD |
1545 | function validate_trace_count |
1546 | { | |
1547 | local event_name=$1 | |
1548 | local trace_path=$2 | |
1549 | local expected_count=$3 | |
1550 | ||
1551 | which $BABELTRACE_BIN >/dev/null | |
1552 | if [ $? -ne 0 ]; then | |
1553 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
1554 | fi | |
1555 | ||
1556 | cnt=0 | |
1557 | OLDIFS=$IFS | |
1558 | IFS="," | |
1559 | for i in $event_name; do | |
1560 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) | |
1561 | if [ "$traced" -ne 0 ]; then | |
1562 | pass "Validate trace for event $i, $traced events" | |
1563 | else | |
1564 | fail "Validate trace for event $i" | |
1565 | diag "Found $traced occurences of $i" | |
1566 | fi | |
1567 | cnt=$(($cnt + $traced)) | |
1568 | done | |
1569 | IFS=$OLDIFS | |
1570 | test $cnt -eq $expected_count | |
1571 | ok $? "Read a total of $cnt events, expected $expected_count" | |
1572 | } | |
1573 | ||
086e6add MD |
1574 | function trace_first_line |
1575 | { | |
1576 | local trace_path=$1 | |
1577 | ||
1578 | which $BABELTRACE_BIN >/dev/null | |
1579 | if [ $? -ne 0 ]; then | |
1580 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
1581 | fi | |
1582 | ||
1583 | $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1 | |
1584 | } | |
1585 | ||
8cfcd41c MD |
1586 | function validate_trace_exp() |
1587 | { | |
1588 | local event_exp=$1 | |
1589 | local trace_path=$2 | |
1590 | ||
1591 | which $BABELTRACE_BIN >/dev/null | |
1592 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation" | |
1593 | ||
1594 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l) | |
1595 | if [ "$traced" -ne 0 ]; then | |
1596 | pass "Validate trace for expression '${event_exp}', $traced events" | |
1597 | else | |
1598 | fail "Validate trace for expression '${event_exp}'" | |
1599 | diag "Found $traced occurences of '${event_exp}'" | |
1600 | fi | |
1601 | ret=$? | |
1602 | return $ret | |
1603 | } | |
1604 | ||
1605 | function validate_trace_only_exp() | |
1606 | { | |
1607 | local event_exp=$1 | |
1608 | local trace_path=$2 | |
1609 | ||
1610 | which $BABELTRACE_BIN >/dev/null | |
1611 | skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" | |
1612 | ||
1613 | local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l) | |
1614 | local total=$($BABELTRACE_BIN $trace_path | wc -l) | |
1615 | ||
1616 | if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then | |
1617 | pass "Trace match with $total for expression '${event_exp}" | |
1618 | else | |
1619 | fail "Trace match" | |
1620 | diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected" | |
1621 | fi | |
1622 | ret=$? | |
1623 | return $ret | |
1624 | } | |
1625 | ||
1626 | function validate_trace_empty() | |
1627 | { | |
1628 | local trace_path=$1 | |
1629 | ||
1630 | which $BABELTRACE_BIN >/dev/null | |
1631 | if [ $? -ne 0 ]; then | |
1632 | skip 0 "Babeltrace binary not found. Skipping trace validation" | |
1633 | fi | |
1634 | ||
b98a9439 JD |
1635 | events=$($BABELTRACE_BIN $trace_path 2>/dev/null) |
1636 | ret=$? | |
1637 | if [ $ret -ne 0 ]; then | |
1638 | fail "Failed to parse trace" | |
1639 | return $ret | |
1640 | fi | |
1641 | ||
1642 | traced=$(echo -n "$events" | wc -l) | |
8cfcd41c MD |
1643 | if [ "$traced" -eq 0 ]; then |
1644 | pass "Validate empty trace" | |
1645 | else | |
1646 | fail "Validate empty trace" | |
1647 | diag "Found $traced events in trace" | |
1648 | fi | |
1649 | ret=$? | |
1650 | return $ret | |
1651 | } | |
801236b0 | 1652 | |
eded6438 | 1653 | function regenerate_metadata () |
801236b0 JD |
1654 | { |
1655 | local expected_to_fail=$1 | |
1656 | local sess_name=$2 | |
1657 | ||
eded6438 | 1658 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate metadata -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
801236b0 JD |
1659 | ret=$? |
1660 | if [[ $expected_to_fail -eq "1" ]]; then | |
1661 | test "$ret" -ne "0" | |
eded6438 | 1662 | ok $? "Expected fail on regenerate metadata $sess_name" |
801236b0 JD |
1663 | else |
1664 | ok $ret "Metadata regenerate $sess_name" | |
1665 | fi | |
1666 | } | |
1667 | ||
eded6438 | 1668 | function regenerate_metadata_ok () |
801236b0 | 1669 | { |
eded6438 | 1670 | regenerate_metadata 0 "$@" |
801236b0 JD |
1671 | } |
1672 | ||
eded6438 | 1673 | function regenerate_metadata_fail () |
801236b0 | 1674 | { |
eded6438 | 1675 | regenerate_metadata 1 "$@" |
801236b0 | 1676 | } |
512eb148 | 1677 | |
54cd6107 JD |
1678 | function regenerate_statedump () |
1679 | { | |
1680 | local expected_to_fail=$1 | |
1681 | local sess_name=$2 | |
1682 | ||
1683 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN regenerate statedump -s $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1684 | ret=$? | |
1685 | if [[ $expected_to_fail -eq "1" ]]; then | |
1686 | test "$ret" -ne "0" | |
1687 | ok $? "Expected fail on regenerate statedump $sess_name" | |
1688 | else | |
3db6ba39 | 1689 | ok $ret "Statedump regenerate $sess_name" |
54cd6107 JD |
1690 | fi |
1691 | } | |
1692 | ||
1693 | function regenerate_statedump_ok () | |
1694 | { | |
1695 | regenerate_statedump 0 "$@" | |
1696 | } | |
1697 | ||
1698 | function regenerate_statedump_fail () | |
1699 | { | |
1700 | regenerate_statedump 1 "$@" | |
1701 | } | |
1702 | ||
512eb148 JD |
1703 | function destructive_tests_enabled () |
1704 | { | |
1705 | if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then | |
1706 | return 0 | |
1707 | else | |
1708 | return 1 | |
1709 | fi | |
1710 | } |