input_common.h: Add retry loop for event device
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.
Signed-off-by Edward Liaw <[email protected]>
--- testcases/kernel/input/input_common.h | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-)
testcases/kernel/input/input_common.h +6 -3
@@ -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
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