From 2a05e025c52eda43f8ebafdbe6f47dc0e80efa77 Mon Sep 17 00:00:00 2001 From: Olivier Dion Date: Thu, 16 Feb 2023 15:34:26 -0500 Subject: [PATCH] Fix: Tests that assume CPU 0 is present MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Add util_event_generator.sh to shellcheck test while at it. Change-Id: I261452496827a5b9fc08b39a1132b13a39d0a7f5 Signed-off-by: Olivier Dion Signed-off-by: Jérémie Galarneau --- tests/meta/test_shellcheck | 1 + tests/regression/tools/clear/test_kernel | 7 ++++--- tests/regression/tools/clear/test_ust | 7 ++++--- .../tools/notification/util_event_generator.sh | 11 +++++++---- tests/regression/tools/snapshots/test_kernel | 4 ++-- tests/regression/ust/blocking/test_blocking | 7 ++++--- tests/utils/utils.sh | 10 ++++++++++ 7 files changed, 32 insertions(+), 15 deletions(-) diff --git a/tests/meta/test_shellcheck b/tests/meta/test_shellcheck index 3806dada1..29a3976d6 100755 --- a/tests/meta/test_shellcheck +++ b/tests/meta/test_shellcheck @@ -8,6 +8,7 @@ # All file must be relative to the test directory. files=( meta/test_shellcheck + regression/tools/notification/util_event_generator.sh run.sh ) diff --git a/tests/regression/tools/clear/test_kernel b/tests/regression/tools/clear/test_kernel index 0d27ec6c9..ce76f85d2 100755 --- a/tests/regression/tools/clear/test_kernel +++ b/tests/regression/tools/clear/test_kernel @@ -15,7 +15,8 @@ TRACE_PATH=$(mktemp -d -t tmp.test_clear_kernel_trace_path.XXXXXX) NUM_TESTS=837 -source $TESTDIR/utils/utils.sh +# shellcheck source=../utils/utils.sh +source "$TESTDIR/utils/utils.sh" function signal_cleanup () { @@ -488,7 +489,7 @@ function test_kernel_streaming_tracefile_rotation_overwrite_files () --tracefile-size=$PAGE_SIZE --tracefile-count=2 enable_kernel_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name start_lttng_tracing_ok $SESSION_NAME - taskset -c 0 echo -n "200000" > /proc/lttng-test-filter-event + taskset -c "$(get_any_available_cpu)" echo -n "200000" > /proc/lttng-test-filter-event do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after stop_lttng_tracing_ok $SESSION_NAME @@ -499,7 +500,7 @@ function test_kernel_streaming_tracefile_rotation_overwrite_files () fi start_lttng_tracing_ok $SESSION_NAME - taskset -c 0 echo -n "400000" > /proc/lttng-test-filter-event + taskset -c "$(get_any_available_cpu)" echo -n "400000" > /proc/lttng-test-filter-event stop_lttng_tracing_ok if [[ $rotate_before -eq 1 ]]; then diff --git a/tests/regression/tools/clear/test_ust b/tests/regression/tools/clear/test_ust index fadf0e952..519671ce3 100755 --- a/tests/regression/tools/clear/test_ust +++ b/tests/regression/tools/clear/test_ust @@ -21,7 +21,8 @@ NUM_TESTS=2071 PAGE_SIZE=$(getconf PAGE_SIZE) TRACE_PATH=$(mktemp -d -t tmp.test_clear_ust_trace_path.XXXXXX) -source $TESTDIR/utils/utils.sh +# shellcheck source=../utils/utils.sh +source "$TESTDIR/utils/utils.sh" if [ ! -x "$TESTAPP_BIN" ]; then BAIL_OUT "No UST events binary detected." @@ -752,7 +753,7 @@ function test_ust_streaming_tracefile_rotation_overwrite_files () --tracefile-size=$PAGE_SIZE --tracefile-count=2 --buffers-$buffer_type enable_ust_lttng_event_ok $SESSION_NAME $EVENT_NAME $channel_name start_lttng_tracing_ok $SESSION_NAME - taskset -c 0 $TESTAPP_BIN -i 200000 + taskset -c "$(get_any_available_cpu)" $TESTAPP_BIN -i 200000 do_clear_session $SESSION_NAME $tracing_active $clear_twice $rotate_before $rotate_after stop_lttng_tracing_ok $SESSION_NAME @@ -767,7 +768,7 @@ function test_ust_streaming_tracefile_rotation_overwrite_files () fi start_lttng_tracing_ok $SESSION_NAME - taskset -c 0 $TESTAPP_BIN -i 400000 + taskset -c "$(get_any_available_cpu)" $TESTAPP_BIN -i 400000 stop_lttng_tracing_ok if [[ $rotate_before -eq 1 ]]; then diff --git a/tests/regression/tools/notification/util_event_generator.sh b/tests/regression/tools/notification/util_event_generator.sh index 55189cf7c..bac089086 100644 --- a/tests/regression/tools/notification/util_event_generator.sh +++ b/tests/regression/tools/notification/util_event_generator.sh @@ -14,6 +14,9 @@ SYSCALL_TESTAPP_BIN=${SYSCALL_TESTAPP_BIN:-"$TESTAPP_PATH/$SYSCALL_TESTAPP_NAME/ USERSPACE_PROBE_ELF_TESTAPP_NAME=${USERSPACE_PROBE_ELF_TESTAPP_NAME:-"userspace-probe-elf-binary"} USERSPACE_PROBE_ELF_TESTAPP_BIN=${USERSPACE_PROBE_ELF_TESTAPP_BIN:-"$TESTAPP_PATH/$USERSPACE_PROBE_ELF_TESTAPP_NAME/.libs/$USERSPACE_PROBE_ELF_TESTAPP_NAME"} +# shellcheck source=../utils/utils.sh +source "$GENERATOR_TESTDIR/utils/utils.sh" + function generate_filter_events { local nr=$1 @@ -25,7 +28,7 @@ function generate_syscalls local nr=$1 shift - for i in $(seq 1 "$nr"); do + for _ in $(seq 1 "$nr"); do # Pass /dev/null so to generate the syscall right away. $SYSCALL_TESTAPP_BIN /dev/null "$@" done @@ -36,7 +39,7 @@ function userspace_probe_testapp local nr=$1 shift - for i in $(seq 1 "$nr"); do + for _ in $(seq 1 "$nr"); do # This userspace probe test has to instrument the actual elf # binary and not the generated libtool wrapper. However, we # can't invoke the wrapper either since it will re-link the test @@ -90,7 +93,7 @@ function ust_event_generator_run_once_per_transition run=true sleep 0.5 elif [ "$run" = true ]; then - taskset -c 0 "$test_app" -i "$nr_iter" -w "$nr_usec_wait" "$@"> /dev/null 2>&1 + taskset -c "$(get_any_available_cpu)" "$test_app" -i "$nr_iter" -w "$nr_usec_wait" "$@"> /dev/null 2>&1 run=false; if [[ -f $state_file ]]; then rm -rf "$state_file" 2> /dev/null @@ -127,7 +130,7 @@ function ust_event_generator # Reset the "run" state sleep 0.5 else - taskset -c 0 "$test_app" -i $nr_iter -w $nr_usec_wait "$@" > /dev/null 2>&1 + taskset -c "$(get_any_available_cpu)" "$test_app" -i $nr_iter -w $nr_usec_wait "$@" > /dev/null 2>&1 if [[ -f $state_file ]]; then rm -rf "$state_file" 2> /dev/null fi diff --git a/tests/regression/tools/snapshots/test_kernel b/tests/regression/tools/snapshots/test_kernel index e22a78a24..870c437b2 100755 --- a/tests/regression/tools/snapshots/test_kernel +++ b/tests/regression/tools/snapshots/test_kernel @@ -96,8 +96,8 @@ function test_kernel_local_snapshot_append_to_metadata () function generate_filter_events_cpu0() { - # Generate many events (fill buffers) on CPU 0 - taskset 0x00000001 /bin/echo -n "$1" > /proc/lttng-test-filter-event 2> /dev/null + # Generate many events (fill buffers) on a single CPU + taskset --cpu-list "$(get_any_available_cpu)" /bin/echo -n "$1" > /proc/lttng-test-filter-event 2> /dev/null } function test_kernel_local_snapshot_discard () diff --git a/tests/regression/ust/blocking/test_blocking b/tests/regression/ust/blocking/test_blocking index 9b36af23f..751b3453b 100755 --- a/tests/regression/ust/blocking/test_blocking +++ b/tests/regression/ust/blocking/test_blocking @@ -19,13 +19,14 @@ EVENT_NAME="tp:tptest" NUM_TESTS=49 -source $TESTDIR/utils/utils.sh +# shellcheck source=../utils/utils.sh +source "$TESTDIR/utils/utils.sh" # MUST set TESTDIR before calling those functions -# Run app on CPU 0 to ensure we only write in a single ring buffer. +# Run app on a single CPU to ensure we only write in a single ring buffer. function run_app() { - taskset 0x00000001 $TESTAPP_BIN -i $NUM_EVENT + taskset --cpu-list "$(get_any_available_cpu)" $TESTAPP_BIN -i $NUM_EVENT ok $? "Application done" } diff --git a/tests/utils/utils.sh b/tests/utils/utils.sh index a6f9a8b6c..9ffcc6ff2 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -282,6 +282,16 @@ function get_exposed_cpus_list() echo "${list[@]}" } +# Return any available CPU found. Do not make assumption about the returned +# value, e.g. that it could be 0. +function get_any_available_cpu() +{ + for cpu in /sys/devices/system/cpu/cpu[0-9]*; do + echo "${cpu#/sys/devices/system/cpu/cpu}" + break; + done +} + # Return the number of _configured_ CPUs. function conf_proc_count() { -- 2.34.1