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 receive events sent from a virtual device,
11 * that in our case is a mouse.
12 */
13
14 #include "input_common.h"
15
16 #define NUM_EVENTS 20
17 #define MOVE_X 10
18 #define MOVE_Y 1
19
20 static int fd_send = -1;
21 static int fd_recv = -1;
22
run(void)23 static void run(void)
24 {
25 struct input_event iev[3];
26
27 tst_res(TINFO, "Sending relative move: (%i, %i)", MOVE_X, MOVE_Y);
28
29 for (int i = 0; i < NUM_EVENTS; i++) {
30 send_relative_move(fd_send, MOVE_X, MOVE_Y);
31 usleep(1000);
32 }
33
34 tst_res(TINFO, "Reading events back");
35
36 for (int i = 0; i < NUM_EVENTS; i++) {
37 SAFE_READ(0, fd_recv, iev, 3 * sizeof(struct input_event));
38
39 TST_EXP_EQ_LI(iev[0].type, EV_REL);
40 TST_EXP_EQ_LI(iev[0].code, REL_X);
41 TST_EXP_EQ_LI(iev[0].value, MOVE_X);
42
43 TST_EXP_EQ_LI(iev[1].type, EV_REL);
44 TST_EXP_EQ_LI(iev[1].code, REL_Y);
45 TST_EXP_EQ_LI(iev[1].value, MOVE_Y);
46
47 TST_EXP_EQ_LI(iev[2].type, EV_SYN);
48 TST_EXP_EQ_LI(iev[2].code, 0);
49 TST_EXP_EQ_LI(iev[2].value, 0);
50 }
51 }
52
setup(void)53 static void setup(void)
54 {
55 fd_send = open_uinput();
56 if (fd_send == -1)
57 tst_brk(TCONF, "Virtual device is not available");
58
59 setup_mouse_events(fd_send);
60 create_input_device(fd_send);
61
62 fd_recv = open_event_device();
63 }
64
cleanup(void)65 static void cleanup(void)
66 {
67 if (fd_send != -1)
68 destroy_input_device(fd_send);
69
70 if (fd_recv != -1)
71 SAFE_CLOSE(fd_recv);
72 }
73
74 static struct tst_test test = {
75 .test_all = run,
76 .setup = setup,
77 .cleanup = cleanup,
78 .needs_root = 1,
79 };
80