Skip to contentSkip to conversation

input_common.h: Add retry loop for event device

PATCH Superseded Edward Liaw via ltp 2 participants 2 messages Feb 27, 2025 – Feb 28, 2025

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 input_common.h: Add retry loop for event device

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.

---
 testcases/kernel/input/input_common.h | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
testcases/kernel/input/input_common.h +6 -3
index 0ac1624b3..06fba753e 100644
@@ -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);
 			}
 		}
 
Signature · 5 lines
2.48.1.711.g2feabab25a-goog


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp
#1 lore raw

Hi!

testcases/kernel/input/input_common.h static inline int open_event_device(void) · line 37

Quoted 6 lines
testcases/kernel/input/input_common.h +6 -0
+			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;
	}
Signature · 5 lines
Cyril Hrubis
[email protected]

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp