From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 4/7] Refactor input04 test
Date: Mon, 25 Nov 2024 13:19:00 +0100 [thread overview]
Message-ID: <20241125-input_refactoring-v1-4-b622b3aa698d@suse.com> (raw)
In-Reply-To: <20241125-input_refactoring-v1-0-b622b3aa698d@suse.com>
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/input/Makefile | 4 +-
testcases/kernel/input/input04.c | 113 ++++++++++++---------------------------
2 files changed, 35 insertions(+), 82 deletions(-)
diff --git a/testcases/kernel/input/Makefile b/testcases/kernel/input/Makefile
index 8c302dbc8c75cf4fd42bc162b4bb8a9882237164..cf35e1bfc150a6c1556ef796d4858c0df9020131 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: LDLIBS += -lltpuinput
+input01 input02 input03 input04: LDLIBS += -lltpuinput
include $(top_srcdir)/include/mk/generic_leaf_target.mk
-input04 input05 input06: %: input_helper.o
+input05 input06: %: input_helper.o
diff --git a/testcases/kernel/input/input04.c b/testcases/kernel/input/input04.c
index e57b76b0b40f8be4f851137f1a9185b37c6e64c0..3c76d7c82ad7fe76f35f5a4ecfc78f27069d3fa0 100644
--- a/testcases/kernel/input/input04.c
+++ b/testcases/kernel/input/input04.c
@@ -1,103 +1,56 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
- *
- * 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 <andrea.cervesato@suse.com>
*/
- /*
- * Create a virtual device (mouse), send empty events to /dev/uinput
- * and check that the events are not received in /dev/inputX
- */
-
-#include <linux/input.h>
-
-#include "test.h"
-#include "safe_macros.h"
-#include "lapi/fcntl.h"
-#include "input_helper.h"
-
-#define NB_TEST 20
+/*\
+ * [Description]
+ *
+ * Verify that /dev/input/eventX doesn't receive any event sent from a virtual
+ * device, that in our case is a mouse, when relative move is (0, 0)
+ */
-static void setup(void);
-static void send_events(void);
-static void cleanup(void);
+#include "input_common.h"
-static int fd, fd2;
+#define NUM_EVENTS 20
-char *TCID = "input04";
+static int fd_send = -1;
+static int fd_recv = -1;
-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 empty relative move");
- 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 /dev/inputX");
- else
- tst_resm(TFAIL,
- "Data received /dev/inputX");
- break;
- }
-
- SAFE_WAITPID(NULL, pid, NULL, 0);
+ for (int i = 0; i < NUM_EVENTS; i++) {
+ send_relative_move(fd_send, 0, 0);
+ usleep(1000);
}
- cleanup();
- tst_exit();
+ verify_no_events_queued(fd_recv);
}
static void setup(void)
{
- tst_require_root();
-
- fd = open_uinput();
- setup_mouse_events(fd);
- create_device(fd);
-
- fd2 = open_device();
-}
-
-static void send_events(void)
-{
- int nb;
+ fd_send = open_uinput();
+ setup_mouse_events(fd_send);
+ create_input_device(fd_send);
- for (nb = 0; nb < NB_TEST; ++nb) {
- send_rel_move(fd, 0, 0);
- usleep(1000);
- }
+ fd_recv = open_event_device();
}
static void cleanup(void)
{
- if (fd2 > 0 && close(fd2))
- tst_resm(TWARN | TERRNO, "close(fd2)");
+ if (fd_send != -1)
+ destroy_input_device(fd_send);
- destroy_device(fd);
+ if (fd_recv != -1)
+ SAFE_CLOSE(fd_recv);
}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+ .cleanup = cleanup,
+ .needs_root = 1,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next prev parent reply other threads:[~2024-11-25 12:21 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-11-25 12:18 [LTP] [PATCH 0/7] Rewrite input testing suite Andrea Cervesato
2024-11-25 12:18 ` [LTP] [PATCH 1/7] Refactor input01 test Andrea Cervesato
2024-11-28 7:33 ` Li Wang
2024-11-25 12:18 ` [LTP] [PATCH 2/7] Refactor input02 test Andrea Cervesato
2024-11-28 7:49 ` Li Wang
2024-11-25 12:18 ` [LTP] [PATCH 3/7] Refactor input03 test Andrea Cervesato
2024-11-28 9:43 ` Li Wang
2024-11-25 12:19 ` Andrea Cervesato [this message]
2024-11-29 2:04 ` [LTP] [PATCH 4/7] Refactor input04 test Li Wang
2024-11-25 12:19 ` [LTP] [PATCH 5/7] Refactor input05 test Andrea Cervesato
2024-11-29 2:10 ` Li Wang
2024-11-25 12:19 ` [LTP] [PATCH 6/7] Refactor input06 test Andrea Cervesato
2024-11-25 12:19 ` [LTP] [PATCH 7/7] Delete depreacted input test suite helper Andrea Cervesato
2024-11-28 10:55 ` Cyril Hrubis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241125-input_refactoring-v1-4-b622b3aa698d@suse.com \
--to=andrea.cervesato@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox