All of lore.kernel.org
 help / color / mirror / Atom feed
From: Cyril Hrubis <chrubis@suse.cz>
To: ltp@lists.linux.it
Subject: [LTP] [PATCH 1/2] Update syscalls/fsync03 to new API
Date: Wed, 9 Oct 2019 17:20:35 +0200	[thread overview]
Message-ID: <20191009152035.GA15291@rei.lan> (raw)
In-Reply-To: <20190917101706.10013-2-mdoucha@suse.cz>

Hi!
> Signed-off-by: Martin Doucha <mdoucha@suse.com>
> ---
>  testcases/kernel/syscalls/fsync/fsync03.c | 152 +++++-----------------
>  1 file changed, 34 insertions(+), 118 deletions(-)
> 
> diff --git a/testcases/kernel/syscalls/fsync/fsync03.c b/testcases/kernel/syscalls/fsync/fsync03.c
> index 60d15f429..82fd52070 100644
> --- a/testcases/kernel/syscalls/fsync/fsync03.c
> +++ b/testcases/kernel/syscalls/fsync/fsync03.c
> @@ -1,141 +1,57 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
>  /*
> - *
> - *   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
> + *   Copyright (c) Wayne Boyer, International Business Machines  Corp., 2001
> + *   Copyright (c) 2019 Martin Doucha <mdoucha@suse.cz>
>   */
>  
>  /*
> - * NAME
> - *	fsync03.c
> - *
> - * DESCRIPTION
> - *	Testcase to check that fsync(2) sets errno correctly.
> - *
> - * ALGORITHM
> - *	1. Call fsync() with an invalid fd, and test for EBADF.
> - *	2. Call fsync() on a pipe(fd), and expect EINVAL.
> - *
> - * USAGE:  <for command-line>
> - *  fsync03 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
> - *     where,  -c n : Run n copies concurrently.
> - *             -e   : Turn on errno logging.
> - *             -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.
> - *
> - * HISTORY
> - *	07/2001 Ported by Wayne Boyer
> - *
> - * RESTRICTIONS
> - *	NONE
> + * Test Description:
> + *  Testcase to check that fsync(2) sets errno correctly.
> + *  1. Call fsync() with an invalid fd, and test for EBADF.
> + *  2. Call fsync() on a pipe(fd), and expect EINVAL.
>   */
>  
>  #include <unistd.h>
>  #include <errno.h>
> -#include "test.h"
> -#include "safe_macros.h"
> +#include "tst_test.h"
>  
> -void setup(void);
> -void cleanup(void);
> +static int pfd[2];		/* fd's for the pipe() call in setup()  */
> +static int bfd = -1;		/* an invalid fd                        */
                                  ^
				  I would say that these two comments
				  are overcommenting.

