All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrea Cervesato <andrea.cervesato@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH v2 2/7] Refactor input02 test
Date: Mon, 02 Dec 2024 11:12:46 +0100	[thread overview]
Message-ID: <20241202-input_refactoring-v2-2-369609492896@suse.com> (raw)
In-Reply-To: <20241202-input_refactoring-v2-0-369609492896@suse.com>

From: Andrea Cervesato <andrea.cervesato@suse.com>

Reviewed-by: Li Wang <liwang@redhat.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
 testcases/kernel/input/Makefile  |   4 +-
 testcases/kernel/input/input02.c | 132 +++++++++++++++------------------------
 2 files changed, 54 insertions(+), 82 deletions(-)

diff --git a/testcases/kernel/input/Makefile b/testcases/kernel/input/Makefile
index e686005c69da8b83d954da754b2e5db93ae89da7..5bc729802d1e302d7d52d71be0b6b22a20efb852 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: LDLIBS += -lltpuinput
+input01 input02: LDLIBS += -lltpuinput
 
 include $(top_srcdir)/include/mk/generic_leaf_target.mk
 
-input02 input03 input04 input05 input06: %: input_helper.o
+input03 input04 input05 input06: %: input_helper.o
diff --git a/testcases/kernel/input/input02.c b/testcases/kernel/input/input02.c
index 6964ed70320a585a755e926e066f5e24fc7a9a30..eeff54ed21cbff6eac2d90dc53c6447d379e29ed 100644
--- a/testcases/kernel/input/input02.c
+++ b/testcases/kernel/input/input02.c
@@ -1,106 +1,78 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /*
  * Copyright (c) 2015 Cedric Hnyda <chnyda@suse.com>
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
  *
- * 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
+ * Verify that /dev/input/eventX won't receive any event sent from a virtual
+ * device, that in our case is a mouse, when the event device has been grabbed
+ * by an another process.
  */
 
- /*
-  *  Create a virtual device (mouse), send events to /dev/uinput
-  *  and check that the events are not received in /dev/input/eventX
-  *  because the device is grabbed by another process
-  */
+#include "input_common.h"
 
-#include <linux/input.h>
+#define MOVE_X 10
+#define MOVE_Y 1
 
-#include "test.h"
-#include "safe_macros.h"
-#include "lapi/fcntl.h"
-#include "input_helper.h"
+static int fd_send = -1;
+static int fd_recv = -1;
 
-#define NB_TEST 20
+static void send_events(void)
+{
+	int fd;
 
-static void setup(void);
-static void send_information(void);
-static void cleanup(void);
+	fd = open_event_device();
 
-static int fd;
-static int fd2;
+	SAFE_IOCTL(fd, EVIOCGRAB, 1);
+	tst_res(TINFO, "The virtual device was grabbed");
 
-char *TCID = "input02";
+	send_relative_move(fd_send, MOVE_X, MOVE_Y);
 
-int main(int ac, char **av)
-{
-	int lc;
-	int pid;
-
-	tst_parse_opts(ac, av, NULL, NULL);
-
-	setup();
-
-	for (lc = 0; TEST_LOOPING(lc); ++lc) {
-		pid = tst_fork();
-
-		fd2 = open_device();
-
-		switch (pid) {
-		case 0:
-			send_information();
-			exit(0);
-		case -1:
-			tst_brkm(TBROK | TERRNO, cleanup, "fork() failed");
-		default:
-			if (no_events_queued(fd2, 0))
-				tst_resm(TPASS, "No data received in eventX");
-			else
-				tst_resm(TFAIL, "Data received in eventX");
-			SAFE_CLOSE(NULL, fd2);
-		break;
-		}
-
-		SAFE_WAITPID(NULL, pid, NULL, 0);
-	}
+	TST_CHECKPOINT_WAKE_AND_WAIT(0);
 
-	cleanup();
-	tst_exit();
+	SAFE_CLOSE(fd);
 }
 
-static void setup(void)
+static void run(void)
 {
-	tst_require_root();
+	if (!SAFE_FORK()) {
+		send_events();
+		exit(0);
+	}
 
-	fd = open_uinput();
-	setup_mouse_events(fd);
-	create_device(fd);
-}
+	TST_CHECKPOINT_WAIT(0);
 
-static void send_information(void)
-{
-	int nb;
+	verify_no_events_queued(fd_recv);
 
-	SAFE_IOCTL(NULL, fd2, EVIOCGRAB, 1);
-	tst_resm(TINFO, "The virtual device was grabbed");
+	TST_CHECKPOINT_WAKE(0);
+}
 
-	for (nb = 0; nb < NB_TEST; ++nb) {
-		send_rel_move(fd, 10, 1);
-		usleep(1000);
-	}
+static void setup(void)
+{
+	fd_send = open_uinput();
+	setup_mouse_events(fd_send);
+	create_input_device(fd_send);
 
-	SAFE_CLOSE(NULL, fd2);
+	fd_recv = open_event_device();
 }
 
 static void cleanup(void)
 {
-	destroy_device(fd);
+	if (fd_send != -1)
+		destroy_input_device(fd_send);
+
+	if (fd_recv != -1)
+		SAFE_CLOSE(fd_recv);
 }
+
+static struct tst_test test = {
+	.test_all = run,
+	.setup = setup,
+	.cleanup = cleanup,
+	.forks_child = 1,
+	.needs_root = 1,
+	.needs_checkpoints = 1,
+};

-- 
2.43.0


-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

  parent reply	other threads:[~2024-12-02 10:14 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-02 10:12 [LTP] [PATCH v2 0/7] Rewrite input testing suite Andrea Cervesato
2024-12-02 10:12 ` [LTP] [PATCH v2 1/7] Refactor input01 test Andrea Cervesato
2024-12-02 15:15   ` Petr Vorel
2024-12-02 10:12 ` Andrea Cervesato [this message]
2024-12-02 10:12 ` [LTP] [PATCH v2 3/7] Refactor input03 test Andrea Cervesato
2024-12-02 10:12 ` [LTP] [PATCH v2 4/7] Refactor input04 test Andrea Cervesato
2024-12-02 10:12 ` [LTP] [PATCH v2 5/7] Refactor input05 test Andrea Cervesato
2024-12-02 10:12 ` [LTP] [PATCH v2 6/7] Refactor input06 test Andrea Cervesato
2024-12-03 11:34   ` Cyril Hrubis
2024-12-03 11:43     ` Andrea Cervesato via ltp
2024-12-02 10:12 ` [LTP] [PATCH v2 7/7] Delete depreacted input test suite helper Andrea Cervesato
2024-12-03 11:49 ` [LTP] [PATCH v2 0/7] Rewrite input testing suite Andrea Cervesato via ltp

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=20241202-input_refactoring-v2-2-369609492896@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.