Fix: Tests that assume CPU 0 is present
authorOlivier Dion <odion@efficios.com>
Thu, 16 Feb 2023 20:34:26 +0000 (15:34 -0500)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Wed, 31 May 2023 21:24:18 +0000 (17:24 -0400)
Add util_event_generator.sh to shellcheck test while at it.

Change-Id: I261452496827a5b9fc08b39a1132b13a39d0a7f5
Signed-off-by: Olivier Dion <odion@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
tests/regression/tools/clear/test_kernel
tests/regression/tools/clear/test_ust
tests/regression/tools/notification/util_event_generator.sh
tests/regression/tools/snapshots/test_kernel
tests/regression/ust/blocking/test_blocking
tests/utils/utils.sh

index c12a153c52dac980814981c97cddbaeed4b00b1b..06fb1c368488c358e2e07bc779b85402225ad668 100755 (executable)
@@ -15,7 +15,8 @@ TRACE_PATH=$(mktemp --tmpdir -d 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
index 81ccb000685c97b352e8cae28661880042ee3b57..efff8fcee8dc5b40c872939b37149f5afe301370 100755 (executable)
@@ -21,7 +21,8 @@ NUM_TESTS=2071
 PAGE_SIZE=$(getconf PAGE_SIZE)
 TRACE_PATH=$(mktemp --tmpdir -d 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
index 55189cf7cec217e88b7f2d3d5c364a79666aaff9..bac089086444c7453301f65a8337c131c6f4067c 100644 (file)
@@ -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
index 5c93296a03a2f8b7a440f1bd9aeacba6c1c8377f..abb2435631c3fd25d603d94ccaa7835275f3ecc4 100755 (executable)
@@ -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 ()
index 617d9a27833a901273735b255dabee9d29faaf78..f6c465d6e1d345097391b35f86c58c915757b670 100755 (executable)
@@ -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"
 }
 
index db1a307afb69ae07426b01b9bdce8358cffd7652..949ed131138865dc5c45e28be0e3984e28d110fe 100644 (file)
@@ -277,6 +277,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()
 {
This page took 0.028772 seconds and 4 git commands to generate.