Linux GPIO subsystem development
 help / color / mirror / Atom feed
* [PATCH libgpiod 0/2] dbus: client: tests: fix racy gpiocli monitor tests
@ 2026-11-25  8:00 Khem Raj
  2026-11-25  8:00 ` [PATCH libgpiod 1/2] dbus: client: tests: wait for each event in test_monitor_all_lines_on_request Khem Raj
  2026-11-25  8:00 ` [PATCH libgpiod 2/2] dbus: client: tests: wait for each event in test_monitor_multiple_lines_by_name Khem Raj
  0 siblings, 2 replies; 3+ messages in thread
From: Khem Raj @ 2026-11-25  8:00 UTC (permalink / raw)
  To: linux-gpio; +Cc: Khem Raj, Bartosz Golaszewski

From: Khem Raj <khem.raj@oss.qualcomm.com>

test_monitor_all_lines_on_request and test_monitor_multiple_lines_by_name
toggle one line twice, with another line in between, before reading the
monitor output. gpio-sim can deliver both changes of the first line as
one interrupt, the rising edge is lost and the tests fail intermittently.
These two patches make the tests wait for each event before triggering
the next one.

Running gpiocli-test.bash in a qemux86-64 guest (kernel 7.2.15) whose
vCPUs were pinned to one host CPU and kept busy, it failed in 7 of 10
runs without these patches (both tests fail) and passed 10 of 10 runs
with them. Without the CPU contention both variants passed 30 of 30 runs.

Khem Raj (2):
  dbus: client: tests: wait for each event in
    test_monitor_all_lines_on_request
  dbus: client: tests: wait for each event in
    test_monitor_multiple_lines_by_name

 dbus/client/gpiocli-test.bash | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)


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

* [PATCH libgpiod 1/2] dbus: client: tests: wait for each event in test_monitor_all_lines_on_request
  2026-11-25  8:00 [PATCH libgpiod 0/2] dbus: client: tests: fix racy gpiocli monitor tests Khem Raj
@ 2026-11-25  8:00 ` Khem Raj
  2026-11-25  8:00 ` [PATCH libgpiod 2/2] dbus: client: tests: wait for each event in test_monitor_multiple_lines_by_name Khem Raj
  1 sibling, 0 replies; 3+ messages in thread
From: Khem Raj @ 2026-11-25  8:00 UTC (permalink / raw)
  To: linux-gpio; +Cc: Khem Raj, Bartosz Golaszewski

The test pulls line 1 up, line 4 up and line 1 down again in quick
succession and only then reads the monitor output. gpio-sim raises the
line interrupts through irq_sim, so two changes of the same line that
happen before the interrupt is handled are delivered as one interrupt,
and as edge detection is set to both edges the kernel derives the edge
type from the line value read in the handler. The rising edge on line 1
is then lost and only a falling edge is reported, timestamped after the
rising edge on line 4:

  ASSERT: '41610700648 falling "foo" 41610665414 rising  4' did not
  match '[0-9]+ rising\s+"foo"'

This fails intermittently, in 12 of 20 runs in a qemux86-64 guest.

Wait for each event before triggering the next one, like the gpiomon
tests in gpio-tools-test.bash do.

Fixes: a5ab76da1e0a ("dbus: add the D-Bus daemon, command-line client and tests")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Khem Raj <raj.khem@gmail.com>
---
 dbus/client/gpiocli-test.bash | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/dbus/client/gpiocli-test.bash b/dbus/client/gpiocli-test.bash
index 5160f57..ede69c9 100755
--- a/dbus/client/gpiocli-test.bash
+++ b/dbus/client/gpiocli-test.bash
@@ -1421,13 +1421,13 @@ test_monitor_all_lines_on_request() {
 	dut_run gpiocli monitor -r "$request"
 
 	gpiosim_set_pull sim0 1 pull-up
+	dut_regex_match "[0-9]+ rising\\s+\"foo\""
+
 	gpiosim_set_pull sim0 4 pull-up
-	gpiosim_set_pull sim0 1 pull-down
+	dut_regex_match "[0-9]+ rising\\s+4"
 
-	dut_read
-	output_regex_match "[0-9]+ rising\\s+\"foo\""
-	output_regex_match "[0-9]+ rising\\s+4"
-	output_regex_match "[0-9]+ falling\\s+\"foo\""
+	gpiosim_set_pull sim0 1 pull-down
+	dut_regex_match "[0-9]+ falling\\s+\"foo\""
 
 	gpiodbus_release_request "$request"
 }

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

