All of lore.kernel.org
 help / color / mirror / Atom feed
* [LTP] [PATCH] syscalls/pipe03: Simplify test using TST_ macros
@ 2023-07-14 15:48 Avinesh Kumar
  2023-07-17  7:20 ` Petr Vorel
  0 siblings, 1 reply; 2+ messages in thread
From: Avinesh Kumar @ 2023-07-14 15:48 UTC (permalink / raw)
  To: ltp

+ 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

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [LTP] [PATCH] syscalls/pipe03: Simplify test using TST_ macros
  2023-07-14 15:48 [LTP] [PATCH] syscalls/pipe03: Simplify test using TST_ macros Avinesh Kumar
@ 2023-07-17  7:20 ` Petr Vorel
  0 siblings, 0 replies; 2+ messages in thread
From: Petr Vorel @ 2023-07-17  7:20 UTC (permalink / raw)
  To: Avinesh Kumar; +Cc: ltp

Hi Avinesh,

nice cleanup, thanks, merged!

Kind regards,
Petr

-- 
Mailing list info: https://lists.linux.it/listinfo/ltp

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2023-07-17  7:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-14 15:48 [LTP] [PATCH] syscalls/pipe03: Simplify test using TST_ macros Avinesh Kumar
2023-07-17  7:20 ` Petr Vorel

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.