Commit | Line | Data |
---|---|---|
9d16b343 | 1 | # Copyright (C) 2012 David Goulet <dgoulet@efficios.com> |
d3e8f6bb | 2 | # |
9d16b343 | 3 | # SPDX-License-Identifier: LGPL-2.1-only |
d3e8f6bb | 4 | # |
d3e8f6bb DG |
5 | |
6 | SESSIOND_BIN="lttng-sessiond" | |
725f658e | 7 | SESSIOND_MATCH=".*lttng-sess.*" |
19356f3a | 8 | RUNAS_BIN="lttng-runas" |
725f658e | 9 | RUNAS_MATCH=".*lttng-runas.*" |
f7613992 | 10 | CONSUMERD_BIN="lttng-consumerd" |
725f658e | 11 | CONSUMERD_MATCH=".*lttng-consumerd.*" |
f4e40ab6 | 12 | RELAYD_BIN="lttng-relayd" |
725f658e | 13 | RELAYD_MATCH=".*lttng-relayd.*" |
d3e8f6bb | 14 | LTTNG_BIN="lttng" |
c125de8f | 15 | BABELTRACE_BIN="babeltrace2" |
2cf48300 JR |
16 | OUTPUT_DEST=/dev/null |
17 | ERROR_OUTPUT_DEST=/dev/null | |
fa182fe0 | 18 | MI_XSD_MAJOR_VERSION=4 |
1f1f7e35 | 19 | MI_XSD_MINOR_VERSION=1 |
fa182fe0 JR |
20 | MI_XSD_PATH="$TESTDIR/../src/common/mi-lttng-${MI_XSD_MAJOR_VERSION}.${MI_XSD_MINOR_VERSION}.xsd" |
21 | MI_VALIDATE="$TESTDIR/utils/xml-utils/validate_xml ${MI_XSD_PATH}" | |
22 | ||
23 | XML_PRETTY="$TESTDIR/utils/xml-utils/pretty_xml" | |
24 | XML_EXTRACT="$TESTDIR/utils/xml-utils/extract_xml" | |
25 | XML_NODE_CHECK="${XML_EXTRACT} -e" | |
d3e8f6bb | 26 | |
bd666153 JR |
27 | # To match 20201127-175802 |
28 | date_time_pattern="[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]-[0-9][0-9][0-9][0-9][0-9][0-9]" | |
29 | # The size of a long on this system | |
30 | system_long_bit_size=$(getconf LONG_BIT) | |
31 | ||
fd4dfcec DG |
32 | # Minimal kernel version supported for session daemon tests |
33 | KERNEL_MAJOR_VERSION=2 | |
34 | KERNEL_MINOR_VERSION=6 | |
35 | KERNEL_PATCHLEVEL_VERSION=27 | |
36 | ||
651b8bb3 JG |
37 | # We set the default UST register timeout and network and app socket timeout to |
38 | # "wait forever", so that basic tests don't have to worry about hitting | |
39 | # timeouts on busy systems. Specialized tests should test those corner-cases. | |
629b9335 | 40 | export LTTNG_UST_REGISTER_TIMEOUT=-1 |
651b8bb3 JG |
41 | export LTTNG_NETWORK_SOCKET_TIMEOUT=-1 |
42 | export LTTNG_APP_SOCKET_TIMEOUT=-1 | |
629b9335 | 43 | |
fd7fe1a8 JR |
44 | # We set the default lttng-sessiond path to /bin/true to prevent the spawning |
45 | # of a daemonized sessiond. This is necessary since 'lttng create' will spawn | |
46 | # its own sessiond if none is running. It also ensures that 'lttng create' | |
47 | # fails when no sessiond is running. | |
48 | export LTTNG_SESSIOND_PATH="/bin/true" | |
49 | ||
29655db7 CB |
50 | source $TESTDIR/utils/tap/tap.sh |
51 | ||
65e663fa | 52 | if [ -z ${LTTNG_TEST_TEARDOWN_TIMEOUT+x} ]; then |
529bb942 MD |
53 | LTTNG_TEST_TEARDOWN_TIMEOUT=60 |
54 | fi | |
55 | ||
a0f8e310 JR |
56 | # Enable job monitor mode. |
57 | # Here we are mostly interested in the following from the monitor mode: | |
58 | # All processes run in a separate process group. | |
59 | # This allows us to ensure that all subprocesses from all background tasks are | |
60 | # cleaned up correctly using signal to process group id. | |
61 | set -m | |
62 | ||
63 | kill_background_jobs () | |
64 | { | |
65 | local pids | |
66 | pids=$(jobs -p) | |
67 | ||
68 | if [ -z "$pids" ]; then | |
69 | # Empty | |
70 | return 0 | |
71 | fi | |
72 | ||
73 | while read -r pid; | |
74 | do | |
75 | # Use negative number to send the signal to the process group. | |
76 | # This ensure that any subprocesses receive the signal. | |
77 | # /dev/null is used since there is an acceptable race between | |
78 | # the moments the pids are listed and the moment we send a | |
79 | # signal. | |
80 | kill -SIGTERM -- "-$pid" 2>/dev/null | |
81 | done <<< "$pids" | |
82 | } | |
83 | ||
84 | function cleanup () | |
1c362dc7 | 85 | { |
529bb942 | 86 | # Try to kill daemons gracefully |
a0f8e310 JR |
87 | stop_lttng_relayd_cleanup SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT |
88 | stop_lttng_sessiond_cleanup SIGTERM $LTTNG_TEST_TEARDOWN_TIMEOUT | |
529bb942 MD |
89 | |
90 | # If daemons are still present, forcibly kill them | |
a0f8e310 JR |
91 | stop_lttng_relayd_cleanup SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT |
92 | stop_lttng_sessiond_cleanup SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT | |
93 | stop_lttng_consumerd_cleanup SIGKILL $LTTNG_TEST_TEARDOWN_TIMEOUT | |
94 | ||
95 | kill_background_jobs | |
96 | } | |
97 | ||
98 | function full_cleanup () | |
99 | { | |
100 | cleanup | |
4e8ea4fa | 101 | exit 1 |
1c362dc7 JR |
102 | } |
103 | ||
a0f8e310 JR |
104 | function LTTNG_BAIL_OUT () |
105 | { | |
106 | cleanup | |
107 | BAIL_OUT "$@" | |
108 | } | |
109 | ||
27b667f7 MD |
110 | function null_pipes () |
111 | { | |
112 | exec 0>/dev/null | |
113 | exec 1>/dev/null | |
114 | exec 2>/dev/null | |
115 | } | |
1c362dc7 JR |
116 | |
117 | trap full_cleanup SIGINT SIGTERM | |
118 | ||
27b667f7 MD |
119 | # perl prove closes its child pipes before giving it a chance to run its |
120 | # signal trap handlers. Redirect pipes to /dev/null if SIGPIPE is caught | |
121 | # to allow those trap handlers to proceed. | |
122 | ||
123 | trap null_pipes SIGPIPE | |
124 | ||
7cb78e2f JR |
125 | # Check pgrep from env, default to pgrep if none |
126 | if [ -z "$PGREP" ]; then | |
127 | PGREP=pgrep | |
128 | fi | |
129 | ||
130 | # Due to the renaming of threads we need to use the full command (pgrep -f) to | |
131 | # identify the pids for multiple lttng related processes. The problem with "pgrep | |
132 | # -f" is that it ends up also looking at the arguments. We use a two stage | |
133 | # lookup. The first one is using "pgrep -f" yielding potential candidate. | |
134 | # The second on perform grep on the basename of the first field of the | |
135 | # /proc/pid/cmdline of the previously identified pids. The first field | |
136 | # correspond to the actual command. | |
137 | function lttng_pgrep () | |
138 | { | |
139 | local pattern=$1 | |
140 | local possible_pids | |
141 | local full_command_no_argument | |
142 | local command_basename | |
143 | ||
144 | possible_pids=$($PGREP -f "$pattern") | |
145 | if [ -z "$possible_pids" ]; then | |
146 | return 0 | |
147 | fi | |
148 | ||
149 | while IFS= read -r pid ; do | |
150 | # /proc/pid/cmdline is null separated. | |
00d1ff64 | 151 | if full_command_no_argument=$(cut -d '' -f 1 2>/dev/null < /proc/"$pid"/cmdline); then |
7cb78e2f JR |
152 | command_basename=$(basename "$full_command_no_argument") |
153 | if grep -q "$pattern" <<< "$command_basename"; then | |
154 | echo "$pid" | |
155 | fi | |
156 | fi | |
157 | done <<< "$possible_pids" | |
158 | return 0 | |
159 | } | |
160 | ||
fec81a7e CB |
161 | function print_ok () |
162 | { | |
163 | # Check if we are a terminal | |
164 | if [ -t 1 ]; then | |
165 | echo -e "\e[1;32mOK\e[0m" | |
166 | else | |
167 | echo -e "OK" | |
168 | fi | |
169 | } | |
170 | ||
171 | function print_fail () | |
172 | { | |
173 | # Check if we are a terminal | |
174 | if [ -t 1 ]; then | |
175 | echo -e "\e[1;31mFAIL\e[0m" | |
176 | else | |
177 | echo -e "FAIL" | |
178 | fi | |
179 | } | |
180 | ||
181 | function print_test_banner () | |
182 | { | |
7d0ad314 | 183 | local desc="$1" |
29655db7 | 184 | diag "$desc" |
fec81a7e CB |
185 | } |
186 | ||
fd4dfcec DG |
187 | function validate_kernel_version () |
188 | { | |
7d0ad314 | 189 | local kern_version=($(uname -r | awk -F. '{ printf("%d.%d.%d\n",$1,$2,$3); }' | tr '.' '\n')) |
fd4dfcec DG |
190 | if [ ${kern_version[0]} -gt $KERNEL_MAJOR_VERSION ]; then |
191 | return 0 | |
192 | fi | |
193 | if [ ${kern_version[1]} -gt $KERNEL_MINOR_VERSION ]; then | |
194 | return 0 | |
195 | fi | |
196 | if [ ${kern_version[2]} -ge $KERNEL_PATCHLEVEL_VERSION ]; then | |
197 | return 0 | |
198 | fi | |
199 | return 1 | |
200 | } | |
201 | ||
9ac429ef | 202 | # Generate a random string |
f4e40ab6 DG |
203 | # $1 = number of characters; defaults to 16 |
204 | # $2 = include special characters; 1 = yes, 0 = no; defaults to yes | |
9ac429ef | 205 | function randstring() |
f4e40ab6 DG |
206 | { |
207 | [ "$2" == "0" ] && CHAR="[:alnum:]" || CHAR="[:graph:]" | |
b89c3a68 | 208 | cat /dev/urandom 2>/dev/null | tr -cd "$CHAR" 2>/dev/null | head -c ${1:-16} 2>/dev/null |
f4e40ab6 DG |
209 | echo |
210 | } | |
211 | ||
9e136324 JG |
212 | # Return the number of _configured_ CPUs. |
213 | function conf_proc_count() | |
214 | { | |
215 | getconf _NPROCESSORS_CONF | |
216 | if [ $? -ne 0 ]; then | |
217 | diag "Failed to get the number of configured CPUs" | |
218 | fi | |
219 | echo | |
220 | } | |
221 | ||
9c8a3964 JR |
222 | # Check if base lttng-modules are present. |
223 | # Bail out on failure | |
224 | function validate_lttng_modules_present () | |
225 | { | |
03f11686 | 226 | # Check for loadable modules. |
9c8a3964 | 227 | modprobe -n lttng-tracer 2>/dev/null |
03f11686 FD |
228 | if [ $? -eq 0 ]; then |
229 | return 0 | |
9c8a3964 | 230 | fi |
03f11686 FD |
231 | |
232 | # Check for builtin modules. | |
233 | ls /proc/lttng > /dev/null 2>&1 | |
234 | if [ $? -eq 0 ]; then | |
235 | return 0 | |
236 | fi | |
237 | ||
a0f8e310 | 238 | LTTNG_BAIL_OUT "LTTng modules not detected." |
9c8a3964 JR |
239 | } |
240 | ||
a4705d55 SM |
241 | # Run the lttng binary. |
242 | # | |
243 | # The first two arguments are stdout and stderr redirect paths, respectively. | |
244 | # The rest of the arguments are forwarded to the lttng binary | |
245 | function _run_lttng_cmd | |
246 | { | |
247 | local stdout_dest="$1" | |
248 | local stderr_dest="$2" | |
249 | shift 2 | |
250 | ||
251 | diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN $*" | |
252 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN "$@" 1> "$stdout_dest" 2> "$stderr_dest" | |
253 | } | |
254 | ||
4a180d9f | 255 | function enable_kernel_lttng_event |
f4e40ab6 | 256 | { |
854382b8 JR |
257 | local withtap="$1" |
258 | local expected_to_fail="$2" | |
259 | local sess_name="$3" | |
260 | local event_name="$4" | |
261 | local channel_name="$5" | |
f4e40ab6 | 262 | |
4a180d9f | 263 | if [ -z "$event_name" ]; then |
f4e40ab6 | 264 | # Enable all event if no event name specified |
29655db7 | 265 | event_name="-a" |
f4e40ab6 DG |
266 | fi |
267 | ||
4a180d9f | 268 | if [ -z "$channel_name" ]; then |
07b86b52 JD |
269 | # default channel if none specified |
270 | chan="" | |
271 | else | |
272 | chan="-c $channel_name" | |
273 | fi | |
274 | ||
a4705d55 SM |
275 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
276 | enable-event "$event_name" $chan -s $sess_name -k | |
4a180d9f MD |
277 | ret=$? |
278 | if [[ $expected_to_fail -eq "1" ]]; then | |
279 | test $ret -ne "0" | |
854382b8 JR |
280 | ret=$? |
281 | if [ $withtap -eq "1" ]; then | |
282 | ok $ret "Enable kernel event $event_name for session $session_name on channel $channel_name failed as expected" | |
283 | fi | |
4a180d9f | 284 | else |
854382b8 JR |
285 | if [ $withtap -eq "1" ]; then |
286 | ok $ret "Enable kernel event $event_name for session $sess_name" | |
287 | fi | |
4a180d9f MD |
288 | fi |
289 | } | |
290 | ||
291 | function enable_kernel_lttng_event_ok () | |
292 | { | |
854382b8 | 293 | enable_kernel_lttng_event 1 0 "$@" |
4a180d9f MD |
294 | } |
295 | ||
296 | function enable_kernel_lttng_event_fail () | |
297 | { | |
854382b8 JR |
298 | enable_kernel_lttng_event 1 1 "$@" |
299 | } | |
300 | ||
301 | function enable_kernel_lttng_event_notap () | |
302 | { | |
303 | enable_kernel_lttng_event 0 0 "$@" | |
4a180d9f MD |
304 | } |
305 | ||
306 | # Old interface | |
307 | function lttng_enable_kernel_event | |
308 | { | |
309 | enable_kernel_lttng_event_ok "$@" | |
f4e40ab6 DG |
310 | } |
311 | ||
8cfcd41c MD |
312 | function lttng_enable_kernel_syscall() |
313 | { | |
314 | local expected_to_fail=$1 | |
315 | local sess_name=$2 | |
316 | local syscall_name=$3 | |
317 | local channel_name=$4 | |
318 | ||
319 | if [ -z $syscall_name ]; then | |
320 | # Enable all event if no syscall name specified | |
321 | syscall_name="-a" | |
322 | fi | |
323 | ||
324 | if [ -z $channel_name ]; then | |
325 | # default channel if none specified | |
326 | chan="" | |
327 | else | |
328 | chan="-c $channel_name" | |
329 | fi | |
330 | ||
a4705d55 SM |
331 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
332 | enable-event --syscall "$syscall_name" $chan -s $sess_name -k | |
8cfcd41c MD |
333 | ret=$? |
334 | if [[ $expected_to_fail -eq "1" ]]; then | |
335 | test $ret -ne "0" | |
336 | ok $? "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name fail as expected" | |
337 | else | |
338 | ok $ret "Enable kernel syscall $syscall_name for session $sess_name on channel $channel_name" | |
339 | fi | |
340 | } | |
341 | ||
342 | function lttng_enable_kernel_syscall_ok() | |
343 | { | |
421b83dc | 344 | lttng_enable_kernel_syscall 0 "$@" |
8cfcd41c MD |
345 | } |
346 | ||
347 | function lttng_enable_kernel_syscall_fail() | |
348 | { | |
421b83dc | 349 | lttng_enable_kernel_syscall 1 "$@" |
8cfcd41c MD |
350 | } |
351 | ||
352 | function lttng_disable_kernel_syscall() | |
353 | { | |
354 | local expected_to_fail=$1 | |
355 | local sess_name=$2 | |
356 | local syscall_name=$3 | |
357 | local channel_name=$4 | |
358 | ||
359 | if [ -z $syscall_name ]; then | |
360 | # Enable all event if no syscall name specified | |
361 | syscall_name="-a" | |
362 | fi | |
363 | ||
364 | if [ -z $channel_name ]; then | |
365 | # default channel if none specified | |
366 | chan="" | |
367 | else | |
368 | chan="-c $channel_name" | |
369 | fi | |
370 | ||
a4705d55 SM |
371 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
372 | disable-event --syscall "$syscall_name" $chan -s $sess_name -k | |
8cfcd41c MD |
373 | |
374 | ret=$? | |
375 | if [[ $expected_to_fail -eq "1" ]]; then | |
376 | test $ret -ne "0" | |
34ab15c5 | 377 | ok $? "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name failed as expected" |
8cfcd41c MD |
378 | else |
379 | ok $ret "Disable kernel syscall $syscall_name for session $sess_name on channel $channel_name" | |
380 | fi | |
381 | } | |
382 | ||
383 | function lttng_disable_kernel_syscall_ok() | |
384 | { | |
421b83dc | 385 | lttng_disable_kernel_syscall 0 "$@" |
8cfcd41c MD |
386 | } |
387 | ||
388 | function lttng_disable_kernel_syscall_fail() | |
389 | { | |
421b83dc | 390 | lttng_disable_kernel_syscall 1 "$@" |
8cfcd41c MD |
391 | } |
392 | ||
b6d14cf3 FD |
393 | function lttng_enable_kernel_function_event () |
394 | { | |
395 | local expected_to_fail="$1" | |
396 | local sess_name="$2" | |
397 | local target="$3" | |
398 | local event_name="$4" | |
399 | ||
400 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event --kernel --function="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST" | |
401 | ret=$? | |
402 | if [[ $expected_to_fail -eq "1" ]]; then | |
403 | test $ret -ne "0" | |
404 | ok $? "Enable kernel function event for session $sess_name failed as expected" | |
405 | else | |
406 | ok $ret "Enable kernel function event for session $sess_name" | |
407 | fi | |
408 | } | |
409 | ||
410 | function lttng_enable_kernel_function_event_ok () | |
411 | { | |
412 | lttng_enable_kernel_function_event 0 "$@" | |
413 | } | |
414 | ||
a9c2df2b FD |
415 | function lttng_enable_kernel_userspace_probe_event () |
416 | { | |
417 | local expected_to_fail="$1" | |
418 | local sess_name="$2" | |
419 | local target="$3" | |
420 | local event_name="$4" | |
421 | ||
422 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event --kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST" | |
423 | ret=$? | |
424 | if [[ $expected_to_fail -eq "1" ]]; then | |
425 | test $ret -ne "0" | |
426 | ok $? "Enable kernel userspace probe event for session $sess_name failed as expected" | |
427 | else | |
428 | ok $ret "Enable kernel userspace probe event for session $sess_name" | |
429 | fi | |
430 | } | |
431 | ||
432 | function lttng_enable_kernel_userspace_probe_event_fail () | |
433 | { | |
434 | lttng_enable_kernel_userspace_probe_event 1 "$@" | |
435 | } | |
436 | ||
437 | function lttng_enable_kernel_userspace_probe_event_ok () | |
438 | { | |
439 | lttng_enable_kernel_userspace_probe_event 0 "$@" | |
440 | } | |
441 | ||
442 | function disable_kernel_lttng_userspace_probe_event_ok () | |
443 | { | |
444 | local sess_name="$1" | |
445 | local event_name="$2" | |
446 | ||
447 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event --kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST" | |
448 | ok $? "Disable kernel event $target for session $sess_name" | |
449 | } | |
d96f6315 MD |
450 | function lttng_enable_kernel_channel() |
451 | { | |
854382b8 JR |
452 | local withtap=$1 |
453 | local expected_to_fail=$2 | |
454 | local sess_name=$3 | |
455 | local channel_name=$4 | |
c28fcefd | 456 | local opts="${@:5}" |
d96f6315 | 457 | |
a4705d55 SM |
458 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
459 | enable-channel -k $channel_name -s $sess_name $opts | |
d96f6315 MD |
460 | ret=$? |
461 | if [[ $expected_to_fail -eq "1" ]]; then | |
462 | test "$ret" -ne "0" | |
854382b8 JR |
463 | ret=$? |
464 | if [ $withtap -eq "1" ]; then | |
465 | ok $ret "Enable channel $channel_name for session $sess_name failed as expected" | |
466 | fi | |
d96f6315 | 467 | else |
854382b8 JR |
468 | if [ $withtap -eq "1" ]; then |
469 | ok $ret "Enable channel $channel_name for session $sess_name" | |
470 | fi | |
d96f6315 MD |
471 | fi |
472 | } | |
473 | ||
474 | function lttng_enable_kernel_channel_ok() | |
475 | { | |
854382b8 | 476 | lttng_enable_kernel_channel 1 0 "$@" |
d96f6315 MD |
477 | } |
478 | ||
479 | function lttng_enable_kernel_channel_fail() | |
480 | { | |
854382b8 JR |
481 | lttng_enable_kernel_channel 1 1 "$@" |
482 | } | |
483 | ||
484 | function lttng_enable_kernel_channel_notap() | |
485 | { | |
486 | lttng_enable_kernel_channel 0 0 "$@" | |
487 | } | |
488 | ||
489 | function enable_kernel_lttng_channel_ok() | |
490 | { | |
491 | lttng_enable_kernel_channel 1 0 "$@" | |
d96f6315 MD |
492 | } |
493 | ||
494 | function lttng_disable_kernel_channel() | |
495 | { | |
496 | local expected_to_fail=$1 | |
497 | local sess_name=$2 | |
498 | local channel_name=$3 | |
499 | ||
a4705d55 SM |
500 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
501 | disable-channel -k $channel_name -s $sess_name | |
d96f6315 MD |
502 | ret=$? |
503 | if [[ $expected_to_fail -eq "1" ]]; then | |
504 | test "$ret" -ne "0" | |
34ab15c5 | 505 | ok $? "Disable channel $channel_name for session $sess_name failed as expected" |
d96f6315 | 506 | else |
34ab15c5 | 507 | ok $ret "Disable channel $channel_name for session $sess_name" |
d96f6315 MD |
508 | fi |
509 | } | |
510 | ||
511 | function lttng_disable_kernel_channel_ok() | |
512 | { | |
421b83dc | 513 | lttng_disable_kernel_channel 0 "$@" |
d96f6315 MD |
514 | } |
515 | ||
516 | function lttng_disable_kernel_channel_fail() | |
517 | { | |
421b83dc | 518 | lttng_disable_kernel_channel 1 "$@" |
d96f6315 MD |
519 | } |
520 | ||
05aa48da | 521 | function start_lttng_relayd_opt() |
f4e40ab6 | 522 | { |
05aa48da | 523 | local withtap=$1 |
f3630ec4 JR |
524 | local process_mode=$2 |
525 | local opt=$3 | |
173af62f | 526 | |
529bb942 | 527 | DIR=$(readlink -f "$TESTDIR") |
f4e40ab6 | 528 | |
7cb78e2f | 529 | if [ -z $(lttng_pgrep "$RELAYD_MATCH") ]; then |
529bb942 | 530 | # shellcheck disable=SC2086 |
f3630ec4 JR |
531 | $DIR/../src/bin/lttng-relayd/$RELAYD_BIN $process_mode $opt 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
532 | #$DIR/../src/bin/lttng-relayd/$RELAYD_BIN $opt -vvv >>/tmp/relayd.log 2>&1 & | |
f4e40ab6 | 533 | if [ $? -eq 1 ]; then |
f3630ec4 JR |
534 | if [ $withtap -eq "1" ]; then |
535 | fail "Start lttng-relayd (process mode: $process_mode opt: $opt)" | |
05aa48da | 536 | fi |
f4e40ab6 DG |
537 | return 1 |
538 | else | |
f3630ec4 JR |
539 | if [ $withtap -eq "1" ]; then |
540 | pass "Start lttng-relayd (process mode: $process_mode opt: $opt)" | |
05aa48da | 541 | fi |
f4e40ab6 DG |
542 | fi |
543 | else | |
29655db7 | 544 | pass "Start lttng-relayd (opt: $opt)" |
f4e40ab6 DG |
545 | fi |
546 | } | |
547 | ||
05aa48da | 548 | function start_lttng_relayd() |
f4e40ab6 | 549 | { |
f3630ec4 | 550 | start_lttng_relayd_opt 1 "-b" "$@" |
05aa48da MD |
551 | } |
552 | ||
553 | function start_lttng_relayd_notap() | |
554 | { | |
f3630ec4 | 555 | start_lttng_relayd_opt 0 "-b" "$@" |
05aa48da MD |
556 | } |
557 | ||
558 | function stop_lttng_relayd_opt() | |
559 | { | |
560 | local withtap=$1 | |
a0f8e310 JR |
561 | local is_cleanup=$2 |
562 | local signal=$3 | |
563 | local timeout_s=$4 | |
564 | local dtimeleft_s= | |
565 | local retval=0 | |
566 | local pids | |
05aa48da | 567 | |
529bb942 MD |
568 | if [ -z "$signal" ]; then |
569 | signal="SIGTERM" | |
05aa48da | 570 | fi |
29655db7 | 571 | |
529bb942 MD |
572 | |
573 | # Multiply time by 2 to simplify integer arithmetic | |
574 | if [ -n "$timeout_s" ]; then | |
575 | dtimeleft_s=$((timeout_s * 2)) | |
576 | fi | |
577 | ||
529bb942 | 578 | |
7cb78e2f | 579 | pids=$(lttng_pgrep "$RELAYD_MATCH") |
529bb942 | 580 | if [ -z "$pids" ]; then |
a0f8e310 JR |
581 | if [ "$is_cleanup" -eq 1 ]; then |
582 | : | |
583 | elif [ "$withtap" -eq "1" ]; then | |
584 | fail "No relay daemon to kill" | |
585 | else | |
586 | LTTNG_BAIL_OUT "No relay daemon to kill" | |
529bb942 MD |
587 | fi |
588 | return 0 | |
589 | fi | |
590 | ||
591 | diag "Killing (signal $signal) lttng-relayd (pid: $pids)" | |
592 | ||
593 | # shellcheck disable=SC2086 | |
594 | if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then | |
595 | retval=1 | |
596 | if [ "$withtap" -eq "1" ]; then | |
05aa48da MD |
597 | fail "Kill relay daemon" |
598 | fi | |
05aa48da | 599 | else |
f4e40ab6 DG |
600 | out=1 |
601 | while [ -n "$out" ]; do | |
7cb78e2f | 602 | out=$(lttng_pgrep "$RELAYD_MATCH") |
529bb942 MD |
603 | if [ -n "$dtimeleft_s" ]; then |
604 | if [ $dtimeleft_s -lt 0 ]; then | |
605 | out= | |
606 | retval=1 | |
607 | fi | |
608 | dtimeleft_s=$((dtimeleft_s - 1)) | |
609 | fi | |
f4e40ab6 DG |
610 | sleep 0.5 |
611 | done | |
529bb942 MD |
612 | if [ "$withtap" -eq "1" ]; then |
613 | if [ "$retval" -eq "0" ]; then | |
614 | pass "Wait after kill relay daemon" | |
615 | else | |
616 | fail "Wait after kill relay daemon" | |
617 | fi | |
05aa48da | 618 | fi |
1fb23888 MD |
619 | fi |
620 | return $retval | |
621 | } | |
622 | ||
05aa48da | 623 | function stop_lttng_relayd() |
1fb23888 | 624 | { |
a0f8e310 | 625 | stop_lttng_relayd_opt 1 0 "$@" |
05aa48da | 626 | } |
1fb23888 | 627 | |
05aa48da MD |
628 | function stop_lttng_relayd_notap() |
629 | { | |
a0f8e310 JR |
630 | stop_lttng_relayd_opt 0 0 "$@" |
631 | } | |
632 | ||
633 | function stop_lttng_relayd_cleanup() | |
634 | { | |
635 | stop_lttng_relayd_opt 0 1 "$@" | |
f4e40ab6 DG |
636 | } |
637 | ||
05aa48da MD |
638 | #First arg: show tap output |
639 | #Second argument: load path for automatic loading | |
640 | function start_lttng_sessiond_opt() | |
355f483d | 641 | { |
05aa48da MD |
642 | local withtap=$1 |
643 | local load_path=$2 | |
8d51ddbc | 644 | |
1d302e3d JR |
645 | # The rest of the arguments will be passed directly to lttng-sessiond. |
646 | shift 2 | |
647 | ||
4b01971f | 648 | local env_vars="" |
b916da6b | 649 | local consumerd="" |
b916da6b | 650 | |
529bb942 MD |
651 | local long_bit_value= |
652 | long_bit_value=$(getconf LONG_BIT) | |
653 | ||
654 | if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then | |
355f483d DG |
655 | # Env variable requested no session daemon |
656 | return | |
657 | fi | |
658 | ||
529bb942 | 659 | DIR=$(readlink -f "$TESTDIR") |
b916da6b JR |
660 | |
661 | # Get long_bit value for 32/64 consumerd | |
662 | case "$long_bit_value" in | |
663 | 32) | |
664 | consumerd="--consumerd32-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd" | |
665 | ;; | |
666 | 64) | |
667 | consumerd="--consumerd64-path=$DIR/../src/bin/lttng-consumerd/lttng-consumerd" | |
668 | ;; | |
669 | *) | |
670 | return | |
671 | ;; | |
672 | esac | |
673 | ||
4b01971f JR |
674 | # Check for env. variable. Allow the use of LD_PRELOAD etc. |
675 | if [[ "x${LTTNG_SESSIOND_ENV_VARS}" != "x" ]]; then | |
529bb942 | 676 | env_vars="${LTTNG_SESSIOND_ENV_VARS} " |
4b01971f | 677 | fi |
529bb942 | 678 | env_vars="${env_vars}$DIR/../src/bin/lttng-sessiond/$SESSIOND_BIN" |
4b01971f | 679 | |
529bb942 | 680 | if ! validate_kernel_version; then |
29655db7 | 681 | fail "Start session daemon" |
a0f8e310 | 682 | LTTNG_BAIL_OUT "*** Kernel too old for session daemon tests ***" |
355f483d DG |
683 | fi |
684 | ||
4ae04234 MJ |
685 | diag "export LTTNG_SESSION_CONFIG_XSD_PATH=${DIR}/../src/common/" |
686 | : "${LTTNG_SESSION_CONFIG_XSD_PATH="${DIR}/../src/common/"}" | |
d3d97763 | 687 | export LTTNG_SESSION_CONFIG_XSD_PATH |
29655db7 | 688 | |
7cb78e2f | 689 | if [ -z "$(lttng_pgrep "${SESSIOND_MATCH}")" ]; then |
8d51ddbc | 690 | # Have a load path ? |
05aa48da | 691 | if [ -n "$load_path" ]; then |
a4705d55 | 692 | diag "env $env_vars --load $load_path --background $consumerd $@" |
529bb942 | 693 | # shellcheck disable=SC2086 |
1d302e3d | 694 | env $env_vars --load "$load_path" --background "$consumerd" "$@" |
8d51ddbc | 695 | else |
a4705d55 | 696 | diag "env $env_vars --background $consumerd $@" |
529bb942 | 697 | # shellcheck disable=SC2086 |
1d302e3d | 698 | env $env_vars --background "$consumerd" "$@" |
8d51ddbc | 699 | fi |
0fc2834c | 700 | #$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 | 701 | status=$? |
529bb942 | 702 | if [ "$withtap" -eq "1" ]; then |
05aa48da MD |
703 | ok $status "Start session daemon" |
704 | fi | |
29655db7 | 705 | fi |
355f483d DG |
706 | } |
707 | ||
05aa48da MD |
708 | function start_lttng_sessiond() |
709 | { | |
710 | start_lttng_sessiond_opt 1 "$@" | |
711 | } | |
712 | ||
713 | function start_lttng_sessiond_notap() | |
d3e8f6bb | 714 | { |
05aa48da MD |
715 | start_lttng_sessiond_opt 0 "$@" |
716 | } | |
717 | ||
718 | function stop_lttng_sessiond_opt() | |
719 | { | |
720 | local withtap=$1 | |
a0f8e310 JR |
721 | local is_cleanup=$2 |
722 | local signal=$3 | |
723 | local timeout_s=$4 | |
724 | local dtimeleft_s= | |
725 | local retval=0 | |
726 | local runas_pids | |
727 | local pids | |
05aa48da | 728 | |
529bb942 MD |
729 | if [ -z "$signal" ]; then |
730 | signal=SIGTERM | |
731 | fi | |
732 | ||
529bb942 MD |
733 | # Multiply time by 2 to simplify integer arithmetic |
734 | if [ -n "$timeout_s" ]; then | |
735 | dtimeleft_s=$((timeout_s * 2)) | |
736 | fi | |
737 | ||
738 | if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then | |
355f483d | 739 | # Env variable requested no session daemon |
529bb942 | 740 | return 0 |
355f483d DG |
741 | fi |
742 | ||
7cb78e2f | 743 | runas_pids=$(lttng_pgrep "$RUNAS_MATCH") |
7cb78e2f | 744 | pids=$(lttng_pgrep "$SESSIOND_MATCH") |
529bb942 MD |
745 | |
746 | if [ -n "$runas_pids" ]; then | |
747 | pids="$pids $runas_pids" | |
4c80129b | 748 | fi |
529bb942 MD |
749 | |
750 | if [ -z "$pids" ]; then | |
33e55711 | 751 | if [ "$is_cleanup" -eq 1 ]; then |
a0f8e310 JR |
752 | : |
753 | elif [ "$withtap" -eq "1" ]; then | |
d3d783bb FD |
754 | fail "No session daemon to kill" |
755 | else | |
a0f8e310 | 756 | LTTNG_BAIL_OUT "No session daemon to kill" |
529bb942 MD |
757 | fi |
758 | return 0 | |
8490897a | 759 | fi |
29655db7 | 760 | |
529bb942 MD |
761 | diag "Killing (signal $signal) $SESSIOND_BIN and lt-$SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')" |
762 | ||
763 | # shellcheck disable=SC2086 | |
764 | if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then | |
765 | retval=1 | |
766 | if [ "$withtap" -eq "1" ]; then | |
05aa48da MD |
767 | fail "Kill sessions daemon" |
768 | fi | |
d3e8f6bb | 769 | else |
5fa32580 DG |
770 | out=1 |
771 | while [ -n "$out" ]; do | |
7cb78e2f | 772 | out=$(lttng_pgrep "${SESSIOND_MATCH}") |
529bb942 MD |
773 | if [ -n "$dtimeleft_s" ]; then |
774 | if [ $dtimeleft_s -lt 0 ]; then | |
775 | out= | |
776 | retval=1 | |
777 | fi | |
778 | dtimeleft_s=$((dtimeleft_s - 1)) | |
779 | fi | |
5fa32580 DG |
780 | sleep 0.5 |
781 | done | |
f7613992 MD |
782 | out=1 |
783 | while [ -n "$out" ]; do | |
7cb78e2f | 784 | out=$(lttng_pgrep "$CONSUMERD_MATCH") |
529bb942 MD |
785 | if [ -n "$dtimeleft_s" ]; then |
786 | if [ $dtimeleft_s -lt 0 ]; then | |
787 | out= | |
788 | retval=1 | |
789 | fi | |
790 | dtimeleft_s=$((dtimeleft_s - 1)) | |
791 | fi | |
f7613992 MD |
792 | sleep 0.5 |
793 | done | |
1c362dc7 | 794 | |
529bb942 MD |
795 | if [ "$withtap" -eq "1" ]; then |
796 | if [ "$retval" -eq "0" ]; then | |
797 | pass "Wait after kill session daemon" | |
798 | else | |
799 | fail "Wait after kill session daemon" | |
800 | fi | |
05aa48da | 801 | fi |
d3e8f6bb | 802 | fi |
529bb942 MD |
803 | if [ "$signal" = "SIGKILL" ]; then |
804 | if [ "$(id -u)" -eq "0" ]; then | |
805 | local modules= | |
806 | modules="$(lsmod | grep ^lttng | awk '{print $1}')" | |
807 | ||
808 | if [ -n "$modules" ]; then | |
809 | diag "Unloading all LTTng modules" | |
d0e263e7 | 810 | modprobe --remove "$modules" |
529bb942 MD |
811 | fi |
812 | fi | |
813 | fi | |
814 | ||
815 | return $retval | |
d3e8f6bb DG |
816 | } |
817 | ||
05aa48da MD |
818 | function stop_lttng_sessiond() |
819 | { | |
a0f8e310 | 820 | stop_lttng_sessiond_opt 1 0 "$@" |
05aa48da MD |
821 | } |
822 | ||
823 | function stop_lttng_sessiond_notap() | |
824 | { | |
a0f8e310 JR |
825 | stop_lttng_sessiond_opt 0 0 "$@" |
826 | } | |
827 | ||
828 | function stop_lttng_sessiond_cleanup() | |
829 | { | |
830 | stop_lttng_sessiond_opt 0 1 "$@" | |
05aa48da MD |
831 | } |
832 | ||
8490897a MD |
833 | function sigstop_lttng_sessiond_opt() |
834 | { | |
835 | local withtap=$1 | |
836 | local signal=SIGSTOP | |
a0f8e310 | 837 | local pids |
8490897a | 838 | |
529bb942 | 839 | if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then |
8490897a MD |
840 | # Env variable requested no session daemon |
841 | return | |
842 | fi | |
843 | ||
a0f8e310 | 844 | pids="$(lttng_pgrep "${SESSIOND_MATCH}") $(lttng_pgrep "$RUNAS_MATCH")" |
8490897a | 845 | |
529bb942 | 846 | if [ "$withtap" -eq "1" ]; then |
a0f8e310 | 847 | diag "Sending SIGSTOP to lt-$SESSIOND_BIN and $SESSIOND_BIN pids: $(echo "$pids" | tr '\n' ' ')" |
8490897a | 848 | fi |
8490897a | 849 | |
529bb942 | 850 | # shellcheck disable=SC2086 |
a0f8e310 | 851 | if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then |
529bb942 | 852 | if [ "$withtap" -eq "1" ]; then |
8490897a MD |
853 | fail "Sending SIGSTOP to session daemon" |
854 | fi | |
855 | else | |
856 | out=1 | |
857 | while [ $out -ne 0 ]; do | |
a0f8e310 | 858 | pids="$(lttng_pgrep "$SESSIOND_MATCH")" |
8490897a MD |
859 | |
860 | # Wait until state becomes stopped for session | |
861 | # daemon(s). | |
862 | out=0 | |
a0f8e310 | 863 | for sessiond_pid in $pids; do |
529bb942 | 864 | state="$(ps -p "$sessiond_pid" -o state= )" |
8490897a MD |
865 | if [[ -n "$state" && "$state" != "T" ]]; then |
866 | out=1 | |
867 | fi | |
868 | done | |
869 | sleep 0.5 | |
870 | done | |
529bb942 | 871 | if [ "$withtap" -eq "1" ]; then |
8490897a MD |
872 | pass "Sending SIGSTOP to session daemon" |
873 | fi | |
874 | fi | |
875 | } | |
876 | ||
877 | function sigstop_lttng_sessiond() | |
878 | { | |
879 | sigstop_lttng_sessiond_opt 1 "$@" | |
880 | } | |
881 | ||
882 | function sigstop_lttng_sessiond_notap() | |
883 | { | |
884 | sigstop_lttng_sessiond_opt 0 "$@" | |
885 | } | |
886 | ||
4c80129b JR |
887 | function stop_lttng_consumerd_opt() |
888 | { | |
889 | local withtap=$1 | |
a0f8e310 JR |
890 | local is_cleanup=$2 |
891 | local signal=$3 | |
892 | local timeout_s=$4 | |
893 | local dtimeleft_s= | |
894 | local retval=0 | |
895 | local pids | |
4c80129b | 896 | |
529bb942 MD |
897 | if [ -z "$signal" ]; then |
898 | signal=SIGTERM | |
899 | fi | |
900 | ||
529bb942 MD |
901 | # Multiply time by 2 to simplify integer arithmetic |
902 | if [ -n "$timeout_s" ]; then | |
903 | dtimeleft_s=$((timeout_s * 2)) | |
4c80129b JR |
904 | fi |
905 | ||
a0f8e310 | 906 | pids="$(lttng_pgrep "$CONSUMERD_MATCH")" |
529bb942 | 907 | |
a0f8e310 JR |
908 | if [ -z "$pids" ]; then |
909 | if [ "$is_cleanup" -eq 1 ]; then | |
910 | : | |
911 | elif [ "$withtap" -eq "1" ]; then | |
912 | fail "No consumerd daemon to kill" | |
913 | else | |
914 | LTTNG_BAIL_OUT "No consumerd daemon to kill" | |
529bb942 MD |
915 | fi |
916 | return 0 | |
4c80129b | 917 | fi |
3355fd4d | 918 | |
a0f8e310 | 919 | diag "Killing (signal $signal) $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')" |
4c80129b | 920 | |
529bb942 | 921 | # shellcheck disable=SC2086 |
a0f8e310 | 922 | if ! kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST; then |
529bb942 MD |
923 | retval=1 |
924 | if [ "$withtap" -eq "1" ]; then | |
4c80129b JR |
925 | fail "Kill consumer daemon" |
926 | fi | |
4c80129b JR |
927 | else |
928 | out=1 | |
929 | while [ $out -ne 0 ]; do | |
a0f8e310 | 930 | pids="$(lttng_pgrep "$CONSUMERD_MATCH")" |
4c80129b JR |
931 | |
932 | # If consumerds are still present check their status. | |
933 | # A zombie status qualifies the consumerd as *killed* | |
934 | out=0 | |
a0f8e310 | 935 | for consumer_pid in $pids; do |
529bb942 | 936 | state="$(ps -p "$consumer_pid" -o state= )" |
4c80129b JR |
937 | if [[ -n "$state" && "$state" != "Z" ]]; then |
938 | out=1 | |
939 | fi | |
940 | done | |
529bb942 MD |
941 | if [ -n "$dtimeleft_s" ]; then |
942 | if [ $dtimeleft_s -lt 0 ]; then | |
943 | out=0 | |
944 | retval=1 | |
945 | fi | |
946 | dtimeleft_s=$((dtimeleft_s - 1)) | |
947 | fi | |
4c80129b JR |
948 | sleep 0.5 |
949 | done | |
529bb942 MD |
950 | if [ "$withtap" -eq "1" ]; then |
951 | if [ "$retval" -eq "0" ]; then | |
952 | pass "Wait after kill consumer daemon" | |
953 | else | |
954 | fail "Wait after kill consumer daemon" | |
955 | fi | |
4c80129b JR |
956 | fi |
957 | fi | |
529bb942 | 958 | |
4c80129b JR |
959 | return $retval |
960 | } | |
961 | ||
962 | function stop_lttng_consumerd() | |
963 | { | |
a0f8e310 | 964 | stop_lttng_consumerd_opt 1 0 "$@" |
4c80129b JR |
965 | } |
966 | ||
967 | function stop_lttng_consumerd_notap() | |
968 | { | |
a0f8e310 JR |
969 | stop_lttng_consumerd_opt 0 0 "$@" |
970 | } | |
971 | ||
972 | function stop_lttng_consumerd_cleanup() | |
973 | { | |
974 | stop_lttng_consumerd_opt 0 1 "$@" | |
4c80129b JR |
975 | } |
976 | ||
8490897a MD |
977 | function sigstop_lttng_consumerd_opt() |
978 | { | |
979 | local withtap=$1 | |
980 | local signal=SIGSTOP | |
a0f8e310 | 981 | local pids |
8490897a | 982 | |
a0f8e310 | 983 | pids="$(lttng_pgrep "$CONSUMERD_MATCH")" |
8490897a | 984 | |
a0f8e310 | 985 | diag "Sending SIGSTOP to $CONSUMERD_BIN pids: $(echo "$pids" | tr '\n' ' ')" |
8490897a | 986 | |
529bb942 | 987 | # shellcheck disable=SC2086 |
a0f8e310 | 988 | kill -s $signal $pids 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST |
8490897a | 989 | retval=$? |
8490897a | 990 | |
529bb942 MD |
991 | if [ $retval -eq 1 ]; then |
992 | if [ "$withtap" -eq "1" ]; then | |
8490897a MD |
993 | fail "Sending SIGSTOP to consumer daemon" |
994 | fi | |
995 | return 1 | |
996 | else | |
997 | out=1 | |
998 | while [ $out -ne 0 ]; do | |
a0f8e310 | 999 | pids="$(lttng_pgrep "$CONSUMERD_MATCH")" |
8490897a MD |
1000 | |
1001 | # Wait until state becomes stopped for all | |
1002 | # consumers. | |
1003 | out=0 | |
a0f8e310 | 1004 | for consumer_pid in $pids; do |
529bb942 | 1005 | state="$(ps -p "$consumer_pid" -o state= )" |
8490897a MD |
1006 | if [[ -n "$state" && "$state" != "T" ]]; then |
1007 | out=1 | |
1008 | fi | |
1009 | done | |
1010 | sleep 0.5 | |
1011 | done | |
529bb942 | 1012 | if [ "$withtap" -eq "1" ]; then |
8490897a MD |
1013 | pass "Sending SIGSTOP to consumer daemon" |
1014 | fi | |
1015 | fi | |
1016 | return $retval | |
1017 | } | |
1018 | ||
1019 | function sigstop_lttng_consumerd() | |
1020 | { | |
1021 | sigstop_lttng_consumerd_opt 1 "$@" | |
1022 | } | |
1023 | ||
1024 | function sigstop_lttng_consumerd_notap() | |
1025 | { | |
1026 | sigstop_lttng_consumerd_opt 0 "$@" | |
1027 | } | |
1028 | ||
873c2aae JRJ |
1029 | function list_lttng_with_opts () |
1030 | { | |
3c4c3582 JR |
1031 | local ret |
1032 | local withtap=$1 | |
1033 | shift | |
7d0ad314 | 1034 | local opts=$1 |
a4705d55 SM |
1035 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1036 | list $opts | |
3c4c3582 JR |
1037 | ret=$? |
1038 | if [ $withtap -eq "1" ]; then | |
1039 | ok $ret "Lttng-tool list command with option $opts" | |
1040 | fi | |
1041 | } | |
1042 | ||
1043 | function list_lttng_ok () | |
1044 | { | |
1045 | list_lttng_with_opts 1 "$@" | |
1046 | } | |
1047 | ||
1048 | function list_lttng_notap () | |
1049 | { | |
1050 | list_lttng_with_opts 0 "$@" | |
873c2aae JRJ |
1051 | } |
1052 | ||
07b86b52 JD |
1053 | function create_lttng_session_no_output () |
1054 | { | |
7d0ad314 | 1055 | local sess_name=$1 |
2a166864 | 1056 | local opts="${@:2}" |
07b86b52 | 1057 | |
a4705d55 SM |
1058 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1059 | create $sess_name --no-output $opts | |
07b86b52 JD |
1060 | ok $? "Create session $sess_name in no-output mode" |
1061 | } | |
1062 | ||
f0d43d3d JR |
1063 | function create_lttng_session_uri () { |
1064 | local sess_name=$1 | |
1065 | local uri=$2 | |
1066 | local opts="${@:3}" | |
1067 | ||
a4705d55 SM |
1068 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1069 | create $sess_name -U $uri $opts | |
f0d43d3d JR |
1070 | ok $? "Create session $sess_name with uri:$uri and opts: $opts" |
1071 | } | |
1072 | ||
d3e8f6bb DG |
1073 | function create_lttng_session () |
1074 | { | |
434f8068 JR |
1075 | local withtap=$1 |
1076 | local expected_to_fail=$2 | |
1077 | local sess_name=$3 | |
1078 | local trace_path=$4 | |
1079 | local opt=$5 | |
d3e8f6bb | 1080 | |
01654d69 JR |
1081 | if [ -z "$trace_path" ]; then |
1082 | # Use lttng-sessiond default output. | |
1083 | trace_path="" | |
1084 | else | |
1085 | trace_path="-o $trace_path" | |
1086 | fi | |
1087 | ||
a4705d55 SM |
1088 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1089 | create "$sess_name" $trace_path $opt | |
873c2aae | 1090 | ret=$? |
434f8068 | 1091 | if [ $expected_to_fail -eq "1" ]; then |
01513c3e | 1092 | test "$ret" -ne "0" |
434f8068 JR |
1093 | ret=$? |
1094 | if [ $withtap -eq "1" ]; then | |
1095 | ok $ret "Create session $sess_name in $trace_path failed as expected" | |
1096 | fi | |
873c2aae | 1097 | else |
434f8068 JR |
1098 | if [ $withtap -eq "1" ]; then |
1099 | ok $ret "Create session $sess_name in $trace_path" | |
1100 | fi | |
873c2aae | 1101 | fi |
434f8068 | 1102 | return $ret |
d4018451 DG |
1103 | } |
1104 | ||
bf6ae429 JR |
1105 | function create_lttng_session_ok () |
1106 | { | |
434f8068 | 1107 | create_lttng_session 1 0 "$@" |
bf6ae429 JR |
1108 | } |
1109 | ||
1110 | function create_lttng_session_fail () | |
1111 | { | |
434f8068 JR |
1112 | create_lttng_session 1 1 "$@" |
1113 | } | |
1114 | ||
1115 | function create_lttng_session_notap () | |
1116 | { | |
1117 | create_lttng_session 0 0 "$@" | |
bf6ae429 JR |
1118 | } |
1119 | ||
1120 | ||
827caf52 | 1121 | function enable_ust_lttng_channel () |
d4018451 | 1122 | { |
434f8068 JR |
1123 | local withtap=$1 |
1124 | local expected_to_fail=$2 | |
1125 | local sess_name=$3 | |
1126 | local channel_name=$4 | |
c28fcefd | 1127 | local opts="${@:5}" |
d4018451 | 1128 | |
a4705d55 SM |
1129 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1130 | enable-channel -u $channel_name -s $sess_name $opts | |
312dabc3 | 1131 | ret=$? |
34ab15c5 | 1132 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1133 | test "$ret" -ne "0" |
434f8068 JR |
1134 | ret=$? |
1135 | if [ $withtap -eq "1" ]; then | |
1136 | ok $ret "Enable channel $channel_name for session $sess_name failed as expected" | |
1137 | fi | |
312dabc3 | 1138 | else |
434f8068 JR |
1139 | if [ $withtap -eq "1" ]; then |
1140 | ok $ret "Enable channel $channel_name for session $sess_name" | |
1141 | fi | |
312dabc3 | 1142 | fi |
434f8068 | 1143 | return $ret |
d4018451 DG |
1144 | } |
1145 | ||
827caf52 JR |
1146 | function enable_ust_lttng_channel_ok () |
1147 | { | |
434f8068 | 1148 | enable_ust_lttng_channel 1 0 "$@" |
827caf52 JR |
1149 | } |
1150 | ||
1151 | function enable_ust_lttng_channel_fail () | |
1152 | { | |
434f8068 JR |
1153 | enable_ust_lttng_channel 1 1 "$@" |
1154 | } | |
1155 | ||
1156 | function enable_ust_lttng_channel_notap () | |
1157 | { | |
1158 | enable_ust_lttng_channel 0 0 "$@" | |
827caf52 JR |
1159 | } |
1160 | ||
29655db7 | 1161 | function disable_ust_lttng_channel() |
d4018451 | 1162 | { |
7d0ad314 JRJ |
1163 | local sess_name=$1 |
1164 | local channel_name=$2 | |
d4018451 | 1165 | |
a4705d55 SM |
1166 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1167 | disable-channel -u $channel_name -s $sess_name | |
29655db7 | 1168 | ok $? "Disable channel $channel_name for session $sess_name" |
d3e8f6bb DG |
1169 | } |
1170 | ||
07b86b52 JD |
1171 | function enable_lttng_mmap_overwrite_kernel_channel() |
1172 | { | |
7d0ad314 JRJ |
1173 | local sess_name=$1 |
1174 | local channel_name=$2 | |
07b86b52 | 1175 | |
a4705d55 SM |
1176 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1177 | enable-channel -s $sess_name $channel_name -k --output mmap --overwrite | |
07b86b52 JD |
1178 | ok $? "Enable channel $channel_name for session $sess_name" |
1179 | } | |
1180 | ||
086e6add MD |
1181 | function enable_lttng_mmap_discard_small_kernel_channel() |
1182 | { | |
1183 | local sess_name=$1 | |
1184 | local channel_name=$2 | |
1185 | ||
a4705d55 SM |
1186 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1187 | enable-channel -s $sess_name $channel_name -k --output mmap --discard --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 | |
086e6add MD |
1188 | ok $? "Enable small discard channel $channel_name for session $sess_name" |
1189 | } | |
1190 | ||
1191 | function enable_lttng_mmap_overwrite_small_kernel_channel() | |
1192 | { | |
1193 | local sess_name=$1 | |
1194 | local channel_name=$2 | |
1195 | ||
a4705d55 SM |
1196 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1197 | enable-channel -s $sess_name $channel_name -k --output mmap --overwrite --subbuf-size=$(getconf PAGE_SIZE) --num-subbuf=2 | |
086e6add MD |
1198 | ok $? "Enable small discard channel $channel_name for session $sess_name" |
1199 | } | |
1200 | ||
ebaaaf5e JD |
1201 | function enable_lttng_mmap_overwrite_ust_channel() |
1202 | { | |
7d0ad314 JRJ |
1203 | local sess_name=$1 |
1204 | local channel_name=$2 | |
ebaaaf5e | 1205 | |
a4705d55 SM |
1206 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1207 | enable-channel -s $sess_name $channel_name -u --output mmap --overwrite | |
ebaaaf5e JD |
1208 | ok $? "Enable channel $channel_name for session $sess_name" |
1209 | } | |
1210 | ||
d3e8f6bb DG |
1211 | function enable_ust_lttng_event () |
1212 | { | |
434f8068 JR |
1213 | local withtap=$1 |
1214 | local expected_to_fail=$2 | |
1215 | local sess_name=$3 | |
1216 | local event_name="$4" | |
1217 | local channel_name=$5 | |
ebaaaf5e JD |
1218 | |
1219 | if [ -z $channel_name ]; then | |
1220 | # default channel if none specified | |
1221 | chan="" | |
1222 | else | |
1223 | chan="-c $channel_name" | |
1224 | fi | |
d3e8f6bb | 1225 | |
a4705d55 SM |
1226 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1227 | enable-event "$event_name" $chan -s "$sess_name" -u | |
01513c3e | 1228 | ret=$? |
c4926bb5 | 1229 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1230 | test $ret -ne "0" |
434f8068 JR |
1231 | ret=$? |
1232 | if [[ $withtap -eq "1" ]]; then | |
1233 | ok $ret "Enable ust event $event_name for session $session_name failed as expected" | |
1234 | fi | |
01513c3e | 1235 | else |
434f8068 JR |
1236 | if [[ $withtap -eq "1" ]]; then |
1237 | ok $ret "Enable ust event $event_name for session $sess_name" | |
1238 | fi | |
01513c3e | 1239 | fi |
434f8068 | 1240 | return $ret |
26b53d3b DG |
1241 | } |
1242 | ||
c4926bb5 JR |
1243 | function enable_ust_lttng_event_ok () |
1244 | { | |
434f8068 | 1245 | enable_ust_lttng_event 1 0 "$@" |
c4926bb5 JR |
1246 | } |
1247 | ||
1248 | function enable_ust_lttng_event_fail () | |
1249 | { | |
434f8068 JR |
1250 | enable_ust_lttng_event 1 1 "$@" |
1251 | } | |
1252 | ||
1253 | function enable_ust_lttng_event_notap () | |
1254 | { | |
1255 | enable_ust_lttng_event 0 0 "$@" | |
c4926bb5 JR |
1256 | } |
1257 | ||
37175ce4 DG |
1258 | function enable_jul_lttng_event() |
1259 | { | |
1260 | sess_name=$1 | |
1261 | event_name="$2" | |
1262 | channel_name=$3 | |
1263 | ||
1264 | if [ -z $channel_name ]; then | |
1265 | # default channel if none specified | |
1266 | chan="" | |
1267 | else | |
1268 | chan="-c $channel_name" | |
1269 | fi | |
1270 | ||
a4705d55 SM |
1271 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1272 | enable-event "$event_name" $chan -s $sess_name -j | |
37175ce4 DG |
1273 | ok $? "Enable JUL event $event_name for session $sess_name" |
1274 | } | |
1275 | ||
b2064f54 DG |
1276 | function enable_jul_lttng_event_loglevel() |
1277 | { | |
7d0ad314 JRJ |
1278 | local sess_name=$1 |
1279 | local event_name="$2" | |
1280 | local loglevel=$3 | |
1281 | local channel_name=$4 | |
b2064f54 DG |
1282 | |
1283 | if [ -z $channel_name ]; then | |
1284 | # default channel if none specified | |
1285 | chan="" | |
1286 | else | |
1287 | chan="-c $channel_name" | |
1288 | fi | |
1289 | ||
a4705d55 SM |
1290 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1291 | enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -j | |
b2064f54 DG |
1292 | ok $? "Enable JUL event $event_name for session $sess_name with loglevel $loglevel" |
1293 | } | |
1294 | ||
504d4ace DG |
1295 | function enable_log4j_lttng_event() |
1296 | { | |
0fd2fd15 MJ |
1297 | local sess_name=$1 |
1298 | local event_name=$2 | |
1299 | local channel_name=$3 | |
504d4ace | 1300 | |
0fd2fd15 MJ |
1301 | local chan_opt=() |
1302 | ||
1303 | # default channel if none specified | |
1304 | if [ -n "$channel_name" ]; then | |
1305 | chan_opt=("-c" "$channel_name") | |
504d4ace DG |
1306 | fi |
1307 | ||
a4705d55 | 1308 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
0fd2fd15 MJ |
1309 | enable-event "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j |
1310 | ok $? "Enable LOG4J event '$event_name' for session '$sess_name'" | |
1311 | } | |
1312 | ||
1313 | function enable_log4j_lttng_event_filter() | |
1314 | { | |
1315 | local sess_name=$1 | |
1316 | local event_name=$2 | |
1317 | local filter=$3 | |
1318 | ||
1319 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ | |
1320 | enable-event "$event_name" -s "$sess_name" --log4j --filter "$filter" | |
1321 | ok $? "Enable LOG4J event '$event_name' with filter '$filter' for session '$sess_name'" | |
1322 | } | |
1323 | ||
1324 | function enable_log4j_lttng_event_filter_loglevel_only() | |
1325 | { | |
1326 | local sess_name=$1 | |
1327 | local event_name=$2 | |
1328 | local filter=$3 | |
1329 | local loglevel=$4 | |
1330 | ||
1331 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ | |
1332 | enable-event --loglevel-only "$loglevel" "$event_name" -s "$sess_name" -l --filter "$filter" | |
1333 | ok $? "Enable LOG4J event '$event_name' with filter '$filter' and loglevel-only '$loglevel' for session '$sess_name'" | |
504d4ace DG |
1334 | } |
1335 | ||
1336 | function enable_log4j_lttng_event_loglevel() | |
1337 | { | |
1338 | local sess_name=$1 | |
0fd2fd15 | 1339 | local event_name=$2 |
504d4ace DG |
1340 | local loglevel=$3 |
1341 | local channel_name=$4 | |
1342 | ||
0fd2fd15 MJ |
1343 | |
1344 | # default channel if none specified | |
1345 | if [ -n "$channel_name" ]; then | |
1346 | chan_opt=("-c" "$channel_name") | |
504d4ace DG |
1347 | fi |
1348 | ||
a4705d55 | 1349 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
0fd2fd15 MJ |
1350 | enable-event --loglevel "$loglevel" "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j |
1351 | ok $? "Enable LOG4J event '$event_name' for session '$sess_name' with loglevel '$loglevel'" | |
1352 | } | |
1353 | ||
1354 | function enable_log4j_lttng_event_loglevel_only() | |
1355 | { | |
1356 | local sess_name=$1 | |
1357 | local event_name=$2 | |
1358 | local loglevel=$3 | |
1359 | local channel_name=$4 | |
1360 | ||
1361 | local chan_opt=() | |
1362 | ||
1363 | # default channel if none specified | |
1364 | if [ -n "$channel_name" ]; then | |
1365 | chan_opt=("-c" "$channel_name") | |
1366 | fi | |
1367 | ||
1368 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ | |
1369 | enable-event --loglevel-only "$loglevel" "$event_name" "${chan_opt[@]}" -s "$sess_name" --log4j | |
1370 | ok $? "Enable LOG4J event '$event_name' for session '$sess_name' with loglevel-only '$loglevel'" | |
504d4ace DG |
1371 | } |
1372 | ||
0e115563 DG |
1373 | function enable_python_lttng_event() |
1374 | { | |
1375 | sess_name=$1 | |
1376 | event_name="$2" | |
1377 | channel_name=$3 | |
1378 | ||
1379 | if [ -z $channel_name ]; then | |
1380 | # default channel if none specified | |
1381 | chan="" | |
1382 | else | |
1383 | chan="-c $channel_name" | |
1384 | fi | |
1385 | ||
a4705d55 SM |
1386 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1387 | enable-event "$event_name" $chan -s $sess_name -p | |
0e115563 DG |
1388 | ok $? "Enable Python event $event_name for session $sess_name" |
1389 | } | |
1390 | ||
1391 | function enable_python_lttng_event_loglevel() | |
1392 | { | |
1393 | local sess_name=$1 | |
1394 | local event_name="$2" | |
1395 | local loglevel=$3 | |
1396 | local channel_name=$4 | |
1397 | ||
1398 | if [ -z $channel_name ]; then | |
1399 | # default channel if none specified | |
1400 | chan="" | |
1401 | else | |
1402 | chan="-c $channel_name" | |
1403 | fi | |
1404 | ||
a4705d55 SM |
1405 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1406 | enable-event --loglevel $loglevel "$event_name" $chan -s $sess_name -p | |
0e115563 DG |
1407 | ok $? "Enable Python event $event_name for session $sess_name with loglevel $loglevel" |
1408 | } | |
1409 | ||
26b53d3b DG |
1410 | function enable_ust_lttng_event_filter() |
1411 | { | |
7d0ad314 JRJ |
1412 | local sess_name="$1" |
1413 | local event_name="$2" | |
1414 | local filter="$3" | |
bc3c79ae JG |
1415 | local channel_name=$4 |
1416 | ||
1417 | if [ -z $channel_name ]; then | |
1418 | # default channel if none specified | |
1419 | chan="" | |
1420 | else | |
1421 | chan="-c $channel_name" | |
1422 | fi | |
26b53d3b | 1423 | |
a4705d55 SM |
1424 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1425 | enable-event $chan "$event_name" -s $sess_name -u --filter "$filter" | |
29655db7 | 1426 | ok $? "Enable event $event_name with filtering for session $sess_name" |
26b53d3b DG |
1427 | } |
1428 | ||
1429 | function enable_ust_lttng_event_loglevel() | |
1430 | { | |
7d0ad314 JRJ |
1431 | local sess_name="$1" |
1432 | local event_name="$2" | |
1433 | local loglevel="$3" | |
26b53d3b | 1434 | |
a4705d55 SM |
1435 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1436 | enable-event "$event_name" -s $sess_name -u --loglevel $loglevel | |
29655db7 | 1437 | ok $? "Enable event $event_name with loglevel $loglevel" |
26b53d3b DG |
1438 | } |
1439 | ||
1440 | function enable_ust_lttng_event_loglevel_only() | |
1441 | { | |
7d0ad314 JRJ |
1442 | local sess_name="$1" |
1443 | local event_name="$2" | |
1444 | local loglevel="$3" | |
26b53d3b | 1445 | |
a4705d55 SM |
1446 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1447 | enable-event "$event_name" -s $sess_name -u --loglevel-only $loglevel | |
29655db7 | 1448 | ok $? "Enable event $event_name with loglevel-only $loglevel" |
26b53d3b DG |
1449 | } |
1450 | ||
1451 | function disable_ust_lttng_event () | |
1452 | { | |
7d0ad314 JRJ |
1453 | local sess_name="$1" |
1454 | local event_name="$2" | |
01513c3e | 1455 | local channel_name="$3" |
26b53d3b | 1456 | |
01513c3e JRJ |
1457 | if [ -z $channel_name ]; then |
1458 | # default channel if none specified | |
1459 | chan="" | |
1460 | else | |
1461 | chan="-c $channel_name" | |
1462 | fi | |
1463 | ||
a4705d55 SM |
1464 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1465 | disable-event "$event_name" -s $sess_name $chan -u | |
29655db7 | 1466 | ok $? "Disable event $event_name for session $sess_name" |
d3e8f6bb DG |
1467 | } |
1468 | ||
1d842d5a DG |
1469 | function disable_jul_lttng_event () |
1470 | { | |
1471 | local sess_name="$1" | |
1472 | local event_name="$2" | |
1473 | ||
1474 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN disable-event "$event_name" -s $sess_name -j >/dev/null 2>&1 | |
1475 | ok $? "Disable JUL event $event_name for session $sess_name" | |
1476 | } | |
1477 | ||
504d4ace DG |
1478 | function disable_log4j_lttng_event () |
1479 | { | |
1480 | local sess_name="$1" | |
1481 | local event_name="$2" | |
1482 | ||
0fd2fd15 MJ |
1483 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1484 | disable-event "$event_name" -s "$sess_name" --log4j | |
1485 | ok $? "Disable LOG4J event '$event_name' for session '$sess_name'" | |
504d4ace DG |
1486 | } |
1487 | ||
0e115563 DG |
1488 | function disable_python_lttng_event () |
1489 | { | |
1490 | local sess_name="$1" | |
1491 | local event_name="$2" | |
1492 | ||
a4705d55 SM |
1493 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1494 | disable-event "$event_name" -s $sess_name -p | |
0e115563 DG |
1495 | ok $? "Disable Python event $event_name for session $sess_name" |
1496 | } | |
1497 | ||
7fe98a98 | 1498 | function start_lttng_tracing_opt () |
d3e8f6bb | 1499 | { |
7fe98a98 JG |
1500 | local withtap=$1 |
1501 | local expected_to_fail=$2 | |
1502 | local sess_name=$3 | |
d3e8f6bb | 1503 | |
a4705d55 SM |
1504 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1505 | start $sess_name | |
01513c3e | 1506 | ret=$? |
e563bbdb | 1507 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1508 | test "$ret" -ne "0" |
7fe98a98 JG |
1509 | ret=$? |
1510 | if [ $withtap -eq "1" ]; then | |
1511 | ok $? "Start tracing for session $sess_name failed as expected" | |
1512 | fi | |
01513c3e | 1513 | else |
7fe98a98 JG |
1514 | if [ $withtap -eq "1" ]; then |
1515 | ok $ret "Start tracing for session $sess_name" | |
1516 | fi | |
01513c3e | 1517 | fi |
d3e8f6bb DG |
1518 | } |
1519 | ||
e563bbdb JR |
1520 | function start_lttng_tracing_ok () |
1521 | { | |
7fe98a98 | 1522 | start_lttng_tracing_opt 1 0 "$@" |
e563bbdb JR |
1523 | } |
1524 | ||
1525 | function start_lttng_tracing_fail () | |
1526 | { | |
7fe98a98 | 1527 | start_lttng_tracing_opt 1 1 "$@" |
e563bbdb JR |
1528 | } |
1529 | ||
7fe98a98 | 1530 | function start_lttng_tracing_notap () |
d3e8f6bb | 1531 | { |
7fe98a98 JG |
1532 | start_lttng_tracing_opt 0 1 "$@" |
1533 | } | |
1534 | ||
1535 | function stop_lttng_tracing_opt () | |
1536 | { | |
1537 | local withtap=$1 | |
1538 | local expected_to_fail=$2 | |
1539 | local sess_name=$3 | |
d3e8f6bb | 1540 | |
a4705d55 SM |
1541 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1542 | stop $sess_name | |
01513c3e | 1543 | ret=$? |
96340a01 | 1544 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1545 | test "$ret" -ne "0" |
7fe98a98 JG |
1546 | ret=$? |
1547 | if [ $withtap -eq "1" ]; then | |
1548 | ok $? "Stop lttng tracing for session $sess_name failed as expected" | |
1549 | fi | |
01513c3e | 1550 | else |
7fe98a98 JG |
1551 | if [ $withtap -eq "1" ]; then |
1552 | ok $ret "Stop lttng tracing for session $sess_name" | |
1553 | fi | |
01513c3e | 1554 | fi |
d3e8f6bb DG |
1555 | } |
1556 | ||
96340a01 JR |
1557 | function stop_lttng_tracing_ok () |
1558 | { | |
7fe98a98 | 1559 | stop_lttng_tracing_opt 1 0 "$@" |
96340a01 JR |
1560 | } |
1561 | ||
1562 | function stop_lttng_tracing_fail () | |
1563 | { | |
7fe98a98 JG |
1564 | stop_lttng_tracing_opt 1 1 "$@" |
1565 | } | |
1566 | ||
1567 | function stop_lttng_tracing_notap () | |
1568 | { | |
1569 | stop_lttng_tracing_opt 0 0 "$@" | |
96340a01 JR |
1570 | } |
1571 | ||
d3e8f6bb DG |
1572 | function destroy_lttng_session () |
1573 | { | |
854382b8 JR |
1574 | local withtap=$1 |
1575 | local expected_to_fail=$2 | |
1576 | local sess_name=$3 | |
d3e8f6bb | 1577 | |
a4705d55 SM |
1578 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1579 | destroy $sess_name | |
01513c3e | 1580 | ret=$? |
96340a01 | 1581 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1582 | test "$ret" -ne "0" |
854382b8 JR |
1583 | ret=$? |
1584 | if [ $withtap -eq "1" ]; then | |
1585 | ok $ret "Destroy session $sess_name failed as expected" | |
1586 | fi | |
01513c3e | 1587 | else |
854382b8 JR |
1588 | if [ $withtap -eq "1" ]; then |
1589 | ok $ret "Destroy session $sess_name" | |
1590 | fi | |
01513c3e | 1591 | fi |
d3e8f6bb DG |
1592 | } |
1593 | ||
67b4c664 JR |
1594 | function destroy_lttng_session_ok () |
1595 | { | |
854382b8 | 1596 | destroy_lttng_session 1 0 "$@" |
67b4c664 JR |
1597 | |
1598 | } | |
1599 | ||
1600 | function destroy_lttng_session_fail () | |
1601 | { | |
854382b8 | 1602 | destroy_lttng_session 1 1 "$@" |
67b4c664 JR |
1603 | } |
1604 | ||
854382b8 JR |
1605 | function destroy_lttng_session_notap () |
1606 | { | |
1607 | destroy_lttng_session 0 0 "$@" | |
1608 | } | |
67b4c664 | 1609 | |
873c2aae JRJ |
1610 | function destroy_lttng_sessions () |
1611 | { | |
a4705d55 SM |
1612 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1613 | destroy --all | |
873c2aae JRJ |
1614 | ok $? "Destroy all lttng sessions" |
1615 | } | |
1616 | ||
07b86b52 JD |
1617 | function lttng_snapshot_add_output () |
1618 | { | |
b5633831 JR |
1619 | local expected_to_fail=$1 |
1620 | local sess_name=$2 | |
1621 | local trace_path=$3 | |
9f0e230a | 1622 | local opts=$4 |
07b86b52 | 1623 | |
a4705d55 SM |
1624 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1625 | snapshot add-output -s $sess_name $trace_path $opts | |
01513c3e | 1626 | ret=$? |
b5633831 | 1627 | if [[ $expected_to_fail -eq 1 ]]; then |
01513c3e | 1628 | test "$ret" -ne "0" |
9f0e230a | 1629 | ok $? "Added snapshot output $trace_path failed as expected" |
01513c3e | 1630 | else |
9f0e230a | 1631 | ok $ret "Added snapshot output $trace_path" |
01513c3e | 1632 | fi |
07b86b52 JD |
1633 | } |
1634 | ||
b5633831 JR |
1635 | function lttng_snapshot_add_output_ok () |
1636 | { | |
1637 | lttng_snapshot_add_output 0 "$@" | |
1638 | } | |
1639 | ||
1640 | function lttng_snapshot_add_output_fail () | |
1641 | { | |
1642 | lttng_snapshot_add_output 1 "$@" | |
1643 | } | |
1644 | ||
26402e0c DG |
1645 | function lttng_snapshot_del_output () |
1646 | { | |
31580dc7 JR |
1647 | local expected_to_fail=$1 |
1648 | local sess_name=$2 | |
1649 | local id=$3 | |
26402e0c | 1650 | |
a4705d55 SM |
1651 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1652 | snapshot del-output -s $sess_name $id | |
01513c3e | 1653 | ret=$? |
31580dc7 | 1654 | if [[ $expected_to_fail -eq "1" ]]; then |
01513c3e | 1655 | test "$ret" -ne "0" |
34ab15c5 | 1656 | ok $? "Deleted snapshot output id $id failed as expected" |
01513c3e JRJ |
1657 | else |
1658 | ok $ret "Deleted snapshot output id $id" | |
1659 | fi | |
26402e0c DG |
1660 | } |
1661 | ||
31580dc7 JR |
1662 | function lttng_snapshot_del_output_ok () |
1663 | { | |
1664 | lttng_snapshot_del_output 0 "$@" | |
1665 | } | |
1666 | ||
1667 | function lttng_snapshot_del_output_fail () | |
1668 | { | |
1669 | lttng_snapshot_del_output 1 "$@" | |
1670 | } | |
1671 | ||
07b86b52 JD |
1672 | function lttng_snapshot_record () |
1673 | { | |
7d0ad314 | 1674 | local sess_name=$1 |
6ac56bb9 | 1675 | local trace_path=$2 |
07b86b52 | 1676 | |
a4705d55 SM |
1677 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1678 | snapshot record -s "$sess_name" "$trace_path" | |
07b86b52 JD |
1679 | ok $? "Snapshot recorded" |
1680 | } | |
1681 | ||
01513c3e JRJ |
1682 | function lttng_snapshot_list () |
1683 | { | |
1684 | local sess_name=$1 | |
a4705d55 SM |
1685 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1686 | snapshot list-output -s $sess_name | |
01513c3e JRJ |
1687 | ok $? "Snapshot list" |
1688 | } | |
1689 | ||
e02b109b DG |
1690 | function lttng_save() |
1691 | { | |
1692 | local sess_name=$1 | |
1693 | local opts=$2 | |
1694 | ||
a4705d55 SM |
1695 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1696 | save $sess_name $opts | |
34ab15c5 | 1697 | ok $? "Session saved" |
e02b109b DG |
1698 | } |
1699 | ||
1700 | function lttng_load() | |
1701 | { | |
192ac418 JR |
1702 | local expected_to_fail=$1 |
1703 | local opts=$2 | |
e02b109b | 1704 | |
a4705d55 SM |
1705 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1706 | load $opts | |
192ac418 JR |
1707 | ret=$? |
1708 | if [[ $expected_to_fail -eq "1" ]]; then | |
1709 | test $ret -ne "0" | |
1710 | ok $? "Load command failed as expected with opts: $opts" | |
1711 | else | |
1712 | ok $ret "Load command with opts: $opts" | |
1713 | fi | |
1714 | } | |
1715 | ||
1716 | function lttng_load_ok() | |
1717 | { | |
1718 | lttng_load 0 "$@" | |
1719 | } | |
1720 | ||
1721 | function lttng_load_fail() | |
1722 | { | |
1723 | lttng_load 1 "$@" | |
e02b109b DG |
1724 | } |
1725 | ||
e83a8bdb JR |
1726 | function lttng_track() |
1727 | { | |
ba5e8d0a | 1728 | local expected_to_fail="$1" |
c47a705b | 1729 | shift 1 |
ba5e8d0a | 1730 | local opts="$@" |
e83a8bdb JR |
1731 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN track $opts >$OUTPUT_DEST |
1732 | ret=$? | |
1733 | if [[ $expected_to_fail -eq "1" ]]; then | |
1734 | test $ret -ne "0" | |
1735 | ok $? "Track command failed as expected with opts: $opts" | |
1736 | else | |
34ab15c5 | 1737 | ok $ret "Track command with opts: $opts" |
e83a8bdb JR |
1738 | fi |
1739 | } | |
1740 | ||
1741 | function lttng_track_ok() | |
1742 | { | |
1743 | lttng_track 0 "$@" | |
1744 | } | |
1745 | ||
1746 | function lttng_track_fail() | |
1747 | { | |
1748 | lttng_track 1 "$@" | |
1749 | } | |
1750 | ||
1751 | function lttng_untrack() | |
1752 | { | |
ba5e8d0a | 1753 | local expected_to_fail="$1" |
c47a705b | 1754 | shift 1 |
ba5e8d0a | 1755 | local opts="$@" |
e83a8bdb JR |
1756 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN untrack $opts >$OUTPUT_DEST |
1757 | ret=$? | |
1758 | if [[ $expected_to_fail -eq "1" ]]; then | |
1759 | test $ret -ne "0" | |
1760 | ok $? "Untrack command failed as expected with opts: $opts" | |
1761 | else | |
34ab15c5 | 1762 | ok $ret "Untrack command with opts: $opts" |
e83a8bdb JR |
1763 | fi |
1764 | } | |
1765 | ||
1766 | function lttng_untrack_ok() | |
1767 | { | |
1768 | lttng_untrack 0 "$@" | |
1769 | } | |
1770 | ||
1771 | function lttng_untrack_fail() | |
1772 | { | |
1773 | lttng_untrack 1 "$@" | |
1774 | } | |
1775 | ||
c8e51d15 FD |
1776 | function lttng_track_pid_ok() |
1777 | { | |
1778 | PID=$1 | |
1779 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track --kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1780 | ok $? "Lttng track pid on the kernel domain" | |
1781 | } | |
1782 | ||
1783 | function lttng_untrack_kernel_all_ok() | |
1784 | { | |
1785 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack --kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST | |
1786 | ok $? "Lttng untrack all pid on the kernel domain" | |
1787 | } | |
1788 | ||
ba5e8d0a MD |
1789 | function lttng_track_ust_ok() |
1790 | { | |
1791 | lttng_track_ok -u "$@" | |
1792 | } | |
1793 | ||
1794 | function lttng_track_ust_fail() | |
1795 | { | |
1796 | lttng_track_fail -u "$@" | |
1797 | } | |
1798 | ||
1799 | function lttng_track_kernel_ok() | |
1800 | { | |
1801 | lttng_track_ok -k "$@" | |
1802 | } | |
1803 | ||
1804 | function lttng_track_kernel_fail() | |
1805 | { | |
1806 | lttng_track_fail -k "$@" | |
1807 | } | |
1808 | ||
1809 | function lttng_untrack_ust_ok() | |
1810 | { | |
1811 | lttng_untrack_ok -u "$@" | |
1812 | } | |
1813 | ||
1814 | function lttng_untrack_ust_fail() | |
1815 | { | |
1816 | lttng_untrack_fail -u "$@" | |
1817 | } | |
1818 | ||
1819 | function lttng_untrack_kernel_ok() | |
1820 | { | |
1821 | lttng_untrack_ok -k "$@" | |
1822 | } | |
1823 | ||
1824 | function lttng_untrack_kernel_fail() | |
1825 | { | |
1826 | lttng_untrack_fail -k "$@" | |
1827 | } | |
1828 | ||
59deec0c JR |
1829 | function lttng_add_context_list() |
1830 | { | |
a4705d55 SM |
1831 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1832 | add-context --list | |
59deec0c JR |
1833 | ret=$? |
1834 | ok $ret "Context listing" | |
1835 | } | |
1836 | ||
8dcef147 JR |
1837 | function add_context_lttng() |
1838 | { | |
1839 | local expected_to_fail="$1" | |
1840 | local domain="$2" | |
1841 | local session_name="$3" | |
1842 | local channel_name="$4" | |
1843 | local type="$5" | |
1844 | ||
a4705d55 SM |
1845 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
1846 | add-context -s $session_name -c $channel_name -t $type $domain | |
8dcef147 JR |
1847 | ret=$? |
1848 | if [[ $expected_to_fail -eq "1" ]]; then | |
1849 | test $ret -ne "0" | |
1850 | ok $? "Add context command failed as expected for type: $type" | |
1851 | else | |
1852 | ok $ret "Add context command for type: $type" | |
1853 | fi | |
1854 | } | |
1855 | ||
1856 | function add_context_ust_ok() | |
1857 | { | |
1858 | add_context_lttng 0 -u "$@" | |
1859 | } | |
1860 | ||
1861 | function add_context_ust_fail() | |
1862 | { | |
1863 | add_context_lttng 1 -u "$@" | |
1864 | } | |
1865 | ||
1866 | function add_context_kernel_ok() | |
1867 | { | |
1868 | add_context_lttng 0 -k "$@" | |
1869 | } | |
1870 | ||
1871 | function add_context_kernel_fail() | |
1872 | { | |
1873 | add_context_lttng 1 -k "$@" | |
1874 | } | |
1875 | ||
c28fcefd JR |
1876 | function wait_live_trace_ready () |
1877 | { | |
1878 | local url=$1 | |
1879 | local zero_client_match=0 | |
1880 | ||
1881 | diag "Waiting for live trace at url: $url" | |
1882 | while [ $zero_client_match -eq 0 ]; do | |
1883 | zero_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "0 client(s) connected" | wc -l) | |
1884 | sleep 0.5 | |
1885 | done | |
1886 | pass "Waiting for live trace at url: $url" | |
1887 | } | |
1888 | ||
1889 | function wait_live_viewer_connect () | |
1890 | { | |
1891 | local url=$1 | |
1892 | local one_client_match=0 | |
1893 | ||
1894 | diag "Waiting for live viewers on url: $url" | |
1895 | while [ $one_client_match -eq 0 ]; do | |
1896 | one_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "1 client(s) connected" | wc -l) | |
1897 | sleep 0.5 | |
1898 | done | |
1899 | pass "Waiting for live viewers on url: $url" | |
1900 | } | |
1901 | ||
c125de8f FD |
1902 | function bail_out_if_no_babeltrace() |
1903 | { | |
1904 | which "$BABELTRACE_BIN" >/dev/null | |
1905 | if [ $? -ne 0 ]; then | |
1906 | LTTNG_BAIL_OUT "\"$BABELTRACE_BIN\" binary not found. Skipping tests" | |
1907 | fi | |
1908 | } | |
1909 | ||
c54b437e FD |
1910 | function validate_metadata_event () |
1911 | { | |
1912 | local event_name=$1 | |
1913 | local nr_event_id=$2 | |
1914 | local trace_path=$3 | |
1915 | ||
fc2dd19e | 1916 | local metadata_file=$(find $trace_path -name "metadata") |
c54b437e FD |
1917 | local metadata_path=$(dirname $metadata_file) |
1918 | ||
c125de8f | 1919 | bail_out_if_no_babeltrace |
c54b437e FD |
1920 | |
1921 | local count=$($BABELTRACE_BIN --output-format=ctf-metadata $metadata_path | grep $event_name | wc -l) | |
1922 | ||
1923 | if [ "$count" -ne "$nr_event_id" ]; then | |
1924 | fail "Metadata match with the metadata of $count event(s) named $event_name" | |
1925 | diag "$count matching event id found in metadata" | |
1926 | else | |
1927 | pass "Metadata match with the metadata of $count event(s) named $event_name" | |
1928 | fi | |
1929 | ||
1930 | } | |
1931 | ||
d3e8f6bb DG |
1932 | function trace_matches () |
1933 | { | |
7d0ad314 JRJ |
1934 | local event_name=$1 |
1935 | local nr_iter=$2 | |
1936 | local trace_path=$3 | |
d3e8f6bb | 1937 | |
c125de8f | 1938 | bail_out_if_no_babeltrace |
d3e8f6bb | 1939 | |
7d0ad314 | 1940 | local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) |
29655db7 | 1941 | |
d3e8f6bb | 1942 | if [ "$count" -ne "$nr_iter" ]; then |
29655db7 | 1943 | fail "Trace match" |
af91abc9 | 1944 | diag "$count matching events found in trace" |
d3e8f6bb | 1945 | else |
29655db7 | 1946 | pass "Trace match" |
d3e8f6bb DG |
1947 | fi |
1948 | } | |
f4e40ab6 | 1949 | |
d53addeb DG |
1950 | function trace_match_only() |
1951 | { | |
1952 | local event_name=$1 | |
1953 | local nr_iter=$2 | |
1954 | local trace_path=$3 | |
1955 | ||
c125de8f FD |
1956 | bail_out_if_no_babeltrace |
1957 | #which "$BABELTRACE_BIN" >/dev/null | |
1958 | #skip $? -ne 0 "\"$BABELTRACE_BIN\" binary not found. Skipping trace comparison" | |
d53addeb DG |
1959 | |
1960 | local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) | |
1961 | local total=$($BABELTRACE_BIN $trace_path | wc -l) | |
1962 | ||
08f96a38 JG |
1963 | if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then |
1964 | pass "Trace match with $total event $event_name" | |
1965 | else | |
1966 | fail "Trace match" | |
1967 | diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count" | |
1968 | fi | |
d53addeb DG |
1969 | } |
1970 | ||
f4e40ab6 DG |
1971 | function validate_trace |
1972 | { | |
7d0ad314 JRJ |
1973 | local event_name=$1 |
1974 | local trace_path=$2 | |
f4e40ab6 | 1975 | |
c125de8f | 1976 | bail_out_if_no_babeltrace |
f4e40ab6 | 1977 | |
07b86b52 JD |
1978 | OLDIFS=$IFS |
1979 | IFS="," | |
1980 | for i in $event_name; do | |
1981 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) | |
1982 | if [ "$traced" -ne 0 ]; then | |
ebaaaf5e | 1983 | pass "Validate trace for event $i, $traced events" |
07b86b52 JD |
1984 | else |
1985 | fail "Validate trace for event $i" | |
8f0646a0 | 1986 | diag "Found $traced occurrences of $i" |
07b86b52 JD |
1987 | fi |
1988 | done | |
1989 | ret=$? | |
1990 | IFS=$OLDIFS | |
1991 | return $ret | |
f4e40ab6 | 1992 | } |
8cfcd41c | 1993 | |
54cd6107 JD |
1994 | function validate_trace_count |
1995 | { | |
1996 | local event_name=$1 | |
1997 | local trace_path=$2 | |
1998 | local expected_count=$3 | |
1999 | ||
c125de8f | 2000 | bail_out_if_no_babeltrace |
54cd6107 JD |
2001 | |
2002 | cnt=0 | |
2003 | OLDIFS=$IFS | |
2004 | IFS="," | |
2005 | for i in $event_name; do | |
2006 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) | |
2007 | if [ "$traced" -ne 0 ]; then | |
2008 | pass "Validate trace for event $i, $traced events" | |
2009 | else | |
2010 | fail "Validate trace for event $i" | |
8f0646a0 | 2011 | diag "Found $traced occurrences of $i" |
54cd6107 JD |
2012 | fi |
2013 | cnt=$(($cnt + $traced)) | |
2014 | done | |
2015 | IFS=$OLDIFS | |
2016 | test $cnt -eq $expected_count | |
2017 | ok $? "Read a total of $cnt events, expected $expected_count" | |
2018 | } | |
2019 | ||
c28fcefd JR |
2020 | function validate_trace_count_range_incl_min_excl_max |
2021 | { | |
2022 | local event_name=$1 | |
2023 | local trace_path=$2 | |
2024 | local expected_min=$3 | |
2025 | local expected_max=$4 | |
2026 | ||
c125de8f | 2027 | bail_out_if_no_babeltrace |
c28fcefd JR |
2028 | |
2029 | cnt=0 | |
2030 | OLDIFS=$IFS | |
2031 | IFS="," | |
2032 | for i in $event_name; do | |
2033 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep $i | wc -l) | |
2034 | if [ "$traced" -ge $expected_min ]; then | |
2035 | pass "Validate trace for event $i, $traced events" | |
2036 | else | |
2037 | fail "Validate trace for event $i" | |
8f0646a0 | 2038 | diag "Found $traced occurrences of $i" |
c28fcefd JR |
2039 | fi |
2040 | cnt=$(($cnt + $traced)) | |
2041 | done | |
2042 | IFS=$OLDIFS | |
2043 | test $cnt -lt $expected_max | |
2044 | ok $? "Read a total of $cnt events, expected between [$expected_min, $expected_max[" | |
2045 | } | |
2046 | ||
086e6add MD |
2047 | function trace_first_line |
2048 | { | |
2049 | local trace_path=$1 | |
2050 | ||
086e6add MD |
2051 | $BABELTRACE_BIN $trace_path 2>/dev/null | head -n 1 |
2052 | } | |
2053 | ||
8cfcd41c MD |
2054 | function validate_trace_exp() |
2055 | { | |
2056 | local event_exp=$1 | |
2057 | local trace_path=$2 | |
2058 | ||
c125de8f | 2059 | bail_out_if_no_babeltrace |
8cfcd41c | 2060 | |
49538c32 | 2061 | traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep --extended-regexp ${event_exp} | wc -l) |
8cfcd41c MD |
2062 | if [ "$traced" -ne 0 ]; then |
2063 | pass "Validate trace for expression '${event_exp}', $traced events" | |
2064 | else | |
2065 | fail "Validate trace for expression '${event_exp}'" | |
8f0646a0 | 2066 | diag "Found $traced occurrences of '${event_exp}'" |
8cfcd41c MD |
2067 | fi |
2068 | ret=$? | |
2069 | return $ret | |
2070 | } | |
2071 | ||
2072 | function validate_trace_only_exp() | |
2073 | { | |
2074 | local event_exp=$1 | |
2075 | local trace_path=$2 | |
2076 | ||
c125de8f | 2077 | bail_out_if_no_babeltrace |
8cfcd41c | 2078 | |
49538c32 | 2079 | local count=$($BABELTRACE_BIN $trace_path | grep --extended-regexp ${event_exp} | wc -l) |
8cfcd41c MD |
2080 | local total=$($BABELTRACE_BIN $trace_path | wc -l) |
2081 | ||
2082 | if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then | |
ab95d85d | 2083 | pass "Trace match with $total for expression '${event_exp}'" |
8cfcd41c MD |
2084 | else |
2085 | fail "Trace match" | |
2086 | diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected" | |
2087 | fi | |
2088 | ret=$? | |
2089 | return $ret | |
2090 | } | |
2091 | ||
2092 | function validate_trace_empty() | |
2093 | { | |
2094 | local trace_path=$1 | |
2095 | ||
c125de8f | 2096 | bail_out_if_no_babeltrace |
8cfcd41c | 2097 | |
2462eee7 JD |
2098 | events=$($BABELTRACE_BIN $trace_path 2>/dev/null) |
2099 | ret=$? | |
2100 | if [ $ret -ne 0 ]; then | |
2101 | fail "Failed to parse trace" | |
2102 | return $ret | |
2103 | fi | |
2104 | ||
2105 | traced=$(echo -n "$events" | wc -l) | |
8cfcd41c MD |
2106 | if [ "$traced" -eq 0 ]; then |
2107 | pass "Validate empty trace" | |
2108 | else | |
2109 | fail "Validate empty trace" | |
2110 | diag "Found $traced events in trace" | |
2111 | fi | |
2112 | ret=$? | |
2113 | return $ret | |
2114 | } | |
801236b0 | 2115 | |
94360c17 | 2116 | function validate_directory_empty () |
ba5e8d0a | 2117 | { |
94360c17 FD |
2118 | local trace_path="$1" |
2119 | ||
c8e000ef FD |
2120 | # Do not double quote `$trace_path` below as we want wildcards to be |
2121 | # expanded. | |
2122 | files="$(ls -A $trace_path)" | |
94360c17 FD |
2123 | ret=$? |
2124 | if [ $ret -ne 0 ]; then | |
2125 | fail "Failed to list content of directory \"$trace_path\"" | |
2126 | return $ret | |
2127 | fi | |
ba5e8d0a | 2128 | |
94360c17 FD |
2129 | nb_files="$(echo -n "$files" | wc -l)" |
2130 | ok $nb_files "Directory \"$trace_path\" is empty" | |
ba5e8d0a MD |
2131 | } |
2132 | ||
2133 | function validate_trace_session_ust_empty() | |
2134 | { | |
94360c17 | 2135 | validate_directory_empty "$1"/ust |
ba5e8d0a MD |
2136 | } |
2137 | ||
2138 | function validate_trace_session_kernel_empty() | |
2139 | { | |
2140 | validate_trace_empty "$1"/kernel | |
2141 | } | |
2142 | ||
eded6438 | 2143 | function regenerate_metadata () |
801236b0 JD |
2144 | { |
2145 | local expected_to_fail=$1 | |
2146 | local sess_name=$2 | |
2147 | ||
a4705d55 SM |
2148 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
2149 | regenerate metadata -s $sess_name | |
801236b0 JD |
2150 | ret=$? |
2151 | if [[ $expected_to_fail -eq "1" ]]; then | |
2152 | test "$ret" -ne "0" | |
eded6438 | 2153 | ok $? "Expected fail on regenerate metadata $sess_name" |
801236b0 JD |
2154 | else |
2155 | ok $ret "Metadata regenerate $sess_name" | |
2156 | fi | |
2157 | } | |
2158 | ||
eded6438 | 2159 | function regenerate_metadata_ok () |
801236b0 | 2160 | { |
eded6438 | 2161 | regenerate_metadata 0 "$@" |
801236b0 JD |
2162 | } |
2163 | ||
eded6438 | 2164 | function regenerate_metadata_fail () |
801236b0 | 2165 | { |
eded6438 | 2166 | regenerate_metadata 1 "$@" |
801236b0 | 2167 | } |
512eb148 | 2168 | |
54cd6107 JD |
2169 | function regenerate_statedump () |
2170 | { | |
2171 | local expected_to_fail=$1 | |
2172 | local sess_name=$2 | |
2173 | ||
a4705d55 SM |
2174 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
2175 | regenerate statedump -s $sess_name | |
54cd6107 JD |
2176 | ret=$? |
2177 | if [[ $expected_to_fail -eq "1" ]]; then | |
2178 | test "$ret" -ne "0" | |
2179 | ok $? "Expected fail on regenerate statedump $sess_name" | |
2180 | else | |
5ebb1a9f | 2181 | ok $ret "Statedump regenerate $sess_name" |
54cd6107 JD |
2182 | fi |
2183 | } | |
2184 | ||
2185 | function regenerate_statedump_ok () | |
2186 | { | |
2187 | regenerate_statedump 0 "$@" | |
2188 | } | |
2189 | ||
2190 | function regenerate_statedump_fail () | |
2191 | { | |
2192 | regenerate_statedump 1 "$@" | |
2193 | } | |
2194 | ||
e7716c6a JD |
2195 | function rotate_session () |
2196 | { | |
2197 | local expected_to_fail=$1 | |
2198 | local sess_name=$2 | |
2199 | ||
a4705d55 SM |
2200 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
2201 | rotate $sess_name | |
e7716c6a JD |
2202 | ret=$? |
2203 | if [[ $expected_to_fail -eq "1" ]]; then | |
2204 | test "$ret" -ne "0" | |
2205 | ok $? "Expected fail on rotate session $sess_name" | |
2206 | else | |
2207 | ok $ret "Rotate session $sess_name" | |
2208 | fi | |
2209 | } | |
2210 | ||
2211 | function rotate_session_ok () | |
2212 | { | |
2213 | rotate_session 0 "$@" | |
2214 | } | |
2215 | ||
2216 | function rotate_session_fail () | |
2217 | { | |
2218 | rotate_session 1 "$@" | |
2219 | } | |
2220 | ||
512eb148 JD |
2221 | function destructive_tests_enabled () |
2222 | { | |
167c84b7 | 2223 | if [ "$LTTNG_ENABLE_DESTRUCTIVE_TESTS" = "will-break-my-system" ]; then |
512eb148 JD |
2224 | return 0 |
2225 | else | |
2226 | return 1 | |
2227 | fi | |
2228 | } | |
e7716c6a JD |
2229 | |
2230 | function lttng_enable_rotation_timer () | |
2231 | { | |
2232 | local expected_to_fail=$1 | |
2233 | local sess_name=$2 | |
2234 | local period=$3 | |
2235 | ||
a4705d55 SM |
2236 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
2237 | enable-rotation -s $sess_name --timer $period | |
e7716c6a JD |
2238 | ret=$? |
2239 | if [[ $expected_to_fail -eq "1" ]]; then | |
2240 | test "$ret" -ne "0" | |
9498e289 | 2241 | ok $? "Expected fail when setting periodic rotation ($period) of session $sess_name" |
e7716c6a | 2242 | else |
795f9063 | 2243 | ok $ret "Set periodic rotation ($period) of session $sess_name" |
e7716c6a JD |
2244 | fi |
2245 | } | |
2246 | ||
2247 | function lttng_enable_rotation_timer_ok () | |
2248 | { | |
2249 | lttng_enable_rotation_timer 0 $@ | |
2250 | } | |
2251 | ||
2252 | function lttng_enable_rotation_timer_fail () | |
2253 | { | |
2254 | lttng_enable_rotation_timer 1 $@ | |
2255 | } | |
2256 | ||
2257 | function lttng_enable_rotation_size () | |
2258 | { | |
2259 | local expected_to_fail=$1 | |
2260 | local sess_name=$2 | |
2261 | local size=$3 | |
2262 | ||
a4705d55 SM |
2263 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
2264 | enable-rotation -s $sess_name --size $size | |
e7716c6a JD |
2265 | ret=$? |
2266 | if [[ $expected_to_fail -eq "1" ]]; then | |
2267 | test "$ret" -ne "0" | |
2268 | ok $? "Expected fail on rotate session $sess_name" | |
2269 | else | |
2270 | ok $ret "Rotate session $sess_name" | |
2271 | fi | |
2272 | } | |
2273 | ||
2274 | function lttng_enable_rotation_size_ok () | |
2275 | { | |
2276 | lttng_enable_rotation_size 0 $@ | |
2277 | } | |
2278 | ||
2279 | function lttng_enable_rotation_size_fail () | |
2280 | { | |
2281 | lttng_enable_rotation_size 1 $@ | |
2282 | } | |
c28fcefd JR |
2283 | |
2284 | function lttng_clear_session () | |
2285 | { | |
2286 | local expected_to_fail=$1 | |
2287 | local sess_name=$2 | |
2288 | ||
a4705d55 SM |
2289 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
2290 | clear $sess_name | |
c28fcefd JR |
2291 | ret=$? |
2292 | if [[ $expected_to_fail -eq "1" ]]; then | |
2293 | test "$ret" -ne "0" | |
2294 | ok $? "Expected fail on clear session $sess_name" | |
2295 | else | |
2296 | ok $ret "Clear session $sess_name" | |
2297 | fi | |
2298 | } | |
2299 | ||
2300 | function lttng_clear_session_ok () | |
2301 | { | |
2302 | lttng_clear_session 0 $@ | |
2303 | } | |
2304 | ||
2305 | function lttng_clear_session_fail () | |
2306 | { | |
2307 | lttng_clear_session 1 $@ | |
2308 | } | |
5ee26199 JR |
2309 | |
2310 | function lttng_clear_all () | |
2311 | { | |
a4705d55 SM |
2312 | _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \ |
2313 | clear --all | |
5ee26199 JR |
2314 | ok $? "Clear all lttng sessions" |
2315 | } | |
70c766ac FD |
2316 | |
2317 | function lttng_add_trigger() | |
2318 | { | |
2319 | local expected_to_fail="$1" | |
2320 | local trigger_name="$2" | |
2321 | shift 2 | |
50ad0862 | 2322 | local args=("$@") |
70c766ac | 2323 | |
50ad0862 SM |
2324 | diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --name $trigger_name ${args[*]}" |
2325 | $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-trigger --name "$trigger_name" "${args[@]}" 1> /dev/null 2> /dev/null | |
70c766ac FD |
2326 | ret=$? |
2327 | if [[ $expected_to_fail -eq "1" ]]; then | |
2328 | test "$ret" -ne "0" | |
2329 | ok $? "Add trigger $trigger_name failed as expected" | |
2330 | else | |
2331 | ok $ret "Add trigger $trigger_name" | |
2332 | fi | |
2333 | } | |
2334 | ||
2335 | function lttng_remove_trigger() | |
2336 | { | |
2337 | local expected_to_fail="$1" | |
2338 | local trigger_name="$2" | |
96bb1ae8 | 2339 | shift 2 |
70c766ac | 2340 | |
651dd74d JR |
2341 | diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN remove-trigger $trigger_name $*" |
2342 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" remove-trigger "$trigger_name" "$@" 1> /dev/null 2> /dev/null | |
70c766ac FD |
2343 | ret=$? |
2344 | if [[ $expected_to_fail -eq "1" ]]; then | |
2345 | test "$ret" -ne "0" | |
2346 | ok $? "Remove trigger $trigger_name failed as expected" | |
2347 | else | |
2348 | ok $ret "Remove trigger $trigger_name" | |
2349 | fi | |
2350 | } | |
2351 | ||
2352 | function lttng_add_trigger_ok() | |
2353 | { | |
2354 | lttng_add_trigger 0 "$@" | |
2355 | } | |
2356 | ||
38eb8a68 FD |
2357 | function lttng_add_trigger_fail() |
2358 | { | |
2359 | lttng_add_trigger 1 "$@" | |
2360 | } | |
2361 | ||
70c766ac FD |
2362 | function lttng_remove_trigger_ok() |
2363 | { | |
2364 | lttng_remove_trigger 0 "$@" | |
2365 | } | |
bd666153 | 2366 | |
76404ef0 FD |
2367 | function list_triggers_matches_ok () |
2368 | { | |
33e55711 FD |
2369 | local tmp_stdout=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX") |
2370 | local tmp_stderr=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX") | |
76404ef0 FD |
2371 | |
2372 | local test_name="$1" | |
2373 | local expected_stdout_file="$2" | |
2374 | ||
2375 | diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN list-triggers" | |
2376 | ||
2377 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" list-triggers > "${tmp_stdout}" 2> "${tmp_stderr}" | |
2378 | ok $? "${test_name}: exit code is 0" | |
2379 | ||
2380 | diff -u "${expected_stdout_file}" "${tmp_stdout}" | |
2381 | ok $? "${test_name}: expected stdout" | |
2382 | ||
2383 | diff -u /dev/null "${tmp_stderr}" | |
2384 | ok $? "${test_name}: expected stderr" | |
2385 | ||
2386 | rm -f "${tmp_stdout}" | |
2387 | rm -f "${tmp_stderr}" | |
2388 | } | |
2389 | ||
dceffc9e JR |
2390 | function list_triggers_matches_mi_ok () |
2391 | { | |
2392 | local tmp_stdout | |
2393 | local tmp_stdout_raw | |
2394 | local tmp_stderr | |
2395 | ||
2396 | local test_name="$1" | |
2397 | local expected_stdout_file="$2" | |
2398 | ||
2399 | tmp_stdout_raw=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX") | |
2400 | tmp_stdout=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stdout.XXXXXX") | |
2401 | tmp_stderr=$(mktemp --tmpdir -t "tmp.${FUNCNAME[0]}_stderr.XXXXXX") | |
2402 | ||
2403 | diag "$TESTDIR/../src/bin/lttng/$LTTNG_BIN --mi xml list-triggers" | |
2404 | ||
2405 | "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" --mi=xml list-triggers > "${tmp_stdout_raw}" 2> "${tmp_stderr}" | |
2406 | ok $? "${test_name}: exit code is 0" | |
2407 | ||
2408 | # Pretty-fy xml before further test. | |
fa182fe0 | 2409 | $XML_PRETTY < "${tmp_stdout_raw}" > "${tmp_stdout}" |
dceffc9e | 2410 | |
fa182fe0 | 2411 | $MI_VALIDATE "${tmp_stdout}" |
dceffc9e JR |
2412 | ok $? "list-trigger mi is valid" |
2413 | ||
2414 | diff -u "${expected_stdout_file}" "${tmp_stdout}" | |
2415 | ok $? "${test_name}: expected stdout" | |
2416 | ||
2417 | diff -u /dev/null "${tmp_stderr}" | |
2418 | ok $? "${test_name}: expected stderr" | |
2419 | ||
2420 | rm -f "${tmp_stdout}" | |
2421 | rm -f "${tmp_stdout_raw}" | |
2422 | rm -f "${tmp_stderr}" | |
2423 | } | |
2424 | ||
bd666153 JR |
2425 | function validate_path_pattern () |
2426 | { | |
2427 | local message=$1 | |
2428 | local pattern=$2 | |
2429 | # Base path is only used in error case and is used to list the content | |
2430 | # of the base path. | |
2431 | local base_path=$3 | |
2432 | ||
2433 | ||
2434 | [ -f $pattern ] | |
2435 | ret=$? | |
2436 | ok $ret "$message" | |
2437 | ||
2438 | if [ "$ret" -ne "0" ]; then | |
2439 | diag "Path pattern expected: $pattern" | |
2440 | # List the tracepath for more info. We use find as a recursive | |
2441 | # directory lister. | |
2442 | diag "The base path content:" | |
2443 | find "$base_path" -print | |
2444 | fi | |
2445 | } | |
2446 | ||
2447 | function validate_trace_path_ust_uid () | |
2448 | { | |
2449 | local trace_path=$1 | |
2450 | local session_name=$2 | |
2451 | local uid=$UID | |
2452 | local pattern="$trace_path/$session_name-$date_time_pattern/ust/uid/$uid/${system_long_bit_size}-bit/metadata" | |
2453 | ||
2454 | validate_path_pattern "UST per-uid trace path is valid" "$pattern" "$trace_path" | |
2455 | } | |
2456 | ||
2457 | function validate_trace_path_ust_uid_network () | |
2458 | { | |
2459 | local trace_path=$1 | |
2460 | local session_name=$2 | |
2461 | local base_path=$3 | |
2462 | local uid=$UID | |
2463 | local hostname=$HOSTNAME | |
2464 | local pattern | |
2465 | local ret | |
2466 | ||
2467 | # If the session was given a network base path (e.g | |
2468 | # 127.0.0.1/my/custom/path on creation, there is no session name | |
2469 | # component to the path on the relayd side. Caller can simply not pass a | |
2470 | # session name for this scenario. | |
2471 | if [ -n "$session_name" ]; then | |
2472 | session_name="$session_name-$date_time_pattern" | |
2473 | if [ -n "$base_path" ]; then | |
2474 | fail "Session name and base path are mutually exclusive" | |
2475 | return | |
2476 | fi | |
2477 | fi | |
2478 | ||
2479 | pattern="$trace_path/$hostname/$base_path/$session_name/ust/uid/$uid/${system_long_bit_size}-bit/metadata" | |
2480 | ||
2481 | validate_path_pattern "UST per-uid network trace path is valid" "$pattern" "$trace_path" | |
2482 | } | |
2483 | ||
2484 | function validate_trace_path_ust_uid_snapshot_network () | |
2485 | { | |
2486 | local trace_path=$1 | |
2487 | local session_name=$2 | |
2488 | local snapshot_name=$3 | |
2489 | local snapshot_number=$4 | |
2490 | local base_path=$5 | |
2491 | local hostname=$HOSTNAME | |
2492 | local uid=$UID | |
2493 | local pattern | |
2494 | local ret | |
2495 | ||
2496 | # If the session/output was given a network base path (e.g | |
2497 | # 127.0.0.1/my/custom/path on creation, there is no session name | |
2498 | # component to the path on the relayd side. Caller can simply not pass a | |
2499 | # session name for this scenario. | |
2500 | if [ -n "$session_name" ]; then | |
2501 | session_name="$session_name-$date_time_pattern" | |
2502 | if [ -n "$base_path" ]; then | |
2503 | fail "Session name and base path are mutually exclusive" | |
2504 | return | |
2505 | fi | |
2506 | fi | |
2507 | ||
2508 | pattern="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata" | |
2509 | ||
2510 | validate_path_pattern "UST per-uid network snapshot trace path is valid" "$pattern" "$trace_path" | |
2511 | } | |
2512 | ||
2513 | function validate_trace_path_ust_uid_snapshot () | |
2514 | { | |
2515 | local trace_path=$1 | |
2516 | local session_name=$2 | |
2517 | local snapshot_name=$3 | |
2518 | local snapshot_number=$4 | |
2519 | local base_path=$5 | |
2520 | local uid=$UID | |
2521 | local pattern | |
2522 | local ret | |
2523 | ||
2524 | # If the session/output was given a network base path (e.g | |
2525 | # 127.0.0.1/my/custom/path) on creation, there is no session name | |
2526 | # component to the path on the relayd side. Caller can simply not pass a | |
2527 | # session name for this scenario. | |
2528 | if [ -n "$session_name" ]; then | |
2529 | session_name="$session_name-$date_time_pattern" | |
2530 | if [ -n "$base_path" ]; then | |
2531 | fail "Session name and base path are mutually exclusive" | |
2532 | return | |
2533 | fi | |
2534 | fi | |
2535 | ||
2536 | pattern="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/ust/uid/$uid/${system_long_bit_size}-bit/metadata" | |
2537 | ||
2538 | validate_path_pattern "UST per-uid snapshot trace path is valid" "$pattern" "$trace_path" | |
2539 | } | |
2540 | ||
2541 | function validate_trace_path_ust_pid () | |
2542 | { | |
2543 | local trace_path=$1 | |
2544 | local session_name=$2 | |
2545 | local app_string=$3 | |
2546 | local pid=$4 | |
2547 | local pattern | |
2548 | local ret | |
2549 | ||
2550 | # If the session was given a trace path on creation, there is no session | |
2551 | # name component to the path. Caller can simply not pass a session name | |
2552 | # for this scenario. | |
2553 | if [ -n "$session_name" ]; then | |
2554 | session_name="$session_name-$date_time_pattern" | |
2555 | fi | |
2556 | ||
2557 | pattern="$trace_path/$session_name/ust/pid/$pid/$app_string-*-$date_time_pattern/metadata" | |
2558 | ||
2559 | validate_path_pattern "UST per-pid trace path is valid" "$pattern" "$trace_path" | |
2560 | } | |
2561 | ||
2562 | function validate_trace_path_kernel () | |
2563 | { | |
2564 | local trace_path=$1 | |
2565 | local session_name=$2 | |
2566 | local pattern | |
2567 | ||
2568 | # If the session was given a trace path on creation, there is no session | |
2569 | # name component to the path. Caller can simply not pass a session name | |
2570 | # for this scenario. | |
2571 | if [ -n "$session_name" ]; then | |
2572 | session_name="$session_name-$date_time_pattern" | |
2573 | fi | |
2574 | ||
2575 | pattern="$trace_path/$session_name/kernel/metadata" | |
2576 | ||
2577 | validate_path_pattern "Kernel trace path is valid" "$pattern" "$trace_path" | |
2578 | } | |
2579 | ||
2580 | function validate_trace_path_kernel_network () | |
2581 | { | |
2582 | local trace_path=$1 | |
2583 | local session_name=$2 | |
2584 | local hostname=$HOSTNAME | |
2585 | local pattern="$trace_path/$hostname/$session_name-$date_time_pattern/kernel/metadata" | |
2586 | ||
2587 | validate_path_pattern "Kernel network trace path is valid" "$pattern" "$trace_path" | |
2588 | } | |
2589 | ||
2590 | function validate_trace_path_kernel_snapshot () | |
2591 | { | |
2592 | local trace_path=$1 | |
2593 | local session_name=$2 | |
2594 | local snapshot_name=$3 | |
2595 | local snapshot_number=$4 | |
2596 | local base_path=$5 | |
2597 | local pattern | |
2598 | local ret | |
2599 | ||
2600 | # If the session/output was given a network base path (e.g | |
2601 | # 127.0.0.1/my/custom/path on creation, there is no session name | |
2602 | # component to the path on the relayd side. Caller can simply not pass a | |
2603 | # session name for this scenario. | |
2604 | if [ -n "$session_name" ]; then | |
2605 | session_name="$session_name-$date_time_pattern" | |
2606 | if [ -n "$base_path" ]; then | |
2607 | fail "Session name and base path are mutually exclusive" | |
2608 | return | |
2609 | fi | |
2610 | fi | |
2611 | ||
2612 | pattern="$trace_path/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata" | |
2613 | ||
2614 | validate_path_pattern "Kernel snapshot trace path is valid" "$pattern" "$trace_path" | |
2615 | } | |
2616 | ||
2617 | function validate_trace_path_kernel_snapshot_network () | |
2618 | { | |
2619 | local trace_path=$1 | |
2620 | local session_name=$2 | |
2621 | local snapshot_name=$3 | |
2622 | local snapshot_number=$4 | |
2623 | local base_path=$5 | |
2624 | local hostname=$HOSTNAME | |
2625 | local pattern | |
2626 | local ret | |
2627 | ||
2628 | # If the session/output was given a network base path (e.g | |
2629 | # 127.0.0.1/my/custom/path on creation, there is no session name | |
2630 | # component to the path on the relayd side. Caller can simply not pass a | |
2631 | # session name for this scenario. | |
2632 | if [ -n "$session_name" ]; then | |
2633 | session_name="$session_name-$date_time_pattern" | |
2634 | if [ -n "$base_path" ]; then | |
2635 | fail "Session name and base path are mutually exclusive" | |
2636 | return | |
2637 | fi | |
2638 | fi | |
2639 | ||
2640 | pattern="$trace_path/$hostname/$base_path/$session_name/$snapshot_name-$date_time_pattern-$snapshot_number/kernel/metadata" | |
2641 | ||
2642 | validate_path_pattern "Kernel network snapshot trace path is valid" "$pattern" "$trace_path" | |
2643 | } |