tests: add check_skip_kernel_test to check root user and lttng kernel modules
authorXiangyu Chen <xiangyu.chen@windriver.com>
Mon, 12 Feb 2024 14:23:54 +0000 (09:23 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Thu, 7 Mar 2024 16:37:42 +0000 (11:37 -0500)
The current tests will run both userspace and kernel testing. Some of
use cases only use lttng for one kind of tracing on an embedded
device (e.g. userspace), so in this scenario, the kernel modules might
not install to target rootfs, the test cases would be fail and exit.

Add LTTNG_TOOLS_DISABLE_KERNEL_TESTS to skip the lttng kernel features
test, this flag can be set via "make":

  make check LTTNG_TOOLS_DISABLE_KERNEL_TESTS=1

When this flag was set, all kernel related testcases would be marked as
SKIP in result.

Since the the LTTNG_TOOLS_DISABLE_KERNEL_TESTS was checked in function
check_skip_kernel_test, lots of testcases also need to check root
permission, so merging the root permission checking into
check_skip_kernel_test.

Change-Id: I49a1f642a9869c21a69e0186c296fd917bd7b525
Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com>
Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
48 files changed:
tests/destructive/metadata-regeneration
tests/perf/test_perf_raw.in
tests/regression/kernel/test_all_events
tests/regression/kernel/test_callstack
tests/regression/kernel/test_channel
tests/regression/kernel/test_clock_override
tests/regression/kernel/test_event_basic
tests/regression/kernel/test_kernel_function
tests/regression/kernel/test_lttng_logger
tests/regression/kernel/test_ns_contexts
tests/regression/kernel/test_ns_contexts_change
tests/regression/kernel/test_rotation_destroy_flush
tests/regression/kernel/test_select_poll_epoll
tests/regression/kernel/test_syscall
tests/regression/kernel/test_userspace_probe
tests/regression/tools/clear/test_kernel
tests/regression/tools/filtering/test_invalid_filter
tests/regression/tools/filtering/test_unsupported_op
tests/regression/tools/filtering/test_valid_filter
tests/regression/tools/health/test_health.sh
tests/regression/tools/health/test_thread_ok
tests/regression/tools/live/test_kernel
tests/regression/tools/live/test_lttng_kernel
tests/regression/tools/metadata/test_kernel
tests/regression/tools/notification/test_notification_kernel_buffer_usage
tests/regression/tools/notification/test_notification_kernel_capture
tests/regression/tools/notification/test_notification_kernel_error
tests/regression/tools/notification/test_notification_kernel_instrumentation
tests/regression/tools/notification/test_notification_kernel_syscall
tests/regression/tools/notification/test_notification_kernel_userspace_probe
tests/regression/tools/notification/test_notification_multi_app
tests/regression/tools/notification/test_notification_notifier_discarded_count
tests/regression/tools/regen-metadata/test_kernel
tests/regression/tools/regen-statedump/test_kernel
tests/regression/tools/rotation/test_kernel
tests/regression/tools/rotation/test_ust_kernel
tests/regression/tools/snapshots/test_kernel
tests/regression/tools/snapshots/test_kernel_streaming
tests/regression/tools/streaming/test_high_throughput_limits
tests/regression/tools/streaming/test_kernel
tests/regression/tools/tracker/test_event_tracker
tests/regression/tools/trigger/test_add_trigger_cli
tests/regression/tools/trigger/test_list_triggers_cli
tests/regression/tools/wildcard/test_event_wildcard
tests/regression/tools/working-directory/test_relayd_working_directory
tests/regression/ust/namespaces/test_ns_contexts_change
tests/regression/ust/test_event_perf
tests/utils/utils.sh

index 048c601b60f06f4f9d0aff58d375c2243e4ddc21..dcae6bce0dfb901f318bd26bdc8012f0e7d51cc3 100755 (executable)
@@ -189,12 +189,6 @@ function test_ust_streaming ()
        rm -f "${file_sync_before_last}"
 }
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
 if ! destructive_tests_enabled ; then
        echo 'Please make sure that ntp is not running while executing this test'
        skip 0 "You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS environment variable to \"will-break-my-system\" to run this test" $NUM_TESTS
