* [LTP] [PATCH v2 00/11] Fix tests failing with setsid
@ 2025-01-06 10:31 Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 01/11] Refactor setpgid01 test Andrea Cervesato
` (10 more replies)
0 siblings, 11 replies; 21+ messages in thread
From: Andrea Cervesato @ 2025-01-06 10:31 UTC (permalink / raw)
To: ltp
Following tests are failing when running on a new session started with
setsid command/syscall: pty01, ptem01, setpgid01.
Tihs patch-set refactor them in order to fix this issue. Some tests like
pty01 and ptem01 have been split into multiple files due to their
complexity.
Fixes: https://github.com/linux-test-project/kirk/issues/28
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
Changes in v2:
- add SAFE_PTSNAME macro
- ptem01: check ptsname() with TBROK
- Link to v1: https://lore.kernel.org/r/20241211-fix_setsid_tests-v1-0-e103f36c6462@suse.com
---
Andrea Cervesato (11):
Refactor setpgid01 test
Add SAFE_PTSNAME macro
Refactor ptem01 test
Add ptem02 test
Add ptem03 test
Add ptem04 test
Add ptem05 test
Add ptem06 test
Refactor pty01 test
Add pty08 test
Add pty09 test
include/tst_safe_macros.h | 4 +
lib/tst_safe_macros.c | 14 +
runtest/pty | 7 +
testcases/kernel/pty/.gitignore | 7 +
testcases/kernel/pty/ptem01.c | 454 +++-----------------------
testcases/kernel/pty/ptem02.c | 73 +++++
testcases/kernel/pty/ptem03.c | 51 +++
testcases/kernel/pty/ptem04.c | 52 +++
testcases/kernel/pty/ptem05.c | 53 +++
testcases/kernel/pty/ptem06.c | 54 +++
testcases/kernel/pty/pty01.c | 416 +++--------------------
testcases/kernel/pty/pty08.c | 57 ++++
testcases/kernel/pty/pty09.c | 86 +++++
testcases/kernel/syscalls/setpgid/setpgid01.c | 152 ++-------
14 files changed, 570 insertions(+), 910 deletions(-)
---
base-commit: 7aea2cea9ad5d9e1586112a57948c7f85dc12970
change-id: 20241204-fix_setsid_tests-876a46267285
Best regards,
--
Andrea Cervesato <andrea.cervesato@suse.com>
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* [LTP] [PATCH v2 01/11] Refactor setpgid01 test
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
@ 2025-01-06 10:31 ` Andrea Cervesato
2025-01-07 15:26 ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 02/11] Add SAFE_PTSNAME macro Andrea Cervesato
` (9 subsequent siblings)
10 siblings, 1 reply; 21+ messages in thread
From: Andrea Cervesato @ 2025-01-06 10:31 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Test used to fail when running inside an executor that is setting a
new session via setsid(). By using the new LTP library, we fix this
issue since it forks parent first, then execute it, enabling any
setsid() to be run in the main process before execution.
Fixes: https://github.com/linux-test-project/kirk/issues/28
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/syscalls/setpgid/setpgid01.c | 152 +++++---------------------
1 file changed, 25 insertions(+), 127 deletions(-)
diff --git a/testcases/kernel/syscalls/setpgid/setpgid01.c b/testcases/kernel/syscalls/setpgid/setpgid01.c
index 60034e01660d5c3aebe8ca960ff64c03f2b539e5..c976c3a5138ce7bca9f92a7d624797a9f2a08154 100644
--- a/testcases/kernel/syscalls/setpgid/setpgid01.c
+++ b/testcases/kernel/syscalls/setpgid/setpgid01.c
@@ -1,150 +1,48 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved.
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of version 2 of the GNU General Public License as
- * published by the Free Software Foundation.
- *
- * 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.
- *
- * Further, this software is distributed without any warranty that it is
- * free of the rightful claim of any third person regarding infringement
- * or the like. Any license provided herein, whether implied or
- * otherwise, applies only to this software file. Patent licenses, if
- * any, provided herein do not apply to combinations of this program with
- * other software, or any other product whatsoever.
- *
- * 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 Street, Fifth Floor, Boston, MA 02110-1301 USA.
- *
- * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
- * Mountain View, CA 94043, or:
- *
- * http://www.sgi.com
- *
- * For further information regarding this notice, see:
- *
- * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
- *
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
*/
-/* $Id: setpgid01.c,v 1.7 2009/11/02 13:57:18 subrata_modak Exp $ */
-/*
- * Description:
- * Verify that:
- * 1. Basic functionality test for setpgid(2).
- * 2. Check functioning of setpgid(2) with pid = 0 and pgid = 0.
+/*\
+ * [Description]
+ *
+ * Verify basic setpgid() functionality, re-setting group ID inside both parent
+ * and child. In the first case, we obtain getpgrp() and set it. In the second
+ * case, we use setpgid(0, 0).
*/
-#include <errno.h>
-#include <string.h>
-#include <signal.h>
-#include <stdlib.h>
-#include <sys/wait.h>
-#include "test.h"
-
-static void setup(void);
-static void cleanup(void);
-
-char *TCID = "setpgid01";
-
-static void setpgid_test1(void);
-static void setpgid_test2(void);
-static void (*testfunc[])(void) = { setpgid_test1, setpgid_test2};
-int TST_TOTAL = ARRAY_SIZE(testfunc);
-
-int main(int ac, char **av)
-{
- int i, lc;
-
- tst_parse_opts(ac, av, NULL, NULL);
-
- setup();
-
- for (lc = 0; TEST_LOOPING(lc); lc++) {
- tst_count = 0;
-
- for (i = 0; i < TST_TOTAL; i++)
- (*testfunc[i])();
- }
-
- cleanup();
- tst_exit();
-}
+#include "tst_test.h"
static void setpgid_test1(void)
{
pid_t pgid, pid;
- pgid = getpgrp();
- pid = getpid();
+ pgid = TST_EXP_PID(getpgrp());
+ pid = TST_EXP_PID(getpid());
- TEST(setpgid(pid, pgid));
- if (TEST_RETURN == -1 || getpgrp() != pgid) {
- tst_resm(TFAIL | TTERRNO, "test setpgid(%d, %d) fail",
- pid, pgid);
- } else {
- tst_resm(TPASS, "test setpgid(%d, %d) success", pid, pgid);
- }
-}
-
-static int wait4child(pid_t child)
-{
- int status;
-
- if (waitpid(child, &status, 0) == -1)
- tst_resm(TBROK|TERRNO, "waitpid");
- if (WIFEXITED(status))
- return WEXITSTATUS(status);
- else
- return status;
+ TST_EXP_PASS(setpgid(pid, pgid));
+ TST_EXP_EQ_LI(pgid, getpgrp());
}
static void setpgid_test2(void)
{
- int ret;
- pid_t pgid, pid;
+ pid_t pgid;
- pid = tst_fork();
- if (pid == -1)
- tst_brkm(TBROK | TERRNO, cleanup, "fork()");
-
- if (pid != 0) {
- ret = wait4child(pid);
- } else {
- pid = getpid();
- TEST(setpgid(0, 0));
- pgid = getpgrp();
- if (TEST_RETURN == -1) {
- fprintf(stderr, "setpgid(0, 0) fails in "
- "child process: %s\n", strerror(TEST_ERRNO));
- exit(1);
- } else if (pgid != pid) {
- fprintf(stderr, "setpgid(0, 0) fails to make PGID"
- "equal to PID\n");
- exit(1);
- } else {
- exit(0);
- }
+ if (!SAFE_FORK()) {
+ pgid = TST_EXP_PID(getpid());
+ TST_EXP_PASS(setpgid(0, 0));
+ TST_EXP_EQ_LI(pgid, getpgrp());
}
-
- if (ret == 0)
- tst_resm(TPASS, "test setpgid(0, 0) success");
- else
- tst_resm(TFAIL, "test setpgid(0, 0) fail");
}
-
-static void setup(void)
+static void run(void)
{
- tst_sig(FORK, DEF_HANDLER, cleanup);
-
- TEST_PAUSE;
+ setpgid_test1();
+ setpgid_test2();
}
-static void cleanup(void)
-{
-}
+static struct tst_test test = {
+ .test_all = run,
+ .forks_child = 1,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [LTP] [PATCH v2 02/11] Add SAFE_PTSNAME macro
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 01/11] Refactor setpgid01 test Andrea Cervesato
@ 2025-01-06 10:31 ` Andrea Cervesato
2025-01-07 15:32 ` Cyril Hrubis
2025-01-08 12:01 ` Petr Vorel
2025-01-06 10:31 ` [LTP] [PATCH v2 03/11] Refactor ptem01 test Andrea Cervesato
` (8 subsequent siblings)
10 siblings, 2 replies; 21+ messages in thread
From: Andrea Cervesato @ 2025-01-06 10:31 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
include/tst_safe_macros.h | 4 ++++
lib/tst_safe_macros.c | 14 ++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/include/tst_safe_macros.h b/include/tst_safe_macros.h
index a9fa7dbe128f17eace381fdf9f2795684e55969b..6985aa4bd80af2ff8a7c606fdba9830bb5ccd195 100644
--- a/include/tst_safe_macros.h
+++ b/include/tst_safe_macros.h
@@ -528,4 +528,8 @@ ssize_t safe_writev(const char *file, const int lineno, char len_strict,
safe_writev(__FILE__, __LINE__, (len_strict), (fildes), \
(iov), (iovcnt))
+char *safe_ptsname(const char *const file, const int lineno, int masterfd);
+#define SAFE_PTSNAME(masterfd) \
+ safe_ptsname(__FILE__, __LINE__, (masterfd))
+
#endif /* TST_SAFE_MACROS_H__ */
diff --git a/lib/tst_safe_macros.c b/lib/tst_safe_macros.c
index 633b00404a56aafce6322e43bd614070d085e643..a837d4582d4402a0aa0dd4f231d36439e1cd046f 100644
--- a/lib/tst_safe_macros.c
+++ b/lib/tst_safe_macros.c
@@ -796,3 +796,17 @@ ssize_t safe_writev(const char *file, const int lineno, char len_strict,
return rval;
}
+
+char *safe_ptsname(const char *const file, const int lineno, int masterfd)
+{
+ char *name;
+
+ name = ptsname(masterfd);
+
+ if (name == NULL) {
+ tst_brk_(file, lineno, TBROK | TERRNO,
+ "ptsname(%d) failed", masterfd);
+ }
+
+ return name;
+}
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [LTP] [PATCH v2 03/11] Refactor ptem01 test
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 01/11] Refactor setpgid01 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 02/11] Add SAFE_PTSNAME macro Andrea Cervesato
@ 2025-01-06 10:31 ` Andrea Cervesato
2025-01-07 16:01 ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 04/11] Add ptem02 test Andrea Cervesato
` (7 subsequent siblings)
10 siblings, 1 reply; 21+ messages in thread
From: Andrea Cervesato @ 2025-01-06 10:31 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Fix test failure when running inside a new session via setsid() and
start spliting its internal tests cases implementations into multiple
files.
Fixes: https://github.com/linux-test-project/kirk/issues/28
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/pty/ptem01.c | 454 ++++--------------------------------------
1 file changed, 37 insertions(+), 417 deletions(-)
diff --git a/testcases/kernel/pty/ptem01.c b/testcases/kernel/pty/ptem01.c
index 20ef5d0a739a55262c1c32ec03e57885dfe09787..0a6844cc68c2c5b57496f81e8c2609a687159956 100644
--- a/testcases/kernel/pty/ptem01.c
+++ b/testcases/kernel/pty/ptem01.c
@@ -1,441 +1,61 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- * Copyright (c) International Business Machines Corp., 2002
- * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
- *
- * 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 will 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 to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
*/
-/* 12/23/2002 Port to LTP robbiew@us.ibm.com */
-/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
+/*\
+ * [Description]
+ *
+ * Verify that it's possible to open a pseudo-terminal via /dev/ptmx, obtain a
+ * slave device and configure termos/termios ioctls.
+ */
#define _GNU_SOURCE
-#include <errno.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <termios.h>
-#include <fcntl.h>
-#include <sys/stat.h>
-#include <sys/poll.h>
-#include <sys/types.h>
-
-#include "test.h"
-#include "safe_macros.h"
-#include "lapi/ioctl.h"
-char *TCID = "ptem01"; /* Test program identifier. */
-int TST_TOTAL = 6; /* Total number of test cases. */
-/**************/
+#include <termio.h>
+#include <termios.h>
+#include "tst_test.h"
-/*
- * pty master clone device
- */
#define MASTERCLONE "/dev/ptmx"
-#define BUFSZ 4096
-
-/*
- * test termio/termios ioctls
- */
-int test1(void)
+static void run(void)
{
int masterfd, slavefd;
char *slavename;
struct termio termio;
struct termios termios;
- masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
-
- slavename = ptsname(masterfd);
- if (slavename == NULL) {
- tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
- }
-
- if (grantpt(masterfd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
- }
-
- if (unlockpt(masterfd) != 0) {
- tst_brkm(TBROK, NULL, "unlockpt() call failed");
- }
-
- if ((slavefd = open(slavename, O_RDWR)) < 0) {
- tst_brkm(TFAIL, NULL, "Could not open %s", slavename);
- }
-
- if (ioctl(slavefd, TCGETS, &termios) != 0) {
- tst_brkm(TFAIL, NULL, "TCGETS");
- }
-
- if (ioctl(slavefd, TCSETS, &termios) != 0) {
- tst_brkm(TFAIL, NULL, "TCSETS");
- }
-
- if (ioctl(slavefd, TCSETSW, &termios) != 0) {
- tst_brkm(TFAIL, NULL, "TCSETSW");
- }
-
- if (ioctl(slavefd, TCSETSF, &termios) != 0) {
- tst_brkm(TFAIL, NULL, "TCSETSF");
- }
-
- if (ioctl(slavefd, TCSETS, &termios) != 0) {
- tst_brkm(TFAIL, NULL, "TCSETS");
- }
-
- if (ioctl(slavefd, TCGETA, &termio) != 0) {
- tst_brkm(TFAIL, NULL, "TCGETA");
- }
-
- if (ioctl(slavefd, TCSETA, &termio) != 0) {
- tst_brkm(TFAIL, NULL, "TCSETA");
- }
-
- if (ioctl(slavefd, TCSETAW, &termio) != 0) {
- tst_brkm(TFAIL, NULL, "TCSETAW");
- }
-
- if (ioctl(slavefd, TCSETAF, &termio) != 0) {
- tst_brkm(TFAIL, NULL, "TCSETAF");
- }
-
- if (close(slavefd) != 0) {
- tst_brkm(TBROK, NULL, "close slave");
- }
-
- if (close(masterfd) != 0) {
- tst_brkm(TBROK, NULL, "close master");
- }
- tst_resm(TPASS, "test1");
-
- /** NOT REACHED **/
- return 0;
-}
-
-/*
- * test window size setting and getting
- */
-int test2(void)
-{
- int masterfd, slavefd;
- char *slavename;
- struct winsize wsz;
- struct winsize wsz1 = { 24, 80, 5, 10 };
- struct winsize wsz2 = { 60, 100, 11, 777 };
-
- masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
-
- slavename = ptsname(masterfd);
- if (slavename == NULL) {
- tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
- }
-
- if (grantpt(masterfd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
- }
-
- if (unlockpt(masterfd) != 0) {
- tst_brkm(TBROK, NULL, "unlockpt() call failed");
- }
-
- if ((slavefd = open(slavename, O_RDWR)) < 0) {
- tst_brkm(TBROK, NULL, "Could not open %s", slavename);
- }
-
- if (ioctl(masterfd, TIOCSWINSZ, &wsz1) != 0) {
- tst_brkm(TFAIL, NULL, "TIOCSWINSZ");
- }
-
- if (ioctl(slavefd, TIOCGWINSZ, &wsz) != 0) {
- tst_brkm(TFAIL, NULL, "TIOCGWINSZ");
- }
-
- if (wsz.ws_row != wsz1.ws_row || wsz.ws_col != wsz1.ws_col ||
- wsz.ws_xpixel != wsz1.ws_xpixel ||
- wsz.ws_ypixel != wsz1.ws_ypixel) {
- tst_brkm(TFAIL, NULL, "unexpected window size returned");
- }
-
- if (ioctl(masterfd, TIOCGWINSZ, &wsz) != 0) {
- tst_brkm(TFAIL, NULL, "TIOCGWINSZ");
- }
-
- if (wsz.ws_row != wsz1.ws_row || wsz.ws_col != wsz1.ws_col ||
- wsz.ws_xpixel != wsz1.ws_xpixel ||
- wsz.ws_ypixel != wsz1.ws_ypixel) {
- tst_brkm(TFAIL, NULL, "unexpected window size returned");
- }
-
- if (ioctl(slavefd, TIOCSWINSZ, &wsz2) != 0) {
- tst_brkm(TFAIL, NULL, "TIOCSWINSZ");
- }
-
- if (ioctl(slavefd, TIOCGWINSZ, &wsz) != 0) {
- tst_brkm(TFAIL, NULL, "TIOCGWINSZ");
- }
-
- if (wsz.ws_row != wsz2.ws_row || wsz.ws_col != wsz2.ws_col ||
- wsz.ws_xpixel != wsz2.ws_xpixel ||
- wsz.ws_ypixel != wsz2.ws_ypixel) {
- tst_brkm(TFAIL, NULL, "unexpected window size returned");
- }
-
- if (close(slavefd) != 0) {
- tst_brkm(TBROK, NULL, "close");
- }
-
- if (close(masterfd) != 0) {
- tst_brkm(TBROK, NULL, "close");
- }
- tst_resm(TPASS, "test2");
-
- /** NOT REACHED **/
- return 0;
-}
-
-/*
- * test sending a break
- */
-int test3(void)
-{
- int masterfd, slavefd;
- char *slavename;
-
- masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
-
- slavename = ptsname(masterfd);
- if (slavename == NULL) {
- tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
- }
-
- if (grantpt(masterfd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
- }
-
- if (unlockpt(masterfd) != 0) {
- tst_brkm(TBROK, NULL, "unlockpt() call failed");
- }
-
- if ((slavefd = open(slavename, O_RDWR)) < 0) {
- tst_brkm(TBROK, NULL, "Could not open %s", slavename);
- }
-
- if (tcsendbreak(masterfd, 10) != 0) {
- tst_brkm(TFAIL, NULL, "tcsendbreak");
- }
-
- if (tcsendbreak(slavefd, 10) != 0) {
- tst_brkm(TFAIL, NULL, "tcsendbreak");
- }
-
- if (close(slavefd) != 0) {
- tst_brkm(TBROK, NULL, "close slave");
- }
-
- if (close(masterfd) != 0) {
- tst_brkm(TBROK, NULL, "close master");
- }
- tst_resm(TPASS, "test3");
-
- /** NOT REACHED **/
- return 0;
-}
-
-/*
- * test multiple opens of slave side
- */
-int test4(void)
-{
- int masterfd, slavefd, slavefd2, slavefd3;
- char *slavename;
-
- masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
-
- slavename = ptsname(masterfd);
- if (slavename == NULL) {
- tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
- }
-
- if (grantpt(masterfd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
- }
-
- if (unlockpt(masterfd) != 0) {
- tst_brkm(TBROK, NULL, "unlockpt() call failed");
- }
-
- if ((slavefd = open(slavename, O_RDWR)) < 0) {
- tst_brkm(TBROK, NULL, "Could not open %s", slavename);
- }
-
- if ((slavefd2 = open(slavename, O_RDWR)) < 0) {
- tst_brkm(TFAIL, NULL, "Could not open %s (again)", slavename);
- }
-
- if ((slavefd3 = open(slavename, O_RDWR)) < 0) {
- tst_brkm(TFAIL, NULL, "Could not open %s (once more)",
- slavename);
- }
-
- if (close(slavefd) != 0) {
- tst_brkm(TBROK, NULL, "close slave");
- }
- if (close(slavefd2) != 0) {
- tst_brkm(TBROK, NULL, "close slave again");
- }
- if (close(slavefd3) != 0) {
- tst_brkm(TBROK, NULL, "close slave once more");
- }
- if (close(masterfd) != 0) {
- tst_brkm(TBROK, NULL, "close master");
- }
- tst_resm(TPASS, "test4");
-
- /** NOT REACHED **/
- return 0;
-}
-
-#define NUMOPENS 6
-
-/*
- * test several simultaneous opens
- */
-int test5(void)
-{
- static int masterfd[NUMOPENS];
- static int slavefd[NUMOPENS];
- char *slavename;
- int i;
+ masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
+ slavename = SAFE_PTSNAME(masterfd);
- for (i = 0; i < NUMOPENS; ++i) {
- masterfd[i] = open(MASTERCLONE, O_RDWR);
- if (masterfd[i] < 0) {
- tst_resm(TBROK, "%s", MASTERCLONE);
- tst_resm(TBROK, "out of ptys");
- for (i = 0; i < NUMOPENS; ++i) {
- if (masterfd[i] != 0) {
- (void)close(masterfd[i]);
- }
- if (slavefd[i] != 0) {
- (void)close(slavefd[i]);
- }
- }
- tst_exit();
- }
+ TST_EXP_PASS(grantpt(masterfd));
+ TST_EXP_PASS(unlockpt(masterfd));
- slavename = ptsname(masterfd[i]);
- if (slavename == NULL) {
- tst_brkm(TBROK | TERRNO, NULL,
- "ptsname() call failed");
- }
+ slavefd = SAFE_OPEN(slavename, O_RDWR);
- if (grantpt(masterfd[i]) != 0) {
- tst_brkm(TBROK | TERRNO, NULL,
- "grantpt() call failed");
- }
+ TST_EXP_POSITIVE(ioctl(slavefd, TCGETS, &termios));
+ TST_EXP_POSITIVE(ioctl(slavefd, TCSETS, &termios));
+ TST_EXP_POSITIVE(ioctl(slavefd, TCSETSW, &termios));
+ TST_EXP_POSITIVE(ioctl(slavefd, TCSETSF, &termios));
+ TST_EXP_POSITIVE(ioctl(slavefd, TCSETS, &termios));
+ TST_EXP_POSITIVE(ioctl(slavefd, TCGETA, &termio));
+ TST_EXP_POSITIVE(ioctl(slavefd, TCSETA, &termio));
+ TST_EXP_POSITIVE(ioctl(slavefd, TCSETAW, &termio));
+ TST_EXP_POSITIVE(ioctl(slavefd, TCSETAF, &termio));
- if (unlockpt(masterfd[i]) != 0) {
- tst_brkm(TBROK, NULL, "unlockpt() call failed");
- }
-
- if ((slavefd[i] = open(slavename, O_RDWR)) < 0) {
- tst_brkm(TFAIL, NULL,
- "Iteration %d: Could not open %s", i,
- slavename);
- }
-
- }
-
- for (i = 0; i < NUMOPENS; ++i) {
- if (close(slavefd[i]) != 0) {
- tst_brkm(TBROK, NULL, "Iteration %d: close slave", i);
- }
- if (close(masterfd[i]) != 0) {
- tst_brkm(TBROK, NULL, "close master");
- }
- }
- tst_resm(TPASS, "test5");
-
- /** NOT REACHED **/
- return 0;
+ SAFE_CLOSE(slavefd);
+ SAFE_CLOSE(masterfd);
}
-/*
- * test hangup semantics
- */
-int test6(void)
+static void setup(void)
{
- static int masterfd;
- static int slavefd;
- char *slavename;
- struct termios termios;
-
- masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
-
- slavename = ptsname(masterfd);
- if (slavename == NULL) {
- tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
- }
-
- if (grantpt(masterfd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
- }
-
- if (unlockpt(masterfd) != 0) {
- tst_brkm(TBROK, NULL, "unlockpt() call failed");
- }
-
- if ((slavefd = open(slavename, O_RDWR)) < 0) {
- tst_brkm(TBROK, NULL, "Could not open %s", slavename);
- }
-
- if (ioctl(slavefd, TCGETS, &termios) != 0) {
- tst_brkm(TFAIL, NULL, "TCGETS");
- }
-
- termios.c_cflag &= ~CBAUD;
- termios.c_cflag |= B0 & CBAUD;
- if (ioctl(slavefd, TCSETS, &termios) != 0) {
- tst_brkm(TFAIL, NULL, "TCGETS");
- }
-
- if (close(slavefd) != 0) {
- tst_brkm(TBROK, NULL, "close");
- }
- if (close(masterfd) != 0) {
- tst_brkm(TBROK, NULL, "close");
- }
- tst_resm(TPASS, "test6");
-
- /** NOT REACHED **/
- return 0;
+ if (access(MASTERCLONE, F_OK))
+ tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
}
-/*
- * main test driver
- */
-int main(void)
-{
- test1();
- test2();
- test3();
- test4();
- test5();
- test6();
- /*
- * all done
- */
- tst_exit();
-}
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [LTP] [PATCH v2 04/11] Add ptem02 test
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
` (2 preceding siblings ...)
2025-01-06 10:31 ` [LTP] [PATCH v2 03/11] Refactor ptem01 test Andrea Cervesato
@ 2025-01-06 10:31 ` Andrea Cervesato
2025-01-07 16:14 ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 05/11] Add ptem03 test Andrea Cervesato
` (6 subsequent siblings)
10 siblings, 1 reply; 21+ messages in thread
From: Andrea Cervesato @ 2025-01-06 10:31 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that it's possible to open a pseudo-terminal via /dev/ptmx,
obtain a slave device and set/get window size.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/pty | 1 +
testcases/kernel/pty/.gitignore | 1 +
testcases/kernel/pty/ptem02.c | 73 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 75 insertions(+)
diff --git a/runtest/pty b/runtest/pty
index df2074153c2ac01038a0ef0ce5ad8938960ae53d..3ce7160e2776e58973def5893fc269ed035376c0 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -7,5 +7,6 @@ pty05 pty05
pty06 pty06
pty07 pty07
ptem01 ptem01
+ptem02 ptem02
hangup01 hangup01
diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index acca3db9a1786f243b31f1fc4a8833d6ed8751a6..e638413a127fad65ed2f58c24dc1ae718219e518 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -1,5 +1,6 @@
/hangup01
/ptem01
+/ptem02
/pty01
/pty02
/pty03
diff --git a/testcases/kernel/pty/ptem02.c b/testcases/kernel/pty/ptem02.c
new file mode 100644
index 0000000000000000000000000000000000000000..683595ff10d20893926310b5901a2e98045fb6ce
--- /dev/null
+++ b/testcases/kernel/pty/ptem02.c
@@ -0,0 +1,73 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that it's possible to open a pseudo-terminal via /dev/ptmx, obtain a
+ * slave device and set/get window size.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+
+#define MASTERCLONE "/dev/ptmx"
+
+static void run(void)
+{
+ int masterfd, slavefd;
+ char *slavename;
+ struct winsize wsz;
+ struct winsize wsz1 = { 24, 80, 5, 10 };
+ struct winsize wsz2 = { 60, 100, 11, 777 };
+
+ masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
+ slavename = SAFE_PTSNAME(masterfd);
+
+ TST_EXP_PASS(grantpt(masterfd));
+ TST_EXP_PASS(unlockpt(masterfd));
+
+ slavefd = SAFE_OPEN(slavename, O_RDWR);
+
+ TST_EXP_POSITIVE(ioctl(masterfd, TIOCSWINSZ, &wsz1));
+ TST_EXP_POSITIVE(ioctl(slavefd, TIOCGWINSZ, &wsz));
+
+ TST_EXP_EQ_LI(wsz.ws_row, wsz1.ws_row);
+ TST_EXP_EQ_LI(wsz.ws_col, wsz1.ws_col);
+ TST_EXP_EQ_LI(wsz.ws_xpixel, wsz1.ws_xpixel);
+ TST_EXP_EQ_LI(wsz.ws_ypixel, wsz1.ws_ypixel);
+
+ TST_EXP_POSITIVE(ioctl(masterfd, TIOCGWINSZ, &wsz));
+
+ TST_EXP_EQ_LI(wsz.ws_row, wsz1.ws_row);
+ TST_EXP_EQ_LI(wsz.ws_col, wsz1.ws_col);
+ TST_EXP_EQ_LI(wsz.ws_xpixel, wsz1.ws_xpixel);
+ TST_EXP_EQ_LI(wsz.ws_ypixel, wsz1.ws_ypixel);
+
+ TST_EXP_POSITIVE(ioctl(slavefd, TIOCSWINSZ, &wsz2));
+ TST_EXP_POSITIVE(ioctl(slavefd, TIOCGWINSZ, &wsz));
+
+ TST_EXP_EQ_LI(wsz.ws_row, wsz2.ws_row);
+ TST_EXP_EQ_LI(wsz.ws_col, wsz2.ws_col);
+ TST_EXP_EQ_LI(wsz.ws_xpixel, wsz2.ws_xpixel);
+ TST_EXP_EQ_LI(wsz.ws_ypixel, wsz2.ws_ypixel);
+
+ SAFE_CLOSE(slavefd);
+ SAFE_CLOSE(masterfd);
+}
+
+static void setup(void)
+{
+ if (access(MASTERCLONE, F_OK))
+ tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [LTP] [PATCH v2 05/11] Add ptem03 test
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
` (3 preceding siblings ...)
2025-01-06 10:31 ` [LTP] [PATCH v2 04/11] Add ptem02 test Andrea Cervesato
@ 2025-01-06 10:31 ` Andrea Cervesato
2025-01-07 16:30 ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 06/11] Add ptem04 test Andrea Cervesato
` (5 subsequent siblings)
10 siblings, 1 reply; 21+ messages in thread
From: Andrea Cervesato @ 2025-01-06 10:31 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that it's possible to open a pseudo-terminal via /dev/ptmx,
obtain a slave device and to send a break to both master and slave.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/pty | 1 +
testcases/kernel/pty/.gitignore | 1 +
testcases/kernel/pty/ptem03.c | 51 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 53 insertions(+)
diff --git a/runtest/pty b/runtest/pty
index 3ce7160e2776e58973def5893fc269ed035376c0..329cc84cdc107ab8e814fea72a8088ea62d5ad25 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -8,5 +8,6 @@ pty06 pty06
pty07 pty07
ptem01 ptem01
ptem02 ptem02
+ptem03 ptem03
hangup01 hangup01
diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index e638413a127fad65ed2f58c24dc1ae718219e518..61fec1ddae3ea39d20e97123e34888708050c25c 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -1,6 +1,7 @@
/hangup01
/ptem01
/ptem02
+/ptem03
/pty01
/pty02
/pty03
diff --git a/testcases/kernel/pty/ptem03.c b/testcases/kernel/pty/ptem03.c
new file mode 100644
index 0000000000000000000000000000000000000000..22ca8647d0ab79f1497613ea354b26cba36599c7
--- /dev/null
+++ b/testcases/kernel/pty/ptem03.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that it's possible to open a pseudo-terminal via /dev/ptmx, obtain a
+ * slave device and to send a break to both master and slave.
+ */
+
+#define _GNU_SOURCE
+
+#include <termios.h>
+#include "tst_test.h"
+
+#define MASTERCLONE "/dev/ptmx"
+
+static void run(void)
+{
+ int masterfd, slavefd;
+ char *slavename;
+
+ masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
+ slavename = SAFE_PTSNAME(masterfd);
+
+ TST_EXP_PASS(grantpt(masterfd));
+ TST_EXP_PASS(unlockpt(masterfd));
+
+ slavefd = SAFE_OPEN(slavename, O_RDWR);
+
+ TST_EXP_PASS(tcsendbreak(masterfd, 10));
+ TST_EXP_PASS(tcsendbreak(slavefd, 10));
+
+ SAFE_CLOSE(slavefd);
+ SAFE_CLOSE(masterfd);
+}
+
+static void setup(void)
+{
+ if (access(MASTERCLONE, F_OK))
+ tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [LTP] [PATCH v2 06/11] Add ptem04 test
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
` (4 preceding siblings ...)
2025-01-06 10:31 ` [LTP] [PATCH v2 05/11] Add ptem03 test Andrea Cervesato
@ 2025-01-06 10:31 ` Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 07/11] Add ptem05 test Andrea Cervesato
` (4 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Andrea Cervesato @ 2025-01-06 10:31 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that it's possible to open a pseudo-terminal via /dev/ptmx,
obtain a slave device and to check if it's possible to open it
multiple times.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/pty | 1 +
testcases/kernel/pty/.gitignore | 1 +
testcases/kernel/pty/ptem04.c | 52 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 54 insertions(+)
diff --git a/runtest/pty b/runtest/pty
index 329cc84cdc107ab8e814fea72a8088ea62d5ad25..63d927eca07aa3dbd312d5c5cc6b6681dbf3627d 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -9,5 +9,6 @@ pty07 pty07
ptem01 ptem01
ptem02 ptem02
ptem03 ptem03
+ptem04 ptem04
hangup01 hangup01
diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index 61fec1ddae3ea39d20e97123e34888708050c25c..c9bb33664f9de55038f4638406841f403f1a86c4 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -2,6 +2,7 @@
/ptem01
/ptem02
/ptem03
+/ptem04
/pty01
/pty02
/pty03
diff --git a/testcases/kernel/pty/ptem04.c b/testcases/kernel/pty/ptem04.c
new file mode 100644
index 0000000000000000000000000000000000000000..85ff1687fe4e8744be1e61effa6ad547d9d4c071
--- /dev/null
+++ b/testcases/kernel/pty/ptem04.c
@@ -0,0 +1,52 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that it's possible to open a pseudo-terminal via /dev/ptmx, obtain a
+ * slave device and to check if it's possible to open it multiple times.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+
+#define MASTERCLONE "/dev/ptmx"
+#define NUM_SLAVES 10
+
+static void run(void)
+{
+ int masterfd;
+ int slavefd[NUM_SLAVES];
+ char *slavename;
+
+ masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
+ slavename = SAFE_PTSNAME(masterfd);
+
+ TST_EXP_PASS(grantpt(masterfd));
+ TST_EXP_PASS(unlockpt(masterfd));
+
+ for (int i = 0; i < NUM_SLAVES; i++)
+ slavefd[i] = TST_EXP_FD(open(slavename, O_RDWR));
+
+ for (int i = 0; i < NUM_SLAVES; i++)
+ SAFE_CLOSE(slavefd[i]);
+
+ SAFE_CLOSE(masterfd);
+}
+
+static void setup(void)
+{
+ if (access(MASTERCLONE, F_OK))
+ tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [LTP] [PATCH v2 07/11] Add ptem05 test
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
` (5 preceding siblings ...)
2025-01-06 10:31 ` [LTP] [PATCH v2 06/11] Add ptem04 test Andrea Cervesato
@ 2025-01-06 10:31 ` Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 08/11] Add ptem06 test Andrea Cervesato
` (3 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Andrea Cervesato @ 2025-01-06 10:31 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that it's possible to open a pseudo-terminal via /dev/ptmx, to
obtain a master + slave pair and to open them multiple times.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/pty | 1 +
testcases/kernel/pty/.gitignore | 1 +
testcases/kernel/pty/ptem05.c | 53 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 55 insertions(+)
diff --git a/runtest/pty b/runtest/pty
index 63d927eca07aa3dbd312d5c5cc6b6681dbf3627d..deb04c3f5725647a32f457eaed638eb7071ab4db 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -10,5 +10,6 @@ ptem01 ptem01
ptem02 ptem02
ptem03 ptem03
ptem04 ptem04
+ptem05 ptem05
hangup01 hangup01
diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index c9bb33664f9de55038f4638406841f403f1a86c4..ef5751907cad087f5e33132b52a374b52ee7905a 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -3,6 +3,7 @@
/ptem02
/ptem03
/ptem04
+/ptem05
/pty01
/pty02
/pty03
diff --git a/testcases/kernel/pty/ptem05.c b/testcases/kernel/pty/ptem05.c
new file mode 100644
index 0000000000000000000000000000000000000000..a1610ada723bd78dc81a915ccec931e177286a38
--- /dev/null
+++ b/testcases/kernel/pty/ptem05.c
@@ -0,0 +1,53 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that it's possible to open a pseudo-terminal via /dev/ptmx, to obtain
+ * a master + slave pair and to open them multiple times.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+
+#define MASTERCLONE "/dev/ptmx"
+#define NUM_OPENS 10
+
+static void run(void)
+{
+ int masterfd[NUM_OPENS];
+ int slavefd[NUM_OPENS];
+ char *slavename;
+
+ for (int i = 0; i < NUM_OPENS; i++) {
+ masterfd[i] = SAFE_OPEN(MASTERCLONE, O_RDWR);
+ slavename = SAFE_PTSNAME(masterfd[i]);
+
+ TST_EXP_PASS(grantpt(masterfd[i]));
+ TST_EXP_PASS(unlockpt(masterfd[i]));
+
+ slavefd[i] = TST_EXP_FD(open(slavename, O_RDWR));
+ }
+
+ for (int i = 0; i < NUM_OPENS; i++) {
+ SAFE_CLOSE(masterfd[i]);
+ SAFE_CLOSE(slavefd[i]);
+ }
+}
+
+static void setup(void)
+{
+ if (access(MASTERCLONE, F_OK))
+ tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [LTP] [PATCH v2 08/11] Add ptem06 test
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
` (6 preceding siblings ...)
2025-01-06 10:31 ` [LTP] [PATCH v2 07/11] Add ptem05 test Andrea Cervesato
@ 2025-01-06 10:31 ` Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 09/11] Refactor pty01 test Andrea Cervesato
` (2 subsequent siblings)
10 siblings, 0 replies; 21+ messages in thread
From: Andrea Cervesato @ 2025-01-06 10:31 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that it's possible to open a pseudo-terminal via /dev/ptmx,
to obtain a slave device and to set baudrate to B0 (which means hang
up).
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/pty | 1 +
testcases/kernel/pty/.gitignore | 1 +
testcases/kernel/pty/ptem06.c | 54 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 56 insertions(+)
diff --git a/runtest/pty b/runtest/pty
index deb04c3f5725647a32f457eaed638eb7071ab4db..6343da391ba17627abaf09aa5a23509e4f745556 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -11,5 +11,6 @@ ptem02 ptem02
ptem03 ptem03
ptem04 ptem04
ptem05 ptem05
+ptem06 ptem06
hangup01 hangup01
diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index ef5751907cad087f5e33132b52a374b52ee7905a..630d7fcf7b0e0adfbc21b793fa456d6c5f5e4ad9 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -4,6 +4,7 @@
/ptem03
/ptem04
/ptem05
+/ptem06
/pty01
/pty02
/pty03
diff --git a/testcases/kernel/pty/ptem06.c b/testcases/kernel/pty/ptem06.c
new file mode 100644
index 0000000000000000000000000000000000000000..bcdb706f60facc54ce4f25d031e28179206e848a
--- /dev/null
+++ b/testcases/kernel/pty/ptem06.c
@@ -0,0 +1,54 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (c) 2020 Petr Vorel <pvorel@suse.cz>
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that it's possible to open a pseudo-terminal via /dev/ptmx, to obtain
+ * a slave device and to set baudrate to B0 (which means hang up).
+ */
+
+#define _GNU_SOURCE
+
+#include <termios.h>
+#include "tst_test.h"
+
+#define MASTERCLONE "/dev/ptmx"
+
+static void run(void)
+{
+ int masterfd, slavefd;
+ struct termios termios;
+ char *slavename;
+
+ masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
+ slavename = SAFE_PTSNAME(masterfd);
+
+ TST_EXP_PASS(grantpt(masterfd));
+ TST_EXP_PASS(unlockpt(masterfd));
+
+ slavefd = SAFE_OPEN(slavename, O_RDWR);
+
+ TST_EXP_PASS(ioctl(slavefd, TCGETS, &termios));
+ termios.c_cflag &= ~CBAUD;
+ termios.c_cflag |= B0 & CBAUD;
+ TST_EXP_PASS(ioctl(slavefd, TCSETS, &termios));
+
+ SAFE_CLOSE(slavefd);
+ SAFE_CLOSE(masterfd);
+}
+
+static void setup(void)
+{
+ if (access(MASTERCLONE, F_OK))
+ tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [LTP] [PATCH v2 09/11] Refactor pty01 test
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
` (7 preceding siblings ...)
2025-01-06 10:31 ` [LTP] [PATCH v2 08/11] Add ptem06 test Andrea Cervesato
@ 2025-01-06 10:31 ` Andrea Cervesato
2025-01-08 12:39 ` Petr Vorel
2025-01-06 10:31 ` [LTP] [PATCH v2 10/11] Add pty08 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 11/11] Add pty09 test Andrea Cervesato
10 siblings, 1 reply; 21+ messages in thread
From: Andrea Cervesato @ 2025-01-06 10:31 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Rewrite part of the code using the new LTP library and fix the execution
of the test inside a new session via setsid(). The test is now split
into multiple files, instead of having multiple test* functions
executing all in one file.
Fixes: https://github.com/linux-test-project/kirk/issues/28
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
testcases/kernel/pty/pty01.c | 416 ++++++-------------------------------------
1 file changed, 50 insertions(+), 366 deletions(-)
diff --git a/testcases/kernel/pty/pty01.c b/testcases/kernel/pty/pty01.c
index 666b221b017fe214b7baa0b2bc608dfc2feff732..c3c03306adf528ef97c4a2836c61db207606dc43 100644
--- a/testcases/kernel/pty/pty01.c
+++ b/testcases/kernel/pty/pty01.c
@@ -1,395 +1,79 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
/*
- *
- * Copyright (c) International Business Machines Corp., 2002
- *
- * 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 will 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 to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
*/
-/* 12/23/2002 Port to LTP robbiew@us.ibm.com */
-/* 06/30/2001 Port to Linux nsharoff@us.ibm.com */
+/*\
+ * [Description]
+ *
+ * Verify that write/read is properly working when master and slave
+ * pseudo terminals communicate with each other.
+ */
#define _GNU_SOURCE
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/wait.h>
-#include <errno.h>
-#include <fcntl.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <termios.h>
-#include <unistd.h>
-#include "test.h"
-#include "safe_macros.h"
-#include "lapi/ioctl.h"
+#include "tst_test.h"
-char *TCID = "pty01"; /* Test program identifier. */
-int TST_TOTAL = 5; /* Total number of test cases. */
-/**************/
-
-/*
- * pty master clone device
- */
#define MASTERCLONE "/dev/ptmx"
+#define STRING "Linux Test Project"
+#define STRING_LEN strlen(STRING)
-/*
- * string for testing read/write on ptys
- */
-#define STRING "Linux Test Project\n"
-
-/*
- * test buffer size
- */
-#define TESTSIZE 1024
-
-/*
- * mode we expect grantpt() to leave pty as
- */
-#define PTY_MODE 020622
-
-/*
- * number of procs for parallel test
- */
-#define NUMPROCS 15
-
-/*
- * test slave locking
- */
-static int test1(void)
+static void run(void)
{
- int masterfd; /* master pty fd */
- int slavefd; /* slave pty fd */
+ int masterfd;
+ int slavefd;
char *slavename;
struct stat st;
- char buf[TESTSIZE];
+ char buf[BUFSIZ];
- masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
+ memset(buf, 0, BUFSIZ);
- slavename = ptsname(masterfd);
- if (slavename == NULL) {
- tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
- }
+ masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
+ slavename = SAFE_PTSNAME(masterfd);
- if (grantpt(masterfd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
- }
+ if (grantpt(masterfd) == -1)
+ tst_brk(TBROK | TERRNO, "grantpt() error");
- if (stat(slavename, &st) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "stat(%s) failed", slavename);
- }
- if (st.st_uid != getuid()) {
- tst_brkm(TBROK, NULL, "uid mismatch");
+ TST_EXP_PASS_SILENT(unlockpt(masterfd));
+ if (TST_RET == -1) {
+ SAFE_CLOSE(masterfd);
+ return;
}
- /* grantpt() is a no-op in bionic. */
+ SAFE_STAT(slavename, &st);
+ TST_EXP_EQ_LI(st.st_uid, getuid());
+
+ /* grantpt() is a no-op in bionic. */
#ifndef __BIONIC__
- if (st.st_mode != (S_IFCHR | S_IRUSR | S_IWUSR | S_IWGRP)) {
- tst_brkm(TBROK, NULL, "mode mismatch (mode=%o)", st.st_mode);
- }
+ TST_EXP_EQ_LI(st.st_mode, 0620);
#endif
- slavefd = open(slavename, O_RDWR);
- if (slavefd >= 0) {
- tst_brkm(TBROK, NULL, "open didn't fail as expected!");
- }
-
- if (unlockpt(masterfd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "unlockpt() failed");
- }
-
- slavefd = SAFE_OPEN(NULL, slavename, O_RDWR);
-
- /*
- * test writing to the master / reading from the slave
- */
- if (write(masterfd, STRING, strlen(STRING)) != strlen(STRING)) {
- /*
- * XXX: the errno printout might be garbage, but better to be
- * safe than sorry..
- */
- tst_brkm(TFAIL | TERRNO, NULL, "write to master");
- }
+ slavefd = SAFE_OPEN(slavename, O_RDWR);
- if (read(slavefd, buf, strlen(STRING)) != strlen(STRING)) {
- /* XXX: Same as write above.. */
- tst_brkm(TFAIL | TERRNO, NULL, "read from slave");
- }
- if (strncmp(STRING, buf, strlen(STRING) - 1) != 0) {
- tst_brkm(TFAIL, NULL,
- "strings are different (STRING = '%s' != buf = '%s')",
- STRING, buf);
- }
+ tst_res(TINFO, "Send message to master and read from slave");
+ SAFE_WRITE(SAFE_WRITE_ALL, masterfd, STRING, STRING_LEN);
+ SAFE_WRITE(SAFE_WRITE_ALL, masterfd, "\n", 1);
+ SAFE_READ(1, slavefd, buf, STRING_LEN);
+ TST_EXP_EQ_STR(STRING, buf);
- /*
- * test writing to the slave / reading from the master
- */
- if (write(slavefd, STRING, strlen(STRING)) != strlen(STRING)) {
- /* XXX: Same as write above.. */
- tst_brkm(TFAIL | TERRNO, NULL, "write to slave");
- }
-
- if (read(masterfd, buf, strlen(STRING)) != strlen(STRING)) {
- /* XXX: Same as write above.. */
- tst_brkm(TFAIL | TERRNO, NULL, "read from master");
- }
- if (strncmp(STRING, buf, strlen(STRING) - 1) != 0) {
- tst_brkm(TFAIL, NULL,
- "strings are different (STRING = '%s' != buf = '%s').",
- STRING, buf);
- }
-
- /*
- * try an invalid ioctl on the slave...
- */
- if (ioctl(slavefd, TIOCGWINSZ, NULL) == 0) {
- tst_brkm(TFAIL, NULL,
- "invalid slave TIOCGWINSZ ioctl succeeded.. it should "
- "have failed");
- }
-
- /*
- * try an invalid ioctl on the master...
- */
- if (ioctl(masterfd, TIOCGWINSZ, NULL) == 0) {
- tst_brkm(TFAIL, NULL,
- "invalid master TIOCGWINSZ ioctl succeeded.. it should "
- "have failed");
- }
+ tst_res(TINFO, "Send message to slave and read from master");
+ SAFE_WRITE(SAFE_WRITE_ALL, slavefd, STRING, STRING_LEN);
+ SAFE_WRITE(SAFE_WRITE_ALL, masterfd, "\n", 1);
+ SAFE_READ(1, masterfd, buf, STRING_LEN);
+ TST_EXP_EQ_STR(STRING, buf);
- /*
- * close pty fds
- */
- if (close(slavefd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "close of slave");
- }
- if (close(masterfd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "close of master");
- }
- tst_resm(TPASS, "test1");
- /** NOTREACHED **/
- return 0;
+ SAFE_CLOSE(slavefd);
+ SAFE_CLOSE(masterfd);
}
-/*
- * test slave operations with closed master
- */
-static void test2(void)
+static void setup(void)
{
- int masterfd; /* master pty fd */
- int slavefd; /* slave pty fd */
- int i;
- char *slavename;
- char c;
-
- masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
-
- slavename = ptsname(masterfd);
- if (slavename == NULL) {
- tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
- }
-
- if (grantpt(masterfd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
- }
-
- if (unlockpt(masterfd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "unlockpt() call failed");
- }
-
- slavefd = SAFE_OPEN(NULL, slavename, O_RDWR);
-
- /*
- * close pty fds. See what happens when we close the master
- * first.
- */
- if (close(masterfd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "close()");
- }
-
- errno = 0;
- if ((i = read(slavefd, &c, 1)) == 1) {
- tst_brkm(TFAIL, NULL,
- "reading from slave fd should have failed, but didn't"
- "(read '%c')", c);
- }
-
- if ((i = write(slavefd, &c, 1)) == 1) {
- tst_brkm(TFAIL, NULL,
- "writing to slave fd should have failed, but didn't");
- }
-
- if (ioctl(slavefd, TIOCGWINSZ, NULL) == 0) {
- tst_brkm(TFAIL, NULL,
- "trying TIOCGWINSZ on slave fd should have failed, "
- "but didn't");
- }
-
- if (close(slavefd) != 0) {
- tst_brkm(TBROK, NULL, "close");
- }
- tst_resm(TPASS, "test2");
+ if (access(MASTERCLONE, F_OK))
+ tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
}
-/*
- * test operations on master with closed slave
- */
-static void test3(void)
-{
- int masterfd; /* master pty fd */
-
- masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
-
- if (ioctl(masterfd, TIOCGWINSZ, NULL) == 0) {
- tst_brkm(TFAIL | TERRNO, NULL,
- "trying TIOCGWINSZ on master with no open slave "
- "succeeded unexpectedly");
- }
- tst_resm(TPASS, "test3");
-}
-
-/*
- * test multiple opens on slave side of pty
- */
-static void test4(void)
-{
- int masterfd; /* master pty fd */
- int slavefd; /* slave pty fd */
- int slavefd2;
- int slavefd3;
- char *slavename;
-
- masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
-
- slavename = ptsname(masterfd);
- if (slavename == NULL) {
- tst_brkm(TBROK, NULL, "ptsname() call failed");
- }
-
- if (grantpt(masterfd) != 0) {
- tst_brkm(TBROK, NULL, "grantpt() call failed");
- }
-
- if (unlockpt(masterfd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "unlockpt() call failed");
- }
-
- slavefd = SAFE_OPEN(NULL, slavename, O_RDWR);
-
- slavefd2 = open(slavename, O_RDWR);
- if (slavefd < 0) {
- tst_brkm(TFAIL | TERRNO, NULL, "Could not open %s (again)",
- slavename);
- }
-
- slavefd3 = open(slavename, O_RDWR);
- if (slavefd < 0) {
- tst_brkm(TFAIL | TERRNO, NULL, "Could not open %s (once more)",
- slavename);
- }
-
- /*
- * close pty fds.
- */
- if (close(slavefd) != 0) {
- tst_brkm(TBROK | TERRNO, NULL, "close slave");
- }
-
- if (close(slavefd2) != 0) {
- tst_brkm(TBROK, NULL, "close slave again");
- }
-
- if (close(slavefd3) != 0) {
- tst_brkm(TBROK, NULL, "close slave once more");
- }
-
- if (close(masterfd) != 0) {
- tst_brkm(TBROK, NULL, "close master");
- }
- tst_resm(TPASS, "test4");
-}
-
-/*
- * test opening/closing lots of ptys in parallel. We may run out
- * of ptys for this test depending on how the system is configured,
- * but that's not a fatal error.
- */
-static void test5(void)
-{
- int masterfd; /* master pty fd */
- char *slavename;
- int status;
- int i;
-
- for (i = 0; i < NUMPROCS; ++i) {
- switch (fork()) {
- case -1:
- tst_brkm(TBROK, NULL, "fork()");
- break;
- case 0:
- masterfd = open(MASTERCLONE, O_RDWR);
- if (masterfd < 0) {
- printf("proc %d: opening %s failed: %s",
- i, MASTERCLONE, strerror(errno));
- exit(1);
- }
- if (grantpt(masterfd) != 0) {
- printf("proc %d: grantpt() call failed: %s",
- i, strerror(errno));
- exit(1);
- }
- slavename = ptsname(masterfd);
- if (slavename == NULL) {
- printf("proc %d: ptsname() call failed: %s",
- i, strerror(errno));
- exit(1);
- }
- sleep(10);
- if (close(masterfd) != 0) {
- printf("proc %d: close failed: %s",
- i, strerror(errno));
- exit(1);
- }
- exit(0);
- default:
- break;
- }
- }
- while (wait(&status) > 0) {
- if (status) {
- tst_brkm(TFAIL, NULL,
- "child exited with non-zero status %d",
- status);
- }
- }
- tst_resm(TPASS, "test5");
-}
-
-/*
- * main test driver
- */
-int main(void)
-{
- test1();
- test2();
- test3();
- test4();
- test5();
-
- /*
- * all done
- */
- tst_exit();
-}
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [LTP] [PATCH v2 10/11] Add pty08 test
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
` (8 preceding siblings ...)
2025-01-06 10:31 ` [LTP] [PATCH v2 09/11] Refactor pty01 test Andrea Cervesato
@ 2025-01-06 10:31 ` Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 11/11] Add pty09 test Andrea Cervesato
10 siblings, 0 replies; 21+ messages in thread
From: Andrea Cervesato @ 2025-01-06 10:31 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that slave pseudo-terminal fails reading/writing if master has
been closed.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/pty | 1 +
testcases/kernel/pty/.gitignore | 1 +
testcases/kernel/pty/pty08.c | 57 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 59 insertions(+)
diff --git a/runtest/pty b/runtest/pty
index 6343da391ba17627abaf09aa5a23509e4f745556..365a46ee9730aa36b22dbbdbfba82ac0d491ac94 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -6,6 +6,7 @@ pty04 pty04
pty05 pty05
pty06 pty06
pty07 pty07
+pty08 pty08
ptem01 ptem01
ptem02 ptem02
ptem03 ptem03
diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index 630d7fcf7b0e0adfbc21b793fa456d6c5f5e4ad9..7d8d4dceda84f2e2695a8bee39abfe894288b8b6 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -12,3 +12,4 @@
/pty05
/pty06
/pty07
+/pty08
diff --git a/testcases/kernel/pty/pty08.c b/testcases/kernel/pty/pty08.c
new file mode 100644
index 0000000000000000000000000000000000000000..c4fdc937d21031845e9d429ab1e345a92fb97240
--- /dev/null
+++ b/testcases/kernel/pty/pty08.c
@@ -0,0 +1,57 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that slave pseudo-terminal fails reading/writing if master has been
+ * closed.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+
+#define MASTERCLONE "/dev/ptmx"
+
+static void run(void)
+{
+ int masterfd, slavefd;
+ char *slavename;
+ char buf;
+
+ masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
+ slavename = SAFE_PTSNAME(masterfd);
+
+ tst_res(TINFO, "pts device location is %s", slavename);
+
+ if (grantpt(masterfd) == -1)
+ tst_brk(TBROK | TERRNO, "grantpt() error");
+
+ if (unlockpt(masterfd) == -1)
+ tst_brk(TBROK | TERRNO, "unlockpt() error");
+
+ slavefd = SAFE_OPEN(slavename, O_RDWR);
+
+ tst_res(TINFO, "Closing master communication");
+ SAFE_CLOSE(masterfd);
+
+ TST_EXP_FAIL(read(slavefd, &buf, 1), EIO);
+ TST_EXP_FAIL(write(slavefd, &buf, 1), EIO);
+
+ SAFE_CLOSE(slavefd);
+}
+
+static void setup(void)
+{
+ if (access(MASTERCLONE, F_OK))
+ tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* [LTP] [PATCH v2 11/11] Add pty09 test
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
` (9 preceding siblings ...)
2025-01-06 10:31 ` [LTP] [PATCH v2 10/11] Add pty08 test Andrea Cervesato
@ 2025-01-06 10:31 ` Andrea Cervesato
10 siblings, 0 replies; 21+ messages in thread
From: Andrea Cervesato @ 2025-01-06 10:31 UTC (permalink / raw)
To: ltp
From: Andrea Cervesato <andrea.cervesato@suse.com>
Verify that slave pseudo-terminal can be opened multiple times
in parallel.
Signed-off-by: Andrea Cervesato <andrea.cervesato@suse.com>
---
runtest/pty | 1 +
testcases/kernel/pty/.gitignore | 1 +
testcases/kernel/pty/pty09.c | 86 +++++++++++++++++++++++++++++++++++++++++
3 files changed, 88 insertions(+)
diff --git a/runtest/pty b/runtest/pty
index 365a46ee9730aa36b22dbbdbfba82ac0d491ac94..4b1abe7a602a14456877f3bc42f2275a3be0f8f0 100644
--- a/runtest/pty
+++ b/runtest/pty
@@ -7,6 +7,7 @@ pty05 pty05
pty06 pty06
pty07 pty07
pty08 pty08
+pty09 pty09
ptem01 ptem01
ptem02 ptem02
ptem03 ptem03
diff --git a/testcases/kernel/pty/.gitignore b/testcases/kernel/pty/.gitignore
index 7d8d4dceda84f2e2695a8bee39abfe894288b8b6..2d0c8bb6ff7d6883abfc7838e257b9be50244b69 100644
--- a/testcases/kernel/pty/.gitignore
+++ b/testcases/kernel/pty/.gitignore
@@ -13,3 +13,4 @@
/pty06
/pty07
/pty08
+/pty09
diff --git a/testcases/kernel/pty/pty09.c b/testcases/kernel/pty/pty09.c
new file mode 100644
index 0000000000000000000000000000000000000000..c9bab86e8a799103c04c15d4e98565a8f907f4d4
--- /dev/null
+++ b/testcases/kernel/pty/pty09.c
@@ -0,0 +1,86 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+/*
+ * Copyright (c) International Business Machines Corp., 2002
+ * Copyright (C) 2024 SUSE LLC Andrea Cervesato <andrea.cervesato@suse.com>
+ */
+
+/*\
+ * [Description]
+ *
+ * Verify that slave pseudo-terminal can be opened multiple times in parallel.
+ */
+
+#define _GNU_SOURCE
+
+#include "tst_test.h"
+
+#define MASTERCLONE "/dev/ptmx"
+
+static unsigned int count_avail_pid(void)
+{
+ DIR *dir;
+ struct dirent *ent;
+ struct rlimit limit;
+ unsigned int count = 0;
+ unsigned int max_pid_num;
+
+ if (access(MASTERCLONE, F_OK))
+ tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
+
+ SAFE_GETRLIMIT(RLIMIT_NOFILE, &limit);
+
+ dir = SAFE_OPENDIR("/proc/self/fd");
+ while ((ent = SAFE_READDIR(dir)))
+ count++;
+
+ SAFE_CLOSEDIR(dir);
+
+ max_pid_num = limit.rlim_cur - count;
+
+ tst_res(TINFO, "Available number of pids: %u", max_pid_num);
+
+ return max_pid_num;
+}
+
+static void run(void)
+{
+ int masterfd;
+ char *slavename;
+ unsigned int max_pid_num;
+
+ masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
+ slavename = SAFE_PTSNAME(masterfd);
+
+ tst_res(TINFO, "pts device location is %s", slavename);
+
+ if (grantpt(masterfd) == -1)
+ tst_brk(TBROK | TERRNO, "grantpt() error");
+
+ if (unlockpt(masterfd) == -1)
+ tst_brk(TBROK | TERRNO, "unlockpt() error");
+
+ max_pid_num = count_avail_pid();
+
+ int slavefd[max_pid_num];
+
+ for (uint32_t i = 0; i < max_pid_num; i++)
+ slavefd[i] = SAFE_OPEN(slavename, O_RDWR);
+
+ tst_res(TPASS, "%s has been opened %d times", slavename, max_pid_num);
+
+ for (uint32_t i = 0; i < max_pid_num; i++)
+ SAFE_CLOSE(slavefd[i]);
+
+ SAFE_CLOSE(masterfd);
+}
+
+static void setup(void)
+{
+ if (access(MASTERCLONE, F_OK))
+ tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
+}
+
+static struct tst_test test = {
+ .test_all = run,
+ .setup = setup,
+};
--
2.43.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply related [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH v2 01/11] Refactor setpgid01 test
2025-01-06 10:31 ` [LTP] [PATCH v2 01/11] Refactor setpgid01 test Andrea Cervesato
@ 2025-01-07 15:26 ` Cyril Hrubis
0 siblings, 0 replies; 21+ messages in thread
From: Cyril Hrubis @ 2025-01-07 15:26 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH v2 02/11] Add SAFE_PTSNAME macro
2025-01-06 10:31 ` [LTP] [PATCH v2 02/11] Add SAFE_PTSNAME macro Andrea Cervesato
@ 2025-01-07 15:32 ` Cyril Hrubis
2025-01-08 12:01 ` Petr Vorel
1 sibling, 0 replies; 21+ messages in thread
From: Cyril Hrubis @ 2025-01-07 15:32 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> + if (name == NULL) {
if (!name) {
Would be shorter.
Anyways:
Reviewed-by: Cyril Hrubis <chrubis@suse.cz>
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH v2 03/11] Refactor ptem01 test
2025-01-06 10:31 ` [LTP] [PATCH v2 03/11] Refactor ptem01 test Andrea Cervesato
@ 2025-01-07 16:01 ` Cyril Hrubis
2025-01-08 12:47 ` Petr Vorel
0 siblings, 1 reply; 21+ messages in thread
From: Cyril Hrubis @ 2025-01-07 16:01 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> + masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
> + slavename = SAFE_PTSNAME(masterfd);
>
> - for (i = 0; i < NUMOPENS; ++i) {
> - masterfd[i] = open(MASTERCLONE, O_RDWR);
> - if (masterfd[i] < 0) {
> - tst_resm(TBROK, "%s", MASTERCLONE);
> - tst_resm(TBROK, "out of ptys");
> - for (i = 0; i < NUMOPENS; ++i) {
> - if (masterfd[i] != 0) {
> - (void)close(masterfd[i]);
> - }
> - if (slavefd[i] != 0) {
> - (void)close(slavefd[i]);
> - }
> - }
> - tst_exit();
> - }
> + TST_EXP_PASS(grantpt(masterfd));
> + TST_EXP_PASS(unlockpt(masterfd));
>
> - slavename = ptsname(masterfd[i]);
> - if (slavename == NULL) {
> - tst_brkm(TBROK | TERRNO, NULL,
> - "ptsname() call failed");
> - }
> + slavefd = SAFE_OPEN(slavename, O_RDWR);
This would be a bit better if done in setup()
> - if (grantpt(masterfd[i]) != 0) {
> - tst_brkm(TBROK | TERRNO, NULL,
> - "grantpt() call failed");
> - }
> + TST_EXP_POSITIVE(ioctl(slavefd, TCGETS, &termios));
> + TST_EXP_POSITIVE(ioctl(slavefd, TCSETS, &termios));
> + TST_EXP_POSITIVE(ioctl(slavefd, TCSETSW, &termios));
> + TST_EXP_POSITIVE(ioctl(slavefd, TCSETSF, &termios));
> + TST_EXP_POSITIVE(ioctl(slavefd, TCSETS, &termios));
> + TST_EXP_POSITIVE(ioctl(slavefd, TCGETA, &termio));
> + TST_EXP_POSITIVE(ioctl(slavefd, TCSETA, &termio));
> + TST_EXP_POSITIVE(ioctl(slavefd, TCSETAW, &termio));
> + TST_EXP_POSITIVE(ioctl(slavefd, TCSETAF, &termio));
Are you sure these shouldn't be TST_EXP_PASS() instead? The original
code was doing != 0 for all of these.
> - if (unlockpt(masterfd[i]) != 0) {
> - tst_brkm(TBROK, NULL, "unlockpt() call failed");
> - }
> -
> - if ((slavefd[i] = open(slavename, O_RDWR)) < 0) {
> - tst_brkm(TFAIL, NULL,
> - "Iteration %d: Could not open %s", i,
> - slavename);
> - }
> -
> - }
> -
> - for (i = 0; i < NUMOPENS; ++i) {
> - if (close(slavefd[i]) != 0) {
> - tst_brkm(TBROK, NULL, "Iteration %d: close slave", i);
> - }
> - if (close(masterfd[i]) != 0) {
> - tst_brkm(TBROK, NULL, "close master");
> - }
> - }
> - tst_resm(TPASS, "test5");
> -
> - /** NOT REACHED **/
> - return 0;
> + SAFE_CLOSE(slavefd);
> + SAFE_CLOSE(masterfd);
And this should be done in cleanup if we do the init in the
setup.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH v2 04/11] Add ptem02 test
2025-01-06 10:31 ` [LTP] [PATCH v2 04/11] Add ptem02 test Andrea Cervesato
@ 2025-01-07 16:14 ` Cyril Hrubis
0 siblings, 0 replies; 21+ messages in thread
From: Cyril Hrubis @ 2025-01-07 16:14 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
The same here:
- TST_EXP_PASS() vs TST_EXP_POSSITIVE()
- possibly initialize the pts in test setup()?
Also if you are going to initialize the masterfd in each test it may
make sense to put that code into a function in a header and include that
in each test.
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH v2 05/11] Add ptem03 test
2025-01-06 10:31 ` [LTP] [PATCH v2 05/11] Add ptem03 test Andrea Cervesato
@ 2025-01-07 16:30 ` Cyril Hrubis
0 siblings, 0 replies; 21+ messages in thread
From: Cyril Hrubis @ 2025-01-07 16:30 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi!
> +static void run(void)
> +{
> + int masterfd, slavefd;
> + char *slavename;
> +
> + masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
> + slavename = SAFE_PTSNAME(masterfd);
> +
> + TST_EXP_PASS(grantpt(masterfd));
> + TST_EXP_PASS(unlockpt(masterfd));
> +
> + slavefd = SAFE_OPEN(slavename, O_RDWR);
This is being repeated in each test so it should be really put into the
test setup function and the function should be put into a common header
and included in all the tests.
> + TST_EXP_PASS(tcsendbreak(masterfd, 10));
> + TST_EXP_PASS(tcsendbreak(slavefd, 10));
Here you are using the TST_EXP_PASS() correctly.
> + SAFE_CLOSE(slavefd);
> + SAFE_CLOSE(masterfd);
> +}
> +
> +static void setup(void)
> +{
> + if (access(MASTERCLONE, F_OK))
> + tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
> +}
> +
> +static struct tst_test test = {
> + .test_all = run,
> + .setup = setup,
> +};
>
> --
> 2.43.0
>
>
> --
> Mailing list info: https://lists.linux.it/listinfo/ltp
--
Cyril Hrubis
chrubis@suse.cz
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH v2 02/11] Add SAFE_PTSNAME macro
2025-01-06 10:31 ` [LTP] [PATCH v2 02/11] Add SAFE_PTSNAME macro Andrea Cervesato
2025-01-07 15:32 ` Cyril Hrubis
@ 2025-01-08 12:01 ` Petr Vorel
1 sibling, 0 replies; 21+ messages in thread
From: Petr Vorel @ 2025-01-08 12:01 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea,
Agree with Cyrils note about if (!name) (can be changed before merge).
Reviewed-by: Petr Vorel <pvorel@suse.cz>
Thanks!
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH v2 09/11] Refactor pty01 test
2025-01-06 10:31 ` [LTP] [PATCH v2 09/11] Refactor pty01 test Andrea Cervesato
@ 2025-01-08 12:39 ` Petr Vorel
2025-01-09 8:28 ` Andrea Cervesato via ltp
0 siblings, 1 reply; 21+ messages in thread
From: Petr Vorel @ 2025-01-08 12:39 UTC (permalink / raw)
To: Andrea Cervesato; +Cc: ltp
Hi Andrea,
> Rewrite part of the code using the new LTP library and fix the execution
> of the test inside a new session via setsid(). The test is now split
> into multiple files, instead of having multiple test* functions
> executing all in one file.
> Fixes: https://github.com/linux-test-project/kirk/issues/28
+1
> +++ b/testcases/kernel/pty/pty01.c
...
> +#define STRING_LEN strlen(STRING)
IMHO this is not much useful, it runs strlen() more times.
How about save the result in the test function to size_t variable?
...
> +static void run(void)
> {
> - int masterfd; /* master pty fd */
> - int slavefd; /* slave pty fd */
> + int masterfd;
> + int slavefd;
> char *slavename;
> struct stat st;
> - char buf[TESTSIZE];
> + char buf[BUFSIZ];
> - masterfd = SAFE_OPEN(NULL, MASTERCLONE, O_RDWR);
> + memset(buf, 0, BUFSIZ);
> - slavename = ptsname(masterfd);
> - if (slavename == NULL) {
> - tst_brkm(TBROK | TERRNO, NULL, "ptsname() call failed");
> - }
> + masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
> + slavename = SAFE_PTSNAME(masterfd);
These two should be in the setup() as Cyril noted to other tests.
> - if (grantpt(masterfd) != 0) {
> - tst_brkm(TBROK | TERRNO, NULL, "grantpt() call failed");
> - }
> + if (grantpt(masterfd) == -1)
> + tst_brk(TBROK | TERRNO, "grantpt() error");
> - if (stat(slavename, &st) != 0) {
> - tst_brkm(TBROK | TERRNO, NULL, "stat(%s) failed", slavename);
> - }
> - if (st.st_uid != getuid()) {
> - tst_brkm(TBROK, NULL, "uid mismatch");
> + TST_EXP_PASS_SILENT(unlockpt(masterfd));
> + if (TST_RET == -1) {
> + SAFE_CLOSE(masterfd);
> + return;
If you have this in the cleanup() as Cyril suggested for other test, there would
be a simple return.
> + SAFE_STAT(slavename, &st);
> + TST_EXP_EQ_LI(st.st_uid, getuid());
> +
> + /* grantpt() is a no-op in bionic. */
> #ifndef __BIONIC__
> - if (st.st_mode != (S_IFCHR | S_IRUSR | S_IWUSR | S_IWGRP)) {
> - tst_brkm(TBROK, NULL, "mode mismatch (mode=%o)", st.st_mode);
> - }
> + TST_EXP_EQ_LI(st.st_mode, 0620);
Here it continues testing, does it makes sense? Previously it quit with
tst_brkm().
> +static void setup(void)
> {
> + if (access(MASTERCLONE, F_OK))
> + tst_brk(TBROK, "%s device doesn't exist", MASTERCLONE);
IMHO this should be TCONF (SUT is not configured to have /dev/ptmx.
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH v2 03/11] Refactor ptem01 test
2025-01-07 16:01 ` Cyril Hrubis
@ 2025-01-08 12:47 ` Petr Vorel
0 siblings, 0 replies; 21+ messages in thread
From: Petr Vorel @ 2025-01-08 12:47 UTC (permalink / raw)
To: Cyril Hrubis; +Cc: ltp
Hi Andrea, Cyril,
> Hi!
> > + masterfd = SAFE_OPEN(MASTERCLONE, O_RDWR);
> > + slavename = SAFE_PTSNAME(masterfd);
> > - for (i = 0; i < NUMOPENS; ++i) {
> > - masterfd[i] = open(MASTERCLONE, O_RDWR);
> > - if (masterfd[i] < 0) {
> > - tst_resm(TBROK, "%s", MASTERCLONE);
> > - tst_resm(TBROK, "out of ptys");
> > - for (i = 0; i < NUMOPENS; ++i) {
> > - if (masterfd[i] != 0) {
> > - (void)close(masterfd[i]);
> > - }
> > - if (slavefd[i] != 0) {
> > - (void)close(slavefd[i]);
> > - }
> > - }
> > - tst_exit();
> > - }
> > + TST_EXP_PASS(grantpt(masterfd));
> > + TST_EXP_PASS(unlockpt(masterfd));
> > - slavename = ptsname(masterfd[i]);
> > - if (slavename == NULL) {
> > - tst_brkm(TBROK | TERRNO, NULL,
> > - "ptsname() call failed");
> > - }
> > + slavefd = SAFE_OPEN(slavename, O_RDWR);
> This would be a bit better if done in setup()
Good catch. If this fails, masterfd will be left unclosest
(it would break on high -i). Also it speedup the test with high -i.
I did not catch it because I thought it's better to close fd in case of repeated
testing with -i, but obviously it should be perfectly safe to have open file
descriptors shared during repeated testing.
> > - if (grantpt(masterfd[i]) != 0) {
> > - tst_brkm(TBROK | TERRNO, NULL,
> > - "grantpt() call failed");
> > - }
> > + TST_EXP_POSITIVE(ioctl(slavefd, TCGETS, &termios));
> > + TST_EXP_POSITIVE(ioctl(slavefd, TCSETS, &termios));
> > + TST_EXP_POSITIVE(ioctl(slavefd, TCSETSW, &termios));
> > + TST_EXP_POSITIVE(ioctl(slavefd, TCSETSF, &termios));
> > + TST_EXP_POSITIVE(ioctl(slavefd, TCSETS, &termios));
> > + TST_EXP_POSITIVE(ioctl(slavefd, TCGETA, &termio));
> > + TST_EXP_POSITIVE(ioctl(slavefd, TCSETA, &termio));
> > + TST_EXP_POSITIVE(ioctl(slavefd, TCSETAW, &termio));
> > + TST_EXP_POSITIVE(ioctl(slavefd, TCSETAF, &termio));
> Are you sure these shouldn't be TST_EXP_PASS() instead? The original
> code was doing != 0 for all of these.
+1
Kind regards,
Petr
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
* Re: [LTP] [PATCH v2 09/11] Refactor pty01 test
2025-01-08 12:39 ` Petr Vorel
@ 2025-01-09 8:28 ` Andrea Cervesato via ltp
0 siblings, 0 replies; 21+ messages in thread
From: Andrea Cervesato via ltp @ 2025-01-09 8:28 UTC (permalink / raw)
To: Petr Vorel, Andrea Cervesato; +Cc: ltp
Hi Petr,
On 1/8/25 13:39, Petr Vorel wrote:
>> + SAFE_STAT(slavename, &st);
>> + TST_EXP_EQ_LI(st.st_uid, getuid());
>> +
>> + /* grantpt() is a no-op in bionic. */
>> #ifndef __BIONIC__
>> - if (st.st_mode != (S_IFCHR | S_IRUSR | S_IWUSR | S_IWGRP)) {
>> - tst_brkm(TBROK, NULL, "mode mismatch (mode=%o)", st.st_mode);
>> - }
>> + TST_EXP_EQ_LI(st.st_mode, 0620);
> Here it continues testing, does it makes sense? Previously it quit with
> tst_brkm().
I'm not even sure if the check makes sense...do you have any idea?
Andrea
--
Mailing list info: https://lists.linux.it/listinfo/ltp
^ permalink raw reply [flat|nested] 21+ messages in thread
end of thread, other threads:[~2025-01-09 8:29 UTC | newest]
Thread overview: 21+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-01-06 10:31 [LTP] [PATCH v2 00/11] Fix tests failing with setsid Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 01/11] Refactor setpgid01 test Andrea Cervesato
2025-01-07 15:26 ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 02/11] Add SAFE_PTSNAME macro Andrea Cervesato
2025-01-07 15:32 ` Cyril Hrubis
2025-01-08 12:01 ` Petr Vorel
2025-01-06 10:31 ` [LTP] [PATCH v2 03/11] Refactor ptem01 test Andrea Cervesato
2025-01-07 16:01 ` Cyril Hrubis
2025-01-08 12:47 ` Petr Vorel
2025-01-06 10:31 ` [LTP] [PATCH v2 04/11] Add ptem02 test Andrea Cervesato
2025-01-07 16:14 ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 05/11] Add ptem03 test Andrea Cervesato
2025-01-07 16:30 ` Cyril Hrubis
2025-01-06 10:31 ` [LTP] [PATCH v2 06/11] Add ptem04 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 07/11] Add ptem05 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 08/11] Add ptem06 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 09/11] Refactor pty01 test Andrea Cervesato
2025-01-08 12:39 ` Petr Vorel
2025-01-09 8:28 ` Andrea Cervesato via ltp
2025-01-06 10:31 ` [LTP] [PATCH v2 10/11] Add pty08 test Andrea Cervesato
2025-01-06 10:31 ` [LTP] [PATCH v2 11/11] Add pty09 test Andrea Cervesato
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox