Add test for UI_GET_NAME ioctl
PATCH 1/1 Add test for UI_GET_NAME ioctl
Fix:#573
--- testcases/kernel/input/input_helper.c | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-)
testcases/kernel/input/input_helper.c +23 -1
@@ -32,6 +32,7 @@static int uinput_loaded;static int check_device (void ); +static int check_ui_get_sysname_ioctl (int fd);static int try_open_device (void ) {
@@ -185,6 +186,27 @@ void send_rel_move(int fd, int x, int y)send_event (fd,EV_SYN ,0 ,0 ); } +static int check_ui_get_sysname_ioctl (int fd) +{ +char name[256 ]; +SAFE_IOCTL (NULL , fd,UI_GET_SYSNAME (sizeof (name)), name,NULL ); + +DIR *test_dir; +struct dirent *ent; + + test_dir =SAFE_OPENDIR (NULL ,"/sys/devices/virtual/input/" ); + +while ((ent =SAFE_READDIR (NULL , test_dir))) { +if (!strcmp (ent->d_name, name)) { +return 1 ; + } +else +continue ; + } + +return 0 ; +} +void create_device (int fd) {int nb;
@@ -202,7 +224,7 @@ void create_device(int fd)SAFE_IOCTL (NULL , fd,UI_DEV_CREATE ,NULL );for (nb =100 ; nb >0 ; nb--) { -if (check_device ()) +if (check_device () &&check_ui_get_sysname_ioctl (fd))return ;usleep (10000 ); }
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v2 1/1 Add test for UI_GET_NAME ioctl
Fix:#573
--- testcases/kernel/input/input_helper.c | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-)
testcases/kernel/input/input_helper.c +24 -1
@@ -32,6 +32,7 @@static int uinput_loaded;static int check_device (void ); +static int check_ui_get_sysname_ioctl (int fd);static int try_open_device (void ) {
@@ -185,6 +186,28 @@ void send_rel_move(int fd, int x, int y)send_event (fd,EV_SYN ,0 ,0 ); } +static int check_ui_get_sysname_ioctl (int fd) +{ +char name[256 ]; + +SAFE_IOCTL (NULL , fd,UI_GET_SYSNAME (sizeof (name)), name,NULL ); + +DIR *test_dir; + +struct dirent *ent; + + test_dir =SAFE_OPENDIR (NULL ,"/sys/devices/virtual/input/" ); + +while ((ent =SAFE_READDIR (NULL , test_dir))) { +if (!strcmp (ent->d_name, name)) +return 1 ; +else +continue ; + } + +return 0 ; +} +void create_device (int fd) {int nb;
@@ -202,7 +225,7 @@ void create_device(int fd)SAFE_IOCTL (NULL , fd,UI_DEV_CREATE ,NULL );for (nb =100 ; nb >0 ; nb--) { -if (check_device ()) +if (check_device () &&check_ui_get_sysname_ioctl (fd))return ;usleep (10000 ); }
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 8 lines
testcases/kernel/input/input_helper.c +8
-0+static int check_ui_get_sysname_ioctl (int fd) +{ +char name[256 ]; + +SAFE_IOCTL (NULL , fd,UI_GET_SYSNAME (sizeof (name)), name,NULL ); + +DIR *test_dir; +
testcases/kernel/input/input_helper.c void send_rel_move(int fd, int x, int y) · line 206
Quoted 10 lines
testcases/kernel/input/input_helper.c +10
-0+struct dirent *ent; + + test_dir =SAFE_OPENDIR (NULL ,"/sys/devices/virtual/input/" ); + +while ((ent =SAFE_READDIR (NULL , test_dir))) { +if (!strcmp (ent->d_name, name)) +return 1 ; +else +continue ; + }
Why do we loop over the directory here? Can't we just directly check that the path /sys/devices/virtual/input/$name/ exists?
I guess that we can as well read the /sys/devices/virtual/input/$name/dev and match that against fstat() on the fd.
testcases/kernel/input/input_helper.c void create_device(int fd) · line 228
Quoted 12 lines
testcases/kernel/input/input_helper.c +4
-1+return 0 ; +} +void create_device (int fd) {int nb;@@ -202,7 +225,7 @@ void create_device(int fd)SAFE_IOCTL (NULL , fd,UI_DEV_CREATE ,NULL );for (nb =100 ; nb >0 ; nb--) { -if (check_device ()) +if (check_device () &&check_ui_get_sysname_ioctl (fd))
Maybe it would be a bit more readable if we did:
if (check_device() {
check_ui_get_sysname_ioctl(fd);
return;
}Quoted 9 lines
testcases/kernel/input/input_helper.c +0
-0return ;usleep (10000 ); }Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 23 lines · Cyril Hrubis
Hi!
Quoted 8 lines
testcases/kernel/input/input_helper.c +8
-0+static int check_ui_get_sysname_ioctl (int fd) +{ +char name[256 ]; + +SAFE_IOCTL (NULL , fd,UI_GET_SYSNAME (sizeof (name)), name,NULL ); + +DIR *test_dir; +testcases/kernel/input/input_helper.c void send_rel_move(int fd, int x, int y) · line 206
Quoted 10 lines
testcases/kernel/input/input_helper.c +10
-0+struct dirent *ent; + + test_dir =SAFE_OPENDIR (NULL ,"/sys/devices/virtual/input/" ); + +while ((ent =SAFE_READDIR (NULL , test_dir))) { +if (!strcmp (ent->d_name, name)) +return 1 ; +else +continue ; + }Why do we loop over the directory here? Can't we just directly check that the path
/sys/devices/virtual/input/$name/exists?
Quoted 3 lines
I guess that we can as well read the
/sys/devices/virtual/input/$name/devand match that againstfstat()on the fd.
Seems no dev node can be found under /sys/devices/virtual/input/$name/.
ll /sys/devices/virtual/input/input13/
total 0
drwxr-xr-x 2 root root 0 Oct 13 21:32 capabilities drwxr-xr-x 3 root root 0 Oct 13 21:32 event8 drwxr-xr-x 2 root root 0 Oct 13 21:32 id
-rw-r--r-- 1 root root 4.0K Oct 13 21:33 inhibited -r--r--r-- 1 root root 4.0K Oct 13 21:33 modalias
drwxr-xr-x 3 root root 0 Oct 13 21:32 mouse3
-r--r--r-- 1 root root 4.0K Oct 13 21:32 name -r--r--r-- 1 root root 4.0K Oct 13 21:32 phys
drwxr-xr-x 2 root root 0 Oct 13 21:33 power
-r--r--r-- 1 root root 4.0K Oct 13 21:32 properties
lrwxrwxrwx 1 root root 0 Oct 13 21:32 subsystem -> ../../../../class/input
-rw-r--r-- 1 root root 4.0K Oct 13 21:32 uevent -r--r--r-- 1 root root 4.0K Oct 13 21:33 uniq
Quoted 34 lines
testcases/kernel/input/input_helper.c void create_device(int fd) · line 228
Quoted 13 lines
testcases/kernel/input/input_helper.c +4
-1+return 0 ; +} +void create_device (int fd) {int nb;@@ -202,7 +225,7 @@ void create_device(int fd)SAFE_IOCTL (NULL , fd,UI_DEV_CREATE ,NULL );for (nb =100 ; nb >0 ; nb--) { -if (check_device ()) +if (check_device () &&check_ui_get_sysname_ioctl (fd))Maybe it would be a bit more readable if we did:
if (check_device() { check_ui_get_sysname_ioctl(fd); return; }Quoted 9 lines
testcases/kernel/input/input_helper.c +0
-0return ;usleep (10000 ); }Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltpSignature · 2 lines
Cyril Hrubis [email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 40 lines
Quoted 22 lines
Quoted 8 lines
testcases/kernel/input/input_helper.c +8
-0+static int check_ui_get_sysname_ioctl (int fd) +{ +char name[256 ]; + +SAFE_IOCTL (NULL , fd,UI_GET_SYSNAME (sizeof (name)), name,NULL ); + +DIR *test_dir; +testcases/kernel/input/input_helper.c void send_rel_move(int fd, int x, int y) · line 206
Quoted 10 lines
testcases/kernel/input/input_helper.c +10
-0+struct dirent *ent; + + test_dir =SAFE_OPENDIR (NULL ,"/sys/devices/virtual/input/" ); + +while ((ent =SAFE_READDIR (NULL , test_dir))) { +if (!strcmp (ent->d_name, name)) +return 1 ; +else +continue ; + }Why do we loop over the directory here? Can't we just directly check that the path
/sys/devices/virtual/input/$name/exists?Quoted 3 lines
I guess that we can as well read the
/sys/devices/virtual/input/$name/devand match that againstfstat()on the fd.Seems no dev node can be found under
/sys/devices/virtual/input/$name/.ll
/sys/devices/virtual/input/input13/
total 0drwxr-xr-x 2 root root 0 Oct 13 21:32 capabilities drwxr-xr-x 3 root root 0 Oct 13 21:32 event8 drwxr-xr-x 2 root root 0 Oct 13 21:32 id(quoted diff) +0
-2-rw-r--r-- 1 root root 4.0K Oct 13 21:33 inhibited -r--r--r-- 1 root root 4.0K Oct 13 21:33 modaliasdrwxr-xr-x 3 root root 0 Oct 13 21:32 mouse3
(quoted diff) +0
-2-r--r--r-- 1 root root 4.0K Oct 13 21:32 name -r--r--r-- 1 root root 4.0K Oct 13 21:32 physdrwxr-xr-x 2 root root 0 Oct 13 21:33 power
-r--r--r-- 1 root root 4.0K Oct 13 21:32 properties
lrwxrwxrwx 1 root root 0 Oct 13 21:32 subsystem -> ../../../../class/input
Review
Quoted 2 lines
(quoted diff) +0
-2-rw-r--r-- 1 root root 4.0K Oct 13 21:32 uevent -r--r--r-- 1 root root 4.0K Oct 13 21:33 uniq
Ah, right, it's under the event8 directory in this case. I guess that we can match name againts the VIRTUAL_DEVICE string instead.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Quoted 38 lines · Cyril Hrubis
Hi!
Quoted 37 lines
Quoted 22 lines
Quoted 8 lines
testcases/kernel/input/input_helper.c +8
-0+static int check_ui_get_sysname_ioctl (int fd) +{ +char name[256 ]; + +SAFE_IOCTL (NULL , fd,UI_GET_SYSNAME (sizeof (name)), name,NULL ); + +DIR *test_dir; +testcases/kernel/input/input_helper.c void send_rel_move(int fd, int x, int y) · line 206
Quoted 10 lines
testcases/kernel/input/input_helper.c +10
-0+struct dirent *ent; + + test_dir =SAFE_OPENDIR (NULL ,"/sys/devices/virtual/input/" ); + +while ((ent =SAFE_READDIR (NULL , test_dir))) { +if (!strcmp (ent->d_name, name)) +return 1 ; +else +continue ; + }Why do we loop over the directory here? Can't we just directly check that the path
/sys/devices/virtual/input/$name/exists?Quoted 3 lines
I guess that we can as well read the
/sys/devices/virtual/input/$name/devand match that againstfstat()on the fd.Seems no dev node can be found under
/sys/devices/virtual/input/$name/.ll
/sys/devices/virtual/input/input13/
total 0drwxr-xr-x 2 root root 0 Oct 13 21:32 capabilities drwxr-xr-x 3 root root 0 Oct 13 21:32 event8 drwxr-xr-x 2 root root 0 Oct 13 21:32 id(quoted diff) +0
-2-rw-r--r-- 1 root root 4.0K Oct 13 21:33 inhibited -r--r--r-- 1 root root 4.0K Oct 13 21:33 modaliasdrwxr-xr-x 3 root root 0 Oct 13 21:32 mouse3
(quoted diff) +0
-2-r--r--r-- 1 root root 4.0K Oct 13 21:32 name -r--r--r-- 1 root root 4.0K Oct 13 21:32 phys
Quoted 8 lines
Review
Quoted 5 lines
drwxr-xr-x 2 root root 0 Oct 13 21:33 power
-r--r--r-- 1 root root 4.0K Oct 13 21:32 properties
lrwxrwxrwx 1 root root 0 Oct 13 21:32 subsystem -> ../../../../class/input(quoted diff) +0
-2-rw-r--r-- 1 root root 4.0K Oct 13 21:32 uevent -r--r--r-- 1 root root 4.0K Oct 13 21:33 uniqAh, right, it's under the event8 directory in this case. I guess that we can match name againts the
VIRTUAL_DEVICEstring instead.
Yes, in v3 patch i start match name againts the VIRTUAL_DEVICE. Thanks for the suggestion.
Quoted 4 lines
Signature · 3 lines
-- Cyril Hrubis [email protected]
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v3 1/1 Add test for UI_GET_NAME ioctl
In reply to Wei Gao via ltpFix:#573
--- testcases/kernel/input/input_helper.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)
testcases/kernel/input/input_helper.c +20 -1
@@ -32,6 +32,7 @@static int uinput_loaded;static int check_device (void ); +static void check_ui_get_sysname_ioctl (int fd);static int try_open_device (void ) {
@@ -185,6 +186,22 @@ void send_rel_move(int fd, int x, int y)send_event (fd,EV_SYN ,0 ,0 ); } +static void check_ui_get_sysname_ioctl (int fd) +{ +char sys_name[256 ]; +char dev_name[256 ]; +char *path; + +SAFE_IOCTL (NULL , fd,UI_GET_SYSNAME (sizeof (sys_name)), sys_name,NULL ); +SAFE_ASPRINTF (NULL , &path,"/sys/devices/virtual/input/%s/name" , sys_name); +SAFE_FILE_SCANF (NULL , path,"%s" , dev_name); + +if (strcmp (VIRTUAL_DEVICE , dev_name)) { +tst_brkm (TBROK ,NULL ,"Unable to find the input device through ioctl" ); + } +free (path); +} +void create_device (int fd) {int nb;
@@ -202,8 +219,10 @@ void create_device(int fd)SAFE_IOCTL (NULL , fd,UI_DEV_CREATE ,NULL );for (nb =100 ; nb >0 ; nb--) { -if (check_device ()) +if (check_device ()) { +check_ui_get_sysname_ioctl (fd);return ; + }usleep (10000 ); }
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 11 lines
Fix:#573
Signed-off-by Wei Gao <[email protected]>--- testcases/kernel/input/input_helper.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-)testcases/kernel/input/input_helper.c +0
-0
testcases/kernel/input/input_helper.c line 35
Quoted 4 lines
testcases/kernel/input/input_helper.c +1
-0@@ -32,6 +32,7 @@static int uinput_loaded;static int check_device (void ); +static void check_ui_get_sysname_ioctl (int fd);
I do not think that this is needed, we do not call the function before it's definition.
Quoted 5 lines
testcases/kernel/input/input_helper.c +0
-0static int try_open_device (void ) {@@ -185,6 +186,22 @@ void send_rel_move(int fd, int x, int y)send_event (fd,EV_SYN ,0 ,0 ); }
testcases/kernel/input/input_helper.c void send_rel_move(int fd, int x, int y) · line 197
Quoted 10 lines
testcases/kernel/input/input_helper.c +9
-0+static void check_ui_get_sysname_ioctl (int fd) +{ +char sys_name[256 ]; +char dev_name[256 ]; +char *path; + +SAFE_IOCTL (NULL , fd,UI_GET_SYSNAME (sizeof (sys_name)), sys_name,NULL ); +SAFE_ASPRINTF (NULL , &path,"/sys/devices/virtual/input/%s/name" , sys_name); +SAFE_FILE_SCANF (NULL , path,"%s" , dev_name);
I would be inclined to use the FILE_SCANF() instead here and report failure if the file does not exist or couldn't be read, something as:
if (FILE_SCANF(NULL, path, "%s", dev_name)) {
tst_res(TFAIL, "Failed to read name from the sysfs path");
free(path);
return;
}testcases/kernel/input/input_helper.c void send_rel_move(int fd, int x, int y) · line 201
Quoted 3 lines
testcases/kernel/input/input_helper.c +3
-0+if (strcmp (VIRTUAL_DEVICE , dev_name)) { +tst_brkm (TBROK ,NULL ,"Unable to find the input device through ioctl" ); + }
I do not think that tst_brkm() is the right here either, this is simple TPASS/TFAIL situation. Can we just print TPASS/TFAIL based on if these names match?
Quoted 24 lines
testcases/kernel/input/input_helper.c +6
-1+free (path); +} +void create_device (int fd) {int nb;@@ -202,8 +219,10 @@ void create_device(int fd)SAFE_IOCTL (NULL , fd,UI_DEV_CREATE ,NULL );for (nb =100 ; nb >0 ; nb--) { -if (check_device ()) +if (check_device ()) { +check_ui_get_sysname_ioctl (fd);return ; + }usleep (10000 ); }Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
PATCH v4 1/1 Add test for UI_GET_NAME ioctl
In reply to Wei Gao via ltpFix:#573
--- testcases/kernel/input/input_helper.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-)
testcases/kernel/input/input_helper.c +26 -1
@@ -185,6 +185,29 @@ void send_rel_move(int fd, int x, int y)send_event (fd,EV_SYN ,0 ,0 ); } +static void check_ui_get_sysname_ioctl (int fd) +{ +char sys_name[256 ]; +char dev_name[256 ]; +char *path; + +SAFE_IOCTL (NULL , fd,UI_GET_SYSNAME (sizeof (sys_name)), sys_name,NULL ); +SAFE_ASPRINTF (NULL , &path,"/sys/devices/virtual/input/%s/name" , sys_name); + +if (FILE_SCANF (path,"%s" , dev_name)) { +tst_resm (TFAIL |TERRNO ,"Failed to read name from the sysfs path" ); +free (path); +return ; + } + +if (!strcmp (VIRTUAL_DEVICE , dev_name)) +tst_resm (TPASS ,"Find the input device through ioctl" ); +else +tst_resm (TFAIL ,"Unable to find the input device through ioctl" ); + +free (path); +} +void create_device (int fd) {int nb;
@@ -202,8 +225,10 @@ void create_device(int fd)SAFE_IOCTL (NULL , fd,UI_DEV_CREATE ,NULL );for (nb =100 ; nb >0 ; nb--) { -if (check_device ()) +if (check_device ()) { +check_ui_get_sysname_ioctl (fd);return ; + }usleep (10000 ); }
Signature · 5 lines
2.35.3 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
I've adjusted the FAIL/PASS messages and pushed, thanks.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi all,
Quoted 2 lines
Hi!
I've adjusted the FAIL/PASS messages and pushed, thanks.
UI_GET_NAME() from include/uapi/linux/uinput.h is not on the old CentOS 7 we still support:
https://github.com/linux-test-project/ltp/actions/runs/6614554688/job/17964785134
/__w/ltp/ltp/testcases/kernel/input/input_helper.c:194:2: error: implicit declaration of function 'UI_GET_SYSNAME' [-Werror=implicit-function-declaration]
SAFE_IOCTL(NULL, fd, UI_GET_SYSNAME(sizeof(sys_name)), sys_name, NULL);
^
I'll have look later today for the fix. I suppose we need lapi/uinput.h with adds a fallback definition. It was added in kernel v3.15 in e3480a61fca7 ("Input: uinput - add UI_GET_SYSNAME ioctl to retrieve the sysfs path")
Also, there is also an API version change, we could use this if simple ifndef UI_GET_SYSNAME + fallback will not be enough (e.g. test fails because it requires newer kernel API).
-#define UINPUT_VERSION 3
+#define UINPUT_VERSION 4
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp
Hi!
Quoted 18 lines
Quoted 1 line
I've adjusted the FAIL/PASS messages and pushed, thanks.
UI_GET_NAME()frominclude/uapi/linux/uinput.his not on the old CentOS 7 we still support:https://github.com/linux-test-project/ltp/actions/runs/6614554688/job/17964785134
/__w/ltp/ltp/testcases/kernel/input/input_helper.c:194:2: error: implicit declaration of function 'UI_GET_SYSNAME' [-Werror=implicit-function-declaration]
SAFE_IOCTL(NULL, fd, UI_GET_SYSNAME(sizeof(sys_name)), sys_name, NULL);
^I'll have look later today for the fix. I suppose we need
lapi/uinput.hwith adds a fallback definition. It was added in kernel v3.15 ine3480a61fca7("Input: uinput - addUI_GET_SYSNAMEioctl to retrieve the sysfs path")Also, there is also an API version change, we could use this if simple ifndef
UI_GET_SYSNAME+ fallback will not be enough (e.g. test fails because it requires newer kernel API).
Review
Quoted 2 lines
(quoted diff) +1
-1-#define UINPUT_VERSION 3 +#define UINPUT_VERSION 4
Given that UI_GET_SYSNAME is a macro we can do as well:
#ifndef UI_GET_SYSNAME
# define UI_GET_SYSNAME(len) ... #endif
However at the same time we would need to actually check if the ioctl is supported or not, because if the CentOS 7 kernel does not support UI_GET_SYSNAME ioctl() the SAFE_IOCTL() will fail with EINVAL.
Also looking at the linux/uinput.h there are three more ioctls() added in version 5 that should be tested as well. I suppose that we will need add an issue for that.
Signature · 5 lines
Cyril Hrubis [email protected] -- Mailing list info: https://lists.linux.it/listinfo/ltp