[LTP] [PATCH v2] Add test for UI_GET_NAME ioctl

Wei Gao wegao@suse.com
Sat Oct 14 05:36:16 CEST 2023


On Thu, Oct 12, 2023 at 04:05:21PM +0200, Cyril Hrubis wrote:
> Hi!
> > +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;
> > +	}
> 
> 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.
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

> 
> > +	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;
> 		}
> 
> >  			return;
> >  		usleep(10000);
> >  	}
> > -- 
> > 2.35.3
> > 
> > 
> > -- 
> > Mailing list info: https://lists.linux.it/listinfo/ltp
> 
> -- 
> Cyril Hrubis
> chrubis@suse.cz


More information about the ltp mailing list