public inbox for linux-gpio@vger.kernel.org
 help / color / mirror / Atom feed
* [libgpiod][PATCH 1/1] gpio-tools-test.bats: modify delays in toggle test
@ 2023-05-24 21:09 joe.slater
  2023-05-25  3:53 ` Kent Gibson
  0 siblings, 1 reply; 14+ messages in thread
From: joe.slater @ 2023-05-24 21:09 UTC (permalink / raw)
  To: linux-gpio; +Cc: joe.slater, randy.macleod

From: Joe Slater <joe.slater@windriver.com>

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.

Signed-off-by: Joe Slater <joe.slater@windriver.com>
---
 tools/gpio-tools-test.bats | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/tools/gpio-tools-test.bats b/tools/gpio-tools-test.bats
index adbce94..977d718 100755
--- a/tools/gpio-tools-test.bats
+++ b/tools/gpio-tools-test.bats
@@ -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]}
+
+	for i in {1..10} ; do
+		VAL=$(<$GPIOSIM_SYSFS/$DEVNAME/$CHIPNAME/sim_gpio$OFFSET/value)
+		[ "$VAL" = "$EXPECTED" ] && return
+		sleep 0.1
+	done
+	return 1
+}
+
 gpiosim_cleanup() {
 	for CHIP in ${!GPIOSIM_CHIP_NAME[@]}
 	do
@@ -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
 }
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2023-06-01 14:54 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-05-24 21:09 [libgpiod][PATCH 1/1] gpio-tools-test.bats: modify delays in toggle test joe.slater
2023-05-25  3:53 ` Kent Gibson
2023-05-25 21:54   ` Slater, Joseph
2023-05-26  0:24     ` Kent Gibson
2023-05-30  9:51     ` Bartosz Golaszewski
2023-05-30 10:04       ` Kent Gibson
2023-05-30 14:13         ` Bartosz Golaszewski
2023-05-30 14:24           ` Kent Gibson
2023-05-30 14:52             ` Bartosz Golaszewski
2023-05-30 15:18               ` Kent Gibson
2023-05-30 16:07                 ` Bartosz Golaszewski
2023-05-31  1:17                   ` Kent Gibson
2023-06-01 13:16                     ` Bartosz Golaszewski
2023-06-01 14:53                       ` Bartosz Golaszewski

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox