From: Olivier Dion Date: Thu, 16 Feb 2023 20:34:26 +0000 (-0500) Subject: Fix: Tests that assume CPU 0 is present X-Git-Tag: v2.12.14~3 X-Git-Url: https://git.lttng.org./?a=commitdiff_plain;h=fe1c64c5d431a7944bd68fb7b0e7e4e86058baa0;p=lttng-tools.git Fix: Tests that assume CPU 0 is present 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 --- diff --git a/tests/regression/tools/clear/test_kernel b/tests/regression/tools/clear/test_kernel index 2fbddb84c..3386ebc42 100755 --- a/tests/regression/tools/clear/test_kernel +++ b/tests/regression/tools/clear/test_kernel @@ -15,7 +15,8 @@ TRACE_PATH=$(mktemp -d) 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 04b713909..f825e6321 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) -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." @@ -754,7 +755,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 @@ -769,7 +770,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/test_notification_multi_app b/tests/regression/tools/notification/test_notification_multi_app index 9468d0a0d..1e94f4441 100755 --- a/tests/regression/tools/notification/test_notification_multi_app +++ b/tests/regression/tools/notification/test_notification_multi_app @@ -86,7 +86,7 @@ function ust_event_generator if [[ -f $state_file ]]; then rm $state_file 2> /dev/null fi - taskset -c 0 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT > /dev/null 2>&1 + taskset -c "$(get_any_available_cpu)" $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT > /dev/null 2>&1 fi done } diff --git a/tests/regression/tools/notification/test_notification_ust b/tests/regression/tools/notification/test_notification_ust index 57ae52cbd..f963bd0ce 100755 --- a/tests/regression/tools/notification/test_notification_ust +++ b/tests/regression/tools/notification/test_notification_ust @@ -53,7 +53,7 @@ function ust_event_generator if [[ -f $state_file ]]; then rm -rf $state_file 2> /dev/null fi - taskset -c 0 $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT > /dev/null 2>&1 + taskset -c "$(get_any_available_cpu)" $TESTAPP_BIN -i $NR_ITER -w $NR_USEC_WAIT > /dev/null 2>&1 fi done } diff --git a/tests/regression/tools/snapshots/test_kernel b/tests/regression/tools/snapshots/test_kernel index 75de4ed45..892784e61 100755 --- a/tests/regression/tools/snapshots/test_kernel +++ b/tests/regression/tools/snapshots/test_kernel @@ -104,7 +104,7 @@ function true_loop_cpu0() { # Generate many system call events (fill buffers) on CPU 0 for a in $(seq 1 $1); do - taskset 0x00000001 /bin/true; + taskset --cpu-list "$(get_any_available_cpu)" /bin/true; done } diff --git a/tests/regression/ust/blocking/test_blocking b/tests/regression/ust/blocking/test_blocking index abd50d459..fcf1ad94d 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 09c4ae28d..89624a421 100644 --- a/tests/utils/utils.sh +++ b/tests/utils/utils.sh @@ -198,6 +198,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() {