From patchwork Fri Aug 17 02:26:23 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Li Wang X-Patchwork-Id: 958628 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) 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=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Received: from picard.linux.it (picard.linux.it [213.254.12.146]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 41s6XD31jfz9s2P for ; Fri, 17 Aug 2018 12:26:36 +1000 (AEST) Received: from picard.linux.it (localhost [IPv6:::1]) by picard.linux.it (Postfix) with ESMTP id 7972B3E64ED for ; Fri, 17 Aug 2018 04:26:33 +0200 (CEST) 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]) by picard.linux.it (Postfix) with ESMTP id CA0473E64D4 for ; Fri, 17 Aug 2018 04:26:31 +0200 (CEST) Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by in-2.smtp.seeweb.it (Postfix) with ESMTPS id 0D48160095F for ; Fri, 17 Aug 2018 04:26:30 +0200 (CEST) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 6F25D8197023; Fri, 17 Aug 2018 02:26:29 +0000 (UTC) Received: from dhcp-12-102.nay.redhat.com (unknown [10.66.12.102]) by smtp.corp.redhat.com (Postfix) with ESMTP id 03F092026D66; Fri, 17 Aug 2018 02:26:26 +0000 (UTC) From: Li Wang To: ltp@lists.linux.it Date: Fri, 17 Aug 2018 10:26:23 +0800 Message-Id: <20180817022623.2657-1-liwang@redhat.com> X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 17 Aug 2018 02:26:29 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.8]); Fri, 17 Aug 2018 02:26:29 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'liwang@redhat.com' RCPT:'' X-Virus-Scanned: clamav-milter 0.99.2 at in-2.smtp.seeweb.it X-Virus-Status: Clean X-Spam-Status: No, score=-0.0 required=7.0 tests=SPF_HELO_PASS,SPF_PASS autolearn=disabled version=3.4.0 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on in-2.smtp.seeweb.it Cc: Eric Biggers Subject: [LTP] [PATCH v2] pty: fix some issues in pty02 X-BeenThere: ltp@lists.linux.it X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux Test Project List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ltp-bounces+incoming=patchwork.ozlabs.org@lists.linux.it Sender: "ltp" 1. Add EXTPROC into lapi 2. Exit the test with TCONF if we get EINVAL from tcsetattr() 3. Write newline to ptmx to avoid read() on pts to block 4. Using tcgetattr() to get attributes before re-setting it Fix this error: tst_test.c:1015: INFO: Timeout per run is 0h 50m 00s pty02.c:42: BROK: tcsetattr() failed: EINVAL POSIX.1 General description: Changes the attributes associated with a terminal. New attributes are specified with a termios control structure. Programs should always issue a tcgetattr() first, modify the desired fields, and then issue a tcsetattr(). tcsetattr() should never be issued using a termios structure that was not obtained using tcgetattr(). tcsetattr() should use only a termios structure that was obtained by tcgetattr(). Signed-off-by: Li Wang Cc: Eric Biggers Cc: Cyril Hrubis Cc: Xiao Yang Cc: Jinhui huang --- Notes: v1 -> v2: * use TST_RET and TST_ERR * do SAFE_WRITE(1, ptmx, "A\n", 2) instead * reword the code comments include/lapi/termbits.h | 25 +++++++++++++++++++++++++ testcases/kernel/pty/pty02.c | 21 +++++++++++++++++---- 2 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 include/lapi/termbits.h diff --git a/include/lapi/termbits.h b/include/lapi/termbits.h new file mode 100644 index 0000000..23ad5a7 --- /dev/null +++ b/include/lapi/termbits.h @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2018 Linux Test Project + * + * 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 + */ + +#ifndef LAPI_TERMBITS_H__ +#define LAPI_TERMBITS_H__ + +#ifndef EXTPROC +# define EXTPROC 0200000 +#endif + +#endif diff --git a/testcases/kernel/pty/pty02.c b/testcases/kernel/pty/pty02.c index fd3d26b..841e233 100644 --- a/testcases/kernel/pty/pty02.c +++ b/testcases/kernel/pty/pty02.c @@ -25,27 +25,40 @@ */ #include +#include #include #include "tst_test.h" +#include "lapi/termbits.h" static void do_test(void) { - struct termios io = { .c_lflag = EXTPROC | ICANON }; + struct termios io; int ptmx, pts; char c = 'A'; int nbytes; ptmx = SAFE_OPEN("/dev/ptmx", O_WRONLY); - if (tcsetattr(ptmx, TCSANOW, &io) != 0) - tst_brk(TBROK | TERRNO, "tcsetattr() failed"); + if (tcgetattr(ptmx, &io) != 0) + tst_brk(TBROK | TERRNO, "tcgetattr() failed"); + + io.c_lflag = EXTPROC | ICANON; + + TEST(tcsetattr(ptmx, TCSANOW, &io)); + if (TEST_RET == -1) { + if (TEST_ERR == EINVAL) + tst_res(TCONF, "tcsetattr(, , EXTPROC | ICANON) is not supported"); + else + tst_brk(TBROK | TERRNO, "tcsetattr() failed"); + } if (unlockpt(ptmx) != 0) tst_brk(TBROK | TERRNO, "unlockpt() failed"); pts = SAFE_OPEN(ptsname(ptmx), O_RDONLY); - SAFE_WRITE(1, ptmx, &c, 1); + /* write newline to ptmx to avoid read() on pts to block */ + SAFE_WRITE(1, ptmx, "A\n", 2); SAFE_READ(1, pts, &c, 1); tst_res(TINFO, "Calling FIONREAD, this will hang in n_tty_ioctl() if the bug is present...");