X-Git-Url: https://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Futils%2Futils.sh;h=94b3a3c45fc12a376c1d4d51d8ff44159fca89c6;hp=e8dfcda3cedf157c334d594bbc187d42020c4864;hb=3355fd4d9665a0899060b66959c48f226a1f3e89;hpb=854382b8a0f18fa77ba97eac55a61dd8d8d8cc85 diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index e8dfcda3c..94b3a3c45 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -125,6 +125,16 @@ function conf_proc_count() echo } +# Check if base lttng-modules are present. +# Bail out on failure +function validate_lttng_modules_present () +{ + modprobe -n lttng-tracer 2>/dev/null + if [ $? -ne 0 ]; then + BAIL_OUT "LTTng modules not detected." + fi +} + function enable_kernel_lttng_event { local withtap="$1" @@ -260,6 +270,41 @@ function lttng_disable_kernel_syscall_fail() lttng_disable_kernel_syscall 1 "$@" } +function lttng_enable_kernel_userspace_probe_event () +{ + local expected_to_fail="$1" + local sess_name="$2" + local target="$3" + local event_name="$4" + + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" enable-event --kernel --userspace-probe="$target" "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST" + ret=$? + if [[ $expected_to_fail -eq "1" ]]; then + test $ret -ne "0" + ok $? "Enable kernel userspace probe event for session $sess_name failed as expected" + else + ok $ret "Enable kernel userspace probe event for session $sess_name" + fi +} + +function lttng_enable_kernel_userspace_probe_event_fail () +{ + lttng_enable_kernel_userspace_probe_event 1 "$@" +} + +function lttng_enable_kernel_userspace_probe_event_ok () +{ + lttng_enable_kernel_userspace_probe_event 0 "$@" +} + +function disable_kernel_lttng_userspace_probe_event_ok () +{ + local sess_name="$1" + local event_name="$2" + + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" disable-event --kernel "$event_name" -s "$sess_name" > "$OUTPUT_DEST" 2> "$ERROR_OUTPUT_DEST" + ok $? "Disable kernel event $target for session $sess_name" +} function lttng_enable_kernel_channel() { local withtap=$1 @@ -601,9 +646,9 @@ function stop_lttng_consumerd_opt() if [ $withtap -eq "1" ]; then diag "Killing $CONSUMERD_BIN pids: $(echo $PID_CONSUMERD | tr '\n' ' ')" fi + kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST retval=$? - set +x if [ $? -eq 1 ]; then if [ $withtap -eq "1" ]; then @@ -658,7 +703,6 @@ function sigstop_lttng_consumerd_opt() fi kill $kill_opt $PID_CONSUMERD 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST retval=$? - set +x if [ $? -eq 1 ]; then if [ $withtap -eq "1" ]; then @@ -713,6 +757,15 @@ function create_lttng_session_no_output () ok $? "Create session $sess_name in no-output mode" } +function create_lttng_session_uri () { + local sess_name=$1 + local uri=$2 + local opts="${@:3}" + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN create $sess_name -U $uri $opts 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + ok $? "Create session $sess_name with uri:$uri and opts: $opts" +} + function create_lttng_session () { local withtap=$1 @@ -1062,54 +1115,76 @@ function disable_python_lttng_event () ok $? "Disable Python event $event_name for session $sess_name" } -function start_lttng_tracing () +function start_lttng_tracing_opt () { - local expected_to_fail=$1 - local sess_name=$2 + local withtap=$1 + local expected_to_fail=$2 + local sess_name=$3 $TESTDIR/../src/bin/lttng/$LTTNG_BIN start $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST ret=$? if [[ $expected_to_fail -eq "1" ]]; then test "$ret" -ne "0" - ok $? "Start tracing for session $sess_name failed as expected" + ret=$? + if [ $withtap -eq "1" ]; then + ok $? "Start tracing for session $sess_name failed as expected" + fi else - ok $ret "Start tracing for session $sess_name" + if [ $withtap -eq "1" ]; then + ok $ret "Start tracing for session $sess_name" + fi fi } function start_lttng_tracing_ok () { - start_lttng_tracing 0 "$@" + start_lttng_tracing_opt 1 0 "$@" } function start_lttng_tracing_fail () { - start_lttng_tracing 1 "$@" + start_lttng_tracing_opt 1 1 "$@" } -function stop_lttng_tracing () +function start_lttng_tracing_notap () { - local expected_to_fail=$1 - local sess_name=$2 + start_lttng_tracing_opt 0 1 "$@" +} + +function stop_lttng_tracing_opt () +{ + local withtap=$1 + local expected_to_fail=$2 + local sess_name=$3 $TESTDIR/../src/bin/lttng/$LTTNG_BIN stop $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST ret=$? if [[ $expected_to_fail -eq "1" ]]; then test "$ret" -ne "0" - ok $? "Stop lttng tracing for session $sess_name failed as expected" + ret=$? + if [ $withtap -eq "1" ]; then + ok $? "Stop lttng tracing for session $sess_name failed as expected" + fi else - ok $ret "Stop lttng tracing for session $sess_name" + if [ $withtap -eq "1" ]; then + ok $ret "Stop lttng tracing for session $sess_name" + fi fi } function stop_lttng_tracing_ok () { - stop_lttng_tracing 0 "$@" + stop_lttng_tracing_opt 1 0 "$@" } function stop_lttng_tracing_fail () { - stop_lttng_tracing 1 "$@" + stop_lttng_tracing_opt 1 1 "$@" +} + +function stop_lttng_tracing_notap () +{ + stop_lttng_tracing_opt 0 0 "$@" } function destroy_lttng_session () @@ -1305,6 +1380,26 @@ function lttng_untrack_fail() lttng_untrack 1 "$@" } +function lttng_track_pid_ok() +{ + PID=$1 + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" track --kernel --pid=$PID 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + ok $? "Lttng track pid on the kernel domain" +} + +function lttng_untrack_kernel_all_ok() +{ + "$TESTDIR/../src/bin/lttng/$LTTNG_BIN" untrack --kernel --pid --all 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + ok $? "Lttng untrack all pid on the kernel domain" +} + +function lttng_add_context_list() +{ + $TESTDIR/../src/bin/lttng/$LTTNG_BIN add-context --list 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + ret=$? + ok $ret "Context listing" +} + function add_context_lttng() { local expected_to_fail="$1" @@ -1343,6 +1438,29 @@ function add_context_kernel_fail() add_context_lttng 1 -k "$@" } +function validate_metadata_event () +{ + local event_name=$1 + local nr_event_id=$2 + local trace_path=$3 + + local metadata_file=$(find $trace_path | grep metadata) + local metadata_path=$(dirname $metadata_file) + + which $BABELTRACE_BIN >/dev/null + skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" + + local count=$($BABELTRACE_BIN --output-format=ctf-metadata $metadata_path | grep $event_name | wc -l) + + if [ "$count" -ne "$nr_event_id" ]; then + fail "Metadata match with the metadata of $count event(s) named $event_name" + diag "$count matching event id found in metadata" + else + pass "Metadata match with the metadata of $count event(s) named $event_name" + fi + +} + function trace_matches () { local event_name=$1 @@ -1374,12 +1492,12 @@ function trace_match_only() local count=$($BABELTRACE_BIN $trace_path | grep $event_name | wc -l) local total=$($BABELTRACE_BIN $trace_path | wc -l) - if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then - pass "Trace match with $total event $event_name" - else - fail "Trace match" - diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count" - fi + if [ "$nr_iter" -eq "$count" ] && [ "$total" -eq "$nr_iter" ]; then + pass "Trace match with $total event $event_name" + else + fail "Trace match" + diag "$total event(s) found, expecting $nr_iter of event $event_name and only found $count" + fi } function validate_trace @@ -1457,7 +1575,7 @@ function validate_trace_exp() which $BABELTRACE_BIN >/dev/null skip $? -ne 0 "Babeltrace binary not found. Skipping trace validation" - traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep ${event_exp} | wc -l) + traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | grep --extended-regexp ${event_exp} | wc -l) if [ "$traced" -ne 0 ]; then pass "Validate trace for expression '${event_exp}', $traced events" else @@ -1476,11 +1594,11 @@ function validate_trace_only_exp() which $BABELTRACE_BIN >/dev/null skip $? -ne 0 "Babeltrace binary not found. Skipping trace matches" - local count=$($BABELTRACE_BIN $trace_path | grep ${event_exp} | wc -l) + local count=$($BABELTRACE_BIN $trace_path | grep --extended-regexp ${event_exp} | wc -l) local total=$($BABELTRACE_BIN $trace_path | wc -l) if [ "$count" -ne 0 ] && [ "$total" -eq "$count" ]; then - pass "Trace match with $total for expression '${event_exp}" + pass "Trace match with $total for expression '${event_exp}'" else fail "Trace match" diag "$total syscall event(s) found, only syscalls matching expression '${event_exp}' ($count occurrences) are expected" @@ -1498,7 +1616,14 @@ function validate_trace_empty() skip 0 "Babeltrace binary not found. Skipping trace validation" fi - traced=$($BABELTRACE_BIN $trace_path 2>/dev/null | wc -l) + events=$($BABELTRACE_BIN $trace_path 2>/dev/null) + ret=$? + if [ $ret -ne 0 ]; then + fail "Failed to parse trace" + return $ret + fi + + traced=$(echo -n "$events" | wc -l) if [ "$traced" -eq 0 ]; then pass "Validate empty trace" else @@ -1559,6 +1684,31 @@ function regenerate_statedump_fail () regenerate_statedump 1 "$@" } +function rotate_session () +{ + local expected_to_fail=$1 + local sess_name=$2 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN rotate $sess_name 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + ret=$? + if [[ $expected_to_fail -eq "1" ]]; then + test "$ret" -ne "0" + ok $? "Expected fail on rotate session $sess_name" + else + ok $ret "Rotate session $sess_name" + fi +} + +function rotate_session_ok () +{ + rotate_session 0 "$@" +} + +function rotate_session_fail () +{ + rotate_session 1 "$@" +} + function destructive_tests_enabled () { if [ ${LTTNG_ENABLE_DESTRUCTIVE_TESTS} = "will-break-my-system" ]; then @@ -1567,3 +1717,55 @@ function destructive_tests_enabled () return 1 fi } + +function lttng_enable_rotation_timer () +{ + local expected_to_fail=$1 + local sess_name=$2 + local period=$3 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --timer $period 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + ret=$? + if [[ $expected_to_fail -eq "1" ]]; then + test "$ret" -ne "0" + ok $? "Expected fail on rotate session $sess_name" + else + ok $ret "Rotate session $sess_name" + fi +} + +function lttng_enable_rotation_timer_ok () +{ + lttng_enable_rotation_timer 0 $@ +} + +function lttng_enable_rotation_timer_fail () +{ + lttng_enable_rotation_timer 1 $@ +} + +function lttng_enable_rotation_size () +{ + local expected_to_fail=$1 + local sess_name=$2 + local size=$3 + + $TESTDIR/../src/bin/lttng/$LTTNG_BIN enable-rotation -s $sess_name --size $size 1> $OUTPUT_DEST 2> $ERROR_OUTPUT_DEST + ret=$? + if [[ $expected_to_fail -eq "1" ]]; then + test "$ret" -ne "0" + ok $? "Expected fail on rotate session $sess_name" + else + ok $ret "Rotate session $sess_name" + fi +} + +function lttng_enable_rotation_size_ok () +{ + lttng_enable_rotation_size 0 $@ +} + +function lttng_enable_rotation_size_fail () +{ + lttng_enable_rotation_size 1 $@ +}