• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License as
6  * published by the Free Software Foundation; either version 2 of
7  * the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it would be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write the Free Software Foundation,
16  * Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
17  */
18 
19  /*
20   *  Create a virtual device (mouse), send empty events to /dev/uinput
21   *  and check that the events are not received in /dev/inputX
22   */
23 
24 #include <linux/input.h>
25 
26 #include "test.h"
27 #include "safe_macros.h"
28 #include "lapi/fcntl.h"
29 #include "input_helper.h"
30 
31 #define NB_TEST 20
32 
33 static void setup(void);
34 static void send_events(void);
35 static void cleanup(void);
36 
37 static int fd, fd2;
38 
39 char *TCID = "input04";
40 
main(int ac,char ** av)41 int main(int ac, char **av)
42 {
43 	int lc;
44 	int pid;
45 
46 	tst_parse_opts(ac, av, NULL, NULL);
47 
48 	setup();
49 
50 	for (lc = 0; TEST_LOOPING(lc); ++lc) {
51 		pid = tst_fork();
52 
53 		switch (pid) {
54 		case 0:
55 			send_events();
56 			exit(0);
57 		case -1:
58 			tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
59 		default:
60 			if (no_events_queued(fd2, 1))
61 				tst_resm(TPASS,
62 					"No data received in /dev/inputX");
63 			else
64 				tst_resm(TFAIL,
65 					"Data received /dev/inputX");
66 		break;
67 		}
68 
69 		SAFE_WAITPID(NULL, pid, NULL, 0);
70 	}
71 
72 	cleanup();
73 	tst_exit();
74 }
75 
setup(void)76 static void setup(void)
77 {
78 	tst_require_root();
79 
80 	fd = open_uinput();
81 	setup_mouse_events(fd);
82 	create_device(fd);
83 
84 	fd2 = open_device();
85 }
86 
send_events(void)87 static void send_events(void)
88 {
89 	int nb;
90 
91 	for (nb = 0; nb < NB_TEST; ++nb) {
92 		send_rel_move(fd, 0, 0);
93 		usleep(1000);
94 	}
95 }
96 
cleanup(void)97 static void cleanup(void)
98 {
99 	if (fd2 > 0 && close(fd2))
100 		tst_resm(TWARN | TERRNO, "close(fd2)");
101 
102 	destroy_device(fd);
103 }
104