Skip to contentSkip to conversation

pty: fix some issues in pty02

PATCH Superseded Li Wang 3 participants 4 messages Aug 17, 2018

lore
Share & tools
lore

Li Wang

author
#0 lore raw

PATCH v2 1/1 pty: fix some issues in pty02

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().

Cc Eric Biggers <[email protected]>
Cc Cyril Hrubis <[email protected]>
Cc Xiao Yang <[email protected]>
Cc Jinhui huang <[email protected]>

---

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
include/lapi/termbits.h new file +25 -0
new file mode 100644
index 0000000..23ad5a7
@@ -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
testcases/kernel/pty/pty02.c +17 -4
index fd3d26b..841e233 100644
@@ -25,27 +25,40 @@
  */
 
 #include <stdlib.h>
+#include <errno.h>
 #include <termio.h>
 
 #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...");
Signature · 1 line
2.9.5
#1 lore raw

PATCH v2 1/1 pty: fix some issues in pty02

Quoted 95 lines · Li Wang

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().

Cc Eric Biggers <[email protected]>
Cc Cyril Hrubis <[email protected]>
Cc Xiao Yang <[email protected]>
Cc Jinhui huang <[email protected]>

---

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
include/lapi/termbits.h new file +25 -0
new file mode 100644
index 0000000..23ad5a7
@@ -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
testcases/kernel/pty/pty02.c +3 -2
index fd3d26b..841e233 100644
@@ -25,27 +25,40 @@
  */
 
 #include <stdlib.h>
+#include <errno.h>
 #include <termio.h>
 
 #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)

testcases/kernel/pty/pty02.c line 51

Quoted 10 lines
testcases/kernel/pty/pty02.c +9 -1
-		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");

Hi Li,

Should we use tst_brk(TCONF, ...) instead?

Thanks,
Xiao Yang

Quoted 14 lines
testcases/kernel/pty/pty02.c +5 -1
+		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...");
author
#2 lore raw

PATCH v2 1/1 pty: fix some issues in pty02

Quoted 8 lines · Xiao Yang

+ TEST(tcsetattr(ptmx, TCSANOW, &io));

testcases/kernel/pty/pty02.c

Quoted 3 lines
testcases/kernel/pty/pty02.c +3 -0
+     if (TEST_RET == -1) {
+             if (TEST_ERR == EINVAL)
+                     tst_res(TCONF, "tcsetattr(, , EXTPROC | ICANON) is

not supported");
Hi Li,

Should we use tst_brk(TCONF, ...) instead?

Yes, right.

Signature · 5 lines
Regards,
Li Wang
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.linux.it/pipermail/ltp/attachments/20180817/a3cee8ec/attachment.html>
#3 lore raw

PATCH v2 1/1 pty: fix some issues in pty02

Hi!

Quoted 10 lines
Quoted 7 lines

testcases/kernel/pty/pty02.c

Quoted 3 lines
testcases/kernel/pty/pty02.c +3 -0
+     if (TEST_RET == -1) {
+             if (TEST_ERR == EINVAL)
+                     tst_res(TCONF, "tcsetattr(, , EXTPROC | ICANON) is

not supported");
Hi Li,

Should we use tst_brk(TCONF, ...) instead?

Yes, right.

I fixed that, as well as TEST_RET -> TST_RET and TEST_ERR -> TST_ERR, and applied, thanks.

Signature · 2 lines
Cyril Hrubis
[email protected]