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