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