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 events to /dev/uinput
21*49cdfc7eSAndroid Build Coastguard Worker * and check that the events are not received in /dev/input/eventX
22*49cdfc7eSAndroid Build Coastguard Worker * because the device is grabbed by another process
23*49cdfc7eSAndroid Build Coastguard Worker */
24*49cdfc7eSAndroid Build Coastguard Worker
25*49cdfc7eSAndroid Build Coastguard Worker #include <linux/input.h>
26*49cdfc7eSAndroid Build Coastguard Worker
27*49cdfc7eSAndroid Build Coastguard Worker #include "test.h"
28*49cdfc7eSAndroid Build Coastguard Worker #include "safe_macros.h"
29*49cdfc7eSAndroid Build Coastguard Worker #include "lapi/fcntl.h"
30*49cdfc7eSAndroid Build Coastguard Worker #include "input_helper.h"
31*49cdfc7eSAndroid Build Coastguard Worker
32*49cdfc7eSAndroid Build Coastguard Worker #define NB_TEST 20
33*49cdfc7eSAndroid Build Coastguard Worker
34*49cdfc7eSAndroid Build Coastguard Worker static void setup(void);
35*49cdfc7eSAndroid Build Coastguard Worker static void send_information(void);
36*49cdfc7eSAndroid Build Coastguard Worker static void cleanup(void);
37*49cdfc7eSAndroid Build Coastguard Worker
38*49cdfc7eSAndroid Build Coastguard Worker static int fd;
39*49cdfc7eSAndroid Build Coastguard Worker static int fd2;
40*49cdfc7eSAndroid Build Coastguard Worker
41*49cdfc7eSAndroid Build Coastguard Worker char *TCID = "input02";
42*49cdfc7eSAndroid Build Coastguard Worker
main(int ac,char ** av)43*49cdfc7eSAndroid Build Coastguard Worker int main(int ac, char **av)
44*49cdfc7eSAndroid Build Coastguard Worker {
45*49cdfc7eSAndroid Build Coastguard Worker int lc;
46*49cdfc7eSAndroid Build Coastguard Worker int pid;
47*49cdfc7eSAndroid Build Coastguard Worker
48*49cdfc7eSAndroid Build Coastguard Worker tst_parse_opts(ac, av, NULL, NULL);
49*49cdfc7eSAndroid Build Coastguard Worker
50*49cdfc7eSAndroid Build Coastguard Worker setup();
51*49cdfc7eSAndroid Build Coastguard Worker
52*49cdfc7eSAndroid Build Coastguard Worker for (lc = 0; TEST_LOOPING(lc); ++lc) {
53*49cdfc7eSAndroid Build Coastguard Worker pid = tst_fork();
54*49cdfc7eSAndroid Build Coastguard Worker
55*49cdfc7eSAndroid Build Coastguard Worker fd2 = open_device();
56*49cdfc7eSAndroid Build Coastguard Worker
57*49cdfc7eSAndroid Build Coastguard Worker switch (pid) {
58*49cdfc7eSAndroid Build Coastguard Worker case 0:
59*49cdfc7eSAndroid Build Coastguard Worker send_information();
60*49cdfc7eSAndroid Build Coastguard Worker exit(0);
61*49cdfc7eSAndroid Build Coastguard Worker case -1:
62*49cdfc7eSAndroid Build Coastguard Worker tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
63*49cdfc7eSAndroid Build Coastguard Worker default:
64*49cdfc7eSAndroid Build Coastguard Worker if (no_events_queued(fd2, 0))
65*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TPASS, "No data received in eventX");
66*49cdfc7eSAndroid Build Coastguard Worker else
67*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TFAIL, "Data received in eventX");
68*49cdfc7eSAndroid Build Coastguard Worker SAFE_CLOSE(NULL, fd2);
69*49cdfc7eSAndroid Build Coastguard Worker break;
70*49cdfc7eSAndroid Build Coastguard Worker }
71*49cdfc7eSAndroid Build Coastguard Worker
72*49cdfc7eSAndroid Build Coastguard Worker SAFE_WAITPID(NULL, pid, NULL, 0);
73*49cdfc7eSAndroid Build Coastguard Worker }
74*49cdfc7eSAndroid Build Coastguard Worker
75*49cdfc7eSAndroid Build Coastguard Worker cleanup();
76*49cdfc7eSAndroid Build Coastguard Worker tst_exit();
77*49cdfc7eSAndroid Build Coastguard Worker }
78*49cdfc7eSAndroid Build Coastguard Worker
setup(void)79*49cdfc7eSAndroid Build Coastguard Worker static void setup(void)
80*49cdfc7eSAndroid Build Coastguard Worker {
81*49cdfc7eSAndroid Build Coastguard Worker tst_require_root();
82*49cdfc7eSAndroid Build Coastguard Worker
83*49cdfc7eSAndroid Build Coastguard Worker fd = open_uinput();
84*49cdfc7eSAndroid Build Coastguard Worker setup_mouse_events(fd);
85*49cdfc7eSAndroid Build Coastguard Worker create_device(fd);
86*49cdfc7eSAndroid Build Coastguard Worker }
87*49cdfc7eSAndroid Build Coastguard Worker
send_information(void)88*49cdfc7eSAndroid Build Coastguard Worker static void send_information(void)
89*49cdfc7eSAndroid Build Coastguard Worker {
90*49cdfc7eSAndroid Build Coastguard Worker int nb;
91*49cdfc7eSAndroid Build Coastguard Worker
92*49cdfc7eSAndroid Build Coastguard Worker SAFE_IOCTL(NULL, fd2, EVIOCGRAB, 1);
93*49cdfc7eSAndroid Build Coastguard Worker tst_resm(TINFO, "The virtual device was grabbed");
94*49cdfc7eSAndroid Build Coastguard Worker
95*49cdfc7eSAndroid Build Coastguard Worker for (nb = 0; nb < NB_TEST; ++nb) {
96*49cdfc7eSAndroid Build Coastguard Worker send_rel_move(fd, 10, 1);
97*49cdfc7eSAndroid Build Coastguard Worker usleep(1000);
98*49cdfc7eSAndroid Build Coastguard Worker }
99*49cdfc7eSAndroid Build Coastguard Worker
100*49cdfc7eSAndroid Build Coastguard Worker SAFE_CLOSE(NULL, fd2);
101*49cdfc7eSAndroid Build Coastguard Worker }
102*49cdfc7eSAndroid Build Coastguard Worker
cleanup(void)103*49cdfc7eSAndroid Build Coastguard Worker static void cleanup(void)
104*49cdfc7eSAndroid Build Coastguard Worker {
105*49cdfc7eSAndroid Build Coastguard Worker destroy_device(fd);
106*49cdfc7eSAndroid Build Coastguard Worker }
107