@@ -202,7 +196,7 @@ if ! destructive_tests_enabled ; then
        exit 0
 fi
 
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test $NUM_TESTS "Skipping all tests." ||
 {
        original_date=$(date)
        start_lttng_relayd "-o $TRACE_PATH"
index 0a451ce63500d97a0bd938e3f860973b4fd399ba..00cdebc5567d1cccdc0ee9ddd13022040f382fc2 100644 (file)
@@ -137,12 +137,6 @@ function test_kernel_raw()
        rm -rf $TRACE_PATH
 }
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
 # MUST set TESTDIR before calling those functions
 plan_tests $NUM_TESTS
 
@@ -154,7 +148,7 @@ have_libpfm
 
 test_ust_raw
 
-skip $isroot "Root access is needed for kernel testing, skipping." 9 ||
+check_skip_kernel_test 9 ||
 {
        modprobe lttng-test
        test_kernel_raw
index 2fb2f611da69069ff7f01e30568b3115e874ee20..dd6dab5e519c98ad64b82472e23b5e8e05497926 100755 (executable)
@@ -43,13 +43,7 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
        start_lttng_sessiond
index cf39089af923414218d727b80e2b51b570648f63..960bb8a44e1511f08ae425a675dc296c75dc4410 100755 (executable)
@@ -136,13 +136,7 @@ print_test_banner "$TEST_DESC"
 
 bail_out_if_no_babeltrace
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
        start_lttng_sessiond
index 5525564d2edd9887ce063a890a79b4ac44d7e165..6c7d2db0791bdbb810bb1ccd9b71bf5a1e11341b 100755 (executable)
@@ -47,13 +47,7 @@ function test_channel_buffer_too_large()
 plan_tests $NUM_TESTS
 print_test_banner "$TEST_DESC"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        start_lttng_sessiond
 
index 524c3c3bb4014e6737459b0796648bf9899c7a16..c3688d3599efa28aed83d8eab7483ba44934bd78 100755 (executable)
@@ -174,13 +174,7 @@ TESTS=(
 TEST_COUNT=${#TESTS[@]}
 i=0
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
        trap signal_cleanup SIGTERM SIGINT
index 9f22d7db83984d47f7452aeea9a2de0bb5d75871..e57cd6d26a1561805da32bc28ba1cb8192bd0433 100755 (executable)
@@ -73,13 +73,7 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test $NUM_TESTS "Skipping all tests." ||
 {
        validate_lttng_modules_present
        start_lttng_sessiond
index 131c1c70b9f8562c9c54b0a477e54f56ca36b13a..3c941c72c78424b947e215117b360b62fff71c0f 100755 (executable)
@@ -43,13 +43,7 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        start_lttng_sessiond_notap
        validate_lttng_modules_present
index 849428807d944ce5787d68f4486dd41a0ad319be..c6ed4f950589a0bdfe0e505f3c614ee4b2cb9932 100755 (executable)
@@ -110,13 +110,7 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
        start_lttng_sessiond
index 7d447bc40859d424ac82d77fbc5cbc3a94471733..1c71ea503e998f26f2519675bfb4e32c3ef986fb 100755 (executable)
@@ -108,13 +108,7 @@ plan_tests $NUM_TESTS
 print_test_banner "$TEST_DESC"
 
 
-isroot=0
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0
-
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." && exit 0
 
 system_has_ns=0
 if [ -d "/proc/$$/ns" ]; then
index 715c67cc8c776c9a9ba7365730338d7b02d1d9cd..10f97f8cbb922fa391dbe1831007da8bde1a7be5 100755 (executable)
@@ -162,14 +162,7 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
-
-isroot=0
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0
-
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." && exit 0
 
 system_has_ns=0
 if [ -d "/proc/$$/ns" ]; then
index 6e568afda769cae29dd40fb41d913e9470df367e..fc22740262afd6ffe259ee26e768a56e65e46c26 100755 (executable)
@@ -120,13 +120,7 @@ TESTS=(
 TEST_COUNT=${#TESTS[@]}
 i=0
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
        trap signal_cleanup SIGTERM SIGINT
index cdde1ea4f04c281eef142fe4466d6f93e31b9e6b..09c911df978854a0f9f661a1d7ddd191fc9d614a 100755 (executable)
@@ -363,15 +363,9 @@ if test $? != 0; then
        exit 0
 fi
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
 diag "Supported syscalls are $SUPPORTED_SYSCALLS_LIST"
 
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
 
index f9b49085835b39b2fc109b53b8ff61998e0710ed..92d79a7bcba884e28995ac75dfd6740a5f79dd7d 100755 (executable)
@@ -664,13 +664,7 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
        start_lttng_sessiond
index bfa260e47a7a00c465429f4951d6e463a4f572f8..38987f7b18aefafacc1953880c736e5fc180ca8f 100755 (executable)
@@ -815,13 +815,7 @@ fi
 plan_tests $NUM_TESTS
 print_test_banner "$TEST_DESC"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
        start_lttng_sessiond
index ce76f85d24102c4ac85ed34cf41f1959331de2a8..2e383b8aa6c0971705831974fefcf0e2b644e776 100755 (executable)
@@ -538,12 +538,6 @@ print_test_banner "$TEST_DESC"
 
 bail_out_if_no_babeltrace
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
 streaming_tests=(test_kernel_streaming
        test_kernel_streaming_rotate_clear
        test_kernel_streaming_clear_rotate
@@ -565,7 +559,7 @@ snapshot_tests=(test_kernel_streaming_snapshot
        test_kernel_local_snapshot
 )
 
-skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping kernel streaming tests." ||
 {
        trap signal_cleanup SIGTERM SIGINT
 
index 8dfbe9eb5707a8ac04d192f1f28b062ab2506598..2dd57b0bbbbcceb1339929b2fc44e63a5fa3120b 100755 (executable)
@@ -170,13 +170,7 @@ done
 
 test_bytecode_limit -u
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel invalid filter tests." $NUM_KERNEL_TESTS ||
+check_skip_kernel_test "$NUM_KERNEL_TESTS" "Skipping kernel invalid filter tests." ||
 {
        diag "Test kernel filters"
        i=0
index dc76f99a696ab8bfdb5302f5522ac81e6c33c991..672a980de959d2494d81c1b40e1373a3af1d8d15 100755 (executable)
@@ -103,13 +103,7 @@ while [ "$i" -lt "$OP_COUNT" ]; do
        let "i++"
 done
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel unsupported filter operations tests." $NUM_KERNEL_TESTS ||
+check_skip_kernel_test $NUM_KERNEL_TESTS "Skipping kernel unsupported filter operations tests." ||
 {
        diag "Test kernel unsupported filter operations"
 
index 0c7ac0bdd5e00f419063f07ac0e18922623ecb42..1d7b0db4726c25be78c1ab94b2cbd8a23636eb26 100755 (executable)
@@ -1454,13 +1454,7 @@ KERNEL_FILTERS=(
 
 IFS=$OLDIFS
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel valid filter tests." $NUM_KERNEL_TESTS ||
+check_skip_kernel_test "$NUM_KERNEL_TESTS" "Skipping kernel valid filter tests." ||
 {
        diag "Test kernel valid filters"
 
index b4b416f929f7c5924611fda3f62f05ce91173104..23cb05075d33a0edabd2dd4a6060710e3d0dbbca 100644 (file)
@@ -82,7 +82,7 @@ function test_health
                diag "With UST consumer daemons"
                enable_ust_lttng_event_ok $SESSION_NAME $UST_EVENT_NAME $CHANNEL_NAME
 
-               skip $isroot "Root access is needed. Skipping kernel consumer health check test." "1" ||
+               check_skip_kernel_test "1" "Skipping kernel consumer health check test." ||
                {
                        diag "With kernel consumer daemon"
                        lttng_enable_kernel_event $SESSION_NAME $KERNEL_EVENT_NAME $CHANNEL_NAME
@@ -113,7 +113,7 @@ function test_health
 
 
        if [ ${test_needs_root} -eq 1 ]; then
-               skip ${isroot} "Root access needed for test \"${test_thread_name}\"." "1" ||
+               check_skip_kernel_test "1" "Skipping \"${test_thread_name}\"." ||
                {
                        report_errors "${test_thread_error_string}" "${test_relayd}"
                }
@@ -271,12 +271,6 @@ STDERR_PATH=$(mktemp -t tmp.test_health_stderr_path.XXXXXX)
 TRACE_PATH=$(mktemp -d -t tmp.test_health_trace_path.XXXXXX)
 HEALTH_PATH=$(mktemp -d -t tmp.test_health_trace_path.XXXXXX)
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
 THREAD_COUNT=${#THREAD[@]}
 i=0
 while [ "$i" -lt "$THREAD_COUNT" ]; do
index 663b7e4cb2eab1bf9bd1bb5ea7d9bb9a5f336c59..5441b2f064b56eb74ecce145c1f5b64268b14aa3 100755 (executable)
@@ -67,7 +67,7 @@ function test_thread_ok
        $CURDIR/$HEALTH_CHECK_BIN > ${STDOUT_PATH} 2> ${STDERR_PATH}
        report_errors
 
-       skip $isroot "Root access is needed. Skipping kernel consumer health check test." "5" ||
+       check_skip_kernel_test "5" "Skipping kernel consumer health check test." ||
        {
                diag "With kernel consumer daemon"
                create_lttng_session_no_output $SESSION_NAME
@@ -115,13 +115,6 @@ STDERR_PATH=$(mktemp -t tmp.test_thread_ok_stderr_path.XXXXXX)
 TRACE_PATH=$(mktemp -d -t tmp.test_thread_ok_trace_path.XXXXXX)
 HEALTH_PATH=$(mktemp -d -t tmp.test_thread_ok_trace_path.XXXXXX)
 
-# The manage kernel thread is only spawned if we are root
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
 test_thread_ok
 
 rm -rf ${HEALTH_PATH}
index 1be703aacf5d4b2e9a48f789afd5ebfbcdbdd1aa..df30fcf56242e940ec974af197414de788bf95fe 100755 (executable)
@@ -39,13 +39,11 @@ function clean_live_tracing()
        rm -rf $TRACE_PATH
 }
 
-# Need root access for kernel tracing.
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       plan_skip_all "Root access is needed. Skipping all tests."
+check_skip_kernel_test &&
+{
+       plan_skip_all "Skipping all tests."
        exit 0
-fi
+}
 
 modprobe lttng-test
 
index ae8c57e6b4a2191050f648d0b8a976e1e1922e6c..94f2c008729c4db25abfd74500b288a41238e4eb 100755 (executable)
@@ -45,13 +45,7 @@ function clean_live_tracing()
 }
 
 # Need root access for kernel tracing.
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        modprobe lttng-test
 
index 9e1e81232128d6000fffb55df13502ff068131cf..d38af841df2d009592f88a5ba23ed34529085398 100755 (executable)
@@ -98,13 +98,7 @@ print_test_banner "$TEST_DESC"
 
 bail_out_if_no_babeltrace
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping kernel metadata tests." ||
 {
        validate_lttng_modules_present
        modprobe lttng-test
index 5a87583dcd1198d803dac3f9a251eb3ea938bd5b..a89355a448ac9e92b3eeac99726ddf4afc6faf2f 100755 (executable)
@@ -63,29 +63,27 @@ function test_buffer_usage_notification
        wait $APP_PID 2> /dev/null
 }
 
-if [ "$(id -u)" == "0" ]; then
-
-       validate_lttng_modules_present
-
+check_skip_kernel_test &&
+{
+       plan_skip_all "Skipping all tests."
+       rm -rf "$TEST_TMPDIR"
+       exit 0
+}
 
-       modprobe lttng-test
+validate_lttng_modules_present
 
-       # Used on sessiond launch.
-       LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \
-               CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
-               LD_PRELOAD=${TESTPOINT}"
-       start_lttng_sessiond_notap
+modprobe lttng-test
 
-       test_buffer_usage_notification
+# Used on sessiond launch.
+LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \
+       CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \
+       LD_PRELOAD=${TESTPOINT}"
+start_lttng_sessiond_notap
 
-       stop_lttng_sessiond_notap
-       rmmod lttng-test
+test_buffer_usage_notification
 
-       rm -rf "${consumerd_pipe[@]}" 2> /dev/null
-else
-       # Kernel tests are skipped.
-       plan_tests $NUM_TESTS
-       skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS
-fi
+stop_lttng_sessiond_notap
+rmmod lttng-test
 
+rm -rf "${consumerd_pipe[@]}" 2> /dev/null
 rm -rf "$TEST_TMPDIR"
index 88a3691eb6500ee568dadedf651230076757fb7c..b65310d8801a6a50c0261db12ad330ef7f6620a4 100755 (executable)
@@ -31,22 +31,21 @@ function test_basic_error_path
 }
 
 
-if [ "$(id -u)" == "0" ]; then
-       validate_lttng_modules_present
+check_skip_kernel_test &&
+{
+       plan_skip_all "Skipping all tests."
+       exit 0
+}
 
-       modprobe lttng-test
+validate_lttng_modules_present
 
-       start_lttng_sessiond_notap
+modprobe lttng-test
 
-       test_basic_error_path
+start_lttng_sessiond_notap
 
-       stop_lttng_sessiond_notap
-       rmmod lttng-test
+test_basic_error_path
 
-else
-       # Kernel tests are skipped.
-       plan_tests $NUM_TESTS
-       skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS
-fi
+stop_lttng_sessiond_notap
+rmmod lttng-test
 
 rm -f "$TESTAPP_STATE_PATH"
index 8911467477550ec3ba6c0c129673d13c79b7789d..5f53f5b1b8399987a1591ba57484d1dda53cea5b 100755 (executable)
@@ -30,23 +30,22 @@ function test_basic_error_path
        wait $APP_PID 2> /dev/null
 }
 
+check_skip_kernel_test &&
+{
+       plan_skip_all "Skipping all tests."
+       exit 0
+}
 
-if [ "$(id -u)" == "0" ]; then
-       validate_lttng_modules_present
+validate_lttng_modules_present
 
-       modprobe lttng-test
+modprobe lttng-test
 
-       start_lttng_sessiond_notap
+start_lttng_sessiond_notap
 
-       test_basic_error_path
+test_basic_error_path
 
-       stop_lttng_sessiond_notap
-       rmmod lttng-test
+stop_lttng_sessiond_notap
+rmmod lttng-test
 
-else
-       # Kernel tests are skipped.
-       plan_tests $NUM_TESTS
-       skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS
-fi
 
 rm -f "$TESTAPP_STATE_PATH"
index b8f0c7eb8df2e44a8da45c3906d06e4b7efab093..9a8d323a1371cabe3847047d9d4791489f7cd64b 100755 (executable)
@@ -28,22 +28,21 @@ function test_kernel_instrumentation_notification
        wait $APP_PID 2> /dev/null
 }
 
-if [ "$(id -u)" == "0" ]; then
-       validate_lttng_modules_present
+check_skip_kernel_test &&
+{
+       plan_skip_all "Skipping all tests."
+       exit 0
+}
 
-       modprobe lttng-test
+validate_lttng_modules_present
 
-       start_lttng_sessiond_notap
+modprobe lttng-test
 
-       test_kernel_instrumentation_notification
+start_lttng_sessiond_notap
 
-       stop_lttng_sessiond_notap
-       rmmod lttng-test
+test_kernel_instrumentation_notification
 
-else
-       # Kernel tests are skipped.
-       plan_tests $NUM_TESTS
-       skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS
-fi
+stop_lttng_sessiond_notap
+rmmod lttng-test
 
 rm -f "$TESTAPP_STATE_PATH"
index ba12716fd99f8c057b01293eb2a0dd79382cf96d..c9a40d077a5967844cf4d9374f13c2b502da578b 100755 (executable)
@@ -31,19 +31,18 @@ function test_kernel_syscall_notification
        wait $APP_PID 2> /dev/null
 }
 
-if [ "$(id -u)" == "0" ]; then
-       validate_lttng_modules_present
+check_skip_kernel_test &&
+{
+       plan_skip_all "Skipping all tests."
+       exit 0
+}
 
-       start_lttng_sessiond_notap
+validate_lttng_modules_present
 
-       test_kernel_syscall_notification
+start_lttng_sessiond_notap
 
-       stop_lttng_sessiond_notap
+test_kernel_syscall_notification
 
-else
-       # Kernel tests are skipped.
-       plan_tests $NUM_TESTS
-       skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS
-fi
+stop_lttng_sessiond_notap
 
 rm -f "$TESTAPP_STATE_PATH"
index 065e66add8523224f7ce4cc54166cb60a62b6ce0..38f5a5f41426e6f887ac963939a77f00ffc37321 100755 (executable)
@@ -29,18 +29,18 @@ function test_kernel_userspace_probe_notification
        wait $APP_PID 2> /dev/null
 }
 
-if [ "$(id -u)" == "0" ]; then
-       validate_lttng_modules_present
+check_skip_kernel_test &&
+{
+       plan_skip_all "Skipping all tests."
+       exit 0
+}
+
+validate_lttng_modules_present
 
-       start_lttng_sessiond_notap
+start_lttng_sessiond_notap
 
-       test_kernel_userspace_probe_notification
+test_kernel_userspace_probe_notification
 
-       stop_lttng_sessiond_notap
-else
-       # Kernel tests are skipped.
-       plan_tests $NUM_TESTS
-       skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS
-fi
+stop_lttng_sessiond_notap
 
 rm -f "$TESTAPP_STATE_PATH"
index 85d8638040458e14beb19e82ba76a9a1bdc141d7..a7156c4fea1dd31a95694476d5a86eac67fb046d 100755 (executable)
@@ -411,22 +411,18 @@ function test_on_register_evaluation ()
        rm -rf "$output_dir"
 }
 
-
 TESTS=(
        test_multi_app_ust
        test_on_register_evaluation_ust
 )
 
-if [ "$(id -u)" == "0" ]; then
+check_skip_kernel_test "$NUM_TEST_KERNEL" "Skipping kernel multi-app notification tests." || {
        validate_lttng_modules_present
        TESTS+=(
-       test_multi_app_kernel
-       test_on_register_evaluation_kernel
-)
-else
-        skip 0 "Root access is needed. Skipping all kernel multi-app notification tests." $NUM_TEST_KERNEL
-fi
-
+               test_multi_app_kernel
+               test_on_register_evaluation_kernel
+       )
+}
 
 for fct_test in ${TESTS[@]};
 do
index 1eb960d024b5d782dc16d6fddbdc7f97ad97294d..25ef370fad0641bafee60a64b56fd3f33c627253 100755 (executable)
@@ -394,7 +394,8 @@ function test_ust_notifier_discarded_regardless_trigger_owner
 test_ust_notifier_discarded_count
 test_ust_notifier_discarded_count_max_bucket
 
-if [ "$(id -u)" == "0" ]; then
+check_skip_kernel_test "$KERNEL_NUM_TESTS" "Skipping kernel notification tests." ||
+{
 
        validate_lttng_modules_present
 
@@ -416,9 +417,7 @@ if [ "$(id -u)" == "0" ]; then
        modprobe --remove lttng-test
 
        rm -rf "${sessiond_pipe[@]}" 2> /dev/null
-else
-       # Kernel tests are skipped.
-       skip 0 "Root access is needed. Skipping all kernel notification tests." $KERNEL_NUM_TESTS
-fi
+
+}
 
 rm -rf "$TEST_TMPDIR"
index 7c4191a47909ae38bd16221fcb0341692972de22..1b5ce2a0b2239545fd58b2a367baef9141cf4a43 100755 (executable)
@@ -99,13 +99,7 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
 
index cb0c0ad5ea8e45527346fbc56815160effd8d564..758b95d071efceea6974fa291aacd2fba6c95408 100755 (executable)
@@ -39,13 +39,7 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
        start_lttng_sessiond
index 817019036f27e8f77590e1b7d7a8cfbe024c6a9d..e66a257a962da00ec612d81e143e133e7bfa9944 100755 (executable)
@@ -107,13 +107,7 @@ plan_tests $NUM_TESTS
 print_test_banner "$TEST_DESC"
 bail_out_if_no_babeltrace
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
 
index 2f19e807af92aa0cf1b3e35742865f79fcd8ce83..af7d452b04fbf66651e591963ea97e0623b57127 100755 (executable)
@@ -85,13 +85,7 @@ plan_tests $NUM_TESTS
 print_test_banner "$TEST_DESC"
 bail_out_if_no_babeltrace
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
 
index 870c437b217fc2ed0eb339628fff428e220312fd..302e5b341c0b800059a5c84750ead2de5b962714 100755 (executable)
@@ -221,14 +221,7 @@ print_test_banner "$TEST_DESC"
 
 bail_out_if_no_babeltrace
 
-
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel snapshot tests" $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
 
        validate_lttng_modules_present
index 2abd838e77336485438e541367946af05fb05e4b..e80e78a8cf64650c94f6507c6f7a05be63356bca 100755 (executable)
@@ -145,13 +145,7 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel streaming tests" $NUM_TESTS ||
+check_skip_kernel_test $NUM_TESTS "Skipping all tests." ||
 {
        validate_lttng_modules_present
 
index 50c21df4d14cfcdcc8bb62d130dd3eae1bef5e71..91ab2fe7b25e945d77eb4f6ba725a03eeea55aa4 100755 (executable)
@@ -174,13 +174,7 @@ print_test_banner "$TEST_DESC"
 
 bail_out_if_no_babeltrace
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed to set bandwith limits. Skipping all tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
 
        # Catch sigint and try to cleanup limits
index aef1e11bc9b414fe5f32eeeec80bc7bf82eac116..3c78ac50bf5283fa9d9433fee3039efd895d8826 100755 (executable)
@@ -47,13 +47,7 @@ plan_tests $NUM_TESTS
 
 print_test_banner "$TEST_DESC"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS ||
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." ||
 {
        validate_lttng_modules_present
 
index be42407405df6e3aca655326f58a3bf13548ecd4..2507498bfb452aa301653650152f0adf2119d8a0 100755 (executable)
@@ -468,13 +468,7 @@ test_event_track_untrack ust 0 "${EVENT_NAME}" "--pid --all"       # backward compat
 test_event_tracker ust 1 "${EVENT_NAME}" "--pid --all" # backward compat
 test_event_pid_tracker ust 1 "${EVENT_NAME}"
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel tracker tests." $NUM_KERNEL_TESTS ||
+check_skip_kernel_test "$NUM_KERNEL_TESTS" "Skipping kernel tracker tests." ||
 {
        diag "Test kernel tracker"
 
index 8566b36078ad17fde84e637a10bfa528e24f5816..eeef3e250b86dc62c362da05fa4f7a9cd27232f5 100755 (executable)
@@ -34,12 +34,6 @@ tmp_stdout=$(mktemp -t test_parse_cli_trigger_stdout.XXXXXX)
 tmp_stderr=$(mktemp -t test_parse_cli_trigger_stderr.XXXXXX)
 uprobe_elf_binary="${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary"
 
-if [ "$(id -u)" == "0" ]; then
-       ist_root=1
-else
-       ist_root=0
-fi
-
 function test_success ()
 {
        local test_name="$1"
@@ -223,7 +217,7 @@ test_success "--exclude-name two" "trigger5" \
        --condition event-rule-matches --type=user --name='jean-*' --exclude-name jean-chretien -x jean-charest \
        --action notify
 
-skip $ist_root "non-root user: skipping kprobe tests" 18 || {
+check_skip_kernel_test 18 "Skipping kprobe tests." || {
        i=0
 
        for type in kprobe kernel:kprobe; do
@@ -262,7 +256,7 @@ skip $ist_root "non-root user: skipping kprobe tests" 18 || {
        done
 }
 
-skip $ist_root "non-root user: skipping uprobe tests" 6 || {
+check_skip_kernel_test 6 "Skipping uprobe tests." || {
        test_success "--condition event-rule-matches uprobe" "uprobe-trigger-0" \
                --name="uprobe-trigger-0" \
                --condition event-rule-matches --type=kernel:uprobe --location=${uprobe_elf_binary}:test_function --event-name=ma-probe \
@@ -274,7 +268,7 @@ skip $ist_root "non-root user: skipping uprobe tests" 6 || {
                --action notify
 }
 
-skip $ist_root "non-root user: skipping syscall tests" 30 || {
+check_skip_kernel_test 30 "Skipping syscall tests." || {
        test_success "--condition event-rule-matches one syscall" "syscall-trigger-0" \
                --name="syscall-trigger-0" \
                --condition event-rule-matches --type=syscall --name=open \
index 836983329f5d3070ff31ff2b07c6d6d33d11f77c..b99288471d92b8ee5b446ea63143887ae2c61b75 100755 (executable)
@@ -36,22 +36,12 @@ uprobe_sdt_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-sdt-binar
 register_some_triggers_bin=$(realpath "${CURDIR}/utils/register-some-triggers")
 
 uid=$(id --user)
-gid=$(id --group)
 
-if [ "$uid" == "0" ]; then
-       ist_root=1
-       ls "$uprobe_sdt_binary" >/dev/null 2>&1
-       if test $? == 0; then
-               hast_sdt_binary=1
-       else
-               hast_sdt_binary=0
-       fi
-else
-       ist_root=0
-       hast_sdt_binary=0
+sdt_binary_present=0
+if [ -f "$uprobe_sdt_binary" ]; then
+       sdt_binary_present=1
 fi
 
-
 test_top_level_options ()
 {
        diag "Listing top level options"
@@ -2695,10 +2685,12 @@ start_lttng_sessiond_notap
 
 test_top_level_options
 test_event_rule_matches_tracepoint
-skip $ist_root "non-root user: skipping kprobe tests" 13 || test_event_rule_matches_probe
-skip $ist_root "non-root user: skipping uprobe tests" 9 || test_event_rule_matches_userspace_probe_elf
-skip $(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 9 || test_event_rule_matches_userspace_probe_sdt
-skip $ist_root "non-root user: skipping syscall tests" 17 || test_event_rule_matches_syscall
+check_skip_kernel_test 48 "Skipping kprobe, uprobe, SDT and syscall tests." || {
+       test_event_rule_matches_probe
+       test_event_rule_matches_userspace_probe_elf
+       skip $sdt_binary_present "No SDT binary. Skipping userspace probe SDT tests" 9 || test_event_rule_matches_userspace_probe_sdt
+       test_event_rule_matches_syscall
+}
 test_session_consumed_size_condition
 test_buffer_usage_conditions
 test_session_rotation_conditions
index 36e669b32f3c471be54347c012d836ad02f68c4d..8777424196e52169f02679e929d88bcbd2104e2e 100755 (executable)
@@ -126,13 +126,7 @@ test_event_wildcard ust 1 'tp*tptest'
 test_event_wildcard ust 1 'tp**tptest'
 test_event_wildcard ust 1 'tp*test'
 
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-else
-       isroot=0
-fi
-
-skip $isroot "Root access is needed. Skipping all kernel wildcard tests." $NUM_KERNEL_TESTS ||
+check_skip_kernel_test "$NUM_KERNEL_TESTS" "Skipping kernel wildcard tests." ||
 {
        diag "Test kernel wildcards"
 
index c196a059ec51830bf1f718540327a16c4ae458a6..db44120e788fd36c122853544b7e335484741ba4 100755 (executable)
@@ -145,9 +145,9 @@ function test_relayd_debug_permission()
        diag "Test lttng-relayd change working directory on non writable directory"
 
        if [ "$(id -u)" == "0" ]; then
-           is_user=0
+               is_user=0
        else
-           is_user=1
+               is_user=1
        fi
 
        skip $is_user "Skipping permission debug output test; operation can't fail as root" 6 ||
index fd16216309bf25a19474f4fe016118f5e3e6a925..ac14748ee1cb93de842cbd55aaac98542812db61 100755 (executable)
@@ -103,12 +103,7 @@ print_test_banner "$TEST_DESC"
 
 bail_out_if_no_babeltrace
 
-isroot=0
-if [ "$(id -u)" == "0" ]; then
-       isroot=1
-fi
-
-skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0
+check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." && exit 0
 
 system_has_ns=0
 if [ -d "/proc/$$/ns" ]; then
index 9b2de4de28817651272c047d59087fa31ff61b09..127cdb0b7f25304257567a7c26995ba127fbf54c 100755 (executable)
@@ -121,17 +121,11 @@ print_test_banner "$TEST_DESC"
 
 bail_out_if_no_babeltrace
 
-if [ "$(id -u)" == "0" ]; then
-        isroot=1
-else
-        isroot=0
-fi
-
 start_lttng_sessiond
 
 test_parsing_raw
 
-skip $isroot "Root access is needed. Skipping UST perf tests." 8 ||
+check_skip_kernel_test 8 "Skipping UST perf tests." ||
 {
        test_event_basic
 }
index c1d702e823c33120f96b256df93bd35044a73d8e..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 ()
This page took 0.047276 seconds and 4 git commands to generate.