Skip to contentSkip to conversation

gpio-tools-test.bats: modify delays in toggle test

PATCH In review [email protected] 2 participants 2 messages Jun 6, 2023 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/1 gpio-tools-test.bats: modify delays in toggle test

From: Joe Slater <[email protected]>

The test "gpioset: toggle (continuous)" uses fixed delays to test toggling values. This is not reliable, so we switch to looking for transitions from one value to another.

We wait for a transition up to 1.5 seconds.

---
 tools/gpio-tools-test.bats | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
tools/gpio-tools-test.bats +16 -5
index c83ca7d..929c35a 100755
@@ -141,6 +141,20 @@ gpiosim_check_value() {
 	[ "$VAL" = "$EXPECTED" ]
 }
 
+gpiosim_wait_value() {
+	local OFFSET=$2
+	local EXPECTED=$3
+	local DEVNAME=${GPIOSIM_DEV_NAME[$1]}
+	local CHIPNAME=${GPIOSIM_CHIP_NAME[$1]}
+	local PORT=$GPIOSIM_SYSFS/$DEVNAME/$CHIPNAME/sim_gpio$OFFSET/value
+
+	for i in {1..15}; do
+		[ "$(<$PORT)" = "$EXPECTED" ] && return
+		sleep 0.1
+	done
+	return 1
+}
+
 gpiosim_cleanup() {
 	for CHIP in ${!GPIOSIM_CHIP_NAME[@]}
 	do
@@ -1567,15 +1581,12 @@ request_release_line() {
 	gpiosim_check_value sim0 4 0
 	gpiosim_check_value sim0 7 0
 
-	sleep 1
-
-	gpiosim_check_value sim0 1 0
+	gpiosim_wait_value sim0 1 0
 	gpiosim_check_value sim0 4 1
 	gpiosim_check_value sim0 7 1
 
-	sleep 1
 
-	gpiosim_check_value sim0 1 1
+	gpiosim_wait_value sim0 1 1
 	gpiosim_check_value sim0 4 0
 	gpiosim_check_value sim0 7 0
 }
Signature · 1 line
2.25.1
#1 lore raw
Quoted 58 lines · On Tue, Jun 6, 2023 at 5:04 PM <[email protected]> wrote:

From: Joe Slater <[email protected]>

The test "gpioset: toggle (continuous)" uses fixed delays to test toggling values. This is not reliable, so we switch to looking for transitions from one value to another.

We wait for a transition up to 1.5 seconds.

---
 tools/gpio-tools-test.bats | 21 ++++++++++++++++-----
 1 file changed, 16 insertions(+), 5 deletions(-)
tools/gpio-tools-test.bats +16 -6
index c83ca7d..929c35a 100755
@@ -141,6 +141,20 @@ gpiosim_check_value() {
        [ "$VAL" = "$EXPECTED" ]
 }
 
+gpiosim_wait_value() {
+       local OFFSET=$2
+       local EXPECTED=$3
+       local DEVNAME=${GPIOSIM_DEV_NAME[$1]}
+       local CHIPNAME=${GPIOSIM_CHIP_NAME[$1]}
+       local PORT=$GPIOSIM_SYSFS/$DEVNAME/$CHIPNAME/sim_gpio$OFFSET/value
+
+       for i in {1..15}; do
+               [ "$(<$PORT)" = "$EXPECTED" ] && return
+               sleep 0.1
+       done
+       return 1
+}
+
 gpiosim_cleanup() {
        for CHIP in ${!GPIOSIM_CHIP_NAME[@]}
        do
@@ -1567,15 +1581,12 @@ request_release_line() {
        gpiosim_check_value sim0 4 0
        gpiosim_check_value sim0 7 0
 
-       sleep 1
-
-       gpiosim_check_value sim0 1 0
+       gpiosim_wait_value sim0 1 0
        gpiosim_check_value sim0 4 1
        gpiosim_check_value sim0 7 1
 
-       sleep 1
 
-       gpiosim_check_value sim0 1 1
+       gpiosim_wait_value sim0 1 1
        gpiosim_check_value sim0 4 0
        gpiosim_check_value sim0 7 0
 }
--
Quoted 2 lines

2.25.1

I responded to the wrong email. I applied this one and tweaked the commit message.

Bart