Message ID | 20230427120800.27849-5-akumar@suse.de |
---|---|
State | Accepted |
Headers | show |
Series | [1/5] dup01.c: use TST_EXP_FD macro and add inode check | expand |
Hi Avinesh, I slightly modified some of the commits and merged the patchset. Thanks! > + update copyright. > + use SAFE_OPEN() and SAFE_CLOSE() ... > /*\ > - * [DESCRIPTION] > + * [Description] +1 > * > * Basic test for dup(2) of a named pipe descriptor > */ > -#include <stdio.h> > + > #include "tst_test.h" > -char Fname[255]; > -int fd; > +#define Fname "dupfile" FYI I renamed to FNAME (don't hesitate to rename constants which aren't lowercase or variables with very long name (expected_errno => exp_err - used widely in LTP). > + > +static int fd; > static void run(void) > { > - TEST(dup(fd)); > - > - if (TST_RET == -1) { > - tst_res(TFAIL | TTERRNO, "dup failed"); > - } else { > - tst_res(TPASS, "dup returned %ld", > - TST_RET); > - > - SAFE_CLOSE(TST_RET); > - } > + TST_EXP_FD(dup(fd), "dup(%d)", fd); > + SAFE_CLOSE(TST_RET); > } > -void setup(void) > +static void setup(void) > { > fd = -1; FYI I moved -1 to declaration: static int fd = -1; Kind regards, Petr
diff --git a/testcases/kernel/syscalls/dup/dup05.c b/testcases/kernel/syscalls/dup/dup05.c index 362f3e170..375fa36a7 100644 --- a/testcases/kernel/syscalls/dup/dup05.c +++ b/testcases/kernel/syscalls/dup/dup05.c @@ -1,55 +1,45 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2000 Silicon Graphics, Inc. All Rights Reserved. - * * 06/1994 AUTHOR: Richard Logan CO-PILOT: William Roske + * Copyright (c) 2023 SUSE LLC */ /*\ - * [DESCRIPTION] + * [Description] * * Basic test for dup(2) of a named pipe descriptor */ -#include <stdio.h> + #include "tst_test.h" -char Fname[255]; -int fd; +#define Fname "dupfile" + +static int fd; static void run(void) { - TEST(dup(fd)); - - if (TST_RET == -1) { - tst_res(TFAIL | TTERRNO, "dup failed"); - } else { - tst_res(TPASS, "dup returned %ld", - TST_RET); - - SAFE_CLOSE(TST_RET); - } + TST_EXP_FD(dup(fd), "dup(%d)", fd); + SAFE_CLOSE(TST_RET); } -void setup(void) +static void setup(void) { fd = -1; - sprintf(Fname, "dupfile"); SAFE_MKFIFO(Fname, 0777); - if ((fd = open(Fname, O_RDWR, 0700)) == -1) - tst_brk(TBROK, "open failed"); + fd = SAFE_OPEN(Fname, O_RDWR, 0700); } -void cleanup(void) +static void cleanup(void) { if (fd != -1) - if (close(fd) == -1) - tst_res(TWARN | TERRNO, "close failed"); + SAFE_CLOSE(fd); } static struct tst_test test = { - .test_all = run, - .setup = setup, - .cleanup = cleanup, + .test_all = run, + .setup = setup, + .cleanup = cleanup, .needs_tmpdir = 1, };
+ update copyright. + use SAFE_OPEN() and SAFE_CLOSE() Signed-off-by: Avinesh Kumar <akumar@suse.de> --- testcases/kernel/syscalls/dup/dup05.c | 40 ++++++++++----------------- 1 file changed, 15 insertions(+), 25 deletions(-)