diff mbox series

[libgpiod] dbus: client: tests: fix the way we wait for simulated chips to appear

Message ID 20250203-fix-dbus-wait-for-chip-v1-1-563f7132c04f@linaro.org
State New
Headers show
Series [libgpiod] dbus: client: tests: fix the way we wait for simulated chips to appear | expand

Commit Message

Bartosz Golaszewski Feb. 3, 2025, 5:20 p.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>

The org.freedesktop.DBus.Peer.Ping() method isn't correct for checking
if a given object is exposed by a service. It only lets us know if the
service is available no matter the object on which it's called (in fact:
it will not return an error even if it's called on a nonexistent object).

While this has worked for most part by accident, if the timing isn't
right, we may start calling methods in chips which are not yet fully
registered. We should try to read the chip's property instead and keep
on waiting for as long as org.freedesktop.DBus.Properties.Get() returns
an error.

While at it: fix the counter increment as its syntax is invalid.

Fixes: a5ab76da1e0a ("dbus: add the D-Bus daemon, command-line client and tests")
Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>
---
 dbus/client/gpiocli-test.bash | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)


---
base-commit: d6457b28e29a8edadcb619d389878ea99cd4bab4
change-id: 20250203-fix-dbus-wait-for-chip-49e36ad58ee2

Best regards,

Comments

Bartosz Golaszewski Feb. 5, 2025, 1:35 p.m. UTC | #1
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org>


On Mon, 03 Feb 2025 18:20:27 +0100, Bartosz Golaszewski wrote:
> The org.freedesktop.DBus.Peer.Ping() method isn't correct for checking
> if a given object is exposed by a service. It only lets us know if the
> service is available no matter the object on which it's called (in fact:
> it will not return an error even if it's called on a nonexistent object).
> 
> While this has worked for most part by accident, if the timing isn't
> right, we may start calling methods in chips which are not yet fully
> registered. We should try to read the chip's property instead and keep
> on waiting for as long as org.freedesktop.DBus.Properties.Get() returns
> an error.
> 
> [...]

Applied, thanks!

[1/1] dbus: client: tests: fix the way we wait for simulated chips to appear
      commit: f52874b19beab4d0a1cfc076f7a0eb7d6df5d1e1

Best regards,
diff mbox series

Patch

diff --git a/dbus/client/gpiocli-test.bash b/dbus/client/gpiocli-test.bash
index f210183..1d2337d 100755
--- a/dbus/client/gpiocli-test.bash
+++ b/dbus/client/gpiocli-test.bash
@@ -14,11 +14,11 @@  wait_for_sim() {
 
 	while true
 	do
-		gdbus call --system --dest io.gpiod1 \
-			--object-path /io/gpiod1/chips/"$1" \
-			--method org.freedesktop.DBus.Peer.Ping > /dev/null 2>&1 && break
+		gdbus call --system --dest io.gpiod1 --object-path /io/gpiod1/chips/"$1" \
+			--method org.freedesktop.DBus.Properties.Get \
+			io.gpiod1.Chip Label > /dev/null 2>&1 && break
 		sleep 0.01
-		COUNTER=$($COUNTER - 1)
+		COUNTER=$(expr $COUNTER - 1)
 		if [ "$COUNTER" -eq 0 ]
 		then
 			fail "error waiting for the GPIO sim chip to be exported on the bus"