linux-fsdevel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eryu Guan <eguan@redhat.com>
To: "Darrick J. Wong" <darrick.wong@oracle.com>
Cc: linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	xfs <linux-xfs@vger.kernel.org>,
	linux-ext4 <linux-ext4@vger.kernel.org>,
	fstests <fstests@vger.kernel.org>
Subject: Re: [PATCH] generic: test negative SEEK_HOLE/SEEK_DATA offsets
Date: Thu, 13 Jul 2017 16:14:58 +0800	[thread overview]
Message-ID: <20170713081458.GE2478@eguan.usersys.redhat.com> (raw)
In-Reply-To: <20170712173923.GD4212@magnolia>

On Wed, Jul 12, 2017 at 10:39:23AM -0700, Darrick J. Wong wrote:
> Check that we get -ENXIO if the user calls SEEK_HOLE/SEEK_DATA with
> a negative file offset.

A minor nit, this might be confusing, lseek returns -1 on error, and set
errno to ENXIO, no one actually returns -ENXIO.

> 
> Signed-off-by: Darrick J. Wong <darrick.wong@oracle.com>
> ---
>  src/seek_sanity_test.c |   25 +++++++++++++++++
>  tests/generic/702      |   70 ++++++++++++++++++++++++++++++++++++++++++++++++
>  tests/generic/702.out  |    2 +
>  tests/generic/group    |    1 +
>  4 files changed, 98 insertions(+)
>  create mode 100755 tests/generic/702
>  create mode 100644 tests/generic/702.out
> 
> diff --git a/src/seek_sanity_test.c b/src/seek_sanity_test.c
> index a58ec36..547f0a4 100644
> --- a/src/seek_sanity_test.c
> +++ b/src/seek_sanity_test.c
> @@ -274,6 +274,30 @@ static int huge_file_test(int fd, int testnum, off_t filsz)
>  	return ret;
>  }
>  
> +/* Make sure we get ENXIO if we pass in a negative offset. */
> +static int test18(int fd, int testnum)
> +{
> +	int ret = 0;
> +	off_t pos;
> +
> +	errno = 0;
> +	pos = lseek(fd, -1, SEEK_HOLE);
> +	if (pos != -1 || errno != ENXIO) {
> +		printf("%02d.1 SEEK_HOLE expected -1 with errno %d, got %jd and %d.\n",
> +		       testnum, -ENXIO, pos, -errno);
> +		ret++;
> +	}
> +
> +	errno = 0;
> +	pos = lseek(fd, -1, SEEK_DATA);
> +	if (pos != -1 || errno != ENXIO) {
> +		printf("%02d.1 SEEK_DATA expected -1 with errno %d, got %jd and %d.\n",
> +		       testnum, -ENXIO, pos, -errno);
> +		ret++;
> +	}
> +	return ret;

Seems cleaner to use do_lseek() helper, e.g.

static int test18(int fd, int testnum)
{
	int ret = 0;

	/* file size doesn't matter in this test, set to 0 */
	ret += do_lseek(testnum, 1, fd, 0, SEEK_HOLE, -1, -1);
	ret += do_lseek(testnum, 2, fd, 0, SEEK_DATA, -1, -1);
	
	return ret;
}

And test reports "succ" or "FAIL" as what other subtests do

18. Test file with negative SEEK_{HOLE,DATA} offsets  
18.01 SEEK_HOLE expected -1 or -1, got 0.                         FAIL
18.02 SEEK_DATA expected -1 with errno -6, got -1.                FAIL

Thanks,
Eryu

  reply	other threads:[~2017-07-13  8:15 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-07-12 17:39 [PATCH] generic: test negative SEEK_HOLE/SEEK_DATA offsets Darrick J. Wong
2017-07-13  8:14 ` Eryu Guan [this message]
2017-07-13 19:04   ` Darrick J. Wong

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=20170713081458.GE2478@eguan.usersys.redhat.com \
    --to=eguan@redhat.com \
    --cc=darrick.wong@oracle.com \
    --cc=fstests@vger.kernel.org \
    --cc=linux-ext4@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-xfs@vger.kernel.org \
    /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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).