Skip to contentSkip to conversation

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

PATCH Superseded [email protected] 2 participants 3 messages Jun 5, 2023 GPIO

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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 | 26 ++++++++++++++++++++------
 1 file changed, 20 insertions(+), 6 deletions(-)
tools/gpio-tools-test.bats +20 -6
index c83ca7d..f7a0e38 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
@@ -154,7 +168,7 @@ gpiosim_cleanup() {
 		ls $BANKPATH/line* > /dev/null 2>&1
 		if [ "$?" = "0" ]
 		then
-			for LINE in $(find $BANKPATH/ | grep -E "line[0-9]+$")
+			for LINE in $(find $BANKPATH/ | egrep "line[0-9]+$")
 			do
 				test -e $LINE/hog && rmdir $LINE/hog
 				rmdir $LINE
@@ -1567,15 +1581,15 @@ request_release_line() {
 	gpiosim_check_value sim0 4 0
 	gpiosim_check_value sim0 7 0
 
-	sleep 1
-
-	gpiosim_check_value sim0 1 0
+	# sleeping fixed amounts can be unreliable, so we
+	# sync to the toggles
+	#
+	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

Mon, Jun 05, 2023 at 12:00:51PM -0700, [email protected] kirjoitti:

Quoted 7 lines

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 gpiosim_check_value() { · line 151

Quoted 8 lines
tools/gpio-tools-test.bats +8 -0
+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

Do you need space before semicolon?

Quoted 5 lines
tools/gpio-tools-test.bats +5 -0
+		[ "$(<$PORT)" = "$EXPECTED" ] && return
+		sleep 0.1
+	done
+	return 1
+}

...

tools/gpio-tools-test.bats gpiosim_cleanup() { · line 171

Quoted 2 lines
tools/gpio-tools-test.bats +1 -1
-			for LINE in $(find $BANKPATH/ | grep -E "line[0-9]+$")
+			for LINE in $(find $BANKPATH/ | egrep "line[0-9]+$")

Seems stray change.

Signature · 2 lines
With Best Regards,
Andy Shevchenko
#2 lore raw
Quoted 42 lines

-----Original Message-----
From: [email protected] <[email protected]>
Sent: Monday, June 5, 2023 1:04 PM
To: Slater, Joseph <[email protected]>
Cc: [email protected]; MacLeod, Randy <[email protected]>
Subject: Re: [v2][libgpiod][PATCH 1/1] gpio-tools-test.bats: modify delays in toggle test

Mon, Jun 05, 2023 at 12:00:51PM -0700, [email protected] kirjoitti:

Quoted 7 lines

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 gpiosim_check_value() {

Quoted 6 lines
tools/gpio-tools-test.bats +6 -0
+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

tools/gpio-tools-test.bats gpiosim_check_value() { · line 151

Quoted 2 lines
tools/gpio-tools-test.bats +2 -0
+
+	for i in {1..15} ; do

Do you need space before semicolon?

Quoted 5 lines
tools/gpio-tools-test.bats +5 -0
+		[ "$(<$PORT)" = "$EXPECTED" ] && return
+		sleep 0.1
+	done
+	return 1
+}

...

Quoted 4 lines

tools/gpio-tools-test.bats gpiosim_cleanup() { · line 171

Quoted 2 lines
tools/gpio-tools-test.bats +1 -1
-			for LINE in $(find $BANKPATH/ | grep -E "line[0-9]+$")
+			for LINE in $(find $BANKPATH/ | egrep "line[0-9]+$")

Seems stray change.

[Slater, Joseph]
The extra space is not necessary. I removed it. Putting egrep back was a mistake. I'll send a V3 in a few minutes.

Joe

Quoted 5 lines

--
With Best Regards,
Andy Shevchenko