Patrick Williams | 03514f1 | 2024-04-05 07:04:11 -0500 | [diff] [blame^] | 1 | From cf558f802b259a33605fe0ede4d74ae2ff6be699 Mon Sep 17 00:00:00 2001 |
| 2 | From: Xiangyu Chen <xiangyu.chen@windriver.com> |
| 3 | Date: Mon, 12 Feb 2024 09:23:54 -0500 |
| 4 | Subject: [PATCH] tests: add check_skip_kernel_test to check root user and |
| 5 | lttng kernel modules |
| 6 | MIME-Version: 1.0 |
| 7 | Content-Type: text/plain; charset=UTF-8 |
| 8 | Content-Transfer-Encoding: 8bit |
| 9 | |
| 10 | The current tests will run both userspace and kernel testing. Some of |
| 11 | use cases only use lttng for one kind of tracing on an embedded |
| 12 | device (e.g. userspace), so in this scenario, the kernel modules might |
| 13 | not install to target rootfs, the test cases would be fail and exit. |
| 14 | |
| 15 | Add LTTNG_TOOLS_DISABLE_KERNEL_TESTS to skip the lttng kernel features |
| 16 | test, this flag can be set via "make": |
| 17 | |
| 18 | make check LTTNG_TOOLS_DISABLE_KERNEL_TESTS=1 |
| 19 | |
| 20 | When this flag was set, all kernel related testcases would be marked as |
| 21 | SKIP in result. |
| 22 | |
| 23 | Since the the LTTNG_TOOLS_DISABLE_KERNEL_TESTS was checked in function |
| 24 | check_skip_kernel_test, lots of testcases also need to check root |
| 25 | permission, so merging the root permission checking into |
| 26 | check_skip_kernel_test. |
| 27 | |
| 28 | Upstream-Status: Backport from |
| 29 | [https://git.lttng.org/?p=lttng-tools.git;a=commit;h=3a1744008331a0604479d3d7461f77056fad3a64] |
| 30 | |
| 31 | Change-Id: I49a1f642a9869c21a69e0186c296fd917bd7b525 |
| 32 | Signed-off-by: Xiangyu Chen <xiangyu.chen@windriver.com> |
| 33 | Signed-off-by: Michael Jeanson <mjeanson@efficios.com> |
| 34 | Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com> |
| 35 | --- |
| 36 | tests/destructive/metadata-regeneration | 8 +---- |
| 37 | tests/perf/test_perf_raw.in | 8 +---- |
| 38 | tests/regression/kernel/test_all_events | 8 +---- |
| 39 | tests/regression/kernel/test_callstack | 8 +---- |
| 40 | tests/regression/kernel/test_channel | 8 +---- |
| 41 | tests/regression/kernel/test_clock_override | 8 +---- |
| 42 | tests/regression/kernel/test_event_basic | 8 +---- |
| 43 | tests/regression/kernel/test_kernel_function | 8 +---- |
| 44 | tests/regression/kernel/test_lttng_logger | 8 +---- |
| 45 | tests/regression/kernel/test_ns_contexts | 8 +---- |
| 46 | .../regression/kernel/test_ns_contexts_change | 9 +---- |
| 47 | .../kernel/test_rotation_destroy_flush | 8 +---- |
| 48 | .../regression/kernel/test_select_poll_epoll | 8 +---- |
| 49 | tests/regression/kernel/test_syscall | 8 +---- |
| 50 | tests/regression/kernel/test_userspace_probe | 8 +---- |
| 51 | tests/regression/tools/clear/test_kernel | 8 +---- |
| 52 | .../tools/filtering/test_invalid_filter | 8 +---- |
| 53 | .../tools/filtering/test_unsupported_op | 8 +---- |
| 54 | .../tools/filtering/test_valid_filter | 8 +---- |
| 55 | tests/regression/tools/health/test_health.sh | 10 ++---- |
| 56 | tests/regression/tools/health/test_thread_ok | 9 +---- |
| 57 | tests/regression/tools/live/test_kernel | 10 +++--- |
| 58 | tests/regression/tools/live/test_lttng_kernel | 8 +---- |
| 59 | tests/regression/tools/metadata/test_kernel | 8 +---- |
| 60 | .../test_notification_kernel_buffer_usage | 36 +++++++++---------- |
| 61 | .../test_notification_kernel_capture | 23 ++++++------ |
| 62 | .../test_notification_kernel_error | 23 ++++++------ |
| 63 | .../test_notification_kernel_instrumentation | 23 ++++++------ |
| 64 | .../test_notification_kernel_syscall | 19 +++++----- |
| 65 | .../test_notification_kernel_userspace_probe | 20 +++++------ |
| 66 | .../notification/test_notification_multi_app | 14 +++----- |
| 67 | ...test_notification_notifier_discarded_count | 9 +++-- |
| 68 | .../tools/regen-metadata/test_kernel | 8 +---- |
| 69 | .../tools/regen-statedump/test_kernel | 8 +---- |
| 70 | tests/regression/tools/rotation/test_kernel | 8 +---- |
| 71 | tests/regression/tools/snapshots/test_kernel | 8 +---- |
| 72 | .../tools/snapshots/test_kernel_streaming | 8 +---- |
| 73 | .../streaming/test_high_throughput_limits | 8 +---- |
| 74 | tests/regression/tools/streaming/test_kernel | 8 +---- |
| 75 | .../tools/tracker/test_event_tracker | 8 +---- |
| 76 | .../tools/trigger/test_add_trigger_cli | 12 ++----- |
| 77 | .../tools/trigger/test_list_triggers_cli | 26 +++++--------- |
| 78 | .../tools/wildcard/test_event_wildcard | 8 +---- |
| 79 | .../test_relayd_working_directory | 4 +-- |
| 80 | .../ust/namespaces/test_ns_contexts_change | 7 +--- |
| 81 | tests/regression/ust/test_event_perf | 8 +---- |
| 82 | tests/utils/utils.sh | 35 ++++++++++++++++++ |
| 83 | 47 files changed, 166 insertions(+), 363 deletions(-) |
| 84 | |
| 85 | diff --git a/tests/destructive/metadata-regeneration b/tests/destructive/metadata-regeneration |
| 86 | index b81e7af32..36b130d17 100755 |
| 87 | --- a/tests/destructive/metadata-regeneration |
| 88 | +++ b/tests/destructive/metadata-regeneration |
| 89 | @@ -185,19 +185,13 @@ function test_ust_streaming () |
| 90 | rm -f ${file_sync_before_last} |
| 91 | } |
| 92 | |
| 93 | -if [ "$(id -u)" == "0" ]; then |
| 94 | - isroot=1 |
| 95 | -else |
| 96 | - isroot=0 |
| 97 | -fi |
| 98 | - |
| 99 | if ! destructive_tests_enabled ; then |
| 100 | echo 'You need to set the LTTNG_ENABLE_DESTRUCTIVE_TESTS to "will-break-my-system" as argument to run this test' |
| 101 | echo 'Moreover, please make sure that ntp is not running while executing this test' |
| 102 | exit 0 |
| 103 | fi |
| 104 | |
| 105 | -skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 106 | +check_skip_kernel_test $NUM_TESTS "Skipping all tests." || |
| 107 | { |
| 108 | start_lttng_relayd "-o $TRACE_PATH" |
| 109 | start_lttng_sessiond |
| 110 | diff --git a/tests/perf/test_perf_raw.in b/tests/perf/test_perf_raw.in |
| 111 | index f293ccd71..d35529a87 100644 |
| 112 | --- a/tests/perf/test_perf_raw.in |
| 113 | +++ b/tests/perf/test_perf_raw.in |
| 114 | @@ -137,12 +137,6 @@ function test_kernel_raw() |
| 115 | rm -rf $TRACE_PATH |
| 116 | } |
| 117 | |
| 118 | -if [ "$(id -u)" == "0" ]; then |
| 119 | - isroot=1 |
| 120 | -else |
| 121 | - isroot=0 |
| 122 | -fi |
| 123 | - |
| 124 | # MUST set TESTDIR before calling those functions |
| 125 | plan_tests $NUM_TESTS |
| 126 | |
| 127 | @@ -154,7 +148,7 @@ have_libpfm |
| 128 | |
| 129 | test_ust_raw |
| 130 | |
| 131 | -skip $isroot "Root access is needed for kernel testing, skipping." 9 || |
| 132 | +check_skip_kernel_test 9 || |
| 133 | { |
| 134 | modprobe lttng-test |
| 135 | test_kernel_raw |
| 136 | diff --git a/tests/regression/kernel/test_all_events b/tests/regression/kernel/test_all_events |
| 137 | index 2e20888df..044f9b65f 100755 |
| 138 | --- a/tests/regression/kernel/test_all_events |
| 139 | +++ b/tests/regression/kernel/test_all_events |
| 140 | @@ -43,13 +43,7 @@ plan_tests $NUM_TESTS |
| 141 | |
| 142 | print_test_banner "$TEST_DESC" |
| 143 | |
| 144 | -if [ "$(id -u)" == "0" ]; then |
| 145 | - isroot=1 |
| 146 | -else |
| 147 | - isroot=0 |
| 148 | -fi |
| 149 | - |
| 150 | -skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 151 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 152 | { |
| 153 | validate_lttng_modules_present |
| 154 | start_lttng_sessiond |
| 155 | diff --git a/tests/regression/kernel/test_callstack b/tests/regression/kernel/test_callstack |
| 156 | index a4477fd7c..d8d6b5e0f 100755 |
| 157 | --- a/tests/regression/kernel/test_callstack |
| 158 | +++ b/tests/regression/kernel/test_callstack |
| 159 | @@ -134,13 +134,7 @@ plan_tests $NUM_TESTS |
| 160 | |
| 161 | print_test_banner "$TEST_DESC" |
| 162 | |
| 163 | -if [ "$(id -u)" == "0" ]; then |
| 164 | - isroot=1 |
| 165 | -else |
| 166 | - isroot=0 |
| 167 | -fi |
| 168 | - |
| 169 | -skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" || |
| 170 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 171 | { |
| 172 | validate_lttng_modules_present |
| 173 | start_lttng_sessiond |
| 174 | diff --git a/tests/regression/kernel/test_channel b/tests/regression/kernel/test_channel |
| 175 | index 9cc74c4e8..4c377bd2a 100755 |
| 176 | --- a/tests/regression/kernel/test_channel |
| 177 | +++ b/tests/regression/kernel/test_channel |
| 178 | @@ -47,13 +47,7 @@ function test_channel_buffer_too_large() |
| 179 | plan_tests $NUM_TESTS |
| 180 | print_test_banner "$TEST_DESC" |
| 181 | |
| 182 | -if [ "$(id -u)" == "0" ]; then |
| 183 | - isroot=1 |
| 184 | -else |
| 185 | - isroot=0 |
| 186 | -fi |
| 187 | - |
| 188 | -skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 189 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 190 | { |
| 191 | start_lttng_sessiond |
| 192 | |
| 193 | diff --git a/tests/regression/kernel/test_clock_override b/tests/regression/kernel/test_clock_override |
| 194 | index 72892898b..48a3f926a 100755 |
| 195 | --- a/tests/regression/kernel/test_clock_override |
| 196 | +++ b/tests/regression/kernel/test_clock_override |
| 197 | @@ -172,13 +172,7 @@ TESTS=( |
| 198 | TEST_COUNT=${#TESTS[@]} |
| 199 | i=0 |
| 200 | |
| 201 | -if [ "$(id -u)" == "0" ]; then |
| 202 | - isroot=1 |
| 203 | -else |
| 204 | - isroot=0 |
| 205 | -fi |
| 206 | - |
| 207 | -skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 208 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 209 | { |
| 210 | validate_lttng_modules_present |
| 211 | trap signal_cleanup SIGTERM SIGINT |
| 212 | diff --git a/tests/regression/kernel/test_event_basic b/tests/regression/kernel/test_event_basic |
| 213 | index ac9ec0549..387e2f733 100755 |
| 214 | --- a/tests/regression/kernel/test_event_basic |
| 215 | +++ b/tests/regression/kernel/test_event_basic |
| 216 | @@ -73,13 +73,7 @@ plan_tests $NUM_TESTS |
| 217 | |
| 218 | print_test_banner "$TEST_DESC" |
| 219 | |
| 220 | -if [ "$(id -u)" == "0" ]; then |
| 221 | - isroot=1 |
| 222 | -else |
| 223 | - isroot=0 |
| 224 | -fi |
| 225 | - |
| 226 | -skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 227 | +check_skip_kernel_test $NUM_TESTS "Skipping all tests." || |
| 228 | { |
| 229 | validate_lttng_modules_present |
| 230 | start_lttng_sessiond |
| 231 | diff --git a/tests/regression/kernel/test_kernel_function b/tests/regression/kernel/test_kernel_function |
| 232 | index b1d5491fc..ea16cdeef 100755 |
| 233 | --- a/tests/regression/kernel/test_kernel_function |
| 234 | +++ b/tests/regression/kernel/test_kernel_function |
| 235 | @@ -43,13 +43,7 @@ plan_tests $NUM_TESTS |
| 236 | |
| 237 | print_test_banner "$TEST_DESC" |
| 238 | |
| 239 | -if [ "$(id -u)" == "0" ]; then |
| 240 | - isroot=1 |
| 241 | -else |
| 242 | - isroot=0 |
| 243 | -fi |
| 244 | - |
| 245 | -skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 246 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 247 | { |
| 248 | start_lttng_sessiond_notap |
| 249 | validate_lttng_modules_present |
| 250 | diff --git a/tests/regression/kernel/test_lttng_logger b/tests/regression/kernel/test_lttng_logger |
| 251 | index b8f7ded82..00eaae823 100755 |
| 252 | --- a/tests/regression/kernel/test_lttng_logger |
| 253 | +++ b/tests/regression/kernel/test_lttng_logger |
| 254 | @@ -110,13 +110,7 @@ plan_tests $NUM_TESTS |
| 255 | |
| 256 | print_test_banner "$TEST_DESC" |
| 257 | |
| 258 | -if [ "$(id -u)" == "0" ]; then |
| 259 | - isroot=1 |
| 260 | -else |
| 261 | - isroot=0 |
| 262 | -fi |
| 263 | - |
| 264 | -skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 265 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 266 | { |
| 267 | validate_lttng_modules_present |
| 268 | start_lttng_sessiond |
| 269 | diff --git a/tests/regression/kernel/test_ns_contexts b/tests/regression/kernel/test_ns_contexts |
| 270 | index 0c8718d78..59e2568f6 100755 |
| 271 | --- a/tests/regression/kernel/test_ns_contexts |
| 272 | +++ b/tests/regression/kernel/test_ns_contexts |
| 273 | @@ -108,13 +108,7 @@ plan_tests $NUM_TESTS |
| 274 | print_test_banner "$TEST_DESC" |
| 275 | |
| 276 | |
| 277 | -isroot=0 |
| 278 | -if [ "$(id -u)" == "0" ]; then |
| 279 | - isroot=1 |
| 280 | -fi |
| 281 | - |
| 282 | -skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0 |
| 283 | - |
| 284 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." && exit 0 |
| 285 | |
| 286 | system_has_ns=0 |
| 287 | if [ -d "/proc/$$/ns" ]; then |
| 288 | diff --git a/tests/regression/kernel/test_ns_contexts_change b/tests/regression/kernel/test_ns_contexts_change |
| 289 | index 42a61276b..3f5e4eeab 100755 |
| 290 | --- a/tests/regression/kernel/test_ns_contexts_change |
| 291 | +++ b/tests/regression/kernel/test_ns_contexts_change |
| 292 | @@ -162,14 +162,7 @@ plan_tests $NUM_TESTS |
| 293 | |
| 294 | print_test_banner "$TEST_DESC" |
| 295 | |
| 296 | - |
| 297 | -isroot=0 |
| 298 | -if [ "$(id -u)" == "0" ]; then |
| 299 | - isroot=1 |
| 300 | -fi |
| 301 | - |
| 302 | -skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0 |
| 303 | - |
| 304 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." && exit 0 |
| 305 | |
| 306 | system_has_ns=0 |
| 307 | if [ -d "/proc/$$/ns" ]; then |
| 308 | diff --git a/tests/regression/kernel/test_rotation_destroy_flush b/tests/regression/kernel/test_rotation_destroy_flush |
| 309 | index cb773d7df..0af514b49 100755 |
| 310 | --- a/tests/regression/kernel/test_rotation_destroy_flush |
| 311 | +++ b/tests/regression/kernel/test_rotation_destroy_flush |
| 312 | @@ -120,13 +120,7 @@ TESTS=( |
| 313 | TEST_COUNT=${#TESTS[@]} |
| 314 | i=0 |
| 315 | |
| 316 | -if [ "$(id -u)" == "0" ]; then |
| 317 | - isroot=1 |
| 318 | -else |
| 319 | - isroot=0 |
| 320 | -fi |
| 321 | - |
| 322 | -skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 323 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 324 | { |
| 325 | validate_lttng_modules_present |
| 326 | trap signal_cleanup SIGTERM SIGINT |
| 327 | diff --git a/tests/regression/kernel/test_select_poll_epoll b/tests/regression/kernel/test_select_poll_epoll |
| 328 | index d8245a0e7..20f0ef0ae 100755 |
| 329 | --- a/tests/regression/kernel/test_select_poll_epoll |
| 330 | +++ b/tests/regression/kernel/test_select_poll_epoll |
| 331 | @@ -374,13 +374,7 @@ if test $? != 0; then |
| 332 | exit 0 |
| 333 | fi |
| 334 | |
| 335 | -if [ "$(id -u)" == "0" ]; then |
| 336 | - isroot=1 |
| 337 | -else |
| 338 | - isroot=0 |
| 339 | -fi |
| 340 | - |
| 341 | -skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 342 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 343 | { |
| 344 | validate_lttng_modules_present |
| 345 | |
| 346 | diff --git a/tests/regression/kernel/test_syscall b/tests/regression/kernel/test_syscall |
| 347 | index 401a18a8d..219d94703 100755 |
| 348 | --- a/tests/regression/kernel/test_syscall |
| 349 | +++ b/tests/regression/kernel/test_syscall |
| 350 | @@ -664,13 +664,7 @@ plan_tests $NUM_TESTS |
| 351 | |
| 352 | print_test_banner "$TEST_DESC" |
| 353 | |
| 354 | -if [ "$(id -u)" == "0" ]; then |
| 355 | - isroot=1 |
| 356 | -else |
| 357 | - isroot=0 |
| 358 | -fi |
| 359 | - |
| 360 | -skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 361 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 362 | { |
| 363 | validate_lttng_modules_present |
| 364 | start_lttng_sessiond |
| 365 | diff --git a/tests/regression/kernel/test_userspace_probe b/tests/regression/kernel/test_userspace_probe |
| 366 | index 1091ee65e..5d984d666 100755 |
| 367 | --- a/tests/regression/kernel/test_userspace_probe |
| 368 | +++ b/tests/regression/kernel/test_userspace_probe |
| 369 | @@ -815,13 +815,7 @@ fi |
| 370 | plan_tests $NUM_TESTS |
| 371 | print_test_banner "$TEST_DESC" |
| 372 | |
| 373 | -if [ "$(id -u)" == "0" ]; then |
| 374 | - isroot=1 |
| 375 | -else |
| 376 | - isroot=0 |
| 377 | -fi |
| 378 | - |
| 379 | -skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 380 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 381 | { |
| 382 | validate_lttng_modules_present |
| 383 | start_lttng_sessiond |
| 384 | diff --git a/tests/regression/tools/clear/test_kernel b/tests/regression/tools/clear/test_kernel |
| 385 | index 06fb1c368..48250a742 100755 |
| 386 | --- a/tests/regression/tools/clear/test_kernel |
| 387 | +++ b/tests/regression/tools/clear/test_kernel |
| 388 | @@ -536,12 +536,6 @@ plan_tests $NUM_TESTS |
| 389 | |
| 390 | print_test_banner "$TEST_DESC" |
| 391 | |
| 392 | -if [ "$(id -u)" == "0" ]; then |
| 393 | - isroot=1 |
| 394 | -else |
| 395 | - isroot=0 |
| 396 | -fi |
| 397 | - |
| 398 | streaming_tests=(test_kernel_streaming |
| 399 | test_kernel_streaming_rotate_clear |
| 400 | test_kernel_streaming_clear_rotate |
| 401 | @@ -563,7 +557,7 @@ snapshot_tests=(test_kernel_streaming_snapshot |
| 402 | test_kernel_local_snapshot |
| 403 | ) |
| 404 | |
| 405 | -skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS || |
| 406 | +check_skip_kernel_test "$NUM_TESTS" "Skipping kernel streaming tests." || |
| 407 | { |
| 408 | trap signal_cleanup SIGTERM SIGINT |
| 409 | |
| 410 | diff --git a/tests/regression/tools/filtering/test_invalid_filter b/tests/regression/tools/filtering/test_invalid_filter |
| 411 | index 7d9e524d9..8435e5546 100755 |
| 412 | --- a/tests/regression/tools/filtering/test_invalid_filter |
| 413 | +++ b/tests/regression/tools/filtering/test_invalid_filter |
| 414 | @@ -168,13 +168,7 @@ done |
| 415 | |
| 416 | test_bytecode_limit -u |
| 417 | |
| 418 | -if [ "$(id -u)" == "0" ]; then |
| 419 | - isroot=1 |
| 420 | -else |
| 421 | - isroot=0 |
| 422 | -fi |
| 423 | - |
| 424 | -skip $isroot "Root access is needed. Skipping all kernel invalid filter tests." $NUM_KERNEL_TESTS || |
| 425 | +check_skip_kernel_test "$NUM_KERNEL_TESTS" "Skipping kernel invalid filter tests." || |
| 426 | { |
| 427 | diag "Test kernel filters" |
| 428 | i=0 |
| 429 | diff --git a/tests/regression/tools/filtering/test_unsupported_op b/tests/regression/tools/filtering/test_unsupported_op |
| 430 | index 299247a3c..91eb86d21 100755 |
| 431 | --- a/tests/regression/tools/filtering/test_unsupported_op |
| 432 | +++ b/tests/regression/tools/filtering/test_unsupported_op |
| 433 | @@ -103,13 +103,7 @@ while [ "$i" -lt "$OP_COUNT" ]; do |
| 434 | let "i++" |
| 435 | done |
| 436 | |
| 437 | -if [ "$(id -u)" == "0" ]; then |
| 438 | - isroot=1 |
| 439 | -else |
| 440 | - isroot=0 |
| 441 | -fi |
| 442 | - |
| 443 | -skip $isroot "Root access is needed. Skipping all kernel unsupported filter operations tests." $NUM_KERNEL_TESTS || |
| 444 | +check_skip_kernel_test $NUM_KERNEL_TESTS "Skipping kernel unsupported filter operations tests." || |
| 445 | { |
| 446 | diag "Test kernel unsupported filter operations" |
| 447 | |
| 448 | diff --git a/tests/regression/tools/filtering/test_valid_filter b/tests/regression/tools/filtering/test_valid_filter |
| 449 | index e76ffa25f..1ba7c79bb 100755 |
| 450 | --- a/tests/regression/tools/filtering/test_valid_filter |
| 451 | +++ b/tests/regression/tools/filtering/test_valid_filter |
| 452 | @@ -1452,13 +1452,7 @@ KERNEL_FILTERS=( |
| 453 | |
| 454 | IFS=$OLDIFS |
| 455 | |
| 456 | -if [ "$(id -u)" == "0" ]; then |
| 457 | - isroot=1 |
| 458 | -else |
| 459 | - isroot=0 |
| 460 | -fi |
| 461 | - |
| 462 | -skip $isroot "Root access is needed. Skipping all kernel valid filter tests." $NUM_KERNEL_TESTS || |
| 463 | +check_skip_kernel_test "$NUM_KERNEL_TESTS" "Skipping kernel valid filter tests." || |
| 464 | { |
| 465 | diag "Test kernel valid filters" |
| 466 | |
| 467 | diff --git a/tests/regression/tools/health/test_health.sh b/tests/regression/tools/health/test_health.sh |
| 468 | index b3d6419d2..68716e6b9 100644 |
| 469 | --- a/tests/regression/tools/health/test_health.sh |
| 470 | +++ b/tests/regression/tools/health/test_health.sh |
| 471 | @@ -82,7 +82,7 @@ function test_health |
| 472 | diag "With UST consumer daemons" |
| 473 | enable_ust_lttng_event_ok $SESSION_NAME $UST_EVENT_NAME $CHANNEL_NAME |
| 474 | |
| 475 | - skip $isroot "Root access is needed. Skipping kernel consumer health check test." "1" || |
| 476 | + check_skip_kernel_test "1" "Skipping kernel consumer health check test." || |
| 477 | { |
| 478 | diag "With kernel consumer daemon" |
| 479 | lttng_enable_kernel_event $SESSION_NAME $KERNEL_EVENT_NAME $CHANNEL_NAME |
| 480 | @@ -113,7 +113,7 @@ function test_health |
| 481 | |
| 482 | |
| 483 | if [ ${test_needs_root} -eq 1 ]; then |
| 484 | - skip ${isroot} "Root access needed for test \"${test_thread_name}\"." "1" || |
| 485 | + check_skip_kernel_test "1" "Skipping \"${test_thread_name}\"." || |
| 486 | { |
| 487 | report_errors "${test_thread_error_string}" "${test_relayd}" |
| 488 | } |
| 489 | @@ -276,12 +276,6 @@ STDERR_PATH=$(mktemp --tmpdir tmp.test_health_stderr_path.XXXXXX) |
| 490 | TRACE_PATH=$(mktemp --tmpdir -d tmp.test_health_trace_path.XXXXXX) |
| 491 | HEALTH_PATH=$(mktemp --tmpdir -d tmp.test_health_trace_path.XXXXXX) |
| 492 | |
| 493 | -if [ "$(id -u)" == "0" ]; then |
| 494 | - isroot=1 |
| 495 | -else |
| 496 | - isroot=0 |
| 497 | -fi |
| 498 | - |
| 499 | THREAD_COUNT=${#THREAD[@]} |
| 500 | i=0 |
| 501 | while [ "$i" -lt "$THREAD_COUNT" ]; do |
| 502 | diff --git a/tests/regression/tools/health/test_thread_ok b/tests/regression/tools/health/test_thread_ok |
| 503 | index e84adb611..e5e23543f 100755 |
| 504 | --- a/tests/regression/tools/health/test_thread_ok |
| 505 | +++ b/tests/regression/tools/health/test_thread_ok |
| 506 | @@ -67,7 +67,7 @@ function test_thread_ok |
| 507 | $CURDIR/$HEALTH_CHECK_BIN > ${STDOUT_PATH} 2> ${STDERR_PATH} |
| 508 | report_errors |
| 509 | |
| 510 | - skip $isroot "Root access is needed. Skipping kernel consumer health check test." "5" || |
| 511 | + check_skip_kernel_test "5" "Skipping kernel consumer health check test." || |
| 512 | { |
| 513 | diag "With kernel consumer daemon" |
| 514 | create_lttng_session_no_output $SESSION_NAME |
| 515 | @@ -115,13 +115,6 @@ STDERR_PATH=$(mktemp --tmpdir tmp.test_thread_ok_stderr_path.XXXXXX) |
| 516 | TRACE_PATH=$(mktemp --tmpdir -d tmp.test_thread_ok_trace_path.XXXXXX) |
| 517 | HEALTH_PATH=$(mktemp --tmpdir -d tmp.test_thread_ok_trace_path.XXXXXX) |
| 518 | |
| 519 | -# The manage kernel thread is only spawned if we are root |
| 520 | -if [ "$(id -u)" == "0" ]; then |
| 521 | - isroot=1 |
| 522 | -else |
| 523 | - isroot=0 |
| 524 | -fi |
| 525 | - |
| 526 | test_thread_ok |
| 527 | |
| 528 | rm -rf ${HEALTH_PATH} |
| 529 | diff --git a/tests/regression/tools/live/test_kernel b/tests/regression/tools/live/test_kernel |
| 530 | index b622b5214..fdaa09f0d 100755 |
| 531 | --- a/tests/regression/tools/live/test_kernel |
| 532 | +++ b/tests/regression/tools/live/test_kernel |
| 533 | @@ -39,13 +39,11 @@ function clean_live_tracing() |
| 534 | rm -rf $TRACE_PATH |
| 535 | } |
| 536 | |
| 537 | -# Need root access for kernel tracing. |
| 538 | -if [ "$(id -u)" == "0" ]; then |
| 539 | - isroot=1 |
| 540 | -else |
| 541 | - plan_skip_all "Root access is needed. Skipping all tests." |
| 542 | +check_skip_kernel_test && |
| 543 | +{ |
| 544 | + plan_skip_all "Skipping all tests." |
| 545 | exit 0 |
| 546 | -fi |
| 547 | +} |
| 548 | |
| 549 | modprobe lttng-test |
| 550 | |
| 551 | diff --git a/tests/regression/tools/live/test_lttng_kernel b/tests/regression/tools/live/test_lttng_kernel |
| 552 | index a23d9373a..1b933648f 100755 |
| 553 | --- a/tests/regression/tools/live/test_lttng_kernel |
| 554 | +++ b/tests/regression/tools/live/test_lttng_kernel |
| 555 | @@ -45,13 +45,7 @@ function clean_live_tracing() |
| 556 | } |
| 557 | |
| 558 | # Need root access for kernel tracing. |
| 559 | -if [ "$(id -u)" == "0" ]; then |
| 560 | - isroot=1 |
| 561 | -else |
| 562 | - isroot=0 |
| 563 | -fi |
| 564 | - |
| 565 | -skip $isroot "Root access is needed. Skipping all tests." $NUM_TESTS || |
| 566 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 567 | { |
| 568 | modprobe lttng-test |
| 569 | |
| 570 | diff --git a/tests/regression/tools/metadata/test_kernel b/tests/regression/tools/metadata/test_kernel |
| 571 | index 57cace6ea..26e95d93a 100755 |
| 572 | --- a/tests/regression/tools/metadata/test_kernel |
| 573 | +++ b/tests/regression/tools/metadata/test_kernel |
| 574 | @@ -91,13 +91,7 @@ plan_tests $NUM_TESTS |
| 575 | print_test_banner "$TEST_DESC" |
| 576 | |
| 577 | |
| 578 | -if [ "$(id -u)" == "0" ]; then |
| 579 | - isroot=1 |
| 580 | -else |
| 581 | - isroot=0 |
| 582 | -fi |
| 583 | - |
| 584 | -skip $isroot "Root access is needed. Skipping all kernel metadata tests." $NUM_TESTS || |
| 585 | +check_skip_kernel_test "$NUM_TESTS" "Skipping kernel metadata tests." || |
| 586 | { |
| 587 | validate_lttng_modules_present |
| 588 | modprobe lttng-test |
| 589 | diff --git a/tests/regression/tools/notification/test_notification_kernel_buffer_usage b/tests/regression/tools/notification/test_notification_kernel_buffer_usage |
| 590 | index 76e69a77e..8fdaabb3e 100755 |
| 591 | --- a/tests/regression/tools/notification/test_notification_kernel_buffer_usage |
| 592 | +++ b/tests/regression/tools/notification/test_notification_kernel_buffer_usage |
| 593 | @@ -60,29 +60,27 @@ function test_buffer_usage_notification |
| 594 | wait $APP_PID 2> /dev/null |
| 595 | } |
| 596 | |
| 597 | -if [ "$(id -u)" == "0" ]; then |
| 598 | - |
| 599 | - validate_lttng_modules_present |
| 600 | - |
| 601 | +check_skip_kernel_test && |
| 602 | +{ |
| 603 | + plan_skip_all "Skipping all tests." |
| 604 | + rm -rf "$TEST_TMPDIR" |
| 605 | + exit 0 |
| 606 | +} |
| 607 | |
| 608 | - modprobe lttng-test |
| 609 | +validate_lttng_modules_present |
| 610 | |
| 611 | - # Used on sessiond launch. |
| 612 | - LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \ |
| 613 | - CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \ |
| 614 | - LD_PRELOAD=${TESTPOINT}" |
| 615 | - start_lttng_sessiond_notap |
| 616 | +modprobe lttng-test |
| 617 | |
| 618 | - test_buffer_usage_notification |
| 619 | +# Used on sessiond launch. |
| 620 | +LTTNG_SESSIOND_ENV_VARS="LTTNG_TESTPOINT_ENABLE=1 \ |
| 621 | + CONSUMER_PAUSE_PIPE_PATH=${TESTPOINT_PIPE_PATH} \ |
| 622 | + LD_PRELOAD=${TESTPOINT}" |
| 623 | +start_lttng_sessiond_notap |
| 624 | |
| 625 | - stop_lttng_sessiond_notap |
| 626 | - rmmod lttng-test |
| 627 | +test_buffer_usage_notification |
| 628 | |
| 629 | - rm -rf "${consumerd_pipe[@]}" 2> /dev/null |
| 630 | -else |
| 631 | - # Kernel tests are skipped. |
| 632 | - plan_tests $NUM_TESTS |
| 633 | - skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS |
| 634 | -fi |
| 635 | +stop_lttng_sessiond_notap |
| 636 | +rmmod lttng-test |
| 637 | |
| 638 | +rm -rf "${consumerd_pipe[@]}" 2> /dev/null |
| 639 | rm -rf "$TEST_TMPDIR" |
| 640 | diff --git a/tests/regression/tools/notification/test_notification_kernel_capture b/tests/regression/tools/notification/test_notification_kernel_capture |
| 641 | index 88f123d3d..0f8a2bc6f 100755 |
| 642 | --- a/tests/regression/tools/notification/test_notification_kernel_capture |
| 643 | +++ b/tests/regression/tools/notification/test_notification_kernel_capture |
| 644 | @@ -31,22 +31,21 @@ function test_basic_error_path |
| 645 | } |
| 646 | |
| 647 | |
| 648 | -if [ "$(id -u)" == "0" ]; then |
| 649 | - validate_lttng_modules_present |
| 650 | +check_skip_kernel_test && |
| 651 | +{ |
| 652 | + plan_skip_all "Skipping all tests." |
| 653 | + exit 0 |
| 654 | +} |
| 655 | |
| 656 | - modprobe lttng-test |
| 657 | +validate_lttng_modules_present |
| 658 | |
| 659 | - start_lttng_sessiond_notap |
| 660 | +modprobe lttng-test |
| 661 | |
| 662 | - test_basic_error_path |
| 663 | +start_lttng_sessiond_notap |
| 664 | |
| 665 | - stop_lttng_sessiond_notap |
| 666 | - rmmod lttng-test |
| 667 | +test_basic_error_path |
| 668 | |
| 669 | -else |
| 670 | - # Kernel tests are skipped. |
| 671 | - plan_tests $NUM_TESTS |
| 672 | - skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS |
| 673 | -fi |
| 674 | +stop_lttng_sessiond_notap |
| 675 | +rmmod lttng-test |
| 676 | |
| 677 | rm -f "$TESTAPP_STATE_PATH" |
| 678 | diff --git a/tests/regression/tools/notification/test_notification_kernel_error b/tests/regression/tools/notification/test_notification_kernel_error |
| 679 | index 80fe6e5b5..b757ec2b4 100755 |
| 680 | --- a/tests/regression/tools/notification/test_notification_kernel_error |
| 681 | +++ b/tests/regression/tools/notification/test_notification_kernel_error |
| 682 | @@ -30,23 +30,22 @@ function test_basic_error_path |
| 683 | wait $APP_PID 2> /dev/null |
| 684 | } |
| 685 | |
| 686 | +check_skip_kernel_test && |
| 687 | +{ |
| 688 | + plan_skip_all "Skipping all tests." |
| 689 | + exit 0 |
| 690 | +} |
| 691 | |
| 692 | -if [ "$(id -u)" == "0" ]; then |
| 693 | - validate_lttng_modules_present |
| 694 | +validate_lttng_modules_present |
| 695 | |
| 696 | - modprobe lttng-test |
| 697 | +modprobe lttng-test |
| 698 | |
| 699 | - start_lttng_sessiond_notap |
| 700 | +start_lttng_sessiond_notap |
| 701 | |
| 702 | - test_basic_error_path |
| 703 | +test_basic_error_path |
| 704 | |
| 705 | - stop_lttng_sessiond_notap |
| 706 | - rmmod lttng-test |
| 707 | +stop_lttng_sessiond_notap |
| 708 | +rmmod lttng-test |
| 709 | |
| 710 | -else |
| 711 | - # Kernel tests are skipped. |
| 712 | - plan_tests $NUM_TESTS |
| 713 | - skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS |
| 714 | -fi |
| 715 | |
| 716 | rm -f "$TESTAPP_STATE_PATH" |
| 717 | diff --git a/tests/regression/tools/notification/test_notification_kernel_instrumentation b/tests/regression/tools/notification/test_notification_kernel_instrumentation |
| 718 | index 90545a541..705f7703d 100755 |
| 719 | --- a/tests/regression/tools/notification/test_notification_kernel_instrumentation |
| 720 | +++ b/tests/regression/tools/notification/test_notification_kernel_instrumentation |
| 721 | @@ -28,22 +28,21 @@ function test_kernel_instrumentation_notification |
| 722 | wait $APP_PID 2> /dev/null |
| 723 | } |
| 724 | |
| 725 | -if [ "$(id -u)" == "0" ]; then |
| 726 | - validate_lttng_modules_present |
| 727 | +check_skip_kernel_test && |
| 728 | +{ |
| 729 | + plan_skip_all "Skipping all tests." |
| 730 | + exit 0 |
| 731 | +} |
| 732 | |
| 733 | - modprobe lttng-test |
| 734 | +validate_lttng_modules_present |
| 735 | |
| 736 | - start_lttng_sessiond_notap |
| 737 | +modprobe lttng-test |
| 738 | |
| 739 | - test_kernel_instrumentation_notification |
| 740 | +start_lttng_sessiond_notap |
| 741 | |
| 742 | - stop_lttng_sessiond_notap |
| 743 | - rmmod lttng-test |
| 744 | +test_kernel_instrumentation_notification |
| 745 | |
| 746 | -else |
| 747 | - # Kernel tests are skipped. |
| 748 | - plan_tests $NUM_TESTS |
| 749 | - skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS |
| 750 | -fi |
| 751 | +stop_lttng_sessiond_notap |
| 752 | +rmmod lttng-test |
| 753 | |
| 754 | rm -f "$TESTAPP_STATE_PATH" |
| 755 | diff --git a/tests/regression/tools/notification/test_notification_kernel_syscall b/tests/regression/tools/notification/test_notification_kernel_syscall |
| 756 | index d273cb55d..7fa235388 100755 |
| 757 | --- a/tests/regression/tools/notification/test_notification_kernel_syscall |
| 758 | +++ b/tests/regression/tools/notification/test_notification_kernel_syscall |
| 759 | @@ -31,19 +31,18 @@ function test_kernel_syscall_notification |
| 760 | wait $APP_PID 2> /dev/null |
| 761 | } |
| 762 | |
| 763 | -if [ "$(id -u)" == "0" ]; then |
| 764 | - validate_lttng_modules_present |
| 765 | +check_skip_kernel_test && |
| 766 | +{ |
| 767 | + plan_skip_all "Skipping all tests." |
| 768 | + exit 0 |
| 769 | +} |
| 770 | |
| 771 | - start_lttng_sessiond_notap |
| 772 | +validate_lttng_modules_present |
| 773 | |
| 774 | - test_kernel_syscall_notification |
| 775 | +start_lttng_sessiond_notap |
| 776 | |
| 777 | - stop_lttng_sessiond_notap |
| 778 | +test_kernel_syscall_notification |
| 779 | |
| 780 | -else |
| 781 | - # Kernel tests are skipped. |
| 782 | - plan_tests $NUM_TESTS |
| 783 | - skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS |
| 784 | -fi |
| 785 | +stop_lttng_sessiond_notap |
| 786 | |
| 787 | rm -f "$TESTAPP_STATE_PATH" |
| 788 | diff --git a/tests/regression/tools/notification/test_notification_kernel_userspace_probe b/tests/regression/tools/notification/test_notification_kernel_userspace_probe |
| 789 | index 8ef8d708d..abddd9be7 100755 |
| 790 | --- a/tests/regression/tools/notification/test_notification_kernel_userspace_probe |
| 791 | +++ b/tests/regression/tools/notification/test_notification_kernel_userspace_probe |
| 792 | @@ -29,18 +29,18 @@ function test_kernel_userspace_probe_notification |
| 793 | wait $APP_PID 2> /dev/null |
| 794 | } |
| 795 | |
| 796 | -if [ "$(id -u)" == "0" ]; then |
| 797 | - validate_lttng_modules_present |
| 798 | +check_skip_kernel_test && |
| 799 | +{ |
| 800 | + plan_skip_all "Skipping all tests." |
| 801 | + exit 0 |
| 802 | +} |
| 803 | + |
| 804 | +validate_lttng_modules_present |
| 805 | |
| 806 | - start_lttng_sessiond_notap |
| 807 | +start_lttng_sessiond_notap |
| 808 | |
| 809 | - test_kernel_userspace_probe_notification |
| 810 | +test_kernel_userspace_probe_notification |
| 811 | |
| 812 | - stop_lttng_sessiond_notap |
| 813 | -else |
| 814 | - # Kernel tests are skipped. |
| 815 | - plan_tests $NUM_TESTS |
| 816 | - skip 0 "Root access is needed. Skipping all kernel notification tests." $NUM_TESTS |
| 817 | -fi |
| 818 | +stop_lttng_sessiond_notap |
| 819 | |
| 820 | rm -f "$TESTAPP_STATE_PATH" |
| 821 | diff --git a/tests/regression/tools/notification/test_notification_multi_app b/tests/regression/tools/notification/test_notification_multi_app |
| 822 | index d8b639225..61891b56f 100755 |
| 823 | --- a/tests/regression/tools/notification/test_notification_multi_app |
| 824 | +++ b/tests/regression/tools/notification/test_notification_multi_app |
| 825 | @@ -411,22 +411,18 @@ function test_on_register_evaluation () |
| 826 | rm -rf "$output_dir" |
| 827 | } |
| 828 | |
| 829 | - |
| 830 | TESTS=( |
| 831 | test_multi_app_ust |
| 832 | test_on_register_evaluation_ust |
| 833 | ) |
| 834 | |
| 835 | -if [ "$(id -u)" == "0" ]; then |
| 836 | +check_skip_kernel_test "$NUM_TEST_KERNEL" "Skipping kernel multi-app notification tests." || { |
| 837 | validate_lttng_modules_present |
| 838 | TESTS+=( |
| 839 | - test_multi_app_kernel |
| 840 | - test_on_register_evaluation_kernel |
| 841 | -) |
| 842 | -else |
| 843 | - skip 0 "Root access is needed. Skipping all kernel multi-app notification tests." $NUM_TEST_KERNEL |
| 844 | -fi |
| 845 | - |
| 846 | + test_multi_app_kernel |
| 847 | + test_on_register_evaluation_kernel |
| 848 | + ) |
| 849 | +} |
| 850 | |
| 851 | for fct_test in ${TESTS[@]}; |
| 852 | do |
| 853 | diff --git a/tests/regression/tools/notification/test_notification_notifier_discarded_count b/tests/regression/tools/notification/test_notification_notifier_discarded_count |
| 854 | index c9235393e..a6c31a728 100755 |
| 855 | --- a/tests/regression/tools/notification/test_notification_notifier_discarded_count |
| 856 | +++ b/tests/regression/tools/notification/test_notification_notifier_discarded_count |
| 857 | @@ -391,7 +391,8 @@ function test_ust_notifier_discarded_regardless_trigger_owner |
| 858 | test_ust_notifier_discarded_count |
| 859 | test_ust_notifier_discarded_count_max_bucket |
| 860 | |
| 861 | -if [ "$(id -u)" == "0" ]; then |
| 862 | +check_skip_kernel_test "$KERNEL_NUM_TESTS" "Skipping kernel notification tests." || |
| 863 | +{ |
| 864 | |
| 865 | validate_lttng_modules_present |
| 866 | |
| 867 | @@ -413,9 +414,7 @@ if [ "$(id -u)" == "0" ]; then |
| 868 | modprobe --remove lttng-test |
| 869 | |
| 870 | rm -rf "${sessiond_pipe[@]}" 2> /dev/null |
| 871 | -else |
| 872 | - # Kernel tests are skipped. |
| 873 | - skip 0 "Root access is needed. Skipping all kernel notification tests." $KERNEL_NUM_TESTS |
| 874 | -fi |
| 875 | + |
| 876 | +} |
| 877 | |
| 878 | rm -rf "$TEST_TMPDIR" |
| 879 | diff --git a/tests/regression/tools/regen-metadata/test_kernel b/tests/regression/tools/regen-metadata/test_kernel |
| 880 | index 49eea32a7..555a4e2ce 100755 |
| 881 | --- a/tests/regression/tools/regen-metadata/test_kernel |
| 882 | +++ b/tests/regression/tools/regen-metadata/test_kernel |
| 883 | @@ -99,13 +99,7 @@ plan_tests $NUM_TESTS |
| 884 | |
| 885 | print_test_banner "$TEST_DESC" |
| 886 | |
| 887 | -if [ "$(id -u)" == "0" ]; then |
| 888 | - isroot=1 |
| 889 | -else |
| 890 | - isroot=0 |
| 891 | -fi |
| 892 | - |
| 893 | -skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS || |
| 894 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 895 | { |
| 896 | validate_lttng_modules_present |
| 897 | |
| 898 | diff --git a/tests/regression/tools/regen-statedump/test_kernel b/tests/regression/tools/regen-statedump/test_kernel |
| 899 | index 8a261355d..bbbac3942 100755 |
| 900 | --- a/tests/regression/tools/regen-statedump/test_kernel |
| 901 | +++ b/tests/regression/tools/regen-statedump/test_kernel |
| 902 | @@ -39,13 +39,7 @@ plan_tests $NUM_TESTS |
| 903 | |
| 904 | print_test_banner "$TEST_DESC" |
| 905 | |
| 906 | -if [ "$(id -u)" == "0" ]; then |
| 907 | - isroot=1 |
| 908 | -else |
| 909 | - isroot=0 |
| 910 | -fi |
| 911 | - |
| 912 | -skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS || |
| 913 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 914 | { |
| 915 | validate_lttng_modules_present |
| 916 | start_lttng_sessiond |
| 917 | diff --git a/tests/regression/tools/rotation/test_kernel b/tests/regression/tools/rotation/test_kernel |
| 918 | index f5f1f5553..efe3fd359 100755 |
| 919 | --- a/tests/regression/tools/rotation/test_kernel |
| 920 | +++ b/tests/regression/tools/rotation/test_kernel |
| 921 | @@ -82,13 +82,7 @@ plan_tests $NUM_TESTS |
| 922 | |
| 923 | print_test_banner "$TEST_DESC" |
| 924 | |
| 925 | -if [ "$(id -u)" == "0" ]; then |
| 926 | - isroot=1 |
| 927 | -else |
| 928 | - isroot=0 |
| 929 | -fi |
| 930 | - |
| 931 | -skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS || |
| 932 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 933 | { |
| 934 | validate_lttng_modules_present |
| 935 | |
| 936 | diff --git a/tests/regression/tools/snapshots/test_kernel b/tests/regression/tools/snapshots/test_kernel |
| 937 | index abb243563..d91876867 100755 |
| 938 | --- a/tests/regression/tools/snapshots/test_kernel |
| 939 | +++ b/tests/regression/tools/snapshots/test_kernel |
| 940 | @@ -217,13 +217,7 @@ plan_tests $NUM_TESTS |
| 941 | |
| 942 | print_test_banner "$TEST_DESC" |
| 943 | |
| 944 | -if [ "$(id -u)" == "0" ]; then |
| 945 | - isroot=1 |
| 946 | -else |
| 947 | - isroot=0 |
| 948 | -fi |
| 949 | - |
| 950 | -skip $isroot "Root access is needed. Skipping all kernel snapshot tests" $NUM_TESTS || |
| 951 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 952 | { |
| 953 | |
| 954 | validate_lttng_modules_present |
| 955 | diff --git a/tests/regression/tools/snapshots/test_kernel_streaming b/tests/regression/tools/snapshots/test_kernel_streaming |
| 956 | index 0c92dc710..dd965afee 100755 |
| 957 | --- a/tests/regression/tools/snapshots/test_kernel_streaming |
| 958 | +++ b/tests/regression/tools/snapshots/test_kernel_streaming |
| 959 | @@ -145,13 +145,7 @@ plan_tests $NUM_TESTS |
| 960 | |
| 961 | print_test_banner "$TEST_DESC" |
| 962 | |
| 963 | -if [ "$(id -u)" == "0" ]; then |
| 964 | - isroot=1 |
| 965 | -else |
| 966 | - isroot=0 |
| 967 | -fi |
| 968 | - |
| 969 | -skip $isroot "Root access is needed. Skipping all kernel streaming tests" $NUM_TESTS || |
| 970 | +check_skip_kernel_test $NUM_TESTS "Skipping all tests." || |
| 971 | { |
| 972 | validate_lttng_modules_present |
| 973 | |
| 974 | diff --git a/tests/regression/tools/streaming/test_high_throughput_limits b/tests/regression/tools/streaming/test_high_throughput_limits |
| 975 | index 2b9e3ad39..c55d51098 100755 |
| 976 | --- a/tests/regression/tools/streaming/test_high_throughput_limits |
| 977 | +++ b/tests/regression/tools/streaming/test_high_throughput_limits |
| 978 | @@ -170,13 +170,7 @@ plan_tests $NUM_TESTS |
| 979 | |
| 980 | print_test_banner "$TEST_DESC" |
| 981 | |
| 982 | -if [ "$(id -u)" == "0" ]; then |
| 983 | - isroot=1 |
| 984 | -else |
| 985 | - isroot=0 |
| 986 | -fi |
| 987 | - |
| 988 | -skip $isroot "Root access is needed to set bandwith limits. Skipping all tests." $NUM_TESTS || |
| 989 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 990 | { |
| 991 | |
| 992 | # Catch sigint and try to cleanup limits |
| 993 | diff --git a/tests/regression/tools/streaming/test_kernel b/tests/regression/tools/streaming/test_kernel |
| 994 | index 33334229f..113eea7bf 100755 |
| 995 | --- a/tests/regression/tools/streaming/test_kernel |
| 996 | +++ b/tests/regression/tools/streaming/test_kernel |
| 997 | @@ -47,13 +47,7 @@ plan_tests $NUM_TESTS |
| 998 | |
| 999 | print_test_banner "$TEST_DESC" |
| 1000 | |
| 1001 | -if [ "$(id -u)" == "0" ]; then |
| 1002 | - isroot=1 |
| 1003 | -else |
| 1004 | - isroot=0 |
| 1005 | -fi |
| 1006 | - |
| 1007 | -skip $isroot "Root access is needed. Skipping all kernel streaming tests." $NUM_TESTS || |
| 1008 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." || |
| 1009 | { |
| 1010 | validate_lttng_modules_present |
| 1011 | |
| 1012 | diff --git a/tests/regression/tools/tracker/test_event_tracker b/tests/regression/tools/tracker/test_event_tracker |
| 1013 | index cc0f698d2..de0c79d36 100755 |
| 1014 | --- a/tests/regression/tools/tracker/test_event_tracker |
| 1015 | +++ b/tests/regression/tools/tracker/test_event_tracker |
| 1016 | @@ -466,13 +466,7 @@ test_event_track_untrack ust 0 "${EVENT_NAME}" "--pid --all" # backward compat |
| 1017 | test_event_tracker ust 1 "${EVENT_NAME}" "--pid --all" # backward compat |
| 1018 | test_event_pid_tracker ust 1 "${EVENT_NAME}" |
| 1019 | |
| 1020 | -if [ "$(id -u)" == "0" ]; then |
| 1021 | - isroot=1 |
| 1022 | -else |
| 1023 | - isroot=0 |
| 1024 | -fi |
| 1025 | - |
| 1026 | -skip $isroot "Root access is needed. Skipping all kernel tracker tests." $NUM_KERNEL_TESTS || |
| 1027 | +check_skip_kernel_test "$NUM_KERNEL_TESTS" "Skipping kernel tracker tests." || |
| 1028 | { |
| 1029 | diag "Test kernel tracker" |
| 1030 | |
| 1031 | diff --git a/tests/regression/tools/trigger/test_add_trigger_cli b/tests/regression/tools/trigger/test_add_trigger_cli |
| 1032 | index 98ecf6272..d1763aa2e 100755 |
| 1033 | --- a/tests/regression/tools/trigger/test_add_trigger_cli |
| 1034 | +++ b/tests/regression/tools/trigger/test_add_trigger_cli |
| 1035 | @@ -34,12 +34,6 @@ tmp_stdout=$(mktemp --tmpdir -t test_parse_cli_trigger_stdout.XXXXXX) |
| 1036 | tmp_stderr=$(mktemp --tmpdir -t test_parse_cli_trigger_stderr.XXXXXX) |
| 1037 | uprobe_elf_binary="${TESTDIR}/utils/testapp/userspace-probe-elf-binary/.libs/userspace-probe-elf-binary" |
| 1038 | |
| 1039 | -if [ "$(id -u)" == "0" ]; then |
| 1040 | - ist_root=1 |
| 1041 | -else |
| 1042 | - ist_root=0 |
| 1043 | -fi |
| 1044 | - |
| 1045 | function test_success () |
| 1046 | { |
| 1047 | local test_name="$1" |
| 1048 | @@ -223,7 +217,7 @@ test_success "--exclude-name two" "trigger5" \ |
| 1049 | --condition event-rule-matches --type=user --name='jean-*' --exclude-name jean-chretien -x jean-charest \ |
| 1050 | --action notify |
| 1051 | |
| 1052 | -skip $ist_root "non-root user: skipping kprobe tests" 18 || { |
| 1053 | +check_skip_kernel_test 18 "Skipping kprobe tests." || { |
| 1054 | i=0 |
| 1055 | |
| 1056 | for type in kprobe kernel:kprobe; do |
| 1057 | @@ -262,7 +256,7 @@ skip $ist_root "non-root user: skipping kprobe tests" 18 || { |
| 1058 | done |
| 1059 | } |
| 1060 | |
| 1061 | -skip $ist_root "non-root user: skipping uprobe tests" 6 || { |
| 1062 | +check_skip_kernel_test 6 "Skipping uprobe tests." || { |
| 1063 | test_success "--condition event-rule-matches uprobe" "uprobe-trigger-0" \ |
| 1064 | --name="uprobe-trigger-0" \ |
| 1065 | --condition event-rule-matches --type=kernel:uprobe --location=${uprobe_elf_binary}:test_function --event-name=ma-probe \ |
| 1066 | @@ -274,7 +268,7 @@ skip $ist_root "non-root user: skipping uprobe tests" 6 || { |
| 1067 | --action notify |
| 1068 | } |
| 1069 | |
| 1070 | -skip $ist_root "non-root user: skipping syscall tests" 30 || { |
| 1071 | +check_skip_kernel_test 30 "Skipping syscall tests." || { |
| 1072 | test_success "--condition event-rule-matches one syscall" "syscall-trigger-0" \ |
| 1073 | --name="syscall-trigger-0" \ |
| 1074 | --condition event-rule-matches --type=syscall --name=open \ |
| 1075 | diff --git a/tests/regression/tools/trigger/test_list_triggers_cli b/tests/regression/tools/trigger/test_list_triggers_cli |
| 1076 | index a04018013..02c3de3e9 100755 |
| 1077 | --- a/tests/regression/tools/trigger/test_list_triggers_cli |
| 1078 | +++ b/tests/regression/tools/trigger/test_list_triggers_cli |
| 1079 | @@ -36,22 +36,12 @@ uprobe_sdt_binary=$(realpath "${TESTDIR}/utils/testapp/userspace-probe-sdt-binar |
| 1080 | register_some_triggers_bin=$(realpath "${CURDIR}/utils/register-some-triggers") |
| 1081 | |
| 1082 | uid=$(id --user) |
| 1083 | -gid=$(id --group) |
| 1084 | |
| 1085 | -if [ "$uid" == "0" ]; then |
| 1086 | - ist_root=1 |
| 1087 | - ls "$uprobe_sdt_binary" >/dev/null 2>&1 |
| 1088 | - if test $? == 0; then |
| 1089 | - hast_sdt_binary=1 |
| 1090 | - else |
| 1091 | - hast_sdt_binary=0 |
| 1092 | - fi |
| 1093 | -else |
| 1094 | - ist_root=0 |
| 1095 | - hast_sdt_binary=0 |
| 1096 | +sdt_binary_present=0 |
| 1097 | +if [ -f "$uprobe_sdt_binary" ]; then |
| 1098 | + sdt_binary_present=1 |
| 1099 | fi |
| 1100 | |
| 1101 | - |
| 1102 | test_top_level_options () |
| 1103 | { |
| 1104 | diag "Listing top level options" |
| 1105 | @@ -2695,10 +2685,12 @@ start_lttng_sessiond_notap |
| 1106 | |
| 1107 | test_top_level_options |
| 1108 | test_event_rule_matches_tracepoint |
| 1109 | -skip $ist_root "non-root user: skipping kprobe tests" 13 || test_event_rule_matches_probe |
| 1110 | -skip $ist_root "non-root user: skipping uprobe tests" 9 || test_event_rule_matches_userspace_probe_elf |
| 1111 | -skip $(($ist_root && $hast_sdt_binary)) "skipping userspace probe SDT tests" 9 || test_event_rule_matches_userspace_probe_sdt |
| 1112 | -skip $ist_root "non-root user: skipping syscall tests" 17 || test_event_rule_matches_syscall |
| 1113 | +check_skip_kernel_test 48 "Skipping kprobe, uprobe, SDT and syscall tests." || { |
| 1114 | + test_event_rule_matches_probe |
| 1115 | + test_event_rule_matches_userspace_probe_elf |
| 1116 | + skip $sdt_binary_present "No SDT binary. Skipping userspace probe SDT tests" 9 || test_event_rule_matches_userspace_probe_sdt |
| 1117 | + test_event_rule_matches_syscall |
| 1118 | +} |
| 1119 | test_session_consumed_size_condition |
| 1120 | test_buffer_usage_conditions |
| 1121 | test_session_rotation_conditions |
| 1122 | diff --git a/tests/regression/tools/wildcard/test_event_wildcard b/tests/regression/tools/wildcard/test_event_wildcard |
| 1123 | index f69baffc4..14d9bb88a 100755 |
| 1124 | --- a/tests/regression/tools/wildcard/test_event_wildcard |
| 1125 | +++ b/tests/regression/tools/wildcard/test_event_wildcard |
| 1126 | @@ -124,13 +124,7 @@ test_event_wildcard ust 1 'tp*tptest' |
| 1127 | test_event_wildcard ust 1 'tp**tptest' |
| 1128 | test_event_wildcard ust 1 'tp*test' |
| 1129 | |
| 1130 | -if [ "$(id -u)" == "0" ]; then |
| 1131 | - isroot=1 |
| 1132 | -else |
| 1133 | - isroot=0 |
| 1134 | -fi |
| 1135 | - |
| 1136 | -skip $isroot "Root access is needed. Skipping all kernel wildcard tests." $NUM_KERNEL_TESTS || |
| 1137 | +check_skip_kernel_test "$NUM_KERNEL_TESTS" "Skipping kernel wildcard tests." || |
| 1138 | { |
| 1139 | diag "Test kernel wildcards" |
| 1140 | |
| 1141 | diff --git a/tests/regression/tools/working-directory/test_relayd_working_directory b/tests/regression/tools/working-directory/test_relayd_working_directory |
| 1142 | index c7e784cca..6bd1e504a 100755 |
| 1143 | --- a/tests/regression/tools/working-directory/test_relayd_working_directory |
| 1144 | +++ b/tests/regression/tools/working-directory/test_relayd_working_directory |
| 1145 | @@ -145,9 +145,9 @@ function test_relayd_debug_permission() |
| 1146 | diag "Test lttng-relayd change working directory on non writable directory" |
| 1147 | |
| 1148 | if [ "$(id -u)" == "0" ]; then |
| 1149 | - is_user=0 |
| 1150 | + is_user=0 |
| 1151 | else |
| 1152 | - is_user=1 |
| 1153 | + is_user=1 |
| 1154 | fi |
| 1155 | |
| 1156 | skip $is_user "Skipping permission debug output test; operation can't fail as root" 6 || |
| 1157 | diff --git a/tests/regression/ust/namespaces/test_ns_contexts_change b/tests/regression/ust/namespaces/test_ns_contexts_change |
| 1158 | index 8a4b62ce3..622241f7b 100755 |
| 1159 | --- a/tests/regression/ust/namespaces/test_ns_contexts_change |
| 1160 | +++ b/tests/regression/ust/namespaces/test_ns_contexts_change |
| 1161 | @@ -101,12 +101,7 @@ plan_tests $NUM_TESTS |
| 1162 | |
| 1163 | print_test_banner "$TEST_DESC" |
| 1164 | |
| 1165 | -isroot=0 |
| 1166 | -if [ "$(id -u)" == "0" ]; then |
| 1167 | - isroot=1 |
| 1168 | -fi |
| 1169 | - |
| 1170 | -skip $isroot "Root access is needed. Skipping all tests." "$NUM_TESTS" && exit 0 |
| 1171 | +check_skip_kernel_test "$NUM_TESTS" "Skipping all tests." && exit 0 |
| 1172 | |
| 1173 | system_has_ns=0 |
| 1174 | if [ -d "/proc/$$/ns" ]; then |
| 1175 | diff --git a/tests/regression/ust/test_event_perf b/tests/regression/ust/test_event_perf |
| 1176 | index 33aab2981..178959a19 100755 |
| 1177 | --- a/tests/regression/ust/test_event_perf |
| 1178 | +++ b/tests/regression/ust/test_event_perf |
| 1179 | @@ -119,17 +119,11 @@ plan_tests $NUM_TESTS |
| 1180 | |
| 1181 | print_test_banner "$TEST_DESC" |
| 1182 | |
| 1183 | -if [ "$(id -u)" == "0" ]; then |
| 1184 | - isroot=1 |
| 1185 | -else |
| 1186 | - isroot=0 |
| 1187 | -fi |
| 1188 | - |
| 1189 | start_lttng_sessiond |
| 1190 | |
| 1191 | test_parsing_raw |
| 1192 | |
| 1193 | -skip $isroot "Root access is needed. Skipping UST perf tests." 8 || |
| 1194 | +check_skip_kernel_test 8 "Skipping UST perf tests." || |
| 1195 | { |
| 1196 | test_event_basic |
| 1197 | } |
| 1198 | diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh |
| 1199 | index faa87e783..da0e0569d 100644 |
| 1200 | --- a/tests/utils/utils.sh |
| 1201 | +++ b/tests/utils/utils.sh |
| 1202 | @@ -318,6 +318,41 @@ function conf_proc_count() |
| 1203 | echo |
| 1204 | } |
| 1205 | |
| 1206 | +# Usage: |
| 1207 | +# check_skip_kernel_test [NB_TESTS] [SKIP_MESSAGE] |
| 1208 | +# Return 0 if LTTNG_TOOLS_DISABLE_KERNEL_TESTS was set or the current user is not a root user |
| 1209 | +# If NB_TESTS is set, call skip() to skip number of tests. |
| 1210 | +# If NB_TESTS is empty, just output a reason with diag. |
| 1211 | +# An optional message can be added. |
| 1212 | + |
| 1213 | +function check_skip_kernel_test () |
| 1214 | +{ |
| 1215 | + local num_tests="$1" |
| 1216 | + local skip_message="$2" |
| 1217 | + |
| 1218 | + # Check for skip test kernel flag |
| 1219 | + if [ "$LTTNG_TOOLS_DISABLE_KERNEL_TESTS" == "1" ]; then |
| 1220 | + if ! test -z "$num_tests"; then |
| 1221 | + skip 0 "LTTNG_TOOLS_DISABLE_KERNEL_TESTS was set.${skip_message+ }${skip_message}" "$num_tests" |
| 1222 | + else |
| 1223 | + diag "LTTNG_TOOLS_DISABLE_KERNEL_TESTS was set.${skip_message+ }${skip_message}" |
| 1224 | + fi |
| 1225 | + return 0 |
| 1226 | + fi |
| 1227 | + |
| 1228 | + # Check if we are running as root |
| 1229 | + if [ "$(id -u)" != "0" ]; then |
| 1230 | + if ! test -z "$num_tests"; then |
| 1231 | + skip 0 "Root access is needed for kernel testing.${skip_message+ }${skip_message}" "$num_tests" |
| 1232 | + else |
| 1233 | + diag "Root access is needed for kernel testing.${skip_message+ }${skip_message}" |
| 1234 | + fi |
| 1235 | + return 0 |
| 1236 | + fi |
| 1237 | + |
| 1238 | + return 1 |
| 1239 | +} |
| 1240 | + |
| 1241 | # Check if base lttng-modules are present. |
| 1242 | # Bail out on failure |
| 1243 | function validate_lttng_modules_present () |
| 1244 | -- |
| 1245 | 2.25.1 |
| 1246 | |