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>
Thu, 16 Mar 2023 15:05:53 +0000 (11:05 -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/meta/test_shellcheck
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 3806dada19093aa1c29a25773e746505507a87be..29a3976d6fe39fe2ffe6ef6c598a20226b5b178d 100755 (executable)
@@ -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
 )
 
index 0d27ec6c9470064726454aa120c6d43b1ec2e845..ce76f85d24102c4ac85ed34cf41f1959331de2a8 100755 (executable)
@@ -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
index fadf0e952ea5427165527805f3cc76edcb8c8ec4..519671ce39c0fe7487cf673af1e097d0f2579f26 100755 (executable)
@@ -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
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 e22a78a247c873b8037b725231b9b0fd94836110..870c437b217fc2ed0eb339628fff428e220312fd 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 9b36af23f8e3818d2041297b63c37fc27a3df410..751b3453b50d7e264e6dd411b96407389931bf1c 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 a6f9a8b6c05cad9b0d5c6dd20ccc5d64792d3b71..9ffcc6ff29e072c03bf1571ec10036126f6f9c42 100644 (file)
@@ -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()
 {
This page took 0.03041 seconds and 4 git commands to generate.