lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [day] [month] [year] [list]
Message-ID: <20251031202226.7148-1-vseokaktusah7@gmail.com>
Date: Fri, 31 Oct 2025 23:22:26 +0300
From: zntsproj <vacacax16@...il.com>
To: linux-kernel@...r.kernel.org
Cc: bamv2005@...il.com,
	shuah@...nel.org,
	linux-gpio@...r.kernel.org,
	linux-kselftest@...r.kernel.org,
	zntsproj <vseokaktusah7@...il.com>
Subject: [PATCH] gpio-selftests: replace fixed sleep with polling+timeout

Replace the hard-coded sleep 0.1 with a polling loop with timeout
to check the sysfs GPIO value. This avoids timing-dependent
flaky failures in CI and on slower machines.
---
 .../testing/selftests/gpio/gpio-aggregator.sh | 59 +++++++++++++++----
 1 file changed, 46 insertions(+), 13 deletions(-)

diff --git a/tools/testing/selftests/gpio/gpio-aggregator.sh b/tools/testing/selftests/gpio/gpio-aggregator.sh
index 9b6f80ad9..1e81e62e9 100755
--- a/tools/testing/selftests/gpio/gpio-aggregator.sh
+++ b/tools/testing/selftests/gpio/gpio-aggregator.sh
@@ -671,26 +671,59 @@ teardown_4() {
 	agg_configfs_cleanup
 }
 
+# helper: wait for sysfs file to become a given value (timeout in seconds)
+wait_for_sysfs_value() {
+    file="$1"
+    expected="$2"
+    timeout="${3:-2}"   # seconds
+    interval="0.01"     # seconds per poll
+    max=$((timeout * 100))
+    i=0
+
+    while [ "$i" -lt "$max" ]; do
+        if [ "$(cat "$file")" = "$expected" ]; then
+            return 0
+        fi
+        sleep "$interval"
+        i=$((i + 1))
+    done
+
+    return 1
+}
+
 echo "4.1. Forwarding set values"
 setup_4
 OFFSET=0
 for SETTING in $SETTINGS; do
-	CHIP=$(echo "$SETTING" | cut -d: -f1)
-	BANK=$(echo "$SETTING" | cut -d: -f2)
-	LINE=$(echo "$SETTING" | cut -d: -f3)
-	DEVNAME=$(cat "$CONFIGFS_SIM_DIR/$CHIP/dev_name")
-	CHIPNAME=$(cat "$CONFIGFS_SIM_DIR/$CHIP/$BANK/chip_name")
-	VAL_PATH="/sys/devices/platform/$DEVNAME/$CHIPNAME/sim_gpio${LINE}/value"
-	test $(cat $VAL_PATH) = "0" || fail "incorrect value read from sysfs"
-	$BASE_DIR/gpio-mockup-cdev -s 1 "/dev/$(agg_configfs_chip_name agg0)" "$OFFSET" &
-	mock_pid=$!
-	sleep 0.1 # FIXME Any better way?
-	test "$(cat $VAL_PATH)" = "1" || fail "incorrect value read from sysfs"
-	kill "$mock_pid"
-	OFFSET=$(expr $OFFSET + 1)
+    CHIP=$(echo "$SETTING" | cut -d: -f1)
+    BANK=$(echo "$SETTING" | cut -d: -f2)
+    LINE=$(echo "$SETTING" | cut -d: -f3)
+    DEVNAME=$(cat "$CONFIGFS_SIM_DIR/$CHIP/dev_name")
+    CHIPNAME=$(cat "$CONFIGFS_SIM_DIR/$CHIP/$BANK/chip_name")
+    VAL_PATH="/sys/devices/platform/$DEVNAME/$CHIPNAME/sim_gpio${LINE}/value"
+
+    test "$(cat "$VAL_PATH")" = "0" || fail "incorrect value read from sysfs"
+
+    $BASE_DIR/gpio-mockup-cdev -s 1 "/dev/$(agg_configfs_chip_name agg0)" "$OFFSET" &
+    mock_pid=$!
+
+    # wait up to 2s for value to flip to "1"
+    if ! wait_for_sysfs_value "$VAL_PATH" "1" 2; then
+        kill "$mock_pid" 2>/dev/null || true
+        wait "$mock_pid" 2>/dev/null || true
+        fail "timeout waiting for $VAL_PATH to become 1"
+    fi
+
+    test "$(cat "$VAL_PATH")" = "1" || fail "incorrect value read from sysfs"
+
+    kill "$mock_pid" 2>/dev/null || true
+    wait "$mock_pid" 2>/dev/null || true
+
+    OFFSET=$((OFFSET + 1))
 done
 teardown_4
 
+
 echo "4.2. Forwarding set config"
 setup_4
 OFFSET=0
-- 
2.51.2


Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