* [LTP] [PATCH] input_common.h: Add retry loop for event device
@ 2025-02-27 18:05 Edward Liaw via ltp
2025-02-28 11:05 ` Cyril Hrubis
0 siblings, 1 reply; 2+ messages in thread
From: Edward Liaw via ltp @ 2025-02-27 18:05 UTC (permalink / raw)
To: ltp; +Cc: kernel-team
Android has a delay between the entry in /proc/bus/input/devices and the
path /dev/input/eventN becoming accessible. Add a 1s retry loop to
account for this.
Signed-off-by: Edward Liaw <edliaw@google.com>
---
testcases/kernel/input/input_common.h | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/testcases/kernel/input/input_common.h b/testcases/kernel/input/input_common.h
index 0ac1624b3..06fba753e 100644
--- a/testcases/kernel/input/input_common.h
+++ b/testcases/kernel/input/input_common.h
@@ -29,9 +29,12 @@ static inline int open_event_device(void)
memset(path, 0, sizeof(path));
snprintf(path, sizeof(path), "/dev/input/%s", device);
- if (!access(path, F_OK)) {
- tst_res(TINFO, "Found event device: %s", path);
- break;
+ for (int i = 100 ; i > 0 ; i--) {
+ if (!access(path, F_OK)) {
+ tst_res(TINFO, "Found event device: %s", path);
+ break;
+ }
+ usleep(10000);
}
}
--
2.48.1.711.g2feabab25a-goog
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [LTP] [PATCH] input_common.h: Add retry loop for event device
2025-02-27 18:05 [LTP] [PATCH] input_common.h: Add retry loop for event device Edward Liaw via ltp
@ 2025-02-28 11:05 ` Cyril Hrubis
0 siblings, 0 replies; 2+ messages in thread
From: Cyril Hrubis @ 2025-02-28 11:05 UTC (permalink / raw)
To: Edward Liaw; +Cc: kernel-team, ltp
Hi!
> + for (int i = 100 ; i > 0 ; i--) {
> + if (!access(path, F_OK)) {
> + tst_res(TINFO, "Found event device: %s", path);
> + break;
> + }
> + usleep(10000);
We do have a TST_RETRY_FUNC() in include/tst_common.h that is slightly
smarter than this loop and also properly scales the timeout on slow
devices automaticaly. So this should be:
if (!TST_RETRY_FUNC(access(path, F_OK), TST_RETVAL_NULL)) {
tst_res(TINFO, "Found event device: %s", path);
break;
}
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-02-28 11:05 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-02-27 18:05 [LTP] [PATCH] input_common.h: Add retry loop for event device Edward Liaw via ltp
2025-02-28 11:05 ` Cyril Hrubis
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).