Message ID | 20240109095026.792527-1-ruansy.fnst@fujitsu.com |
---|---|
State | Changes Requested |
Headers | show |
Series | dup06: Convert to new API | expand |
Hi Shiyang, > Signed-off-by: Shiyang Ruan <ruansy.fnst@fujitsu.com> > --- > testcases/kernel/syscalls/dup/dup06.c | 141 ++++++++++---------------- > 1 file changed, 52 insertions(+), 89 deletions(-) > diff --git a/testcases/kernel/syscalls/dup/dup06.c b/testcases/kernel/syscalls/dup/dup06.c > index e3f8070bf..84fc260a1 100644 > --- a/testcases/kernel/syscalls/dup/dup06.c > +++ b/testcases/kernel/syscalls/dup/dup06.c > @@ -1,42 +1,22 @@ > +// SPDX-License-Identifier: GPL-2.0-or-later > /* > - * Copyright (c) International Business Machines Corp., 2002 > - * ported from SPIE, section2/iosuite/dup1.c, by Airong Zhang > - * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz> ... > + * Copyright (c) International Business Machines Corp., 2002 > + * ported from SPIE, section2/iosuite/dup1.c, by Airong Zhang > + * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz> Could you please also add your or LTP copyright for this rewrite? E.g. * Copyright (c) Linux Test Project, 2003-2015 + your copyright, or just: * Copyright (c) Linux Test Project, 2003-2024 $ make check-dup06 CHECK testcases/kernel/syscalls/dup/dup06.c dup06.c:28: ERROR: return is not a function, parentheses are not required dup06.c:53: ERROR: do not use assignment in if condition dup06.c:56: WARNING: braces {} are not necessary for any arm of this statement Therefore I'm going to merge with following change (+ please let me know if you want to add your copyright). Reviewed-by: Petr Vorel <pvorel@suse.cz> Kind regards, Petr diff --git testcases/kernel/syscalls/dup/dup06.c testcases/kernel/syscalls/dup/dup06.c index 84fc260a1..e7e27b8f9 100644 --- testcases/kernel/syscalls/dup/dup06.c +++ testcases/kernel/syscalls/dup/dup06.c @@ -1,8 +1,9 @@ // SPDX-License-Identifier: GPL-2.0-or-later /* * Copyright (c) International Business Machines Corp., 2002 - * ported from SPIE, section2/iosuite/dup1.c, by Airong Zhang + * ported from SPIE, section2/iosuite/dup1.c, by Airong Zhang * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz> + * Copyright (c) Linux Test Project, 2003-2024 */ /*\ @@ -17,6 +18,7 @@ static int *pfildes; static int minfd, maxfd, freefds; static char pfilname[40]; + static int cnt_free_fds(int maxfd) { int freefds = 0; @@ -25,7 +27,7 @@ static int cnt_free_fds(int maxfd) if (fcntl(maxfd, F_GETFD) == -1 && errno == EBADF) freefds++; - return (freefds); + return freefds; } static void setup(void) @@ -50,16 +52,17 @@ static void run(void) pfildes[0] = SAFE_CREAT(pfilname, 0666); for (i = 1; i < maxfd; i++) { - if ((pfildes[i] = dup(pfildes[i - 1])) == -1) + pfildes[i] = dup(pfildes[i - 1]); + if (pfildes[i] == -1) break; } - if (i < freefds) { + + if (i < freefds) tst_res(TFAIL, "Not enough files duped"); - } else if (i > freefds) { + else if (i > freefds) tst_res(TFAIL, "Too many files duped"); - } else { - tst_res(TPASS, "Test passed."); - } + else + tst_res(TPASS, "Test passed"); SAFE_UNLINK(pfilname);
在 2024/1/11 2:29, Petr Vorel 写道: > Hi Shiyang, > >> Signed-off-by: Shiyang Ruan <ruansy.fnst@fujitsu.com> >> --- >> testcases/kernel/syscalls/dup/dup06.c | 141 ++++++++++---------------- >> 1 file changed, 52 insertions(+), 89 deletions(-) > >> diff --git a/testcases/kernel/syscalls/dup/dup06.c b/testcases/kernel/syscalls/dup/dup06.c >> index e3f8070bf..84fc260a1 100644 >> --- a/testcases/kernel/syscalls/dup/dup06.c >> +++ b/testcases/kernel/syscalls/dup/dup06.c >> @@ -1,42 +1,22 @@ >> +// SPDX-License-Identifier: GPL-2.0-or-later >> /* >> - * Copyright (c) International Business Machines Corp., 2002 >> - * ported from SPIE, section2/iosuite/dup1.c, by Airong Zhang >> - * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz> > ... >> + * Copyright (c) International Business Machines Corp., 2002 >> + * ported from SPIE, section2/iosuite/dup1.c, by Airong Zhang >> + * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz> > Could you please also add your or LTP copyright for this rewrite? > E.g. > * Copyright (c) Linux Test Project, 2003-2015 > + your copyright, or just: > * Copyright (c) Linux Test Project, 2003-2024 > > $ make check-dup06 > CHECK testcases/kernel/syscalls/dup/dup06.c > dup06.c:28: ERROR: return is not a function, parentheses are not required > dup06.c:53: ERROR: do not use assignment in if condition > dup06.c:56: WARNING: braces {} are not necessary for any arm of this statement > > Therefore I'm going to merge with following change (+ please let me know if you > want to add your copyright). > > Reviewed-by: Petr Vorel <pvorel@suse.cz> Thanks, adding LTP copyright is fine. Let me send a new version of these two patches because the next one has the same issue. I've fixed it. -- Ruan. > > Kind regards, > Petr > > diff --git testcases/kernel/syscalls/dup/dup06.c testcases/kernel/syscalls/dup/dup06.c > index 84fc260a1..e7e27b8f9 100644 > --- testcases/kernel/syscalls/dup/dup06.c > +++ testcases/kernel/syscalls/dup/dup06.c > @@ -1,8 +1,9 @@ > // SPDX-License-Identifier: GPL-2.0-or-later > /* > * Copyright (c) International Business Machines Corp., 2002 > - * ported from SPIE, section2/iosuite/dup1.c, by Airong Zhang > + * ported from SPIE, section2/iosuite/dup1.c, by Airong Zhang > * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz> > + * Copyright (c) Linux Test Project, 2003-2024 > */ > > /*\ > @@ -17,6 +18,7 @@ > static int *pfildes; > static int minfd, maxfd, freefds; > static char pfilname[40]; > + > static int cnt_free_fds(int maxfd) > { > int freefds = 0; > @@ -25,7 +27,7 @@ static int cnt_free_fds(int maxfd) > if (fcntl(maxfd, F_GETFD) == -1 && errno == EBADF) > freefds++; > > - return (freefds); > + return freefds; > } > > static void setup(void) > @@ -50,16 +52,17 @@ static void run(void) > > pfildes[0] = SAFE_CREAT(pfilname, 0666); > for (i = 1; i < maxfd; i++) { > - if ((pfildes[i] = dup(pfildes[i - 1])) == -1) > + pfildes[i] = dup(pfildes[i - 1]); > + if (pfildes[i] == -1) > break; > } > - if (i < freefds) { > + > + if (i < freefds) > tst_res(TFAIL, "Not enough files duped"); > - } else if (i > freefds) { > + else if (i > freefds) > tst_res(TFAIL, "Too many files duped"); > - } else { > - tst_res(TPASS, "Test passed."); > - } > + else > + tst_res(TPASS, "Test passed"); > > SAFE_UNLINK(pfilname); >
diff --git a/testcases/kernel/syscalls/dup/dup06.c b/testcases/kernel/syscalls/dup/dup06.c index e3f8070bf..84fc260a1 100644 --- a/testcases/kernel/syscalls/dup/dup06.c +++ b/testcases/kernel/syscalls/dup/dup06.c @@ -1,42 +1,22 @@ +// SPDX-License-Identifier: GPL-2.0-or-later /* - * Copyright (c) International Business Machines Corp., 2002 - * ported from SPIE, section2/iosuite/dup1.c, by Airong Zhang - * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See - * the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * Copyright (c) International Business Machines Corp., 2002 + * ported from SPIE, section2/iosuite/dup1.c, by Airong Zhang + * Copyright (c) 2013 Cyril Hrubis <chrubis@suse.cz> */ -/* - WHAT: Does dup return -1 on the 21st file? - HOW: Create up to _NFILE (20) files and check for -1 return on the - next attempt - Should check NOFILE as well as _NFILE. 19-Jun-84 Dale. -*/ - -#include <stdio.h> -#include <fcntl.h> -#include <errno.h> -#include <unistd.h> -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/param.h> -#include "test.h" +/*\ + * [Description] + * + * Test for dup(2) syscall with max open file descriptors. + */ -char *TCID = "dup06"; -int TST_TOTAL = 1; +#include <stdlib.h> +#include "tst_test.h" +static int *pfildes; +static int minfd, maxfd, freefds; +static char pfilname[40]; static int cnt_free_fds(int maxfd) { int freefds = 0; @@ -48,67 +28,50 @@ static int cnt_free_fds(int maxfd) return (freefds); } -static void setup(void); -static void cleanup(void); - -int main(int ac, char **av) +static void setup(void) { - int *fildes, i; - int min; - int freefds; - int lc; - const char *pfilname = "dup06"; - - tst_parse_opts(ac, av, NULL, NULL); - - setup(); - - min = getdtablesize(); - freefds = cnt_free_fds(min); - fildes = malloc((min + 5) * sizeof(int)); - - for (i = 0; i < min + 5; i++) - fildes[i] = 0; - - for (lc = 0; TEST_LOOPING(lc); lc++) { - unlink(pfilname); - - if ((fildes[0] = creat(pfilname, 0666)) == -1) { - tst_resm(TFAIL, "Cannot open first file"); - } else { - for (i = 1; i < min + 5; i++) { - if ((fildes[i] = dup(fildes[i - 1])) == -1) - break; - } - if (i < freefds) { - tst_resm(TFAIL, "Not enough files duped"); - } else if (i > freefds) { - tst_resm(TFAIL, "Too many files duped"); - } else { - tst_resm(TPASS, "Test passed."); - } - } + minfd = getdtablesize(); /* get number of files allowed open */ + maxfd = minfd + 5; + freefds = cnt_free_fds(minfd); + pfildes = SAFE_MALLOC(maxfd * sizeof(int)); + memset(pfildes, -1, maxfd * sizeof(int)); + sprintf(pfilname, "./dup06.%d\n", getpid()); +} - unlink(pfilname); +static void cleanup(void) +{ + if (pfildes != NULL) + free(pfildes); +} - for (i = 0; i < min + 5; i++) { - if (fildes[i] != 0 && fildes[i] != -1) - close(fildes[i]); +static void run(void) +{ + int i; - fildes[i] = 0; - } + pfildes[0] = SAFE_CREAT(pfilname, 0666); + for (i = 1; i < maxfd; i++) { + if ((pfildes[i] = dup(pfildes[i - 1])) == -1) + break; + } + if (i < freefds) { + tst_res(TFAIL, "Not enough files duped"); + } else if (i > freefds) { + tst_res(TFAIL, "Too many files duped"); + } else { + tst_res(TPASS, "Test passed."); } - cleanup(); - tst_exit(); -} + SAFE_UNLINK(pfilname); -static void setup(void) -{ - tst_tmpdir(); + for (i = 0; i < maxfd; i++) { + if (pfildes[i] != 0 && pfildes[i] != -1) + SAFE_CLOSE(pfildes[i]); + } } -static void cleanup(void) -{ - tst_rmdir(); -} +static struct tst_test test = { + .needs_tmpdir = 1, + .test_all = run, + .setup = setup, + .cleanup = cleanup, +};
Signed-off-by: Shiyang Ruan <ruansy.fnst@fujitsu.com> --- testcases/kernel/syscalls/dup/dup06.c | 141 ++++++++++---------------- 1 file changed, 52 insertions(+), 89 deletions(-)