diff --git a/runtest/pty b/runtest/pty index 6343da391ba..365a46ee973 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 630d7fcf7b0..7d8d4dceda8 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 00000000000..45e99d18ba8 --- /dev/null +++ b/testcases/kernel/pty/pty08.c @@ -0,0 +1,38 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Copyright (c) International Business Machines Corp., 2002 + * Copyright (C) 2024 SUSE LLC Andrea Cervesato + */ + +/*\ + * [Description] + * + * Verify that slave pseudo-terminal fails reading/writing if master has been + * closed. + */ + +#define _GNU_SOURCE + +#include "common.h" + +static void run(void) +{ + int slavefd; + int masterfd; + char buf; + + masterfd = open_master(); + slavefd = open_slave(masterfd); + + tst_res(TINFO, "Closing master communication"); + SAFE_CLOSE(masterfd); + + TST_EXP_EQ_LI(read(slavefd, &buf, 1), 0); + TST_EXP_FAIL(write(slavefd, &buf, 1), EIO); + + SAFE_CLOSE(slavefd); +} + +static struct tst_test test = { + .test_all = run, +};