* [PATCH libgpiod 2/2] dbus: client: tests: wait for each event in test_monitor_multiple_lines_by_name
  2026-11-25  8:00 [PATCH libgpiod 0/2] dbus: client: tests: fix racy gpiocli monitor tests Khem Raj
  2026-11-25  8:00 ` [PATCH libgpiod 1/2] dbus: client: tests: wait for each event in test_monitor_all_lines_on_request Khem Raj
@ 2026-11-25  8:00 ` Khem Raj
  1 sibling, 0 replies; 3+ messages in thread
From: Khem Raj @ 2026-11-25  8:00 UTC (permalink / raw)
  To: linux-gpio; +Cc: Khem Raj, Bartosz Golaszewski

From: Khem Raj <khem.raj@oss.qualcomm.com>

The test pulls line foo up, line xyz up and line foo down again in quick
succession and only then reads the monitor output, which is the same
race test_monitor_all_lines_on_request had. Two changes of the same line
that happen before the gpio-sim interrupt is handled are delivered as
one interrupt, and as edge detection is set to both edges the kernel
derives the edge type from the line value read in the handler. The
rising edge on foo is then lost and only a falling edge is reported,
timestamped after the rising edge on xyz:

  ASSERT: '45056166795 falling "foo" 45056147828 rising  "xyz"' did not
  match '[0-9]+ rising\s+"foo"'

This fails intermittently, in 13 of 20 runs in a qemux86-64 guest.

Wait for each event before triggering the next one. Matching the next
line of output instead of searching all of it also makes the test
verify that the change of line bar, which is not monitored, is ignored.

Fixes: a5ab76da1e0a ("dbus: add the D-Bus daemon, command-line client and tests")
Assisted-by: Claude:claude-opus-5-5
Signed-off-by: Khem Raj <khem.raj@oss.qualcomm.com>
---
 dbus/client/gpiocli-test.bash | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/dbus/client/gpiocli-test.bash b/dbus/client/gpiocli-test.bash
index ede69c9..ebddcbf 100755
--- a/dbus/client/gpiocli-test.bash
+++ b/dbus/client/gpiocli-test.bash
@@ -1376,14 +1376,14 @@ test_monitor_multiple_lines_by_name() {
 	dut_run gpiocli monitor foo xyz
 
 	gpiosim_set_pull sim0 1 pull-up
+	dut_regex_match "[0-9]+ rising\\s+\"foo\""
+
 	gpiosim_set_pull sim0 5 pull-up # This should be ignored
 	gpiosim_set_pull sim0 11 pull-up
-	gpiosim_set_pull sim0 1 pull-down
+	dut_regex_match "[0-9]+ rising\\s+\"xyz\""
 
-	dut_read
-	output_regex_match "[0-9]+ rising\\s+\"foo\""
-	output_regex_match "[0-9]+ rising\\s+\"xyz\""
-	output_regex_match "[0-9]+ falling\\s+\"foo\""
+	gpiosim_set_pull sim0 1 pull-down
+	dut_regex_match "[0-9]+ falling\\s+\"foo\""
 
 	gpiodbus_release_request "$request"
 }

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

end of thread, other threads:[~2026-11-25  8:00 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25  8:00 [PATCH libgpiod 0/2] dbus: client: tests: fix racy gpiocli monitor tests Khem Raj
2026-11-25  8:00 ` [PATCH libgpiod 1/2] dbus: client: tests: wait for each event in test_monitor_all_lines_on_request Khem Raj
2026-11-25  8:00 ` [PATCH libgpiod 2/2] dbus: client: tests: wait for each event in test_monitor_multiple_lines_by_name Khem Raj

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