X-Git-Url: http://git.lttng.org/?p=lttng-tools.git;a=blobdiff_plain;f=tests%2Futils%2Futils.sh;fp=tests%2Futils%2Futils.sh;h=0e8ec54dd4f102b99424466eafc5275f0ba10092;hp=c1d702e823c33120f96b256df93bd35044a73d8e;hb=3a1744008331a0604479d3d7461f77056fad3a64;hpb=f2b390e97d3b6ec347fe7c4af3b46256716ae054 diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index c1d702e82..0e8ec54dd 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -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 ()