All of lore.kernel.org
 help / color / mirror / Atom feed
From: xuyang2018.jy@fujitsu.com <xuyang2018.jy@fujitsu.com>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 4/5] syscalls/dup2/dup204: Convert dup204 to the new API
Date: Tue, 7 Sep 2021 09:36:24 +0000	[thread overview]
Message-ID: <6137328D.5020009@fujitsu.com> (raw)
In-Reply-To: <20210902115849.72382-5-qi.fuli@fujitsu.com>

Hi Qi

I think we can merge this case into dup202 directly.
So dup202 not only check modes doesn't change but also check inode 
number doesn't change.

Best Regards
Yang Xu
> From: QI Fuli<qi.fuli@fujitsu.com>
>
> Signed-off-by: QI Fuli<qi.fuli@fujitsu.com>
> ---
>   testcases/kernel/syscalls/dup2/dup204.c | 135 ++++++------------------
>   1 file changed, 35 insertions(+), 100 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/dup2/dup204.c b/testcases/kernel/syscalls/dup2/dup204.c
> index a357bc17e..3fd6b0832 100644
> --- a/testcases/kernel/syscalls/dup2/dup204.c
> +++ b/testcases/kernel/syscalls/dup2/dup204.c
> @@ -1,118 +1,25 @@
> -/*
> - *
> - *   Copyright (c) International Business Machines  Corp., 2001
> - *
> - *   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
> - */
> +// SPDX-License-Identifier: GPL-2.0-or-later
>
>   /*
> - * NAME
> - *	dup204.c
> + * Copyright (c) International Business Machines  Corp., 2001
>    *
> - * DESCRIPTION
> + * DESCRIPTION:
>    *	Testcase to check the basic functionality of dup2(2).
> - *
> - * ALGORITHM
> - *	attempt to call dup2() on read/write ends of a pipe
> - *
> - * USAGE:<for command-line>
> - *  dup204 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
> - *     where,  -c n : Run n copies concurrently.
> - *             -f   : Turn off functionality Testing.
> - *             -i n : Execute test n times.
> - *             -I x : Execute test for x seconds.
> - *             -P x : Pause for x seconds between iterations.
> - *             -t   : Turn on syscall timing.
> - *
> - * RESTRICTION
> - *	NONE
>    */
>
>   #ifndef _GNU_SOURCE
>   #define _GNU_SOURCE
>   #endif
> -#include<sys/types.h>
> -#include<fcntl.h>
> -#include<sys/stat.h>
> -#include<errno.h>
> -#include<signal.h>
> -#include<string.h>
> -#include "test.h"
> -#include "safe_macros.h"
> -
> -void setup();
> -void cleanup();
> -
> -char *TCID = "dup204";
> -int TST_TOTAL = 2;
> +#include "tst_test.h"
> +#include "tst_safe_macros.h"
>
>   int fd[2];
>   int nfd[2];
>
> -int main(int ac, char **av)
> -{
> -	int lc;
> -	int i;
> -	struct stat oldbuf, newbuf;
> -
> -	tst_parse_opts(ac, av, NULL, NULL);
> -
> -	setup();
> -
> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
> -
> -		tst_count = 0;
> -
> -		/* loop through the test cases */
> -		for (i = 0; i<  TST_TOTAL; i++) {
> -			TEST(dup2(fd[i], nfd[i]));
> -
> -			if (TEST_RETURN == -1) {
> -				tst_resm(TFAIL, "call failed unexpectedly");
> -				continue;
> -			}
> -
> -			SAFE_FSTAT(cleanup, fd[i],&oldbuf);
> -			SAFE_FSTAT(cleanup, nfd[i],&newbuf);
> -
> -			if (oldbuf.st_ino != newbuf.st_ino)
> -				tst_resm(TFAIL, "original and duped "
> -					 "inodes do not match");
> -			else
> -				tst_resm(TPASS, "original and duped "
> -					 "inodes are the same");
> -
> -			SAFE_CLOSE(cleanup, TEST_RETURN);
> -		}
> -	}
> -
> -	cleanup();
> -	tst_exit();
> -}
> -
>   void setup(void)
>   {
>   	fd[0] = -1;
> -
> -	tst_sig(FORK, DEF_HANDLER, cleanup);
> -
> -	TEST_PAUSE;
> -
> -	tst_tmpdir();
> -
> -	SAFE_PIPE(cleanup, fd);
> +	SAFE_PIPE(fd);
>   }
>
>   void cleanup(void)
> @@ -123,6 +30,34 @@ void cleanup(void)
>   		close(fd[i]);
>   		close(nfd[i]);
>   	}
> +}
> +
> +static void run(unsigned int i)
> +{
> +	struct stat oldbuf, newbuf;
> +
> +	TEST(dup2(fd[i], nfd[i]));
>
> -	tst_rmdir();
> +	if (TST_RET == -1) {
> +		tst_res(TFAIL, "call failed unexpectedly");
> +		return;
> +	}
> +
> +	SAFE_FSTAT(fd[i],&oldbuf);
> +	SAFE_FSTAT(nfd[i],&newbuf);
> +
> +	if (oldbuf.st_ino != newbuf.st_ino)
> +		tst_res(TFAIL, "original and duped inodes do not match");
> +	else
> +		tst_res(TPASS, "original and duped inodes are the same");
> +
> +	SAFE_CLOSE(TST_RET);
>   }
> +
> +static struct tst_test test = {
> +	.needs_tmpdir = 1,
> +	.tcnt = 2,
> +	.test = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +};

WARNING: multiple messages have this Message-ID (diff)
From: "xuyang2018.jy@fujitsu.com" <xuyang2018.jy@fujitsu.com>
To: QI Fuli <fukuri.sai@gmail.com>
Cc: "qi.fuli@fujitsu.com" <qi.fuli@fujitsu.com>,
	"ltp@lists.linux.it" <ltp@lists.linux.it>
Subject: Re: [LTP] [PATCH 4/5] syscalls/dup2/dup204: Convert dup204 to the new API
Date: Tue, 7 Sep 2021 09:36:24 +0000	[thread overview]
Message-ID: <6137328D.5020009@fujitsu.com> (raw)
Message-ID: <20210907093624.YUVbyPQgI0fPR9fQCdoz-VuIBM2UtirOGBYSqmEyc5A@z> (raw)
In-Reply-To: <20210902115849.72382-5-qi.fuli@fujitsu.com>

Hi Qi

I think we can merge this case into dup202 directly.
So dup202 not only check modes doesn't change but also check inode 
number doesn't change.

Best Regards
Yang Xu
> From: QI Fuli<qi.fuli@fujitsu.com>
>
> Signed-off-by: QI Fuli<qi.fuli@fujitsu.com>
> ---
>   testcases/kernel/syscalls/dup2/dup204.c | 135 ++++++------------------
>   1 file changed, 35 insertions(+), 100 deletions(-)
>
> diff --git a/testcases/kernel/syscalls/dup2/dup204.c b/testcases/kernel/syscalls/dup2/dup204.c
> index a357bc17e..3fd6b0832 100644
> --- a/testcases/kernel/syscalls/dup2/dup204.c
> +++ b/testcases/kernel/syscalls/dup2/dup204.c
> @@ -1,118 +1,25 @@
> -/*
> - *
> - *   Copyright (c) International Business Machines  Corp., 2001
> - *
> - *   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
> - */
> +// SPDX-License-Identifier: GPL-2.0-or-later
>
>   /*
> - * NAME
> - *	dup204.c
> + * Copyright (c) International Business Machines  Corp., 2001
>    *
> - * DESCRIPTION
> + * DESCRIPTION:
>    *	Testcase to check the basic functionality of dup2(2).
> - *
> - * ALGORITHM
> - *	attempt to call dup2() on read/write ends of a pipe
> - *
> - * USAGE:<for command-line>
> - *  dup204 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
> - *     where,  -c n : Run n copies concurrently.
> - *             -f   : Turn off functionality Testing.
> - *             -i n : Execute test n times.
> - *             -I x : Execute test for x seconds.
> - *             -P x : Pause for x seconds between iterations.
> - *             -t   : Turn on syscall timing.
> - *
> - * RESTRICTION
> - *	NONE
>    */
>
>   #ifndef _GNU_SOURCE
>   #define _GNU_SOURCE
>   #endif
> -#include<sys/types.h>
> -#include<fcntl.h>
> -#include<sys/stat.h>
> -#include<errno.h>
> -#include<signal.h>
> -#include<string.h>
> -#include "test.h"
> -#include "safe_macros.h"
> -
> -void setup();
> -void cleanup();
> -
> -char *TCID = "dup204";
> -int TST_TOTAL = 2;
> +#include "tst_test.h"
> +#include "tst_safe_macros.h"
>
>   int fd[2];
>   int nfd[2];
>
> -int main(int ac, char **av)
> -{
> -	int lc;
> -	int i;
> -	struct stat oldbuf, newbuf;
> -
> -	tst_parse_opts(ac, av, NULL, NULL);
> -
> -	setup();
> -
> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
> -
> -		tst_count = 0;
> -
> -		/* loop through the test cases */
> -		for (i = 0; i<  TST_TOTAL; i++) {
> -			TEST(dup2(fd[i], nfd[i]));
> -
> -			if (TEST_RETURN == -1) {
> -				tst_resm(TFAIL, "call failed unexpectedly");
> -				continue;
> -			}
> -
> -			SAFE_FSTAT(cleanup, fd[i],&oldbuf);
> -			SAFE_FSTAT(cleanup, nfd[i],&newbuf);
> -
> -			if (oldbuf.st_ino != newbuf.st_ino)
> -				tst_resm(TFAIL, "original and duped "
> -					 "inodes do not match");
> -			else
> -				tst_resm(TPASS, "original and duped "
> -					 "inodes are the same");
> -
> -			SAFE_CLOSE(cleanup, TEST_RETURN);
> -		}
> -	}
> -
> -	cleanup();
> -	tst_exit();
> -}
> -
>   void setup(void)
>   {
>   	fd[0] = -1;
> -
> -	tst_sig(FORK, DEF_HANDLER, cleanup);
> -
> -	TEST_PAUSE;
> -
> -	tst_tmpdir();
> -
> -	SAFE_PIPE(cleanup, fd);
> +	SAFE_PIPE(fd);
>   }
>
>   void cleanup(void)
> @@ -123,6 +30,34 @@ void cleanup(void)
>   		close(fd[i]);
>   		close(nfd[i]);
>   	}
> +}
> +
> +static void run(unsigned int i)
> +{
> +	struct stat oldbuf, newbuf;
> +
> +	TEST(dup2(fd[i], nfd[i]));
>
> -	tst_rmdir();
> +	if (TST_RET == -1) {
> +		tst_res(TFAIL, "call failed unexpectedly");
> +		return;
> +	}
> +
> +	SAFE_FSTAT(fd[i],&oldbuf);
> +	SAFE_FSTAT(nfd[i],&newbuf);
> +
> +	if (oldbuf.st_ino != newbuf.st_ino)
> +		tst_res(TFAIL, "original and duped inodes do not match");
> +	else
> +		tst_res(TPASS, "original and duped inodes are the same");
> +
> +	SAFE_CLOSE(TST_RET);
>   }
> +
> +static struct tst_test test = {
> +	.needs_tmpdir = 1,
> +	.tcnt = 2,
> +	.test = run,
> +	.setup = setup,
> +	.cleanup = cleanup,
> +};

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

  reply	other threads:[~2021-09-07  9:36 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-02 11:58 [LTP] [PATCH 0/5] Convert syscalls/dup2/dup2{01...05} to the new API QI Fuli
2021-09-02 11:58 ` [LTP] [PATCH 1/5] syscalls/dup2/dup201: Convert dup201 " QI Fuli
2021-09-06  9:29   ` Xiao Yang
2021-09-06  9:29     ` Xiao Yang
2021-09-07  0:42     ` qi.fuli
2021-09-07  0:42       ` qi.fuli
2021-09-07  8:28   ` xuyang2018.jy
2021-09-07  8:28     ` xuyang2018.jy
2021-09-02 11:58 ` [LTP] [PATCH 2/5] syscalls/dup2/dup202: Convert dup202 " QI Fuli
2021-09-07  1:46   ` Xiao Yang
2021-09-07  1:46     ` Xiao Yang
2021-09-07  9:14   ` xuyang2018.jy
2021-09-07  9:14     ` xuyang2018.jy
2021-09-02 11:58 ` [LTP] [PATCH 3/5] syscalls/dup2/dup203: Convert dup203 " QI Fuli
2021-09-07  9:27   ` xuyang2018.jy
2021-09-07  9:27     ` xuyang2018.jy
2021-09-02 11:58 ` [LTP] [PATCH 4/5] syscalls/dup2/dup204: Convert dup204 " QI Fuli
2021-09-07  9:36   ` xuyang2018.jy [this message]
2021-09-07  9:36     ` xuyang2018.jy
2021-09-02 11:58 ` [LTP] [PATCH 5/5] syscalls/dup2/dup205: Convert dup205 " QI Fuli
2021-09-07 10:06   ` xuyang2018.jy
2021-09-07 10:06     ` xuyang2018.jy

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=6137328D.5020009@fujitsu.com \
    --to=xuyang2018.jy@fujitsu.com \
    --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 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.