Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 19944C0032E for ; Wed, 25 Oct 2023 11:09:35 +0000 (UTC) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 8D8F33CF90A for ; Wed, 25 Oct 2023 13:09:33 +0200 (CEST) Received: from in-6.smtp.seeweb.it (in-6.smtp.seeweb.it [IPv6:2001:4b78:1:20::6]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-384)) (No client certificate requested) by picard.linux.it (Postfix) with ESMTPS id 47DDF3CCBF9 for ; Wed, 25 Oct 2023 13:08:38 +0200 (CEST) Received: from smtp-out1.suse.de (smtp-out1.suse.de [IPv6:2001:67c:2178:6::1c]) (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-6.smtp.seeweb.it (Postfix) with ESMTPS id 3DB7714011B0 for ; Wed, 25 Oct 2023 13:08:38 +0200 (CEST) Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by smtp-out1.suse.de (Postfix) with ESMTPS id 939C821B3D; Wed, 25 Oct 2023 11:08:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_rsa; t=1698232117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EkO8/BHIpMPPDs041FF5c6PQoBvcfmderAgm92J3maQ=; b=iDb4y5fioYwCwYGfqXi27+sCf9rqBgHAxMwfTdoDmJWzFrI19M9j2GHgzgTOxfirUEBHnQ dpwZpz+8obWUMNEpIZnPsZRjSJ0iXhSMb+qwQ9qvrjAVv8XG7BbgAES/+1vWlCkxfXzy4D W+3UhhLVab186p7pNpbeQ7PsLq3zDzU= DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=suse.de; s=susede2_ed25519; t=1698232117; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=EkO8/BHIpMPPDs041FF5c6PQoBvcfmderAgm92J3maQ=; b=CPYvMfHq40QumkSFtX6CYjDoH4JSQTK3wImWWZLhKQ8phj/vuRw5PJo226mMRYSP1Dl2f5 6XPY0mKzw/BUkqCg== Received: from imap2.suse-dmz.suse.de (imap2.suse-dmz.suse.de [192.168.254.74]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (P-521) server-digest SHA512) (No client certificate requested) by imap2.suse-dmz.suse.de (Postfix) with ESMTPS id 7F1A813A9B; Wed, 25 Oct 2023 11:08:37 +0000 (UTC) Received: from dovecot-director2.suse.de ([192.168.254.65]) by imap2.suse-dmz.suse.de with ESMTPSA id aMIHHjX3OGUVUgAAMHmgww (envelope-from ); Wed, 25 Oct 2023 11:08:37 +0000 From: Marius Kittler To: ltp@lists.linux.it Date: Wed, 25 Oct 2023 13:08:35 +0200 Message-ID: <20231025110835.28832-5-mkittler@suse.de> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20231025110835.28832-1-mkittler@suse.de> References: <20231025110835.28832-1-mkittler@suse.de> MIME-Version: 1.0 Authentication-Results: smtp-out1.suse.de; none X-Spamd-Result: default: False [-6.10 / 50.00]; ARC_NA(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; FROM_HAS_DN(0.00)[]; TO_DN_SOME(0.00)[]; TO_MATCH_ENVRCPT_ALL(0.00)[]; R_MISSING_CHARSET(2.50)[]; MIME_GOOD(-0.10)[text/plain]; REPLY(-4.00)[]; BROKEN_CONTENT_TYPE(1.50)[]; NEURAL_HAM_LONG(-3.00)[-1.000]; DKIM_SIGNED(0.00)[suse.de:s=susede2_rsa,suse.de:s=susede2_ed25519]; NEURAL_HAM_SHORT(-1.00)[-1.000]; RCPT_COUNT_TWO(0.00)[2]; MID_CONTAINS_FROM(1.00)[]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; RCVD_COUNT_TWO(0.00)[2]; RCVD_TLS_ALL(0.00)[]; BAYES_HAM(-3.00)[100.00%] X-Virus-Scanned: clamav-milter 1.0.1 at in-6.smtp.seeweb.it X-Virus-Status: Clean Subject: [LTP] [PATCH v8 4/4] Extend ioctl02 to test termio and termios 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ltp-bounces+ltp=archiver.kernel.org@lists.linux.it Sender: "ltp" Signed-off-by: Marius Kittler --- testcases/kernel/syscalls/ioctl/ioctl02.c | 188 +++++++++++++--------- 1 file changed, 116 insertions(+), 72 deletions(-) diff --git a/testcases/kernel/syscalls/ioctl/ioctl02.c b/testcases/kernel/syscalls/ioctl/ioctl02.c index d5d19e1b9..365ce5a1f 100644 --- a/testcases/kernel/syscalls/ioctl/ioctl02.c +++ b/testcases/kernel/syscalls/ioctl/ioctl02.c @@ -8,26 +8,28 @@ /*\ * [Description] * - * Testcase to test the TCGETA, and TCSETA ioctl implementations for - * the tty driver + * Testcase to test the TCGETA/TCGETS, and TCSETA/TCSETS ioctl + * implementations for the tty driver * * In this test, the parent and child open the parentty and the childtty * respectively. After opening the childtty the child flushes the stream * and wakes the parent (thereby asking it to continue its testing). The - * parent, then starts the testing. It issues a TCGETA ioctl to get all - * the tty parameters. It then changes them to known values by issuing a - * TCSETA ioctl. Then the parent issues a TCGETA ioctl again and compares - * the received values with what it had set earlier. The test fails if - * TCGETA or TCSETA fails, or if the received values don't match those - * that were set. The parent does all the testing, the requirement of the - * child process is to moniter the testing done by the parent, and hence - * the child just waits for the parent. + * parent, then starts the testing. It issues a TCGETA/TCGETS ioctl to + * get all the tty parameters. It then changes them to known values by + * issuing a TCSETA/TCSETS ioctl. Then the parent issues a TCSETA/TCGETS + * ioctl again and compares the received values with what it had set + * earlier. The test fails if TCGETA/TCGETS or TCSETA/TCSETS fails, or if + * the received values don't match those that were set. The parent does + * all the testing, the requirement of the child process is to moniter + * the testing done by the parent, and hence the child just waits for the + * parent. */ #include #include #include #include +#include #include #include #include @@ -39,22 +41,51 @@ #include "tst_test.h" #include "tst_safe_macros.h" -static struct termio termio, save_io; +static struct termio termio, termio_exp; +static struct termios termios, termios_exp, termios_bak; static char *parenttty, *childtty; static int parentfd = -1; static int parentpid, childpid; static void do_child(void); +static void prepare_termio(void); static void run_ptest(void); -static void chk_tty_parms(void); +static void chk_tty_parms_termio(void); +static void chk_tty_parms_termios(void); static void setup(void); static void cleanup(void); static char *device; +static struct variant { + const char *name; + void *termio, *termio_exp, *termio_bak; + void (*check)(void); + int tcget, tcset; +} variants[] = { + { + .name = "termio", + .termio = &termio, + .termio_exp = &termio_exp, + .check = &chk_tty_parms_termio, + .tcget = TCGETA, + .tcset = TCSETA, + }, + { + .name = "termios", + .termio = &termios, + .termio_exp = &termios_exp, + .check = &chk_tty_parms_termios, + .tcget = TCGETS, + .tcset = TCSETS, + }, +}; + static void verify_ioctl(void) { + tst_res(TINFO, "Testing %s variant", variants[tst_variant].name); + parenttty = device; childtty = device; @@ -76,97 +107,107 @@ static void verify_ioctl(void) TST_CHECKPOINT_WAKE(0); } -/* - * run_ptest() - setup the various termio structure values and issue - * the TCSETA ioctl call with the TEST macro. - */ -static void run_ptest(void) +static void prepare_termio(void) { /* Use "old" line discipline */ - termio.c_line = 0; + termios_exp.c_line = termio_exp.c_line = 0; /* Set control modes */ - termio.c_cflag = B50 | CS7 | CREAD | PARENB | PARODD | CLOCAL; + termios_exp.c_cflag = termio_exp.c_cflag = B50 | CS7 | CREAD | PARENB | PARODD | CLOCAL; /* Set control chars. */ for (int i = 0; i < NCC; i++) { if (i == VEOL2) continue; - termio.c_cc[i] = CSTART; + termios_exp.c_cc[i] = termio_exp.c_cc[i] = CSTART; } /* Set local modes. */ - termio.c_lflag = + termios_exp.c_lflag = termio_exp.c_lflag = ((unsigned short)(ISIG | ICANON | XCASE | ECHO | ECHOE | NOFLSH)); /* Set input modes. */ - termio.c_iflag = + termios_exp.c_iflag = termio_exp.c_iflag = BRKINT | IGNPAR | INPCK | ISTRIP | ICRNL | IUCLC | IXON | IXANY | IXOFF; /* Set output modes. */ - termio.c_oflag = OPOST | OLCUC | ONLCR | ONOCR; - - SAFE_IOCTL(parentfd, TCSETA, &termio); + termios_exp.c_oflag = termio_exp.c_oflag = OPOST | OLCUC | ONLCR | ONOCR; - /* Get termio and see if all parameters actually got set */ - SAFE_IOCTL(parentfd, TCGETA, &termio); - chk_tty_parms(); + /* Init termio/termios structures used to check if all params got set */ + memset(&termio, 0, sizeof(termio)); + memset(&termios, 0, sizeof(termios)); } -static void chk_tty_parms(void) +/* + * run_ptest() - setup the various termio/termios structure values and issue + * the TCSETA/TCSETS ioctl call with the TEST macro. + */ +static void run_ptest(void) { - int i, flag = 0; + struct variant *v = &variants[tst_variant]; - if (termio.c_line != 0) { - tst_res(TFAIL, "line discipline has incorrect value %o", - termio.c_line); - flag++; - } - - for (i = 0; i < NCC; i++) { - if (i == VEOL2) { - if (!termio.c_cc[i]) { - continue; - } else { - tst_res(TFAIL, "control char %d has " - "incorrect value %d", i, termio.c_cc[i]); - flag++; - continue; - } - } - - if (termio.c_cc[i] != CSTART) { - tst_res(TFAIL, "control char %d has incorrect " - "value %d.", i, termio.c_cc[i]); - flag++; - } - } + SAFE_IOCTL(parentfd, v->tcset, v->termio_exp); - if (termio.c_lflag != (ISIG | ICANON | XCASE | ECHO | ECHOE - | NOFLSH)) { - tst_res(TFAIL, "lflag has incorrect value. %o", - termio.c_lflag); - flag++; - } + /* Get termio and see if all parameters actually got set */ + SAFE_IOCTL(parentfd, v->tcget, v->termio); + v->check(); +} - if (termio.c_iflag != (BRKINT | IGNPAR | INPCK | ISTRIP - | ICRNL | IUCLC | IXON | IXANY | IXOFF)) { - tst_res(TFAIL, "iflag has incorrect value. %o", - termio.c_iflag); - flag++; +#define CMP_ATTR(tcexp, tcval, attr) \ + do { \ + if ((tcval).attr != (tcexp).attr) { \ + tst_res(TINFO, #attr " has incorrect value %o", \ + (tcval).attr); \ + flag++; \ + } \ + } while (0) + +#define CECK_CONTROL_CHARS(tcval) \ + for (i = 0; i < NCC; i++) { \ + if (i == VEOL2) { \ + if (!(tcval).c_cc[i]) { \ + continue; \ + } else { \ + tst_res(TFAIL, "control char %d has " \ + "incorrect value %d", i, (tcval).c_cc[i]); \ + flag++; \ + continue; \ + } \ + } \ + if ((tcval).c_cc[i] != CSTART) { \ + tst_res(TFAIL, "control char %d has incorrect " \ + "value %d.", i, (tcval).c_cc[i]); \ + flag++; \ + } \ } - if (termio.c_oflag != (OPOST | OLCUC | ONLCR | ONOCR)) { - tst_res(TFAIL, "oflag has incorrect value. %o", - termio.c_oflag); - flag++; - } +static void chk_tty_parms_termio(void) +{ + int i, flag = 0; + CMP_ATTR(termio_exp, termio, c_line); + CECK_CONTROL_CHARS(termio); + CMP_ATTR(termio_exp, termio, c_lflag); + CMP_ATTR(termio_exp, termio, c_iflag); + CMP_ATTR(termio_exp, termio, c_oflag); if (!flag) tst_res(TPASS, "TCGETA/TCSETA tests"); } +static void chk_tty_parms_termios(void) +{ + int i, flag = 0; + + CMP_ATTR(termios_exp, termios, c_line); + CECK_CONTROL_CHARS(termios); + CMP_ATTR(termios_exp, termios, c_lflag); + CMP_ATTR(termios_exp, termios, c_iflag); + CMP_ATTR(termios_exp, termios, c_oflag); + if (!flag) + tst_res(TPASS, "TCGETS/TCSETS tests"); +} + static void do_child(void) { int cfd = SAFE_OPEN(childtty, O_RDWR, 0777); @@ -189,14 +230,16 @@ static void setup(void) int fd = SAFE_OPEN(device, O_RDWR, 0777); - SAFE_IOCTL(fd, TCGETA, &save_io); + SAFE_IOCTL(fd, TCGETS, &termios_bak); SAFE_CLOSE(fd); + + prepare_termio(); } static void cleanup(void) { if (parentfd >= 0) { - SAFE_IOCTL(parentfd, TCSETA, &save_io); + SAFE_IOCTL(parentfd, TCSETS, &termios_bak); SAFE_CLOSE(parentfd); } } @@ -208,6 +251,7 @@ static struct tst_test test = { .setup = setup, .cleanup = cleanup, .test_all = verify_ioctl, + .test_variants = 2, .options = (struct tst_option[]) { {"D:", &device, "Tty device. For example, /dev/tty[0-9]"}, {} -- 2.42.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp