1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
4 * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
5 */
6
7 /*\
8 * [Description]
9 *
10 * Verify that /dev/input/eventX doesn't receive any event sent from a virtual
11 * device, that in our case is a mouse, when events not advertised in the input
12 * device bits are filtered.
13 */
14
15 #include <linux/uinput.h>
16
17 #include "input_common.h"
18
19 #define NUM_EVENTS 20
20 #define MOVE_X 10
21 #define MOVE_Y 10
22
23 static int fd_send = -1;
24 static int fd_recv = -1;
25
run(void)26 static void run(void)
27 {
28 tst_res(TINFO, "Sending relative mouse move (%i, %i)", MOVE_X, MOVE_Y);
29
30 for (int i = 0; i < NUM_EVENTS; i++) {
31 send_relative_move(fd_send, MOVE_X, MOVE_Y);
32 usleep(1000);
33 }
34
35 verify_no_events_queued(fd_recv);
36 }
37
setup(void)38 static void setup(void)
39 {
40 fd_send = open_uinput();
41 if (fd_send == -1)
42 tst_brk(TCONF, "Virtual device is not available");
43
44 SAFE_IOCTL(fd_send, UI_SET_EVBIT, EV_KEY);
45 SAFE_IOCTL(fd_send, UI_SET_KEYBIT, BTN_LEFT);
46 create_input_device(fd_send);
47
48 fd_recv = open_event_device();
49 }
50
cleanup(void)51 static void cleanup(void)
52 {
53 if (fd_send != -1)
54 destroy_input_device(fd_send);
55
56 if (fd_recv != -1)
57 SAFE_CLOSE(fd_recv);
58 }
59
60 static struct tst_test test = {
61 .test_all = run,
62 .setup = setup,
63 .cleanup = cleanup,
64 .needs_root = 1,
65 };
66