Fix: tests: don't assume sequential cpuids
authorMichael Jeanson <mjeanson@efficios.com>
Tue, 9 Aug 2022 15:38:16 +0000 (15:38 +0000)
committerJérémie Galarneau <jeremie.galarneau@efficios.com>
Fri, 19 Aug 2022 15:18:35 +0000 (11:18 -0400)
On Linux CPU ids aren't sequential if a CPU is offlined or unplugged.
Get the list of currently available CPU ids from sysfs and pick a random
one, if sysfs is not available use the previous behavior.

Signed-off-by: Michael Jeanson <mjeanson@efficios.com>
Signed-off-by: Jérémie Galarneau <jeremie.galarneau@efficios.com>
Change-Id: Ibdb63c7d036389104ac2f629827a6dce59e06983

tests/regression/tools/tracefile-limits/test_tracefile_count

index eb5d1a5f13c146aa78771414112d139f2c141bc9..37d15905acbbe148b6e0f1e25c307f0b44d05df1 100755 (executable)
@@ -17,16 +17,37 @@ TESTAPP_BIN="$TESTAPP_PATH/$TESTAPP_NAME/$TESTAPP_NAME"
 STATS_BIN="$TESTDIR/utils/babelstats.pl"
 NUM_TESTS=74
 
-NUM_CPUS=$(nproc)
 PAGE_SIZE=$(getconf PAGE_SIZE)
 TRACEFILE_SIZE=$PAGE_SIZE
 
 source "$TESTDIR"/utils/utils.sh
 
+NUM_CPUS=$(conf_proc_count)
+
 if [ ! -x "$TESTAPP_BIN" ]; then
        BAIL_OUT "No UST events binary detected."
 fi
 
+function pick_random_cpuid ()
+{
+        local cpuid=0
+
+        # On Linux pick a random available cpuid from sysfs
+        if [ -d "/sys/devices/system/cpu" ]; then
+                local cpuids=()
+
+                for i in /sys/devices/system/cpu/cpu[0-9]*; do
+                        cpuids+=("${i#/sys/devices/system/cpu/cpu}")
+                done
+
+                cpuid=${cpuids[ $RANDOM % ${#cpuids[@]} ]}
+        else
+                cpuid=$((RANDOM % NUM_CPUS))
+        fi
+
+        echo $cpuid
+}
+
 function enable_lttng_channel_count_limit ()
 {
        sess_name="$1"
@@ -82,7 +103,7 @@ function test_tracefile_count_limit ()
        local count_limit="$1"
 
        local channel_name="channel"
-       local cpuno=$((RANDOM % NUM_CPUS))
+       local cpuno=$(pick_random_cpuid)
        local event_name="tp:tptest"
        local expected_size=$((count_limit * TRACEFILE_SIZE))
        local num_iter=100000
This page took 0.027814 seconds and 4 git commands to generate.