From: Avinesh Kumar <akumar@suse.de>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH] syscalls/pipe03: Simplify test using TST_ macros
Date: Fri, 14 Jul 2023 21:18:01 +0530 [thread overview]
Message-ID: <20230714154802.27819-1-akumar@suse.de> (raw)
+ docparse comment and reword
+ updated copyright
Signed-off-by: Avinesh Kumar <akumar@suse.de>
---
testcases/kernel/syscalls/pipe/pipe03.c | 51 ++++++++++---------------
1 file changed, 21 insertions(+), 30 deletions(-)
diff --git a/testcases/kernel/syscalls/pipe/pipe03.c b/testcases/kernel/syscalls/pipe/pipe03.c
index 89c0911c1..b786a618e 100644
--- a/testcases/kernel/syscalls/pipe/pipe03.c
+++ b/testcases/kernel/syscalls/pipe/pipe03.c
@@ -1,51 +1,42 @@
// SPDX-License-Identifier: GPL-2.0-or-later
/*
* Copyright (c) International Business Machines Corp., 2002
+ * Copyright (c) 2023 Linux Test Project
*/
-/*
- * Make sure that writing to the read end of a pipe and reading from
- * the write end of a pipe both fail.
+/*\
+ * [Description]
+ *
+ * Verify that, an attempt to write to the read end of a pipe fails with EBADF
+ * and an attempt to read from the write end of a pipe also fails with EBADF.
*/
-#include <unistd.h>
-#include <errno.h>
#include "tst_test.h"
static int fd[2];
static void verify_pipe(void)
{
- char buf[2];
-
- TEST(pipe(fd));
- if (TST_RET == -1) {
- tst_res(TFAIL | TTERRNO, "pipe() failed unexpectedly");
- return;
- }
-
- TEST(write(fd[0], "A", 1));
- if (TST_RET == -1 && errno == EBADF) {
- tst_res(TPASS | TTERRNO, "expected failure writing "
- "to read end of pipe");
- } else {
- tst_res(TFAIL | TTERRNO, "unexpected failure writing "
- "to read end of pipe");
- }
-
- TEST(read(fd[1], buf, 1));
- if (TST_RET == -1 && errno == EBADF) {
- tst_res(TPASS | TTERRNO, "expected failure reading "
- "from write end of pipe");
- } else {
- tst_res(TFAIL | TTERRNO, "unexpected failure reading "
- "from write end of pipe");
- }
+ char buf[] = "abcdef";
+
+ SAFE_PIPE(fd);
+
+ TST_EXP_FAIL2(write(fd[0], "A", 1), EBADF);
+ TST_EXP_FAIL2(read(fd[1], buf, 1), EBADF);
SAFE_CLOSE(fd[0]);
SAFE_CLOSE(fd[1]);
}
+static void cleanup(void)
+{
+ if (fd[0] > 0)
+ SAFE_CLOSE(fd[0]);
+ if (fd[1] > 0)
+ SAFE_CLOSE(fd[1]);
+}
+
static struct tst_test test = {
.test_all = verify_pipe,
+ .cleanup = cleanup
};
--
2.41.0
--
Mailing list info: https://lists.linux.it/listinfo/ltp
next reply other threads:[~2023-07-14 15:48 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-14 15:48 Avinesh Kumar [this message]
2023-07-17 7:20 ` [LTP] [PATCH] syscalls/pipe03: Simplify test using TST_ macros Petr Vorel
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20230714154802.27819-1-akumar@suse.de \
--to=akumar@suse.de \
--cc=ltp@lists.linux.it \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox