Add testcases to test the kernel input stack
PATCH v2 1/1 Add testcases to test the kernel input stack
1) Create a virtual mouse and write in /dev/uinput and check that the data is well received in /dev/input/eventX
2) Create a virtual mouse, write in /dev/uinput, grab the device and check that the data are not received in other proccess.
3) Create a virtual mouse and check that the data are well received in /dev/input/mice
4) Create a virtual mouse and send empty moves: check that nothing is received in /dev/input/mice
5) Create a virtual mouse and send events which cannot be sent and check that they are not received in eventX
6) Test auto-repeat
--- runtest/input | 6 ++ scenario_groups/default | 1 + testcases/kernel/Makefile | 1 + testcases/kernel/input/.gitignore | 6 ++ testcases/kernel/input/Makefile | 27 +++++ testcases/kernel/input/input01.c | 185 ++++++++++++++++++++++++++++++++++ testcases/kernel/input/input02.c | 100 ++++++++++++++++++ testcases/kernel/input/input03.c | 126 +++++++++++++++++++++++ testcases/kernel/input/input04.c | 116 +++++++++++++++++++++ testcases/kernel/input/input05.c | 99 ++++++++++++++++++ testcases/kernel/input/input06.c | 143 ++++++++++++++++++++++++++ testcases/kernel/input/input_helper.c | 184 +++++++++++++++++++++++++++++++++ testcases/kernel/input/input_helper.h | 37 +++++++ 13 files changed, 1031 insertions(+) create mode 100644 runtest/input create mode 100644 testcases/kernel/input/.gitignore create mode 100644 testcases/kernel/input/Makefile create mode 100644 testcases/kernel/input/input01.c create mode 100644 testcases/kernel/input/input02.c create mode 100644 testcases/kernel/input/input03.c create mode 100644 testcases/kernel/input/input04.c create mode 100644 testcases/kernel/input/input05.c create mode 100644 testcases/kernel/input/input06.c create mode 100644 testcases/kernel/input/input_helper.c create mode 100644 testcases/kernel/input/input_helper.h
runtest/input new file +6 -0
@@ -0,0 +1,6 @@ +input01 input01 +input02 input02 +input03 input03 +input04 input04 +input05 input05 +input06 input06
scenario_groups/default +1 -0
@@ -32,3 +32,4 @@ dma_thread_diotest can cpuhotplug ipv6_lib +input
testcases/kernel/Makefile +1 -0
@@ -42,6 +42,7 @@ SUBDIRS += connectors \ firmware \ fs \ hotplug \ + input \ io \ ipc \ logging \
testcases/kernel/input/.gitignore new file +6 -0
@@ -0,0 +1,6 @@ +/input01 +/input02 +/input03 +/input04 +/input05 +/input06
testcases/kernel/input/Makefile new file +27 -0
@@ -0,0 +1,27 @@ +# +# Copyright (c) SUSE 2015 +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See +# the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +# + +top_srcdir ?= ../../.. + +include $(top_srcdir)/include/mk/testcases.mk + +FILTER_OUT_MAKE_TARGETS := input_helper + +include $(top_srcdir)/include/mk/generic_leaf_target.mk + +$(MAKE_TARGETS): %: %.o input_helper.o
testcases/kernel/input/input01.c new file +185 -0
185 lines not on this page · raw message
testcases/kernel/input/input02.c new file +100 -0
100 lines not on this page · raw message
testcases/kernel/input/input03.c new file +126 -0
126 lines not on this page · raw message
testcases/kernel/input/input04.c new file +116 -0
116 lines not on this page · raw message
testcases/kernel/input/input05.c new file +99 -0
99 lines not on this page · raw message
testcases/kernel/input/input06.c new file +143 -0
143 lines not on this page · raw message
testcases/kernel/input/input_helper.c new file +184 -0
184 lines not on this page · raw message
testcases/kernel/input/input_helper.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* Copyright (c) 2015 Cedric Hnyda <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef INPUT_HELPER_H +#define INPUT_HELPER_H + +#define VIRTUAL_DEVICE "virtual-device-ltp" + +#include <sys/types.h> +#include <dirent.h> + +char *find_event (DIR *d,char *namedir1); +int setup_read (void ); +void send_rel_move (int fd,int x,int y); +void send_event (int fd,int event,int code,int value); +int open_uinput (void ); +void create_device (int fd); +void setup_mouse_events (int fd); +void destroy_device (int fd); +int check_no_data (int fd); + +#endif /* INPUT_HELPER_H */
Signature · 1 line
2.1.4
PATCH v2 1/1 Add testcases to test the kernel input stack
Hi!
This version looks much better. A few comments below.
Quoted 20 lines
+++
b/testcases/kernel/input/input01.ctestcases/kernel/input/input01.c new file +18
-0@@ -0,0 +1,185 @@ +/* +* Copyright (c) 2015 Cedric Hnyda <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +
testcases/kernel/input/input01.c line 28
Quoted 10 lines
testcases/kernel/input/input01.c new file +10
-0+/* +* +* Create a virtual device (mouse), send events to /dev/uinput +* and check that the events are well received in /dev/input/eventX +* +*/ + +#include <linux/input.h> +#include <linux/uinput.h> +#include <fnmatch.h>
Here as well, the fnmatch.h is no longer needed.
Quoted 181 lines
testcases/kernel/input/input01.c new file +156
-0+#include "input_helper.h" +#include "test.h" +#include "safe_macros.h" +#include "lapi/fcntl.h" + +#define NB_TEST 100 + +static void setup (void ); +static void send_information (void ); +static int verify_data (struct input_event *iev,int *nb); +static int check_information (void ); +static void cleanup (void ); + +static int fd; +static int fd2; + +char *TCID ="input01" ; + +int main (int ac,char **av) +{ +int lc; +int pid; + +tst_parse_opts (ac, av,NULL ,NULL ); + +for (lc =0 ; lc <TEST_LOOPING (lc); ++lc) { + +setup (); + pid =tst_fork (); + +if (!pid) { +send_information (); +cleanup (); + }else { + fd2 =setup_read (); +if (check_information ()) +tst_resm (TFAIL , +"Wrong data received in eventX" ); +else +tst_resm (TPASS ,"Data received in eventX" ); + } + } +tst_exit (); +} + +static void setup (void ) +{ +tst_require_root (); + + fd =open_uinput (); + +setup_mouse_events (fd); + +create_device (fd); +} + +static void send_information (void ) +{ +int nb; + +for (nb =0 ; nb <NB_TEST ; ++nb) { +send_rel_move (fd,10 ,1 ); +usleep (100 ); + } +} + +static int check_information (void ) +{ +int nb; +int fail; +int rd; +uint i; +struct input_event iev[64 ]; + + fail =0 ; + nb =0 ; + +while (nb <NB_TEST *3 && !fail) { + rd =read (fd2, iev,sizeof (struct input_event ) *64 ); + +if (rd ==0 || rd %sizeof (struct input_event ) !=0 ) { +tst_resm (TINFO , +"Unexpected return value of read: %i" , rd); + fail =1 ; + } + +for (i =0 ; i < rd /sizeof (struct input_event ) && !fail; i++) + fail =verify_data (&iev[i], &nb); + } + +SAFE_CLOSE (NULL , fd2); +return fail; +} + +static int verify_data (struct input_event *iev,int *nb) +{ +if (*nb %3 ==0 ) { +if (iev->type !=EV_REL ) { +tst_resm (TINFO , +"%i: Unexpected event type %i expected %i" , + *nb, iev->type,EV_REL ); +return 1 ; + } + +if (iev->code !=REL_X ) +return 1 ; + +if (iev->value !=10 ) +return 1 ; + + (*nb)++; +return 0 ; + } + +if (*nb %3 ==1 ) { +if (iev->type !=EV_REL ) { +tst_resm (TINFO , +"%i: Unexpected event type %i expected %i" , + *nb, iev->type,EV_REL ); +return 1 ; + } + +if (iev->code !=REL_Y ) +return 1 ; + +if (iev->value !=1 ) +return 1 ; + + (*nb)++; +return 0 ; + } + +if (*nb %3 ==2 ) { +if (iev->type !=EV_SYN ) { +tst_resm (TINFO , +"%i: Unexpected event type %i expected %i" , + *nb, iev->type,EV_SYN ); +return 1 ; + } + +if (iev->code !=0 ) +return 1 ; + +if (iev->value !=0 ) +return 1 ; + + (*nb)++; +return 0 ; + } +return 1 ; +} + +static void cleanup (void ) +{ +destroy_device (fd); +}testcases/kernel/input/input02.c new file +19
-0@@ -0,0 +1,100 @@ +/* +* Copyright (c) 2015 Cedric Hnyda <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/*
testcases/kernel/input/input02.c line 29
Quoted 10 lines
testcases/kernel/input/input02.c new file +10
-0+* +* Create a virtual device (mouse), send events to /dev/uinput +* and check that the events are not received in /dev/input/eventX +* because the device is grabbed by another process +* +*/ + +#include <linux/input.h> +#include <linux/uinput.h> +#include <fnmatch.h>
Here as well, the fnmatch.h is no longer needed.
Quoted 94 lines
testcases/kernel/input/input02.c new file +70
-0+#include "test.h" +#include "safe_macros.h" +#include "lapi/fcntl.h" +#include "input_helper.h" + +#define NB_TEST 100 + +static void setup (void ); +static void send_information (void ); +static void cleanup (void ); + +static int fd; +static int fd2; + +char *TCID ="input02" ; + +int main (int ac,char **av) +{ +int lc; +int pid; + +tst_parse_opts (ac, av,NULL ,NULL ); + +for (lc =0 ; lc <TEST_LOOPING (lc); ++lc) { + +setup (); + pid =tst_fork (); + fd2 =setup_read (); + +if (!pid) { +send_information (); +cleanup (); + }else { +if (check_no_data (fd2)) +tst_resm (TPASS ,"No data received in eventX" ); +else +tst_resm (TFAIL ,"Data received in eventX" ); + } + } +tst_exit (); +} + +static void setup (void ) +{ +tst_require_root (); + + fd =open_uinput (); + +setup_mouse_events (fd); + +create_device (fd); +} + +static void send_information (void ) +{ +int nb; + +SAFE_IOCTL (NULL , fd2,EVIOCGRAB ,1 ); +tst_resm (TINFO ,"The virtual device was grabbed" ); + +for (nb =0 ; nb <NB_TEST ; ++nb) { +send_rel_move (fd,10 ,1 ); +usleep (100 ); + } +} + +static void cleanup (void ) +{ +destroy_device (fd); +}testcases/kernel/input/input03.c new file +18
-0@@ -0,0 +1,126 @@ +/* +* Copyright (c) 2015 Cedric Hnyda <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ +
testcases/kernel/input/input03.c line 28
Quoted 10 lines
testcases/kernel/input/input03.c new file +10
-0+/* +* +* Create a virtual device (mouse), send events to /dev/uinput +* and check that the events are well received in /dev/input/mice +* +*/ + +#include <linux/input.h> +#include <linux/uinput.h> +#include <fnmatch.h>
Here as well, the fnmatch.h is no longer needed.
Quoted 77 lines
testcases/kernel/input/input03.c new file +77
-0+#include "test.h" +#include "safe_macros.h" +#include "lapi/fcntl.h" +#include "input_helper.h" + +#define NB_TEST 100 +#define X_VALUE 10 +#define Y_VALUE 10 + +static void setup (void ); +static void send_information (void ); +static int check_information (void ); +static void cleanup (void ); + +static int fd; +static int fd2; + +char *TCID ="input03" ; + +int main (int ac,char **av) +{ +int lc; +int pid; + +tst_parse_opts (ac, av,NULL ,NULL ); + +for (lc =0 ; lc <TEST_LOOPING (lc); ++lc) { + +setup (); + pid =tst_fork (); + +if (!pid) { +send_information (); +cleanup (); + }else { +if (check_information ()) +tst_resm (TFAIL ,"Wrong data received" ); +else +tst_resm (TPASS , +"Data received in /dev/input/mice" ); + } + } +tst_exit (); +} + +static void setup (void ) +{ +tst_require_root (); + + fd =open_uinput (); + +setup_mouse_events (fd); + +create_device (fd); +} + +static void send_information (void ) +{ +int nb; + +for (nb =0 ; nb <NB_TEST ; ++nb) { + +send_rel_move (fd,X_VALUE ,Y_VALUE ); +usleep (100 ); + } +} + +static int check_information (void ) +{ +int nb; +int fail; +int rd; +char buf[3 ]; + + fd2 =SAFE_OPEN (NULL ,"/dev/input/mice" ,O_RDONLY ); + fail =0 ; + nb =0 ;
testcases/kernel/input/input03.c line 116
Quoted 10 lines
testcases/kernel/input/input03.c new file +10
-0+ +while (nb <NB_TEST && !fail) { +memset (buf,0 ,3 ); + rd =read (fd2, buf,3 ); + +if (rd <3 ) + fail =1 ; +if (buf[1 ] !=X_VALUE || buf[2 ] != -Y_VALUE || buf[0 ] !=40 ) + fail =1 ; + nb++;
Here as well. I guess that the test may fail if we move the mouse while it runs.
Maybe we can make it fail only if we do not get the expected events (and ignore everything else)...
Quoted 43 lines
testcases/kernel/input/input03.c new file +10
-0+ } + +SAFE_CLOSE (NULL , fd2); +return fail; +} + +static void cleanup (void ) +{ +destroy_device (fd); +}testcases/kernel/input/input04.c new file +27
-0@@ -0,0 +1,116 @@ +/* +* Copyright (c) 2015 Cedric Hnyda <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* +* +* Create a virtual device (mouse), send empty events to /dev/uinput +* and check that the events are not received in /dev/input/mice +* +*/ + +#include <linux/input.h> +#include <linux/uinput.h>
testcases/kernel/input/input04.c line 37
Quoted 10 lines
testcases/kernel/input/input04.c new file +10
-0+#include <fnmatch.h> + +#include "test.h" +#include "safe_macros.h" +#include "lapi/fcntl.h" +#include "input_helper.h" + +#define NB_TEST 100 +#define X_VALUE 0 +#define Y_VALUE 0
The X_VALUE and Y_VALUE are not used, please remove them.
Quoted 63 lines
testcases/kernel/input/input04.c new file +63
-0+static void setup (void ); +static void send_information (void ); +static int check_information (void ); +static void cleanup (void ); + +static int fd; +static int fd2; + +char *TCID ="input04" ; + +int main (int ac,char **av) +{ +int lc; +int pid; + +tst_parse_opts (ac, av,NULL ,NULL ); + +for (lc =0 ; lc <TEST_LOOPING (lc); ++lc) { + +setup (); + pid =tst_fork (); + +if (!pid) { +send_information (); +cleanup (); + }else { +if (check_information ()) +tst_resm (TPASS , +"No data received in /dev/input/mice" ); +else +tst_resm (TFAIL , +"Data received /dev/input/mice" ); + } + } +tst_exit (); +} + +static void setup (void ) +{ +tst_require_root (); + + fd =open_uinput (); + +setup_mouse_events (fd); + +create_device (fd); +} + +static void send_information (void ) +{ +int nb; + +for (nb =0 ; nb <NB_TEST ; ++nb) +send_rel_move (fd,0 ,0 ); +} + +static int check_information (void ) +{ +int rv; +struct timeval timeout; +fd_set set; + + fd2 =SAFE_OPEN (NULL ,"/dev/input/mice" ,O_RDWR );
testcases/kernel/input/input04.c line 111
Quoted 10 lines
testcases/kernel/input/input04.c new file +10
-0+FD_ZERO (&set); +FD_SET (fd2, &set); + timeout.tv_sec =0 ; + timeout.tv_usec =200000 ; + rv =select (fd2 +1 , &set,NULL ,NULL , &timeout); +if (rv <0 ) +tst_brkm (TBROK ,NULL ,"select failed" ); +SAFE_CLOSE (NULL , fd2); +return rv ==0 ; +}
Hmm, I guess that the /dev/input/mice tests may fail if you move your mouse while they run. I guess that we should at least add a warning to the test description.
Or we can make the testcase more robust and expecte that no events with relx == 0 and rely == 0 are generated (and ignore everything else).
Quoted 23 lines
testcases/kernel/input/input04.c new file +4
-0+static void cleanup (void ) +{ +destroy_device (fd); +}testcases/kernel/input/input05.c new file +13
-0@@ -0,0 +1,99 @@ +/* +* Copyright (c) 2015 Cedric Hnyda <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*
testcases/kernel/input/input05.c line 23
Quoted 10 lines
testcases/kernel/input/input05.c new file +10
-0+* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* +* +* Create a virtual device (mouse), send events to /dev/uinput +* and check that the events are not received in /dev/input/eventX +* because it is not possible to sent such events
Maybe we should rather write something as:
"Check that events not advertised in the input device bits are filtered."
Because I had to read the text twice before I figured out what the test should do.
testcases/kernel/input/input05.c line 28
Quoted 5 lines
testcases/kernel/input/input05.c new file +5
-0+*/ + +#include <linux/input.h> +#include <linux/uinput.h> +#include <fnmatch.h>
The fnmatch() is not used only in the helper, no need to include it in the testcases, right?
Quoted 158 lines
testcases/kernel/input/input05.c new file +69
-0+#include "test.h" +#include "safe_macros.h" +#include "lapi/fcntl.h" +#include "input_helper.h" + +#define X_VALUE 10 +#define Y_VALUE 10 + +#define NB_TEST 100 + +static void setup (void ); +static void send_information (void ); +static void cleanup (void ); + +static int fd; +static int fd2; + +char *TCID ="input05" ; + +int main (int ac,char **av) +{ +int lc; +int pid; + +tst_parse_opts (ac, av,NULL ,NULL ); + +for (lc =0 ; lc <TEST_LOOPING (lc); ++lc) { + +setup (); + pid =tst_fork (); + fd2 =setup_read (); + +if (!pid) { +send_information (); +cleanup (); + }else { +if (check_no_data (fd2)) +tst_resm (TPASS ,"No data received in eventX" ); +else +tst_resm (TFAIL ,"Data received in eventX" ); + } + } +tst_exit (); +} + +static void setup (void ) +{ +tst_require_root (); + + fd =open_uinput (); + +SAFE_IOCTL (NULL , fd,UI_SET_EVBIT ,EV_KEY ); +SAFE_IOCTL (NULL , fd,UI_SET_KEYBIT ,BTN_LEFT ); + +create_device (fd); +} + +static void send_information (void ) +{ +int nb; + +for (nb =0 ; nb <NB_TEST ; ++nb) +send_rel_move (fd,X_VALUE ,Y_VALUE ); +} + +static void cleanup (void ) +{ +destroy_device (fd); +}testcases/kernel/input/input06.c new file +83
-0@@ -0,0 +1,143 @@ +/* +* Copyright (c) 2015 Cedric Hnyda <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +/* +* +* Create a virtual device, activate auto-repeat and +* and check that auto repeat is working +* +*/ + +#include <linux/input.h> +#include <linux/uinput.h> +#include <fnmatch.h> +#include <linux/kd.h> + +#include "test.h" +#include "safe_macros.h" +#include "lapi/fcntl.h" +#include "input_helper.h" + +#define NB_TEST 100 + +static void setup (void ); +static void send_information (void ); +static int check_information (void ); +static void cleanup (void ); + +static int fd; +static int caps; + +char *TCID ="input06" ; + +int main (int ac,char **av) +{ +int lc; +int pid; + +tst_parse_opts (ac, av,NULL ,NULL ); + +for (lc =0 ; lc <TEST_LOOPING (lc); ++lc) { + +setup (); + pid =tst_fork (); + +if (!pid) { +send_information (); + }else { +if (check_information ()) +tst_resm (TFAIL , +"Wrong data received in eventX" ); +else +tst_resm (TPASS ,"Data received in eventX" ); + } + } +tst_exit (); +} + +static void setup (void ) +{ +tst_require_root (); + + fd =open_uinput (); + +SAFE_IOCTL (NULL , fd,UI_SET_EVBIT ,EV_KEY ); +SAFE_IOCTL (NULL , fd,UI_SET_KEYBIT ,KEY_X ); +SAFE_IOCTL (NULL , fd,UI_SET_KEYBIT ,KEY_Y ); +SAFE_IOCTL (NULL , fd,UI_SET_KEYBIT ,KEY_ENTER ); +
testcases/kernel/input/input06.c line 93
Quoted 10 lines
testcases/kernel/input/input06.c new file +10
-0+create_device (fd); +} + +static void send_information (void ) +{ +send_event (fd,EV_KEY ,KEY_X ,10 ); +send_event (fd,EV_SYN ,0 ,0 ); + +/* sleep to keep the key pressed for some time (auto-repeat) */ +sleep (1 );
Hmm, I do not like the test hanging for one second to wait for auto-repeat.
What about adjusting auto repeat values so that it kicks in in less than 0.1s?
You can apparently do that by writing EV_REP events to the device. The REP_DELAY should control how long it takes to start auto repeat and REP_PERIOD should control the rate once auto-repeat is active.
Quoted 5 lines
testcases/kernel/input/input06.c new file +5
-0+send_event (fd,EV_KEY ,KEY_Y ,10 ); +send_event (fd,EV_KEY ,KEY_ENTER ,10 ); +send_event (fd,EV_SYN ,0 ,0 ); + +cleanup ();
testcases/kernel/input/input06.c line 109
Quoted 10 lines
testcases/kernel/input/input06.c new file +10
-0+} + +static int check_information (void ) +{ +int rd; +uint i; +char buf[128 ]; + + i =1 ; + rd =read (STDIN_FILENO , buf,sizeof (buf));
I do not think that this would work when the test is executed from the runltp script. The problem is that the test driver ltp-pan runs the testcases on background and the ltp-pan process is the process leader (and that makes the ltp-pan the only program that gets the stdin).
I guess that we will have to open the /dev/inputXXX device and read events from there instead.
Quoted 75 lines
testcases/kernel/input/input06.c new file +34
-0+if (rd <1 ) +return 1 ; + +if (buf[0 ] =='X' ) + caps =32 ; +while (buf[i] !='y' - caps) { + +if (buf[i] !='x' - caps) { +tst_resm (TINFO ,"Unexpected input %c expected %c" , + buf[i],'x' - caps); +return 1 ; + } + + i++; + } + +if (i <=1 ) { +tst_resm (TINFO ,"autorepeat didn't work" ); +return 1 ; + } + +if (i !=strlen (buf) -2 ) { +tst_resm (TINFO , +"the buffer is filled with unwanted chararacters" ); +return 1 ; + } + +return 0 ; +} + +static void cleanup (void ) +{ +destroy_device (fd); +}testcases/kernel/input/input_helper.c new file +35
-0@@ -0,0 +1,184 @@ +/* +* Copyright (c) 2015 Cedric Hnyda <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include <linux/input.h> +#include <linux/uinput.h> +#include <fnmatch.h> +#include <errno.h> +#include "test.h" +#include "safe_macros.h" +#include "input_helper.h" + +#define VIRTUAL_DEVICE_REGEX "*virtual-device-ltp*" + +static int check_device (void ); + +int setup_read (void ) +{ +DIR *d; +char path[256 ]; +char name[256 ];
testcases/kernel/input/input_helper.c line 45
Quoted 10 lines
testcases/kernel/input/input_helper.c new file +10
-0+struct dirent *dp; +int fd; +int ret; + + ret =0 ; + fd =-1 ; + d =opendir ("/dev/input" ); + +while ((dp =readdir (d))) { +if (fnmatch ("event[0-9]*" , dp->d_name,0 ) ==0 ) {
You can do here:
if (fnmatch("event[0-9]*", dp->d_name, 0))
continue;
To save some indentation level for the code below. (I also think that it's a bit more elegant that way)
testcases/kernel/input/input_helper.c line 48
Quoted 3 lines
testcases/kernel/input/input_helper.c new file +3
-0+memset (path,0 ,256 ); +strcat (path,"/dev/input/" ); +strcat (path, dp->d_name);
Just use snprintf(path, sizeof(path), "/dev/input/%s", dp->d_name) instead.
testcases/kernel/input/input_helper.c line 56
Quoted 8 lines
testcases/kernel/input/input_helper.c new file +8
-0+ fd =open (path,O_RDONLY ); +if (fd <0 ) { +tst_resm (TINFO ,"failed to open %s" , path); +break ; + } + ret =ioctl (fd,EVIOCGNAME (256 ), name); +if (ret <0 ) { +tst_resm (TINFO ,"ioctl failed" );
Please be more informative with these messages: tst_resm(TINFO | TERRNO, "ioctl(%s, EVIOCGNAME(256), ...) failed", dp->d_name);
Quoted 16 lines
testcases/kernel/input/input_helper.c new file +16
-0+break ; + } +if (strcmp (name,VIRTUAL_DEVICE ) ==0 ) +break ; + } + } + +closedir (d); +if (fd >0 && ret >=0 ) +return fd; +tst_brkm (TBROK ,NULL ,"unable to find the right event" ); +return -1 ; +} + +int open_uinput (void ) +{
testcases/kernel/input/input_helper.c line 82
Quoted 10 lines
testcases/kernel/input/input_helper.c new file +10
-0+int fd; + + fd =open ("/dev/input/uinput" ,O_WRONLY |O_NONBLOCK ); + +if (fd <0 && errno ==ENOENT ) + fd =open ("/dev/uinput" ,O_WRONLY |O_NONBLOCK ); + +if (fd <0 && errno ==ENOENT ) +tst_brkm (TCONF ,NULL ,"unable to find and open uinput" ); +else if (fd <0 )
^
No need for the else, since tst_brkm() will exit the test.
testcases/kernel/input/input_helper.c line 83
Quoted 1 line
testcases/kernel/input/input_helper.c new file +1
-0+tst_brkm (TBROK ,NULL ,"open failed" );
^ TERRNO here.
Quoted 70 lines
testcases/kernel/input/input_helper.c new file +70
-0+return fd; +} + +void send_event (int fd,int event,int code,int value) +{ +struct input_event ev; + +memset (&ev,0 ,sizeof (struct input_event )); + ev.type = event; + ev.code = code; + ev.value = value; +SAFE_WRITE (NULL ,1 , fd, &ev,sizeof (struct input_event )); +} + +void send_rel_move (int fd,int x,int y) +{ +send_event (fd,EV_REL ,REL_X , x); +send_event (fd,EV_REL ,REL_Y , y); +send_event (fd,EV_SYN ,0 ,0 ); +} + +void create_device (int fd) +{ +struct uinput_user_dev uidev; +int nb; + +memset (&uidev,0 ,sizeof (uidev)); +snprintf (uidev.name,UINPUT_MAX_NAME_SIZE ,VIRTUAL_DEVICE ); + uidev.id.bustype =BUS_USB ; + uidev.id.vendor =0x1 ; + uidev.id.product =0x1 ; + uidev.id.version =1 ; + +SAFE_WRITE (NULL ,1 , fd, &uidev,sizeof (uidev)); +SAFE_IOCTL (NULL , fd,UI_DEV_CREATE ,NULL ); + + nb =20 ; +do { +usleep (100000 ); +if (check_device ()) +return ; + nb--; + + }while (nb >0 ); + +destroy_device (fd); +tst_brkm (TBROK ,NULL ,"failed to create device" ); + +} + +void setup_mouse_events (int fd) +{ +SAFE_IOCTL (NULL , fd,UI_SET_EVBIT ,EV_KEY ); +SAFE_IOCTL (NULL , fd,UI_SET_KEYBIT ,BTN_LEFT ); +SAFE_IOCTL (NULL , fd,UI_SET_EVBIT ,EV_REL ); +SAFE_IOCTL (NULL , fd,UI_SET_RELBIT ,REL_X ); +SAFE_IOCTL (NULL , fd,UI_SET_RELBIT ,REL_Y ); +} + +void destroy_device (int fd) +{ +SAFE_IOCTL (NULL , fd,UI_DEV_DESTROY ,NULL ); +SAFE_CLOSE (NULL , fd); +} + +/* +* read will eventually return ENODEV because +* the device will be destroyed by the other process +* after having sent the informations +*/
testcases/kernel/input/input_helper.c line 164
Quoted 10 lines
testcases/kernel/input/input_helper.c new file +10
-0+int check_no_data (int fd) +{ +int rd; +struct input_event iev[64 ]; + + rd =read (fd, iev,sizeof (struct input_event ) *64 ); + +SAFE_CLOSE (NULL , fd); +return rd <0 && errno ==ENODEV ; +}
This function is called twice right after setup_read() it would make more sense to call the setup_read() here instead and call this function without any parameters. Since it's not obvious that this function actually closes the fd (the name of the function does not contain "close" or "destroy" or something that would suggest that the file descriptor is being closed).
Quoted 37 lines
testcases/kernel/input/input_helper.c new file +19
-0+static int check_device (void ) +{ +FILE *file; +char line[256 ]; + + file =fopen ("/proc/bus/input/devices" ,"r" ); +if (!file) +return 0 ; + +while (fgets (line,256 , file)) { + +if (fnmatch (VIRTUAL_DEVICE_REGEX , line,0 ) ==0 ) +return 1 ; + } + +fclose (file); + +return 0 ; +}testcases/kernel/input/input_helper.h new file +12
-0@@ -0,0 +1,37 @@ +/* +* Copyright (c) 2015 Cedric Hnyda <[email protected]> +* +* This program is free software; you can redistribute it and/or +* modify it under the terms of the GNU General Public License as +* published by the Free Software Foundation; either version 2 of +* the License, or (at your option) any later version. +* +* This program is distributed in the hope that it would be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details.
testcases/kernel/input/input_helper.h line 22
Quoted 10 lines
testcases/kernel/input/input_helper.h new file +10
-0+* +* You should have received a copy of the GNU General Public License +* along with this program; if not, write the Free Software Foundation, +* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#ifndef INPUT_HELPER_H +#define INPUT_HELPER_H + +#define VIRTUAL_DEVICE "virtual-device-ltp"
This macro is not used anywhere else than in the input_helper.c code, right? In that case it shouldn't be exported in the header.
testcases/kernel/input/input_helper.h line 27
Quoted 4 lines
testcases/kernel/input/input_helper.h new file +4
-0+#include <sys/types.h> +#include <dirent.h> + +char *find_event (DIR *d,char *namedir1);
This function does not seem to exists at all.
Quoted 16 lines
testcases/kernel/input/input_helper.h new file +10
-0+int setup_read (void ); +void send_rel_move (int fd,int x,int y); +void send_event (int fd,int event,int code,int value); +int open_uinput (void ); +void create_device (int fd); +void setup_mouse_events (int fd); +void destroy_device (int fd); +int check_no_data (int fd); + +#endif /* INPUT_HELPER_H */ Signature · 5 lines
2.1.4 -- Mailing list info: http://lists.linux.it/listinfo/ltp
Signature · 2 lines
Cyril Hrubis [email protected]