> -int fd[2];			/* fd's for the pipe() call in setup()  */
> -int pfd;			/* holds the value for fd[1]            */
> -int bfd = -1;			/* an invalid fd                        */
> -
> -struct test_case_t {
> +struct test_case {
>  	int *fd;
>  	int error;
>  } TC[] = {
>  	/* EBADF - fd is invalid (-1) */
> -	{
> -	&bfd, EBADF},
> -	    /* EINVAL - fsync() on pipe should not succeed. */
> -	{
> -	&pfd, EINVAL}
> +	{&bfd, EBADF},
> +	/* EINVAL - fsync() on pipe should not succeed. */
> +	{pfd, EINVAL}
>  };
>  
> -char *TCID = "fsync03";
> -int TST_TOTAL = 2;
> -
> -int main(int ac, char **av)
> -{
> -	int lc;
> -	int i;
> -
> -	tst_parse_opts(ac, av, NULL, NULL);
> -
> -	setup();
> -
> -	for (lc = 0; TEST_LOOPING(lc); lc++) {
> -
> -		tst_count = 0;
> +static void test_fsync(unsigned int n) {
> +	struct test_case *tc = TC + n;

This opening curly brace should be on a separate line for functions. We
do follow the LKML coding style in LTP, see:

https://www.kernel.org/doc/html/v4.10/process/coding-style.html

You can also use checkpatch script for identifying common problems:

https://github.com/torvalds/linux/blob/master/scripts/checkpatch.pl

> -		/* loop through the test cases */
> -		for (i = 0; i < TST_TOTAL; i++) {
> -
> -			TEST(fsync(*(TC[i].fd)));
> -
> -			if (TEST_RETURN != -1) {
> -				tst_resm(TFAIL, "call succeeded unexpectedly");
> -				continue;
> -			}
> -
> -			if (TEST_ERRNO == TC[i].error) {
> -				tst_resm(TPASS, "expected failure - "
> -					 "errno = %d : %s", TEST_ERRNO,
> -					 strerror(TEST_ERRNO));
> -			} else {
> -				tst_resm(TFAIL, "unexpected error - %d : %s - "
> -					 "expected %d", TEST_ERRNO,
> -					 strerror(TEST_ERRNO), TC[i].error);
> -			}
> -		}
> +	if (!fsync(*tc->fd)) {
> +		tst_res(TFAIL, "fsync() succeeded unexpectedly");
> +	} else if (errno != tc->error) {
> +		tst_res(TFAIL | TERRNO, "Unexpected error");
> +	} else {
> +		tst_res(TPASS, "fsync() failed as expected");
>  	}

I would be a bit more pedantic with the return value, i.e. check that
the failure returns exactly -1 as described in the manual page.

> -	cleanup();
> -
> -	tst_exit();
>  }
>  
> -/*
> - * setup() - performs all ONE TIME setup for this test.
> - */
> -void setup(void)
> -{
> -
> -	tst_sig(NOFORK, DEF_HANDLER, cleanup);
> -
> -	TEST_PAUSE;
> -
> -	/* make a temporary directory and cd to it */
> -	tst_tmpdir();
> -
> -	SAFE_PIPE(cleanup, fd);
> -
> -	pfd = fd[1];
> +static void setup(void) {
> +	SAFE_PIPE(pfd);
>  }
>  
> -/*
> - * cleanup() - performs all ONE TIME cleanup for this test at
> - *	       completion or premature exit.
> - */
> -void cleanup(void)
> -{
> -
> -	/* delete the test directory created in setup() */
> -	tst_rmdir();
> -
> +static void cleanup(void) {
> +	close(pfd[0]);
> +	close(pfd[1]);
>  }
> +
> +static struct tst_test test = {
> +	.test = test_fsync,
> +	.tcnt = ARRAY_SIZE(TC),
> +	.setup = setup,
> +	.cleanup = cleanup
> +};
> -- 
> 2.22.1
> 
> 
> -- 
> Mailing list info: https://lists.linux.it/listinfo/ltp

-- 
Cyril Hrubis
chrubis@suse.cz

  reply	other threads:[~2019-10-09 15:20 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-17 10:17 [LTP] [PATCH 0/2] Increase fsync() coverage - GH#452 Martin Doucha
2019-09-17 10:17 ` [LTP] [PATCH 1/2] Update syscalls/fsync03 to new API Martin Doucha
2019-10-09 15:20   ` Cyril Hrubis [this message]
2019-09-17 10:17 ` [LTP] [PATCH 2/2] Improve coverage in syscalls/fsync03 Martin Doucha
2019-10-09 15:24   ` Cyril Hrubis
2019-10-31 10:21     ` [LTP] [PATCH v3 0/2] Increase fsync() coverage - GH#452 Martin Doucha
2019-10-31 10:21       ` [LTP] [PATCH v3 1/2] Update syscalls/fsync03 to new API Martin Doucha
2019-10-31 10:21       ` [LTP] [PATCH v3 2/2] Improve coverage in syscalls/fsync03 Martin Doucha
2019-11-07 13:58         ` Cyril Hrubis

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=20191009152035.GA15291@rei.lan \
    --to=chrubis@suse.cz \
    --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.