syscalls/pipe03: Simplify test using TST_ macros
PATCH 1/1 syscalls/pipe03: Simplify test using TST_ macros
+ docparse comment and reword
+ updated copyright
Signed-off-by Avinesh Kumar <[email protected]>
--- testcases/kernel/syscalls/pipe/pipe03.c | 51 ++++++++++--------------- 1 file changed, 21 insertions(+), 30 deletions(-)
testcases/kernel/syscalls/pipe/pipe03.c +21 -30
@@ -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 };
Signature · 5 lines
2.41.0 -- Mailing list info: https://lists.linux.it/listinfo/ltp
Hi Avinesh,
nice cleanup, thanks, merged!
Kind regards,
Petr
Signature · 1 line
Mailing list info: https://lists.linux.it/listinfo/ltp