From 9f558d3461849b45e500ad49e808671af59aa87d Mon Sep 17 00:00:00 2001 From: Andrea Cervesato Date: Fri, 15 Nov 2024 14:58:52 +0100 Subject: [PATCH] Refactor input05 test Signed-off-by: Andrea Cervesato --- testcases/kernel/input/Makefile | 6 +- testcases/kernel/input/input05.c | 119 ++++++++++--------------------- 2 files changed, 40 insertions(+), 85 deletions(-) diff --git a/testcases/kernel/input/Makefile b/testcases/kernel/input/Makefile index cf35e1bfc15..a37aa28fc27 100644 --- a/testcases/kernel/input/Makefile +++ b/testcases/kernel/input/Makefile @@ -8,8 +8,8 @@ LTPLIBS = uinput include $(top_srcdir)/include/mk/testcases.mk FILTER_OUT_MAKE_TARGETS := input_helper -input01 input02 input03 input04: LDLIBS += -lltpuinput +input01 input02 input03 input04 input05: LDLIBS += -lltpuinput -include $(top_srcdir)/include/mk/generic_leaf_target.mk +input06: %: input_helper.o -input05 input06: %: input_helper.o +include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/input/input05.c b/testcases/kernel/input/input05.c index 46b4fe8b27c..4e5072a038e 100644 --- a/testcases/kernel/input/input05.c +++ b/testcases/kernel/input/input05.c @@ -1,107 +1,62 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) 2015 Cedric Hnyda - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of - * the License, or (at your option) any later version. - * - * This program is distributed in the hope that it would be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (C) 2024 SUSE LLC Andrea Cervesato */ - /* - * Create a virtual device (mouse), send events to /dev/uinput - * and Check that events not advertised in the input device bits - * are filtered. - */ +/*\ + * [Description] + * + * Verify that /dev/input/eventX doesn't receive any event sent from a virtual + * device, that in our case is a mouse, when events not advertised in the input + * device bits are filtered. + */ -#include #include -#include "test.h" -#include "safe_macros.h" -#include "lapi/fcntl.h" -#include "input_helper.h" - -#define X_VALUE 10 -#define Y_VALUE 10 +#include "input_common.h" -#define NB_TEST 20 +#define NUM_EVENTS 20 +#define MOVE_X 10 +#define MOVE_Y 10 -static void setup(void); -static void send_events(void); -static void cleanup(void); +static int fd_send = -1; +static int fd_recv = -1; -static int fd; -static int fd2; - -char *TCID = "input05"; - -int main(int ac, char **av) +static void run(void) { - int lc; - int pid; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); ++lc) { - pid = tst_fork(); + tst_res(TINFO, "Sending relative mouse move (%i, %i)", MOVE_X, MOVE_Y); - switch (pid) { - case 0: - send_events(); - exit(0); - case -1: - tst_brkm(TBROK | TERRNO, cleanup, "fork() failed"); - default: - if (no_events_queued(fd2, 1)) - tst_resm(TPASS, "No data received in eventX"); - else - tst_resm(TFAIL, "Data received in eventX"); - break; - } - - SAFE_WAITPID(NULL, pid, NULL, 0); + for (int i = 0; i < NUM_EVENTS; i++) { + send_relative_move(fd_send, MOVE_X, MOVE_Y); + usleep(1000); } - cleanup(); - tst_exit(); + verify_no_events_queued(fd_recv); } static void setup(void) { - tst_require_root(); - - fd = open_uinput(); + fd_send = open_uinput(); + SAFE_IOCTL(fd_send, UI_SET_EVBIT, EV_KEY); + SAFE_IOCTL(fd_send, UI_SET_KEYBIT, BTN_LEFT); + create_input_device(fd_send); - SAFE_IOCTL(NULL, fd, UI_SET_EVBIT, EV_KEY); - SAFE_IOCTL(NULL, fd, UI_SET_KEYBIT, BTN_LEFT); - - create_device(fd); - - fd2 = open_device(); + fd_recv = open_event_device(); } -static void send_events(void) +static void cleanup(void) { - int nb; + if (fd_send != -1) + destroy_input_device(fd_send); - for (nb = 0; nb < NB_TEST; ++nb) { - send_rel_move(fd, X_VALUE, Y_VALUE); - usleep(1000); - } + if (fd_recv != -1) + SAFE_CLOSE(fd_recv); } -static void cleanup(void) -{ - destroy_device(fd); -} +static struct tst_test test = { + .test_all = run, + .setup = setup, + .cleanup = cleanup, + .needs_root = 1, +};