Clean-up: modernize pretty_xml.cpp
[lttng-tools.git] / tests / utils / utils.sh
index 291cb578a98fdfd27d12a0944216ba255a511934..0e8ec54dd4f102b99424466eafc5275f0ba10092 100644 (file)
@@ -323,6 +323,41 @@ function conf_proc_count()
        echo
 }
 
+# Usage:
+# check_skip_kernel_test [NB_TESTS] [SKIP_MESSAGE]
+# Return 0 if LTTNG_TOOLS_DISABLE_KERNEL_TESTS was set or the current user is not a root user
+# If NB_TESTS is set, call skip() to skip number of tests.
+# If NB_TESTS is empty, just output a reason with diag.
+# An optional message can be added.
+
+function check_skip_kernel_test ()
+{
+       local num_tests="$1"
+       local skip_message="$2"
+
+       # Check for skip test kernel flag
+       if [ "$LTTNG_TOOLS_DISABLE_KERNEL_TESTS" == "1" ]; then
+               if ! test -z "$num_tests"; then
+                       skip 0 "LTTNG_TOOLS_DISABLE_KERNEL_TESTS was set.${skip_message+ }${skip_message}" "$num_tests"
+               else
+                       diag "LTTNG_TOOLS_DISABLE_KERNEL_TESTS was set.${skip_message+ }${skip_message}"
+               fi
+               return 0
+       fi
+
+       # Check if we are running as root
+       if [ "$(id -u)" != "0" ]; then
+               if ! test -z "$num_tests"; then
+                       skip 0 "Root access is needed for kernel testing.${skip_message+ }${skip_message}" "$num_tests"
+               else
+                       diag "Root access is needed for kernel testing.${skip_message+ }${skip_message}"
+               fi
+               return 0
+       fi
+
+       return 1
+}
+
 # Check if base lttng-modules are present.
 # Bail out on failure
 function validate_lttng_modules_present ()
@@ -675,8 +710,9 @@ function stop_lttng_relayd_opt()
 
 
        # Multiply time by 2 to simplify integer arithmetic
+       # Multiply time by 5 to adjust for sleeping every 0.1s
        if [ -n "$timeout_s" ]; then
-               dtimeleft_s=$((timeout_s * 2))
+               dtimeleft_s=$((timeout_s * 2 * 5))
        fi
 
 
@@ -711,7 +747,7 @@ function stop_lttng_relayd_opt()
                                fi
                                dtimeleft_s=$((dtimeleft_s - 1))
                        fi
-                       sleep 0.5
+                       sleep 0.1
                done
                if [ "$withtap" -eq "1" ]; then
                        if [ "$retval" -eq "0" ]; then
@@ -835,8 +871,9 @@ function stop_lttng_sessiond_opt()
        fi
 
        # Multiply time by 2 to simplify integer arithmetic
+       # Multiply time by 5 to adjust for sleeping every 0.1s
        if [ -n "$timeout_s" ]; then
-               dtimeleft_s=$((timeout_s * 2))
+               dtimeleft_s=$((timeout_s * 2 * 5))
        fi
 
        if [ -n "$TEST_NO_SESSIOND" ] && [ "$TEST_NO_SESSIOND" == "1" ]; then
@@ -881,7 +918,7 @@ function stop_lttng_sessiond_opt()
                                fi
                                dtimeleft_s=$((dtimeleft_s - 1))
                        fi
-                       sleep 0.5
+                       sleep 0.1
                done
                out=1
                while [ -n "$out" ]; do
@@ -893,7 +930,7 @@ function stop_lttng_sessiond_opt()
                                fi
                                dtimeleft_s=$((dtimeleft_s - 1))
                        fi
-                       sleep 0.5
+                       sleep 0.1
                done
 
                if [ "$withtap" -eq "1" ]; then
@@ -1003,8 +1040,9 @@ function stop_lttng_consumerd_opt()
        fi
 
        # Multiply time by 2 to simplify integer arithmetic
+       # Multiply time by 5 to adjust for sleeping every 0.1s
        if [ -n "$timeout_s" ]; then
-               dtimeleft_s=$((timeout_s * 2))
+               dtimeleft_s=$((timeout_s * 2 * 5))
        fi
 
        pids="$(lttng_pgrep "$CONSUMERD_MATCH")"
@@ -1049,7 +1087,7 @@ function stop_lttng_consumerd_opt()
                                fi
                                dtimeleft_s=$((dtimeleft_s - 1))
                        fi
-                       sleep 0.5
+                       sleep 0.1
                done
                if [ "$withtap" -eq "1" ]; then
                        if [ "$retval" -eq "0" ]; then
@@ -1688,9 +1726,10 @@ function destroy_lttng_session ()
        local withtap=$1
        local expected_to_fail=$2
        local sess_name=$3
+       shift 3
 
        _run_lttng_cmd "$OUTPUT_DEST" "$ERROR_OUTPUT_DEST" \
-               destroy $sess_name
+               destroy $sess_name $@
        ret=$?
        if [[ $expected_to_fail -eq "1" ]]; then
                test "$ret" -ne "0"
@@ -1995,7 +2034,7 @@ function wait_live_trace_ready ()
        diag "Waiting for live trace at url: $url"
        while [ $zero_client_match -eq 0 ]; do
                zero_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "0 client(s) connected" | wc -l)
-               sleep 0.5
+               sleep 0.1
        done
        pass "Waiting for live trace at url: $url"
 }
@@ -2008,7 +2047,7 @@ function wait_live_viewer_connect ()
        diag "Waiting for live viewers on url: $url"
        while [ $one_client_match -eq 0 ]; do
                one_client_match=$($BABELTRACE_BIN -i lttng-live $url | grep "1 client(s) connected" | wc -l)
-               sleep 0.5
+               sleep 0.1
        done
        pass "Waiting for live viewers on url: $url"
 }
This page took 0.024983 seconds and 4 git commands to generate.