From 3a1744008331a0604479d3d7461f77056fad3a64 Mon Sep 17 00:00:00 2001 From: Xiangyu Chen Date: Mon, 12 Feb 2024 09:23:54 -0500 Subject: [PATCH] tests: add check_skip_kernel_test to check root user and lttng kernel modules MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 Signed-off-by: Michael Jeanson Signed-off-by: Jérémie Galarneau --- tests/destructive/metadata-regeneration | 8 +---- tests/perf/test_perf_raw.in | 8 +---- tests/regression/kernel/test_all_events | 8 +---- tests/regression/kernel/test_callstack | 8 +---- tests/regression/kernel/test_channel | 8 +---- tests/regression/kernel/test_clock_override | 8 +---- tests/regression/kernel/test_event_basic | 8 +---- tests/regression/kernel/test_kernel_function | 8 +---- tests/regression/kernel/test_lttng_logger | 8 +---- tests/regression/kernel/test_ns_contexts | 8 +---- .../regression/kernel/test_ns_contexts_change | 9 +---- .../kernel/test_rotation_destroy_flush | 8 +---- .../regression/kernel/test_select_poll_epoll | 8 +---- tests/regression/kernel/test_syscall | 8 +---- tests/regression/kernel/test_userspace_probe | 8 +---- tests/regression/tools/clear/test_kernel | 8 +---- .../tools/filtering/test_invalid_filter | 8 +---- .../tools/filtering/test_unsupported_op | 8 +---- .../tools/filtering/test_valid_filter | 8 +---- tests/regression/tools/health/test_health.sh | 10 ++---- tests/regression/tools/health/test_thread_ok | 9 +---- tests/regression/tools/live/test_kernel | 10 +++--- tests/regression/tools/live/test_lttng_kernel | 8 +---- tests/regression/tools/metadata/test_kernel | 8 +---- .../test_notification_kernel_buffer_usage | 36 +++++++++---------- .../test_notification_kernel_capture | 23 ++++++------ .../test_notification_kernel_error | 23 ++++++------ .../test_notification_kernel_instrumentation | 23 ++++++------ .../test_notification_kernel_syscall | 19 +++++----- .../test_notification_kernel_userspace_probe | 20 +++++------ .../notification/test_notification_multi_app | 14 +++----- ...test_notification_notifier_discarded_count | 9 +++-- .../tools/regen-metadata/test_kernel | 8 +---- .../tools/regen-statedump/test_kernel | 8 +---- tests/regression/tools/rotation/test_kernel | 8 +---- .../regression/tools/rotation/test_ust_kernel | 8 +---- tests/regression/tools/snapshots/test_kernel | 9 +---- .../tools/snapshots/test_kernel_streaming | 8 +---- .../streaming/test_high_throughput_limits | 8 +---- tests/regression/tools/streaming/test_kernel | 8 +---- .../tools/tracker/test_event_tracker | 8 +---- .../tools/trigger/test_add_trigger_cli | 12 ++----- .../tools/trigger/test_list_triggers_cli | 26 +++++--------- .../tools/wildcard/test_event_wildcard | 8 +---- .../test_relayd_working_directory | 4 +-- .../ust/namespaces/test_ns_contexts_change | 7 +--- tests/regression/ust/test_event_perf | 8 +---- tests/utils/utils.sh | 35 ++++++++++++++++++ 48 files changed, 167 insertions(+), 371 deletions(-) diff --git a/tests/destructive/metadata-regeneration b/tests/destructive/metadata-regeneration index 048c601b6..dcae6bce0 100755 --- a/tests/destructive/metadata-regeneration +++ b/tests/destructive/metadata-regeneration @@ -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" diff --git a/tests/perf/test_perf_raw.in b/tests/perf/test_perf_raw.in index 0a451ce63..00cdebc55 100644 --- a/tests/perf/test_perf_raw.in +++ b/tests/perf/test_perf_raw.in @@ -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 diff --git a/tests/regression/kernel/test_all_events b/tests/regression/kernel/test_all_events index 2fb2f611d..dd6dab5e5 100755 --- a/tests/regression/kernel/test_all_events +++ b/tests/regression/kernel/test_all_events @@ -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 diff --git a/tests/regression/kernel/test_callstack b/tests/regression/kernel/test_callstack index cf39089af..960bb8a44 100755 --- a/tests/regression/kernel/test_callstack +++ b/tests/regression/kernel/test_callstack @@ -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 diff --git a/tests/regression/kernel/test_channel b/tests/regression/kernel/test_channel index 5525564d2..6c7d2db07 100755 --- a/tests/regression/kernel/test_channel +++ b/tests/regression/kernel/test_channel @@ -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 diff --git a/tests/regression/kernel/test_clock_override b/tests/regression/kernel/test_clock_override index 524c3c3bb..c3688d359 100755 --- a/tests/regression/kernel/test_clock_override +++ b/tests/regression/kernel/test_clock_override @@ -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 diff --git a/tests/regression/kernel/test_event_basic b/tests/regression/kernel/test_event_basic index 9f22d7db8..e57cd6d26 100755 --- a/tests/regression/kernel/test_event_basic +++ b/tests/regression/kernel/test_event_basic @@ -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 diff --git a/tests/regression/kernel/test_kernel_function b/tests/regression/kernel/test_kernel_function index 131c1c70b..3c941c72c 100755 --- a/tests/regression/kernel/test_kernel_function +++ b/tests/regression/kernel/test_kernel_function @@ -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 diff --git a/tests/regression/kernel/test_lttng_logger b/tests/regression/kernel/test_lttng_logger index 849428807..c6ed4f950 100755 --- a/tests/regression/kernel/test_lttng_logger +++ b/tests/regression/kernel/test_lttng_logger @@ -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 diff --git a/tests/regression/kernel/test_ns_contexts b/tests/regression/kernel/test_ns_contexts index 7d447bc40..1c71ea503 100755 --- a/tests/regression/kernel/test_ns_contexts +++ b/tests/regression/kernel/test_ns_contexts @@ -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 diff --git a/tests/regression/kernel/test_ns_contexts_change b/tests/regression/kernel/test_ns_contexts_change index 715c67cc8..10f97f8cb 100755 --- a/tests/regression/kernel/test_ns_contexts_change +++ b/tests/regression/kernel/test_ns_contexts_change @@ -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 diff --git a/tests/regression/kernel/test_rotation_destroy_flush b/tests/regression/kernel/test_rotation_destroy_flush index 6e568afda..fc2274026 100755 --- a/tests/regression/kernel/test_rotation_destroy_flush +++ b/tests/regression/kernel/test_rotation_destroy_flush @@ -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 diff --git a/tests/regression/kernel/test_select_poll_epoll b/tests/regression/kernel/test_select_poll_epoll index cdde1ea4f..09c911df9 100755 --- a/tests/regression/kernel/test_select_poll_epoll +++ b/tests/regression/kernel/test_select_poll_epoll @@ -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 diff --git a/tests/regression/kernel/test_syscall b/tests/regression/kernel/test_syscall index f9b490858..92d79a7bc 100755 --- a/tests/regression/kernel/test_syscall +++ b/tests/regression/kernel/test_syscall @@ -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 diff --git a/tests/regression/kernel/test_userspace_probe b/tests/regression/kernel/test_userspace_probe index bfa260e47..38987f7b1 100755 --- a/tests/regression/kernel/test_userspace_probe +++ b/tests/regression/kernel/test_userspace_probe @@ -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 diff --git a/tests/regression/tools/clear/test_kernel b/tests/regression/tools/clear/test_kernel index ce76f85d2..2e383b8aa 100755 --- a/tests/regression/tools/clear/test_kernel +++ b/tests/regression/tools/clear/test_kernel @@ -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 diff --git a/tests/regression/tools/filtering/test_invalid_filter b/tests/regression/tools/filtering/test_invalid_filter index 8dfbe9eb5..2dd57b0bb 100755 --- a/tests/regression/tools/filtering/test_invalid_filter +++ b/tests/regression/tools/filtering/test_invalid_filter @@ -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 diff --git a/tests/regression/tools/filtering/test_unsupported_op b/tests/regression/tools/filtering/test_unsupported_op index dc76f99a6..672a980de 100755 --- a/tests/regression/tools/filtering/test_unsupported_op +++ b/tests/regression/tools/filtering/test_unsupported_op @@ -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" diff --git a/tests/regression/tools/filtering/test_valid_filter b/tests/regression/tools/filtering/test_valid_filter index 0c7ac0bdd..1d7b0db47 100755 --- a/tests/regression/tools/filtering/test_valid_filter +++ b/tests/regression/tools/filtering/test_valid_filter @@ -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" diff --git a/tests/regression/tools/health/test_health.sh b/tests/regression/tools/health/test_health.sh index b4b416f92..23cb05075 100644 --- a/tests/regression/tools/health/test_health.sh +++ b/tests/regression/tools/health/test_health.sh @@ -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 diff --git a/tests/regression/tools/health/test_thread_ok b/tests/regression/tools/health/test_thread_ok index 663b7e4cb..5441b2f06 100755 --- a/tests/regression/tools/health/test_thread_ok +++ b/tests/regression/tools/health/test_thread_ok @@ -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} diff --git a/tests/regression/tools/live/test_kernel b/tests/regression/tools/live/test_kernel index 1be703aac..df30fcf56 100755 --- a/tests/regression/tools/live/test_kernel +++ b/tests/regression/tools/live/test_kernel @@ -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 diff --git a/tests/regression/tools/live/test_lttng_kernel b/tests/regression/tools/live/test_lttng_kernel index ae8c57e6b..94f2c0087 100755 --- a/tests/regression/tools/live/test_lttng_kernel +++ b/tests/regression/tools/live/test_lttng_kernel @@ -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 diff --git a/tests/regression/tools/metadata/test_kernel b/tests/regression/tools/metadata/test_kernel index 9e1e81232..d38af841d 100755 --- a/tests/regression/tools/metadata/test_kernel +++ b/tests/regression/tools/metadata/test_kernel @@ -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 diff --git a/tests/regression/tools/notification/test_notification_kernel_buffer_usage b/tests/regression/tools/notification/test_notification_kernel_buffer_usage index 5a87583dc..a89355a44 100755 --- a/tests/regression/tools/notification/test_notification_kernel_buffer_usage +++ b/tests/regression/tools/notification/test_notification_kernel_buffer_usage @@ -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" diff --git a/tests/regression/tools/notification/test_notification_kernel_capture b/tests/regression/tools/notification/test_notification_kernel_capture index 88a3691eb..b65310d88 100755 --- a/tests/regression/tools/notification/test_notification_kernel_capture +++ b/tests/regression/tools/notification/test_notification_kernel_capture @@ -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" diff --git a/tests/regression/tools/notification/test_notification_kernel_error b/tests/regression/tools/notification/test_notification_kernel_error index 891146747..5f53f5b1b 100755 --- a/tests/regression/tools/notification/test_notification_kernel_error +++ b/tests/regression/tools/notification/test_notification_kernel_error @@ -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" diff --git a/tests/regression/tools/notification/test_notification_kernel_instrumentation b/tests/regression/tools/notification/test_notification_kernel_instrumentation index b8f0c7eb8..9a8d323a1 100755 --- a/tests/regression/tools/notification/test_notification_kernel_instrumentation +++ b/tests/regression/tools/notification/test_notification_kernel_instrumentation @@ -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" diff --git a/tests/regression/tools/notification/test_notification_kernel_syscall b/tests/regression/tools/notification/test_notification_kernel_syscall index ba12716fd..c9a40d077 100755 --- a/tests/regression/tools/notification/test_notification_kernel_syscall +++ b/tests/regression/tools/notification/test_notification_kernel_syscall @@ -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" diff --git a/tests/regression/tools/notification/test_notification_kernel_userspace_probe b/tests/regression/tools/notification/test_notification_kernel_userspace_probe index 065e66add..38f5a5f41 100755 --- a/tests/regression/tools/notification/test_notification_kernel_userspace_probe +++ b/tests/regression/tools/notification/test_notification_kernel_userspace_probe @@ -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" diff --git a/tests/regression/tools/notification/test_notification_multi_app b/tests/regression/tools/notification/test_notification_multi_app index 85d863804..a7156c4fe 100755 --- a/tests/regression/tools/notification/test_notification_multi_app +++ b/tests/regression/tools/notification/test_notification_multi_app @@ -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 diff --git a/tests/regression/tools/notification/test_notification_notifier_discarded_count b/tests/regression/tools/notification/test_notification_notifier_discarded_count index 1eb960d02..25ef370fa 100755 --- a/tests/regression/tools/notification/test_notification_notifier_discarded_count +++ b/tests/regression/tools/notification/test_notification_notifier_discarded_count @@ -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" diff --git a/tests/regression/tools/regen-metadata/test_kernel b/tests/regression/tools/regen-metadata/test_kernel index 7c4191a47..1b5ce2a0b 100755 --- a/tests/regression/tools/regen-metadata/test_kernel +++ b/tests/regression/tools/regen-metadata/test_kernel @@ -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 diff --git a/tests/regression/tools/regen-statedump/test_kernel b/tests/regression/tools/regen-statedump/test_kernel index cb0c0ad5e..758b95d07 100755 --- a/tests/regression/tools/regen-statedump/test_kernel +++ b/tests/regression/tools/regen-statedump/test_kernel @@ -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 diff --git a/tests/regression/tools/rotation/test_kernel b/tests/regression/tools/rotation/test_kernel index 817019036..e66a257a9 100755 --- a/tests/regression/tools/rotation/test_kernel +++ b/tests/regression/tools/rotation/test_kernel @@ -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 diff --git a/tests/regression/tools/rotation/test_ust_kernel b/tests/regression/tools/rotation/test_ust_kernel index 2f19e807a..af7d452b0 100755 --- a/tests/regression/tools/rotation/test_ust_kernel +++ b/tests/regression/tools/rotation/test_ust_kernel @@ -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 diff --git a/tests/regression/tools/snapshots/test_kernel b/tests/regression/tools/snapshots/test_kernel index 870c437b2..302e5b341 100755 --- a/tests/regression/tools/snapshots/test_kernel +++ b/tests/regression/tools/snapshots/test_kernel @@ -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 diff --git a/tests/regression/tools/snapshots/test_kernel_streaming b/tests/regression/tools/snapshots/test_kernel_streaming index 2abd838e7..e80e78a8c 100755 --- a/tests/regression/tools/snapshots/test_kernel_streaming +++ b/tests/regression/tools/snapshots/test_kernel_streaming @@ -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 diff --git a/tests/regression/tools/streaming/test_high_throughput_limits b/tests/regression/tools/streaming/test_high_throughput_limits index 50c21df4d..91ab2fe7b 100755 --- a/tests/regression/tools/streaming/test_high_throughput_limits +++ b/tests/regression/tools/streaming/test_high_throughput_limits @@ -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 diff --git a/tests/regression/tools/streaming/test_kernel b/tests/regression/tools/streaming/test_kernel index aef1e11bc..3c78ac50b 100755 --- a/tests/regression/tools/streaming/test_kernel +++ b/tests/regression/tools/streaming/test_kernel @@ -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 diff --git a/tests/regression/tools/tracker/test_event_tracker b/tests/regression/tools/tracker/test_event_tracker index be4240740..2507498bf 100755 --- a/tests/regression/tools/tracker/test_event_tracker +++ b/tests/regression/tools/tracker/test_event_tracker @@ -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" diff --git a/tests/regression/tools/trigger/test_add_trigger_cli b/tests/regression/tools/trigger/test_add_trigger_cli index 8566b3607..eeef3e250 100755 --- a/tests/regression/tools/trigger/test_add_trigger_cli +++ b/tests/regression/tools/trigger/test_add_trigger_cli @@ -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 \ diff --git a/tests/regression/tools/trigger/test_list_triggers_cli b/tests/regression/tools/trigger/test_list_triggers_cli index 836983329..b99288471 100755 --- a/tests/regression/tools/trigger/test_list_triggers_cli +++ b/tests/regression/tools/trigger/test_list_triggers_cli @@ -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 diff --git a/tests/regression/tools/wildcard/test_event_wildcard b/tests/regression/tools/wildcard/test_event_wildcard index 36e669b32..877742419 100755 --- a/tests/regression/tools/wildcard/test_event_wildcard +++ b/tests/regression/tools/wildcard/test_event_wildcard @@ -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" diff --git a/tests/regression/tools/working-directory/test_relayd_working_directory b/tests/regression/tools/working-directory/test_relayd_working_directory index c196a059e..db44120e7 100755 --- a/tests/regression/tools/working-directory/test_relayd_working_directory +++ b/tests/regression/tools/working-directory/test_relayd_working_directory @@ -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 || diff --git a/tests/regression/ust/namespaces/test_ns_contexts_change b/tests/regression/ust/namespaces/test_ns_contexts_change index fd1621630..ac14748ee 100755 --- a/tests/regression/ust/namespaces/test_ns_contexts_change +++ b/tests/regression/ust/namespaces/test_ns_contexts_change @@ -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 diff --git a/tests/regression/ust/test_event_perf b/tests/regression/ust/test_event_perf index 9b2de4de2..127cdb0b7 100755 --- a/tests/regression/ust/test_event_perf +++ b/tests/regression/ust/test_event_perf @@ -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 } 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 () -- 2.34.1