From patchwork Mon Dec 2 10:12:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 2017058 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=AuQ2DuIm; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Re6u5r5y; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=AuQ2DuIm; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=Re6u5r5y; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y203Z4BV0z1xt3 for ; Mon, 2 Dec 2024 21:13:14 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D633C3DD282 for ; Mon, 2 Dec 2024 11:13:12 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 33E093DD246 for ; Mon, 2 Dec 2024 11:12:52 +0100 (CET) Authentication-Results: in-7.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.de (client-ip=195.135.223.130; helo=smtp-out1.suse.de; envelope-from=andrea.cervesato@suse.de; receiver=lists.linux.it) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id A1A1B203C56 for ; Mon, 2 Dec 2024 11:12:51 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id AF80B211B8; Mon, 2 Dec 2024 10:12:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134370; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8mHzBlVx7wYmaYU2aQ47NripNNtxxJKYdN1gSuJZqqg=; b=AuQ2DuImtHUM6T0pNTygFrzp6WvUZ065IoAV4N9NEh+MRVuaHn3oFA3v5Z1RMISETwrvYf 8j6RnYq6e3eGACpqxZPDCg+UQJSGp2G2ihnewt2zf/aqWsSyZeWa6CyNhcncSs7dYJmUeg ynFEtD5I0hV5CLQFy2afPixlNOxi7eM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134370; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8mHzBlVx7wYmaYU2aQ47NripNNtxxJKYdN1gSuJZqqg=; b=Re6u5r5yMhuQGuY+bXnF5l7rsbRkz0mubN0q7klffmtUPBHqkWkOt8yYmsBFQ4AiTV9TTg oTxdEVYdm36XqkAw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134370; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8mHzBlVx7wYmaYU2aQ47NripNNtxxJKYdN1gSuJZqqg=; b=AuQ2DuImtHUM6T0pNTygFrzp6WvUZ065IoAV4N9NEh+MRVuaHn3oFA3v5Z1RMISETwrvYf 8j6RnYq6e3eGACpqxZPDCg+UQJSGp2G2ihnewt2zf/aqWsSyZeWa6CyNhcncSs7dYJmUeg ynFEtD5I0hV5CLQFy2afPixlNOxi7eM= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134370; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=8mHzBlVx7wYmaYU2aQ47NripNNtxxJKYdN1gSuJZqqg=; b=Re6u5r5yMhuQGuY+bXnF5l7rsbRkz0mubN0q7klffmtUPBHqkWkOt8yYmsBFQ4AiTV9TTg oTxdEVYdm36XqkAw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 90AC013A40; Mon, 2 Dec 2024 10:12:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id UH5+ISKITWcNSwAAD6G6ig (envelope-from ); Mon, 02 Dec 2024 10:12:50 +0000 From: Andrea Cervesato Date: Mon, 02 Dec 2024 11:12:45 +0100 MIME-Version: 1.0 Message-Id: <20241202-input_refactoring-v2-1-369609492896@suse.com> References: <20241202-input_refactoring-v2-0-369609492896@suse.com> In-Reply-To: <20241202-input_refactoring-v2-0-369609492896@suse.com> To: ltp@lists.linux.it X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733134370; l=10357; i=andrea.cervesato@suse.com; s=20240812; h=from:subject:message-id; bh=Wc1cH84xtXonixepp885728aRQFDk9JNahLsz/vvzOA=; b=+GXKuyVrVEMmSViiWYljbzv5w2G1M9lUPSti19N2Y5qnAmuVRc1BWAAZt3jFJtIY+5yebgRxE T7vJjdXUGUQCEzq1KQMHkbcW5otGyfoO2YOIlsmfQZiSC/d13LFghT0 X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=RG/nLJ5snb1tLKGwSORQXBJ5XA4juT0WF2Pc/lq9meo= X-Spam-Score: -4.30 X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.com:mid, suse.com:email, imap1.dmz-prg2.suse.org:helo] X-Spam-Level: X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-7.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-7.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v2 1/7] Refactor input01 test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Andrea Cervesato Reviewed-by: Li Wang Signed-off-by: Andrea Cervesato Reviewed-by: Petr Vorel --- libs/uinput/tst_uinput.c | 26 ++++- testcases/kernel/input/Makefile | 5 +- testcases/kernel/input/input01.c | 205 ++++++++-------------------------- testcases/kernel/input/input_common.h | 97 ++++++++++++++++ 4 files changed, 173 insertions(+), 160 deletions(-) diff --git a/libs/uinput/tst_uinput.c b/libs/uinput/tst_uinput.c index 6dc8a7d4ec41f1c53eb675c894cdcd059ee1198a..36f3d5e2759bc13c5ae989799741bbd288a2c234 100644 --- a/libs/uinput/tst_uinput.c +++ b/libs/uinput/tst_uinput.c @@ -13,6 +13,7 @@ #include "tst_test.h" #include "tst_uinput.h" +#include "tst_safe_stdio.h" #define VIRTUAL_DEVICE "virtual-device-ltp" @@ -127,6 +128,27 @@ void destroy_input_device(int fd) SAFE_CLOSE(fd); } +static void check_ui_get_sysname_ioctl(int fd) +{ + char sys_name[256]; + char dev_name[256]; + char *path; + + SAFE_IOCTL(fd, UI_GET_SYSNAME(sizeof(sys_name)), sys_name, NULL); + SAFE_ASPRINTF(&path, "/sys/devices/virtual/input/%s/name", sys_name); + + if (FILE_SCANF(path, "%s", dev_name)) { + tst_brk(TBROK|TERRNO, "Failed to read '%s'", path); + free(path); + return; + } + + if (strcmp(VIRTUAL_DEVICE, dev_name)) + tst_brk(TBROK, "ioctl UI_GET_SYSNAME returned wrong name"); + + free(path); +} + void create_input_device(int fd) { int nb; @@ -144,8 +166,10 @@ void create_input_device(int fd) SAFE_IOCTL(fd, UI_DEV_CREATE, NULL); for (nb = 100; nb > 0; nb--) { - if (check_device()) + if (check_device()) { + check_ui_get_sysname_ioctl(fd); return; + } usleep(10000); } diff --git a/testcases/kernel/input/Makefile b/testcases/kernel/input/Makefile index 032254444e1a1e5d53e3299dfe5d7e4cba6a5162..e686005c69da8b83d954da754b2e5db93ae89da7 100644 --- a/testcases/kernel/input/Makefile +++ b/testcases/kernel/input/Makefile @@ -3,10 +3,13 @@ top_srcdir ?= ../../.. +LTPLIBS = uinput + include $(top_srcdir)/include/mk/testcases.mk FILTER_OUT_MAKE_TARGETS := input_helper +input01: LDLIBS += -lltpuinput include $(top_srcdir)/include/mk/generic_leaf_target.mk -$(MAKE_TARGETS): %: input_helper.o +input02 input03 input04 input05 input06: %: input_helper.o diff --git a/testcases/kernel/input/input01.c b/testcases/kernel/input/input01.c index 95db3f43f37f361db2691beb0d077626e81b6368..0872204111b81fd19a1525ef7f099e8ddead9658 100644 --- a/testcases/kernel/input/input01.c +++ b/testcases/kernel/input/input01.c @@ -1,187 +1,76 @@ +// 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 the events are well received in /dev/input/eventX - */ - -#include - -#include "input_helper.h" -#include "test.h" -#include "safe_macros.h" -#include "lapi/fcntl.h" - -#define NB_TEST 20 +/*\ + * [Description] + * + * Verify that /dev/input/eventX receive events sent from a virtual device, + * that in our case is a mouse. + */ -static void setup(void); -static void send_events(void); -static int verify_data(struct input_event *iev, int nb); -static int check_events(void); -static void cleanup(void); +#include "input_common.h" -static int fd; -static int fd2; +#define NUM_EVENTS 20 +#define MOVE_X 10 +#define MOVE_Y 1 -char *TCID = "input01"; +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(); - - switch (pid) { - case 0: - send_events(); - exit(0); - case -1: - tst_brkm(TBROK | TERRNO, cleanup, "fork() failed"); - default: - if (check_events()) - tst_resm(TFAIL, "Wrong data read from eventX"); - else - tst_resm(TPASS, "Data received from eventX"); - break; - } - - SAFE_WAITPID(NULL, pid, NULL, 0); - } + struct input_event iev[3]; - cleanup(); - tst_exit(); -} + tst_res(TINFO, "Sending relative move: (%i, %i)", MOVE_X, MOVE_Y); -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; - - for (nb = 0; nb < NB_TEST; ++nb) { - send_rel_move(fd, 10, 1); + for (int i = 0; i < NUM_EVENTS; i++) { + send_relative_move(fd_send, MOVE_X, MOVE_Y); usleep(1000); } -} -static int check_events(void) -{ - int nb, rd; - unsigned int i; - struct input_event iev[64]; - - nb = 0; + tst_res(TINFO, "Reading events back"); - while (nb < NB_TEST * 3) { - rd = read(fd2, iev, sizeof(iev)); + for (int i = 0; i < NUM_EVENTS; i++) { + SAFE_READ(0, fd_recv, iev, 3 * sizeof(struct input_event)); - if (rd < 0) - tst_brkm(TBROK | TERRNO, cleanup, "read()"); + TST_EXP_EQ_LI(iev[0].type, EV_REL); + TST_EXP_EQ_LI(iev[0].code, REL_X); + TST_EXP_EQ_LI(iev[0].value, MOVE_X); - if (rd == 0 || rd % sizeof(struct input_event)) { - tst_resm(TINFO, "read() returned unexpected %i", rd); - return 1; - } + TST_EXP_EQ_LI(iev[1].type, EV_REL); + TST_EXP_EQ_LI(iev[1].code, REL_Y); + TST_EXP_EQ_LI(iev[1].value, MOVE_Y); - for (i = 0; i < rd / sizeof(struct input_event); i++) { - if (verify_data(&iev[i], nb++)) - return 1; - } + TST_EXP_EQ_LI(iev[2].type, EV_SYN); + TST_EXP_EQ_LI(iev[2].code, 0); + TST_EXP_EQ_LI(iev[2].value, 0); } - - return 0; } -static int verify_data(struct input_event *iev, int nb) +static void setup(void) { - if (nb % 3 == 0) { - if (iev->type != EV_REL) { - tst_resm(TINFO, - "%i: Unexpected event type %i expected %i", - nb, iev->type, EV_REL); - return 1; - } - - if (iev->code != REL_X) - return 1; - - if (iev->value != 10) - return 1; - - return 0; - } - - if (nb % 3 == 1) { - if (iev->type != EV_REL) { - tst_resm(TINFO, - "%i: Unexpected event type %i expected %i", - nb, iev->type, EV_REL); - return 1; - } + fd_send = open_uinput(); + setup_mouse_events(fd_send); + create_input_device(fd_send); - if (iev->code != REL_Y) - return 1; - - if (iev->value != 1) - return 1; - - return 0; - } - - if (nb % 3 == 2) { - if (iev->type != EV_SYN) { - tst_resm(TINFO, - "%i: Unexpected event type %i expected %i", - nb, iev->type, EV_SYN); - return 1; - } - - if (iev->code != 0) - return 1; - - if (iev->value != 0) - return 1; - - return 0; - } - return 1; + 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, +}; diff --git a/testcases/kernel/input/input_common.h b/testcases/kernel/input/input_common.h new file mode 100644 index 0000000000000000000000000000000000000000..0ac1624b3042f0bd14f063db76189dfc18d84674 --- /dev/null +++ b/testcases/kernel/input/input_common.h @@ -0,0 +1,97 @@ +/* SPDX-License-Identifier: GPL-2.0-or-later */ +/* + * Copyright (C) 2024 SUSE LLC Andrea Cervesato + */ + +#ifndef INPUT_COMMON_H__ +#define INPUT_COMMON_H__ + +#include +#include + +#include "tst_test.h" +#include "tst_uinput.h" + +static inline int open_event_device(void) +{ + int fd; + char path[1024]; + char *device; + char *handlers; + + memset(path, 0, sizeof(path)); + + handlers = get_input_field_value('H'); + device = strtok(handlers, " "); + + while (device) { + if (strstr(device, "event") != NULL) { + memset(path, 0, sizeof(path)); + snprintf(path, sizeof(path), "/dev/input/%s", device); + + if (!access(path, F_OK)) { + tst_res(TINFO, "Found event device: %s", path); + break; + } + } + + device = strtok(NULL, " "); + } + + free(handlers); + + if (path[0] == '\0') + tst_brk(TBROK, "Can't find event device"); + + fd = SAFE_OPEN(path, O_RDONLY); + + return fd; +} + +static inline void send_event( + const int fd, const int event, + const int code, const int value) +{ + struct input_event ev = { + .type = event, + .code = code, + .value = value, + }; + + SAFE_WRITE(SAFE_WRITE_ALL, fd, &ev, sizeof(ev)); +} + +static inline void send_relative_move(const int fd, const int x, const int y) +{ + send_event(fd, EV_REL, REL_X, x); + send_event(fd, EV_REL, REL_Y, y); + send_event(fd, EV_SYN, 0, 0); +} + +static inline void verify_no_events_queued(const int fd_recv) +{ + int num_bytes; + int num_events; + struct input_event ev; + struct pollfd fds = { + .fd = fd_recv, + .events = POLLIN + }; + + num_events = poll(&fds, 1, 30); + + TST_EXP_EQ_LI(num_events, 0); + if (!num_events) + return; + + num_bytes = SAFE_READ(0, fd_recv, &ev, sizeof(ev)); + if (!num_bytes) + return; + + tst_res(TFAIL, "Received unexpected event: " + "type=%i, code=%i, value=%i", + ev.type, + ev.code, + ev.value); +} +#endif From patchwork Mon Dec 2 10:12:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 2017063 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=iQs/ImHY; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=UjbdbSKm; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=iQs/ImHY; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=UjbdbSKm; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y205B5Wrdz1xt3 for ; Mon, 2 Dec 2024 21:14:38 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id D82C83DD283 for ; Mon, 2 Dec 2024 11:14:36 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-2.smtp.seeweb.it (in-2.smtp.seeweb.it [IPv6:2001:4b78:1:20::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id ACC323DD246 for ; Mon, 2 Dec 2024 11:12:52 +0100 (CET) Authentication-Results: in-2.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.de (client-ip=195.135.223.130; helo=smtp-out1.suse.de; envelope-from=andrea.cervesato@suse.de; receiver=lists.linux.it) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 843BC66EB2A for ; Mon, 2 Dec 2024 11:12:51 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id D58E4211AD; Mon, 2 Dec 2024 10:12:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134370; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ROv/MiFMrRgeqbdxb3f4BBkEwCDdiJwxAYerya1Bla0=; b=iQs/ImHYV+g1rpim8dNOCvFoYMjqHXVOqO9KmTIi8mMnHOs+Ny39bWR0rqqptHBaCqVWHD tH9E/gq8BzXZxqCIGL3oUaBcQPHWCQJj8vSs/VWS+rrRSfzGRbM/at+3qWIN1/411MudC8 o2R2i+kSY0pfDVQnmSSGFv2PV7M26a0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134370; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ROv/MiFMrRgeqbdxb3f4BBkEwCDdiJwxAYerya1Bla0=; b=UjbdbSKmnqueLRAJNtvNfow/TQ8i3vBjP2knCy5AoXsD7lI6oB/BlNb3rMSh0TQqeeB2Q5 o6pZQJ0M+CuunPDA== Authentication-Results: smtp-out1.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="iQs/ImHY"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=UjbdbSKm DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134370; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ROv/MiFMrRgeqbdxb3f4BBkEwCDdiJwxAYerya1Bla0=; b=iQs/ImHYV+g1rpim8dNOCvFoYMjqHXVOqO9KmTIi8mMnHOs+Ny39bWR0rqqptHBaCqVWHD tH9E/gq8BzXZxqCIGL3oUaBcQPHWCQJj8vSs/VWS+rrRSfzGRbM/at+3qWIN1/411MudC8 o2R2i+kSY0pfDVQnmSSGFv2PV7M26a0= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134370; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=ROv/MiFMrRgeqbdxb3f4BBkEwCDdiJwxAYerya1Bla0=; b=UjbdbSKmnqueLRAJNtvNfow/TQ8i3vBjP2knCy5AoXsD7lI6oB/BlNb3rMSh0TQqeeB2Q5 o6pZQJ0M+CuunPDA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id B5A7A13A43; Mon, 2 Dec 2024 10:12:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id wDKXKiKITWcNSwAAD6G6ig (envelope-from ); Mon, 02 Dec 2024 10:12:50 +0000 From: Andrea Cervesato Date: Mon, 02 Dec 2024 11:12:46 +0100 MIME-Version: 1.0 Message-Id: <20241202-input_refactoring-v2-2-369609492896@suse.com> References: <20241202-input_refactoring-v2-0-369609492896@suse.com> In-Reply-To: <20241202-input_refactoring-v2-0-369609492896@suse.com> To: ltp@lists.linux.it X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733134370; l=5026; i=andrea.cervesato@suse.com; s=20240812; h=from:subject:message-id; bh=C2qgRUpBGrsd4txdQ9E7FRSn9QynmjyxofhGXRlTc78=; b=qi0NvMH7soQuBbQvMgC8ydr8zpJkh9yBVp0S26U9OIFOAq4J3dcNkqWcoQANRLpBzCpM7PC2r FLkd6mP2K4TDeDfuXBt4tgDPGwHqxBzZ1/U6UyZDtU0itmqREKIakQb X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=RG/nLJ5snb1tLKGwSORQXBJ5XA4juT0WF2Pc/lq9meo= X-Rspamd-Queue-Id: D58E4211AD X-Spam-Level: X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCPT_COUNT_TWO(0.00)[2]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[suse.de:dkim,imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.com:email,suse.com:mid]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -4.51 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-2.smtp.seeweb.it Subject: [LTP] [PATCH v2 2/7] Refactor input02 test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Andrea Cervesato Reviewed-by: Li Wang Signed-off-by: Andrea Cervesato --- 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 + * Copyright (C) 2024 SUSE LLC Andrea Cervesato + */ + +/*\ + * [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 +#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, +}; From patchwork Mon Dec 2 10:12:47 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 2017057 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=sydyaOFz; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=QsQzySlr; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=sydyaOFz; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=QsQzySlr; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y203F2FNHz1xt3 for ; Mon, 2 Dec 2024 21:12:57 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 289133DD276 for ; Mon, 2 Dec 2024 11:12:55 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-3.smtp.seeweb.it (in-3.smtp.seeweb.it [217.194.8.3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 0AA393DD246 for ; Mon, 2 Dec 2024 11:12:51 +0100 (CET) Authentication-Results: in-3.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.de (client-ip=195.135.223.130; helo=smtp-out1.suse.de; envelope-from=andrea.cervesato@suse.de; receiver=lists.linux.it) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-3.smtp.seeweb.it (Postfix) with ESMTPS id 816A51BE85F9 for ; Mon, 2 Dec 2024 11:12:51 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 0050B211BA; Mon, 2 Dec 2024 10:12:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aoBtueZOmaV9g3axA68bzJ+P7wevourCYoq+ja/JvWE=; b=sydyaOFznd3hDOcAdaeS6n+gyFVoCy59uno9KDeREC1ROg+B+c4mHXTs+JsKBF3Ou1DcfG 4XKSyYWggpe/Lg3h31OoV6NscfqHCK4lreHE/Xjt7SXx+rzCNuTQI5MiPs4TzyYS+/fOn+ Gug55DD4rdYFZBTnu5jW/EmBa8X+g/c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aoBtueZOmaV9g3axA68bzJ+P7wevourCYoq+ja/JvWE=; b=QsQzySlr+1Qidn4s+7yy6ECNyxsePV/JQxBmkrXShGbexMhFgBANzjYRmXGx0tq7IvRi2q uoTEhJ36MuLtN9Aw== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aoBtueZOmaV9g3axA68bzJ+P7wevourCYoq+ja/JvWE=; b=sydyaOFznd3hDOcAdaeS6n+gyFVoCy59uno9KDeREC1ROg+B+c4mHXTs+JsKBF3Ou1DcfG 4XKSyYWggpe/Lg3h31OoV6NscfqHCK4lreHE/Xjt7SXx+rzCNuTQI5MiPs4TzyYS+/fOn+ Gug55DD4rdYFZBTnu5jW/EmBa8X+g/c= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=aoBtueZOmaV9g3axA68bzJ+P7wevourCYoq+ja/JvWE=; b=QsQzySlr+1Qidn4s+7yy6ECNyxsePV/JQxBmkrXShGbexMhFgBANzjYRmXGx0tq7IvRi2q uoTEhJ36MuLtN9Aw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id DAAC613A40; Mon, 2 Dec 2024 10:12:50 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id gHujMyKITWcNSwAAD6G6ig (envelope-from ); Mon, 02 Dec 2024 10:12:50 +0000 From: Andrea Cervesato Date: Mon, 02 Dec 2024 11:12:47 +0100 MIME-Version: 1.0 Message-Id: <20241202-input_refactoring-v2-3-369609492896@suse.com> References: <20241202-input_refactoring-v2-0-369609492896@suse.com> In-Reply-To: <20241202-input_refactoring-v2-0-369609492896@suse.com> To: ltp@lists.linux.it X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733134370; l=6429; i=andrea.cervesato@suse.com; s=20240812; h=from:subject:message-id; bh=HtbkLFM6+ORsgAA45HAcMDHxzzK8+FbVBi2oMR0TAkw=; b=DLlsxESBYTljFE2KRPblOYURWl1rhuZ6l8WikS/n1akfTigRjKF06KheLZXdDyD6elwK2BWPc QHI6j4JutyMBmZSaKH8M5kG6WLXtjU3AGn5EDOttoy4tfiTWwKzMvpU X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=RG/nLJ5snb1tLKGwSORQXBJ5XA4juT0WF2Pc/lq9meo= X-Spam-Score: -4.30 X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo, suse.com:mid, suse.com:email] X-Spam-Level: X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-3.smtp.seeweb.it Subject: [LTP] [PATCH v2 3/7] Refactor input03 test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Andrea Cervesato Reviewed-by: Li Wang Signed-off-by: Andrea Cervesato --- testcases/kernel/input/Makefile | 4 +- testcases/kernel/input/input03.c | 176 ++++++++++++++++----------------------- 2 files changed, 73 insertions(+), 107 deletions(-) diff --git a/testcases/kernel/input/Makefile b/testcases/kernel/input/Makefile index 5bc729802d1e302d7d52d71be0b6b22a20efb852..8c302dbc8c75cf4fd42bc162b4bb8a9882237164 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: LDLIBS += -lltpuinput +input01 input02 input03: LDLIBS += -lltpuinput include $(top_srcdir)/include/mk/generic_leaf_target.mk -input03 input04 input05 input06: %: input_helper.o +input04 input05 input06: %: input_helper.o diff --git a/testcases/kernel/input/input03.c b/testcases/kernel/input/input03.c index 6cd753d0b1bf98ce671dfa739cde817b4c52c547..4a3eb464ee0322b134f44158a08dbb4ed000216f 100644 --- a/testcases/kernel/input/input03.c +++ b/testcases/kernel/input/input03.c @@ -1,145 +1,111 @@ +// 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 the events are well received in /dev/input/mice - */ +/*\ + * [Description] + * + * Verify that /dev/input/mice receive events sent from a virtual device, + * that in our case is a mouse. The events are a sequence of mouse right click. + */ -#include #include -#include "test.h" -#include "safe_macros.h" -#include "lapi/fcntl.h" -#include "input_helper.h" +#include "input_common.h" -#define NB_TEST 10 +#define NUM_EVENTS 10 #define PS2_RIGHT_BTN 0x02 +#define MOUSE_DEV "/dev/input/mice" -static void setup(void); -static void send_events(void); -static int check_events(void); -static void cleanup(void); +static int fd_send = -1; +static int fd_recv = -1; -static int fd, fd2; - -char *TCID = "input03"; - -int main(int ac, char **av) +static void recv_data(void) { - int lc; - int pid; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - for (lc = 0; TEST_LOOPING(lc); ++lc) { - pid = tst_fork(); - - switch (pid) { - case 0: - send_events(); - exit(0); - case -1: - tst_brkm(TBROK | TERRNO, cleanup, "fork() failed"); - default: - if (check_events()) - tst_resm(TFAIL, "Wrong data received"); - else - tst_resm(TPASS, - "Data received in /dev/input/mice"); - break; - } + tst_res(TINFO, "Reading events back"); - SAFE_WAITPID(NULL, pid, NULL, 0); - } + char buf[30]; + int events = 0; + int pressed = 0; + int num_bytes = 0; - cleanup(); - tst_exit(); -} + TST_CHECKPOINT_WAKE(0); -static void setup(void) -{ - tst_require_root(); + while (events < NUM_EVENTS) { + memset(buf, 0, sizeof(buf)); - fd = open_uinput(); + num_bytes = SAFE_READ(0, fd_recv, buf, sizeof(buf)); - setup_mouse_events(fd); - SAFE_IOCTL(NULL, fd, UI_SET_EVBIT, EV_KEY); - SAFE_IOCTL(NULL, fd, UI_SET_KEYBIT, BTN_RIGHT); + for (int i = 0; i < num_bytes / 3; i++) { + if (buf[3*i] & PS2_RIGHT_BTN) + pressed = 1; - create_device(fd); + if (pressed == 1 && !(buf[3*i] & PS2_RIGHT_BTN)) { + pressed = 0; + events++; + } + } + } - fd2 = SAFE_OPEN(NULL, "/dev/input/mice", O_RDONLY); + TST_EXP_EQ_LI(events, NUM_EVENTS); } -static void send_events(void) +static void send_mouse_events(void) { - int nb; + tst_res(TINFO, "Sending right click"); + + TST_CHECKPOINT_WAIT(0); - for (nb = 0; nb < NB_TEST; ++nb) { - send_event(fd, EV_KEY, BTN_RIGHT, 1); - send_event(fd, EV_SYN, 0, 0); + for (int i = 0; i < NUM_EVENTS; i++) { + send_event(fd_send, EV_KEY, BTN_RIGHT, 1); + send_event(fd_send, EV_SYN, 0, 0); usleep(1000); - send_event(fd, EV_KEY, BTN_RIGHT, 0); - send_event(fd, EV_SYN, 0, 0); + + send_event(fd_send, EV_KEY, BTN_RIGHT, 0); + send_event(fd_send, EV_SYN, 0, 0); usleep(1000); } } -static int check_events(void) +static void run(void) { - int nb, rd, i, pressed = 0; - char buf[30]; - - nb = 0; - - while (nb < NB_TEST) { - rd = read(fd2, buf, sizeof(buf)); + if (!SAFE_FORK()) { + send_mouse_events(); + exit(0); + } - if (rd < 0) - tst_brkm(TBROK | TERRNO, NULL, "read() failed"); + recv_data(); +} - if (rd % 3) { - tst_resm(TINFO, "read() returned %i", rd); - return 1; - } +static void setup(void) +{ + fd_send = open_uinput(); - for (i = 0; i < rd / 3; i++) { - if (buf[3*i] & PS2_RIGHT_BTN) - pressed = 1; + setup_mouse_events(fd_send); + SAFE_IOCTL(fd_send, UI_SET_EVBIT, EV_KEY); + SAFE_IOCTL(fd_send, UI_SET_KEYBIT, BTN_RIGHT); - if (pressed == 1 && !(buf[3*i] & PS2_RIGHT_BTN)) { - pressed = 0; - nb++; - } - } - } + create_input_device(fd_send); - return nb != NB_TEST; + fd_recv = SAFE_OPEN(MOUSE_DEV, O_RDONLY); } static void cleanup(void) { - if (fd2 > 0 && close(fd2)) - tst_resm(TWARN, "close(fd2) failed"); + 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, + .forks_child = 1, + .needs_root = 1, + .needs_checkpoints = 1, +}; From patchwork Mon Dec 2 10:12:48 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 2017064 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=d5+reOLi; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8kt5PrWQ; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=d5+reOLi; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=8kt5PrWQ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y205r1xsZz1yQN for ; Mon, 2 Dec 2024 21:15:12 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 824AD3DD287 for ; Mon, 2 Dec 2024 11:15:10 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [IPv6:2001:4b78:1:20::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 0B5073DD27C for ; Mon, 2 Dec 2024 11:12:53 +0100 (CET) Authentication-Results: in-7.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.de (client-ip=2a07:de40:b251:101:10:150:64:2; helo=smtp-out2.suse.de; envelope-from=andrea.cervesato@suse.de; receiver=lists.linux.it) Received: from smtp-out2.suse.de (smtp-out2.suse.de [IPv6:2a07:de40:b251:101:10:150:64:2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id C0951219111 for ; Mon, 2 Dec 2024 11:12:52 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 271E61F444; Mon, 2 Dec 2024 10:12:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qwZAgogNBkPakN7CPuznyIdwZGHLgs1c+jpUyrWV/Ng=; b=d5+reOLiMrfd3XodpIsQz33iHe8Pm3auZHKy3+4PywQBEutn5e6K4a+fAeK60dAN/NP8iG RpS5gWTgoiJWP97IGJIlWAxHavhHHLRQ5+0B3OyTAEq3UjES2ry4kXS6xQA5hzRTj/fhmu rafik++PLenFNqJae6Gx0iaUTqPrfWg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qwZAgogNBkPakN7CPuznyIdwZGHLgs1c+jpUyrWV/Ng=; b=8kt5PrWQQWTQuxQWSacj84yqL3MPOoEME77AhfSXOPHnIgCT4uKxd31+T5I2L3/813aNji MoqWZVsCUveeE5AQ== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b=d5+reOLi; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=8kt5PrWQ DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qwZAgogNBkPakN7CPuznyIdwZGHLgs1c+jpUyrWV/Ng=; b=d5+reOLiMrfd3XodpIsQz33iHe8Pm3auZHKy3+4PywQBEutn5e6K4a+fAeK60dAN/NP8iG RpS5gWTgoiJWP97IGJIlWAxHavhHHLRQ5+0B3OyTAEq3UjES2ry4kXS6xQA5hzRTj/fhmu rafik++PLenFNqJae6Gx0iaUTqPrfWg= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=qwZAgogNBkPakN7CPuznyIdwZGHLgs1c+jpUyrWV/Ng=; b=8kt5PrWQQWTQuxQWSacj84yqL3MPOoEME77AhfSXOPHnIgCT4uKxd31+T5I2L3/813aNji MoqWZVsCUveeE5AQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 0BC3813A31; Mon, 2 Dec 2024 10:12:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id gIoXASOITWcNSwAAD6G6ig (envelope-from ); Mon, 02 Dec 2024 10:12:51 +0000 From: Andrea Cervesato Date: Mon, 02 Dec 2024 11:12:48 +0100 MIME-Version: 1.0 Message-Id: <20241202-input_refactoring-v2-4-369609492896@suse.com> References: <20241202-input_refactoring-v2-0-369609492896@suse.com> In-Reply-To: <20241202-input_refactoring-v2-0-369609492896@suse.com> To: ltp@lists.linux.it X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733134370; l=4520; i=andrea.cervesato@suse.com; s=20240812; h=from:subject:message-id; bh=DtVIhdT/DMeTx8539HR6oBGEFZOj4cLjb9hWOqrlOSE=; b=tJXr+Nw8sqIf0wOU9azoS74KHkj6mKkTwKIL+HOZhJ7v2kidHstqa5rM6xCXaqC5llpxyx42v Yasnu2tfpCJBlonin+4JtSBEDHpl0ofj4sGYf0PSENhLtxDh+8Ivha3 X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=RG/nLJ5snb1tLKGwSORQXBJ5XA4juT0WF2Pc/lq9meo= X-Rspamd-Queue-Id: 271E61F444 X-Spam-Level: X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; FUZZY_BLOCKED(0.00)[rspamd.com]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; MIME_TRACE(0.00)[0:+]; ARC_NA(0.00)[]; TO_DN_SOME(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; RCPT_COUNT_TWO(0.00)[2]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.de:dkim,suse.com:email,suse.com:mid]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -4.51 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-7.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-7.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v2 4/7] Refactor input04 test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Andrea Cervesato Reviewed-by: Li Wang Signed-off-by: Andrea Cervesato --- 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 - * - * 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 empty events to /dev/uinput - * and check that the events are not received in /dev/inputX - */ - -#include - -#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, +}; From patchwork Mon Dec 2 10:12:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 2017059 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=r4ErxSMi; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=EfstxJpo; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=r4ErxSMi; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=EfstxJpo; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=2001:1418:10:5::2; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [IPv6:2001:1418:10:5::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y203v0vxTz1xt3 for ; Mon, 2 Dec 2024 21:13:31 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 526AB3DD278 for ; Mon, 2 Dec 2024 11:13:29 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-4.smtp.seeweb.it (in-4.smtp.seeweb.it [217.194.8.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 41BE03DD275 for ; Mon, 2 Dec 2024 11:12:52 +0100 (CET) Authentication-Results: in-4.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.de (client-ip=195.135.223.130; helo=smtp-out1.suse.de; envelope-from=andrea.cervesato@suse.de; receiver=lists.linux.it) Received: from smtp-out1.suse.de (smtp-out1.suse.de [195.135.223.130]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-4.smtp.seeweb.it (Postfix) with ESMTPS id AA6E2101BC79 for ; Mon, 2 Dec 2024 11:12:51 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 4BB19211BB; Mon, 2 Dec 2024 10:12:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dnr9d0rrUMuyabUO32sVdf+XrNiYUr6i/gUbdz8So2s=; b=r4ErxSMilPFSDUmlKhraYUjPsPPribpiFwiO8KhV9oVe0uKX4UCcjOhCccg4Yx5YEBr1Ef 4fRa3snVWL5AN0oPRG9WIjLcfJbCiEJG0dAAsfa3SbiyrVMc9Jm+l0/IK3XDMOx8JbkpJG yU8LR9RDvY918EVnXTW1o8QLGiZefBA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dnr9d0rrUMuyabUO32sVdf+XrNiYUr6i/gUbdz8So2s=; b=EfstxJpoi2880nYK02R6LGftm+Osx+uIVT3nWbPTMuVju6yQDxeT3+GkVraoiDZJfZj+xG LOe59n5HcraFzhAQ== Authentication-Results: smtp-out1.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dnr9d0rrUMuyabUO32sVdf+XrNiYUr6i/gUbdz8So2s=; b=r4ErxSMilPFSDUmlKhraYUjPsPPribpiFwiO8KhV9oVe0uKX4UCcjOhCccg4Yx5YEBr1Ef 4fRa3snVWL5AN0oPRG9WIjLcfJbCiEJG0dAAsfa3SbiyrVMc9Jm+l0/IK3XDMOx8JbkpJG yU8LR9RDvY918EVnXTW1o8QLGiZefBA= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dnr9d0rrUMuyabUO32sVdf+XrNiYUr6i/gUbdz8So2s=; b=EfstxJpoi2880nYK02R6LGftm+Osx+uIVT3nWbPTMuVju6yQDxeT3+GkVraoiDZJfZj+xG LOe59n5HcraFzhAQ== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 30A6B13A40; Mon, 2 Dec 2024 10:12:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id GAoVCiOITWcNSwAAD6G6ig (envelope-from ); Mon, 02 Dec 2024 10:12:51 +0000 From: Andrea Cervesato Date: Mon, 02 Dec 2024 11:12:49 +0100 MIME-Version: 1.0 Message-Id: <20241202-input_refactoring-v2-5-369609492896@suse.com> References: <20241202-input_refactoring-v2-0-369609492896@suse.com> In-Reply-To: <20241202-input_refactoring-v2-0-369609492896@suse.com> To: ltp@lists.linux.it X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733134370; l=4878; i=andrea.cervesato@suse.com; s=20240812; h=from:subject:message-id; bh=3oC5HSTkBi5vH12Hjk4+FEDbGl5EHx0aKZvuOga0R8s=; b=wgRDUQCIbTLE9i6rdnbGHyfJPeW0bNBlQP7DgY1u4Uzj5JYoERW3FpJP3tggtcuhkHNloDpxs gXMjE6fbUZfDpdgQvPkDy0BT/U6mMAieAj8ZHtOySji3NZYEyu2KnEa X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=RG/nLJ5snb1tLKGwSORQXBJ5XA4juT0WF2Pc/lq9meo= X-Spam-Score: -4.30 X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo, suse.com:mid, suse.com:email] X-Spam-Level: X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-4.smtp.seeweb.it Subject: [LTP] [PATCH v2 5/7] Refactor input05 test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Andrea Cervesato Reviewed-by: Li Wang 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 cf35e1bfc150a6c1556ef796d4858c0df9020131..a37aa28fc27688901e0555a0338395a681b45b39 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 46b4fe8b27cfcfe2d025d84c4dc005e528d46dae..4e5072a038ea8e4f7b8e0899d88a58bdf18e9e94 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, +}; From patchwork Mon Dec 2 10:12:50 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 2017061 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=eOLwc/gM; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=1xKd1CTz; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=eOLwc/gM; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=1xKd1CTz; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y204X2DRKz1yR5 for ; Mon, 2 Dec 2024 21:14:04 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 744143DD28C for ; Mon, 2 Dec 2024 11:14:02 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-7.smtp.seeweb.it (in-7.smtp.seeweb.it [217.194.8.7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 6BD3C3DD246 for ; Mon, 2 Dec 2024 11:12:52 +0100 (CET) Authentication-Results: in-7.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.de (client-ip=195.135.223.131; helo=smtp-out2.suse.de; envelope-from=andrea.cervesato@suse.de; receiver=lists.linux.it) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-7.smtp.seeweb.it (Postfix) with ESMTPS id E5A37217036 for ; Mon, 2 Dec 2024 11:12:51 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (imap1.dmz-prg2.suse.org [IPv6:2a07:de40:b281:104:10:150:64:97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 6957B1F747 for ; Mon, 2 Dec 2024 10:12:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=++FEL+nStN2kw3jFeJSIMnfiGfr/iQJw1VdpOFLStzw=; b=eOLwc/gM2LaKcHX30UidBV5ziU6/pXykuze6iz689Qhj0mqqdNvi3s0MwWwTDxiWTGKYLV Bl13cw/q6AGkkDoaJWHUhLcu3rAnqSxJk84M6V9qa/DJBYoK2lu9OTtQCvNk6UXAReak1O jVZ+WVTXiSJ7dFoSoXi4pPL72lG6iok= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=++FEL+nStN2kw3jFeJSIMnfiGfr/iQJw1VdpOFLStzw=; b=1xKd1CTzpoXzTbBtdfIRon8WY1sSMX3mytPIqkW/FB6Ga6El/B82tjkWtnQgMx/yxv2Jtm pdVThpnL4WHAbzBA== Authentication-Results: smtp-out2.suse.de; dkim=pass header.d=suse.de header.s=susede2_rsa header.b="eOLwc/gM"; dkim=pass header.d=suse.de header.s=susede2_ed25519 header.b=1xKd1CTz DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=++FEL+nStN2kw3jFeJSIMnfiGfr/iQJw1VdpOFLStzw=; b=eOLwc/gM2LaKcHX30UidBV5ziU6/pXykuze6iz689Qhj0mqqdNvi3s0MwWwTDxiWTGKYLV Bl13cw/q6AGkkDoaJWHUhLcu3rAnqSxJk84M6V9qa/DJBYoK2lu9OTtQCvNk6UXAReak1O jVZ+WVTXiSJ7dFoSoXi4pPL72lG6iok= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=++FEL+nStN2kw3jFeJSIMnfiGfr/iQJw1VdpOFLStzw=; b=1xKd1CTzpoXzTbBtdfIRon8WY1sSMX3mytPIqkW/FB6Ga6El/B82tjkWtnQgMx/yxv2Jtm pdVThpnL4WHAbzBA== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 55C7713A31 for ; Mon, 2 Dec 2024 10:12:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id WLUbEyOITWcNSwAAD6G6ig (envelope-from ) for ; Mon, 02 Dec 2024 10:12:51 +0000 From: Andrea Cervesato Date: Mon, 02 Dec 2024 11:12:50 +0100 MIME-Version: 1.0 Message-Id: <20241202-input_refactoring-v2-6-369609492896@suse.com> References: <20241202-input_refactoring-v2-0-369609492896@suse.com> In-Reply-To: <20241202-input_refactoring-v2-0-369609492896@suse.com> To: ltp@lists.linux.it X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733134370; l=8529; i=andrea.cervesato@suse.com; s=20240812; h=from:subject:message-id; bh=p4yLVLPjcCTTBj+dkNjWo7wyyJULRIGPy4MCTaFMzdE=; b=Rd4owCr/XjN524KZktWrjA1HqrrYhEJZZnVhEX2C+/qA0+xPqoD8iBdwetNW/FPTvOi+N2xj1 82h5+WOFnhxBszl6Q4+pnHgN6EYCv7VdQrUup56ms1ItFUKplQxdF40 X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=RG/nLJ5snb1tLKGwSORQXBJ5XA4juT0WF2Pc/lq9meo= X-Rspamd-Queue-Id: 6957B1F747 X-Spam-Level: X-Spamd-Result: default: False [-4.51 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_DKIM_ALLOW(-0.20)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; MX_GOOD(-0.01)[]; RBL_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RECEIVED_SPAMHAUS_BLOCKED_OPENRESOLVER(0.00)[2a07:de40:b281:106:10:150:64:167:received]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_ONE(0.00)[1]; FUZZY_BLOCKED(0.00)[rspamd.com]; RCVD_TLS_ALL(0.00)[]; SPAMHAUS_XBL(0.00)[2a07:de40:b281:104:10:150:64:97:from]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo,imap1.dmz-prg2.suse.org:rdns,suse.com:email,suse.com:mid,suse.de:dkim]; TO_DN_NONE(0.00)[]; PREVIOUSLY_DELIVERED(0.00)[ltp@lists.linux.it]; TO_MATCH_ENVRCPT_ALL(0.00)[]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; DKIM_TRACE(0.00)[suse.de:+] X-Rspamd-Server: rspamd2.dmz-prg2.suse.org X-Rspamd-Action: no action X-Spam-Score: -4.51 X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-7.smtp.seeweb.it X-Virus-Scanned: clamav-milter 1.0.3 at in-7.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v2 6/7] Refactor input06 test X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Andrea Cervesato Signed-off-by: Andrea Cervesato --- testcases/kernel/input/Makefile | 5 +- testcases/kernel/input/input06.c | 190 ++++++++++++++++----------------------- 2 files changed, 79 insertions(+), 116 deletions(-) diff --git a/testcases/kernel/input/Makefile b/testcases/kernel/input/Makefile index a37aa28fc27688901e0555a0338395a681b45b39..945299a13bfcecc3eeae029931ef5ae44781b7ad 100644 --- a/testcases/kernel/input/Makefile +++ b/testcases/kernel/input/Makefile @@ -7,9 +7,6 @@ LTPLIBS = uinput include $(top_srcdir)/include/mk/testcases.mk -FILTER_OUT_MAKE_TARGETS := input_helper -input01 input02 input03 input04 input05: LDLIBS += -lltpuinput - -input06: %: input_helper.o +LDLIBS += -lltpuinput include $(top_srcdir)/include/mk/generic_leaf_target.mk diff --git a/testcases/kernel/input/input06.c b/testcases/kernel/input/input06.c index b698c277d875ed2df8a0f07a88784997944eeee4..5527e160c4569a94d5b5f50da3dc3360143f231d 100644 --- a/testcases/kernel/input/input06.c +++ b/testcases/kernel/input/input06.c @@ -1,102 +1,30 @@ +// 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, activate auto-repeat and - * and check that auto repeat is working - */ +/*\ + * [Description] + * + * Verify that auto-repeat is working on a virtual device, that in our case + * it's a mouse. + */ -#include #include -#include - -#include "test.h" -#include "safe_macros.h" -#include "lapi/fcntl.h" -#include "input_helper.h" -static void setup(void); -static void send_events(void); -static int check_events(void); -static void cleanup(void); +#include "input_common.h" -static int fd; -static int fd2; struct input_event events[64]; static int num_events; static int ev_iter; - -char *TCID = "input06"; - -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(); - - switch (pid) { - case 0: - send_events(); - exit(0); - case -1: - tst_brkm(TBROK | TERRNO, cleanup, "fork() failed"); - default: - if (!check_events()) - tst_resm(TFAIL, - "Wrong data received in eventX"); - else - tst_resm(TPASS, "Data received in eventX"); - break; - } - - SAFE_WAITPID(NULL, pid, NULL, 0); - } - - cleanup(); - tst_exit(); -} - -static void setup(void) -{ - tst_require_root(); - - fd = open_uinput(); - - SAFE_IOCTL(NULL, fd, UI_SET_EVBIT, EV_KEY); - SAFE_IOCTL(NULL, fd, UI_SET_EVBIT, EV_REP); - SAFE_IOCTL(NULL, fd, UI_SET_KEYBIT, KEY_X); - - create_device(fd); - - fd2 = open_device(); - SAFE_IOCTL(NULL, fd2, EVIOCGRAB, 1); -} +static int fd_send = -1; +static int fd_recv = -1; static void send_events(void) { - send_event(fd, EV_KEY, KEY_X, 1); - send_event(fd, EV_SYN, 0, 0); + send_event(fd_send, EV_KEY, KEY_X, 1); + send_event(fd_send, EV_SYN, 0, 0); /* * Sleep long enough to keep the key pressed for some time @@ -106,8 +34,8 @@ static void send_events(void) */ usleep(500000); - send_event(fd, EV_KEY, KEY_X, 0); - send_event(fd, EV_SYN, 0, 0); + send_event(fd_send, EV_KEY, KEY_X, 0); + send_event(fd_send, EV_SYN, 0, 0); } static int check_event(struct input_event *iev, int event, int code, int value) @@ -117,20 +45,18 @@ static int check_event(struct input_event *iev, int event, int code, int value) static void read_events(void) { - int rd = read(fd2, events, sizeof(events)); - if (rd < 0) - tst_brkm(TBROK | TERRNO, cleanup, "read() failed"); + int num_bytes = SAFE_READ(0, fd_recv, events, sizeof(events)); - if (rd == 0) - tst_brkm(TBROK, cleanup, "Failed to read events"); + if (!num_bytes) + tst_brk(TBROK, "Failed to read events"); - if (rd % sizeof(struct input_event) != 0) { - tst_brkm(TBROK, cleanup, "read size %i not multiple of %zu", - rd, sizeof(struct input_event)); + if (num_bytes % sizeof(struct input_event) != 0) { + tst_brk(TBROK, "Read size %i is not multiple of %zu", + num_bytes, sizeof(struct input_event)); } ev_iter = 0; - num_events = rd / sizeof(struct input_event); + num_events = num_bytes / sizeof(struct input_event); } static int have_events(void) @@ -146,29 +72,37 @@ static struct input_event *next_event(void) return &events[ev_iter++]; } +static int check_event_code(struct input_event *iev, int event, int code) +{ + return iev->type == event && iev->code == code; +} + static int parse_autorepeat_config(struct input_event *iev) { if (!check_event_code(iev, EV_REP, REP_DELAY)) { - tst_resm(TFAIL, - "Didn't get EV_REP configuration with code REP_DELAY"); + tst_res(TFAIL, "Didn't get EV_REP type with REP_DELAY code"); return 0; } if (!check_event_code(next_event(), EV_REP, REP_PERIOD)) { - tst_resm(TFAIL, - "Didn't get EV_REP configuration with code REP_PERIOD"); + tst_res(TFAIL, "Didn't get EV_REP type with REP_PERIOD code"); return 0; } return 1; } +static int check_sync_event(struct input_event *iev) +{ + return check_event_code(iev, EV_SYN, SYN_REPORT); +} + static int parse_key(struct input_event *iev) { int autorep_count = 0; if (!check_event(iev, EV_KEY, KEY_X, 1) || !check_sync_event(next_event())) { - tst_resm(TFAIL, "Didn't get expected key press for KEY_X"); + tst_res(TFAIL, "Didn't get expected key press for KEY_X"); return 0; } @@ -180,19 +114,16 @@ static int parse_key(struct input_event *iev) /* make sure we have at least one auto-repeated key event */ if (!autorep_count) { - tst_resm(TFAIL, - "Didn't get autorepeat events for the key - KEY_X"); + tst_res(TFAIL, "Didn't get autorepeat events for the key - KEY_X"); return 0; } if (!check_event(iev, EV_KEY, KEY_X, 0) || !check_sync_event(next_event())) { - tst_resm(TFAIL, - "Didn't get expected key release for KEY_X"); + tst_res(TFAIL, "Didn't get expected key release for KEY_X"); return 0; } - tst_resm(TINFO, - "Received %d repititions for KEY_X", autorep_count); + tst_res(TINFO, "Received %d repetitions for KEY_X", autorep_count); return 1; } @@ -218,8 +149,7 @@ static int check_events(void) rep_keys_done = 1; break; default: - tst_resm(TFAIL, - "Unexpected event type '0x%04x' received", + tst_res(TFAIL, "Unexpected event type '0x%04x' received", iev->type); ret = 0; break; @@ -232,10 +162,46 @@ static int check_events(void) return ret; } +static void run(void) +{ + if (!SAFE_FORK()) { + send_events(); + exit(0); + } + + if (!check_events()) + tst_res(TFAIL, "Wrong data received from input device"); + else + tst_res(TPASS, "Data received from input device"); +} + +static void setup(void) +{ + fd_send = open_uinput(); + + SAFE_IOCTL(fd_send, UI_SET_EVBIT, EV_KEY); + SAFE_IOCTL(fd_send, UI_SET_EVBIT, EV_REP); + SAFE_IOCTL(fd_send, UI_SET_KEYBIT, KEY_X); + + create_input_device(fd_send); + + fd_recv = open_event_device(); + SAFE_IOCTL(fd_recv, EVIOCGRAB, 1); +} + static void cleanup(void) { - if (fd2 > 0 && close(fd2)) - tst_resm(TWARN | TERRNO, "close(fd2) failed"); + 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, + .forks_child = 1, +}; From patchwork Mon Dec 2 10:12:51 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrea Cervesato X-Patchwork-Id: 2017062 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=IObOwtzn; dkim=fail reason="signature verification failed" header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=2kFKl9YW; dkim=fail reason="signature verification failed" (1024-bit key) header.d=suse.de header.i=@suse.de header.a=rsa-sha256 header.s=susede2_rsa header.b=IObOwtzn; dkim=neutral header.d=suse.de header.i=@suse.de header.a=ed25519-sha256 header.s=susede2_ed25519 header.b=2kFKl9YW; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.linux.it (client-ip=213.254.12.146; helo=picard.linux.it; envelope-from=ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it; receiver=patchwork.ozlabs.org) Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Y204s3vHMz1xt3 for ; Mon, 2 Dec 2024 21:14:21 +1100 (AEDT) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id BB46A3DD27E for ; Mon, 2 Dec 2024 11:14:19 +0100 (CET) X-Original-To: ltp@lists.linux.it Delivered-To: ltp@picard.linux.it Received: from in-5.smtp.seeweb.it (in-5.smtp.seeweb.it [IPv6:2001:4b78:1:20::5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 7E0F83DD275 for ; Mon, 2 Dec 2024 11:12:52 +0100 (CET) Authentication-Results: in-5.smtp.seeweb.it; spf=pass (sender SPF authorized) smtp.mailfrom=suse.de (client-ip=195.135.223.131; helo=smtp-out2.suse.de; envelope-from=andrea.cervesato@suse.de; receiver=lists.linux.it) Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by in-5.smtp.seeweb.it (Postfix) with ESMTPS id E88B763F3BA for ; Mon, 2 Dec 2024 11:12:51 +0100 (CET) Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id 882FD1F749 for ; Mon, 2 Dec 2024 10:12:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lQR/dioxjDi9ZeOBsCZvrT1XcZODqUF11Mui5X4Uqp0=; b=IObOwtzn2RNtP873WXYcldn6xWyB5Bw5Z+Sq8X8VxUVLjEh9FmMQWdQMFLJEsyJABxmh2V 31fZz9dG/jJsLargaSv/hI0HSZoWAvuYBvBRKhEtPC+3TsZWOsrwfE2T2cxS7kCOe4Yhog QW9Pqc9lR5CMeuNvhX+zoCROwBnM33E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lQR/dioxjDi9ZeOBsCZvrT1XcZODqUF11Mui5X4Uqp0=; b=2kFKl9YWrRwblQ2LCFmzl6nxfFXS7ZhMgCqd6Det9nLHvN6JFL34Qw/QwLwolYploelfD7 B/m89Yc8nbu8OCCw== Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lQR/dioxjDi9ZeOBsCZvrT1XcZODqUF11Mui5X4Uqp0=; b=IObOwtzn2RNtP873WXYcldn6xWyB5Bw5Z+Sq8X8VxUVLjEh9FmMQWdQMFLJEsyJABxmh2V 31fZz9dG/jJsLargaSv/hI0HSZoWAvuYBvBRKhEtPC+3TsZWOsrwfE2T2cxS7kCOe4Yhog QW9Pqc9lR5CMeuNvhX+zoCROwBnM33E= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1733134371; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc: mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=lQR/dioxjDi9ZeOBsCZvrT1XcZODqUF11Mui5X4Uqp0=; b=2kFKl9YWrRwblQ2LCFmzl6nxfFXS7ZhMgCqd6Det9nLHvN6JFL34Qw/QwLwolYploelfD7 B/m89Yc8nbu8OCCw== Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 7301B13A40 for ; Mon, 2 Dec 2024 10:12:51 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id wGNdGiOITWcNSwAAD6G6ig (envelope-from ) for ; Mon, 02 Dec 2024 10:12:51 +0000 From: Andrea Cervesato Date: Mon, 02 Dec 2024 11:12:51 +0100 MIME-Version: 1.0 Message-Id: <20241202-input_refactoring-v2-7-369609492896@suse.com> References: <20241202-input_refactoring-v2-0-369609492896@suse.com> In-Reply-To: <20241202-input_refactoring-v2-0-369609492896@suse.com> To: ltp@lists.linux.it X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1733134370; l=9319; i=andrea.cervesato@suse.com; s=20240812; h=from:subject:message-id; bh=AbFZiAYaBhWRb6Pojk+RFtsGkfnrAtFnuhk3KJTElSE=; b=UJ6zto6opOBqeqWFYyKu2jfNI/SBsIGzhWe9Ele9R1MG0VyXUzuaUzWsaY9QiQvB1Ta0FXjAq WSgDQxJG1bIBWn2aFa9HB344cu2n/V1COsu7RbpOsDCG3D6hXg2ACK/ X-Developer-Key: i=andrea.cervesato@suse.com; a=ed25519; pk=RG/nLJ5snb1tLKGwSORQXBJ5XA4juT0WF2Pc/lq9meo= X-Spam-Score: -4.30 X-Spamd-Result: default: False [-4.30 / 50.00]; BAYES_HAM(-3.00)[100.00%]; NEURAL_HAM_LONG(-1.00)[-1.000]; NEURAL_HAM_SHORT(-0.20)[-1.000]; MIME_GOOD(-0.10)[text/plain]; RCVD_TLS_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; ARC_NA(0.00)[]; RCPT_COUNT_ONE(0.00)[1]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; FUZZY_BLOCKED(0.00)[rspamd.com]; PREVIOUSLY_DELIVERED(0.00)[ltp@lists.linux.it]; FROM_EQ_ENVFROM(0.00)[]; FROM_HAS_DN(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; TO_MATCH_ENVRCPT_ALL(0.00)[]; TO_DN_NONE(0.00)[]; DBL_BLOCKED_OPENRESOLVER(0.00)[imap1.dmz-prg2.suse.org:helo, suse.com:mid, suse.com:email] X-Spam-Level: X-Spam-Status: No, score=0.1 required=7.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS shortcircuit=no autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on in-5.smtp.seeweb.it Subject: [LTP] [PATCH v2 7/7] Delete depreacted input test suite helper X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" From: Andrea Cervesato Signed-off-by: Andrea Cervesato --- testcases/kernel/input/input_helper.c | 313 ---------------------------------- testcases/kernel/input/input_helper.h | 36 ---- 2 files changed, 349 deletions(-) diff --git a/testcases/kernel/input/input_helper.c b/testcases/kernel/input/input_helper.c deleted file mode 100644 index c929de6bab64df49cd48ac6c73b44d26e8f04e96..0000000000000000000000000000000000000000 --- a/testcases/kernel/input/input_helper.c +++ /dev/null @@ -1,313 +0,0 @@ -/* - * 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 - */ - -#include -#include -#include -#include -#include - -#include "test.h" -#include "safe_macros.h" -#include "input_helper.h" -#include "lapi/uinput.h" - -#define VIRTUAL_DEVICE "virtual-device-ltp" - -#define VIRTUAL_DEVICE_REGEX "*virtual-device-ltp*" - -static int uinput_loaded; -static int check_device(void); - -static int try_open_device(void) -{ - char path[256]; - char name[256]; - int ret, fd = -1; - unsigned int i; - - for (i = 0; i < 100; i++) { - snprintf(path, sizeof(path), "/dev/input/event%i", i); - - fd = open(path, O_RDONLY); - - if (fd < 0 && errno == ENOENT) - continue; - - if (fd < 0) { - tst_resm(TINFO | TERRNO, "failed to open %s", path); - break; - } - - ret = ioctl(fd, EVIOCGNAME(sizeof(name)), name); - if (ret < 0) { - tst_resm(TINFO | TERRNO, - "ioctl(%s, EVIOCGNAME(256), ...) failed", - path); - break; - } - - if (strcmp(name, VIRTUAL_DEVICE) == 0) - return fd; - close(fd); - } - - return -1; -} - -int open_device(void) -{ - int fd; - int retries = 10; - - while (retries--) { - fd = try_open_device(); - if (fd > 0) - return fd; - tst_resm(TINFO, "Device not found, retrying..."); - usleep(10000); - } - - tst_brkm(TBROK, NULL, "Unable to find the input device"); -} - -static int try_load_uinput(void) -{ - const char *argv[] = {"modprobe", "uinput", NULL}; - int ret; - - tst_resm(TINFO, "Trying to load uinput kernel module"); - - ret = tst_cmd(NULL, argv, NULL, NULL, TST_CMD_PASS_RETVAL); - if (ret) { - tst_resm(TINFO, "Failed to load the uinput module"); - return 0; - } - - return 1; -} - -static void unload_uinput(void) -{ - const char *argv[] = {"modprobe", "-r", "uinput", NULL}; - int ret; - - tst_resm(TINFO, "Unloading uinput kernel module"); - - ret = tst_cmd(NULL, argv, NULL, NULL, TST_CMD_PASS_RETVAL); - if (ret) - tst_resm(TWARN, "Failed to unload uinput module"); -} - -static const char *uinput_paths[] = { - "/dev/input/uinput", - "/dev/uinput", -}; - -static int try_open_uinput(void) -{ - unsigned int i; - int fd; - - for (i = 0; i < ARRAY_SIZE(uinput_paths); i++) { - fd = open(uinput_paths[i], O_WRONLY | O_NONBLOCK); - - if (fd > 0) { - tst_resm(TINFO, "Found uinput dev at %s", - uinput_paths[i]); - return fd; - } - - if (fd < 0 && errno != ENOENT) { - tst_brkm(TBROK | TERRNO, NULL, - "open(%s)", uinput_paths[i]); - } - } - - return -1; -} - -int open_uinput(void) -{ - int fd; - int retries = 10; - - fd = try_open_uinput(); - if (fd > 0) - return fd; - - if (try_load_uinput()) { - while (retries--) { - fd = try_open_uinput(); - if (fd > 0) { - uinput_loaded = 1; - return fd; - } - tst_resm(TINFO, "Uinput dev not found, retrying..."); - usleep(10000); - } - - unload_uinput(); - } - - tst_brkm(TCONF, NULL, "Unable to find and open uinput"); -} - -void send_event(int fd, int event, int code, int value) -{ - struct input_event ev = { - .type = event, - .code = code, - .value = value, - }; - - SAFE_WRITE(NULL, SAFE_WRITE_ALL, fd, &ev, sizeof(ev)); -} - -void send_rel_move(int fd, int x, int y) -{ - send_event(fd, EV_REL, REL_X, x); - send_event(fd, EV_REL, REL_Y, y); - send_event(fd, EV_SYN, 0, 0); -} - -static void check_ui_get_sysname_ioctl(int fd) -{ - char sys_name[256]; - char dev_name[256]; - char *path; - - SAFE_IOCTL(NULL, fd, UI_GET_SYSNAME(sizeof(sys_name)), sys_name, NULL); - SAFE_ASPRINTF(NULL, &path, "/sys/devices/virtual/input/%s/name", sys_name); - - if (FILE_SCANF(path, "%s", dev_name)) { - tst_resm(TFAIL|TERRNO, "Failed to read '%s'", path); - free(path); - return; - } - - if (!strcmp(VIRTUAL_DEVICE, dev_name)) - tst_resm(TPASS, "ioctl UI_GET_SYSNAME returned correct name"); - else - tst_resm(TFAIL, "ioctl UI_GET_SYSNAME returned wrong name"); - - free(path); -} - -void create_device(int fd) -{ - int nb; - struct uinput_user_dev uidev = { - .name = VIRTUAL_DEVICE, - .id = { - .bustype = BUS_USB, - .vendor = 0x1, - .product = 0x1, - .version = 1, - } - }; - - SAFE_WRITE(NULL, SAFE_WRITE_ALL, fd, &uidev, sizeof(uidev)); - SAFE_IOCTL(NULL, fd, UI_DEV_CREATE, NULL); - - for (nb = 100; nb > 0; nb--) { - if (check_device()) { - check_ui_get_sysname_ioctl(fd); - return; - } - usleep(10000); - } - - destroy_device(fd); - tst_brkm(TBROK, NULL, "Failed to create device"); -} - -void setup_mouse_events(int fd) -{ - SAFE_IOCTL(NULL, fd, UI_SET_EVBIT, EV_KEY); - SAFE_IOCTL(NULL, fd, UI_SET_KEYBIT, BTN_LEFT); - SAFE_IOCTL(NULL, fd, UI_SET_EVBIT, EV_REL); - SAFE_IOCTL(NULL, fd, UI_SET_RELBIT, REL_X); - SAFE_IOCTL(NULL, fd, UI_SET_RELBIT, REL_Y); -} - -void destroy_device(int fd) -{ - SAFE_IOCTL(NULL, fd, UI_DEV_DESTROY, NULL); - SAFE_CLOSE(NULL, fd); - - if (uinput_loaded) - unload_uinput(); -} - -int check_event_code(struct input_event *iev, int event, int code) -{ - return iev->type == event && iev->code == code; -} - -int check_sync_event(struct input_event *iev) -{ - return check_event_code(iev, EV_SYN, SYN_REPORT); -} - -/* - * the value of stray_sync_event: - * 0: EV_SYN/SYN_REPORT events should not be received in /dev/input/eventX - * 1: EV_SYN/SYN_REPORT events may be received in /dev/input/eventX - * On an old kernel(before v3.7.0), EV_SYN/SYN_REPORT events are always - * received even though we send empty moves. - */ -int no_events_queued(int fd, int stray_sync_event) -{ - struct pollfd fds = {.fd = fd, .events = POLLIN}; - int ret, res; - struct input_event ev; - - ret = poll(&fds, 1, 30); - - if (ret > 0) { - res = read(fd, &ev, sizeof(ev)); - - if (res == sizeof(ev)) { - tst_resm(TINFO, - "Unexpected ev type=%i code=%i value=%i", - ev.type, ev.code, ev.value); - } - } - - return ret == 0; -} - -static int check_device(void) -{ - FILE *file; - char line[256]; - - file = fopen("/proc/bus/input/devices", "r"); - if (!file) - return 0; - - while (fgets(line, 256, file)) { - if (fnmatch(VIRTUAL_DEVICE_REGEX, line, 0) == 0) - return 1; - } - - fclose(file); - - return 0; -} diff --git a/testcases/kernel/input/input_helper.h b/testcases/kernel/input/input_helper.h deleted file mode 100644 index 7f61be1e9a4a647ff0887aa14a89a48bd2e882a9..0000000000000000000000000000000000000000 --- a/testcases/kernel/input/input_helper.h +++ /dev/null @@ -1,36 +0,0 @@ -/* - * 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 - */ - -#ifndef INPUT_HELPER_H -#define INPUT_HELPER_H - -#include -#include - -int open_device(void); -void send_rel_move(int fd, int x, int y); -void send_event(int fd, int event, int code, int value); -int open_uinput(void); -void create_device(int fd); -void setup_mouse_events(int fd); -void destroy_device(int fd); -int check_event_code(struct input_event *iev, int event, int code); -int check_sync_event(struct input_event *iev); -int no_events_queued(int fd, int stray_sync_event); - -#endif /* INPUT_HELPER_H */