generic: test negative SEEK_HOLE/SEEK_DATA offsets
PATCH 1/1 generic: test negative SEEK_HOLE/SEEK_DATA offsets
Check that we get -ENXIO if the user calls SEEK_HOLE/SEEK_DATA with a negative file offset.
--- 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
src/seek_sanity_test.c +25 -0
@@ -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; +} +static int test17 (int fd,int testnum) {char *buf =NULL ;
@@ -969,6 +993,7 @@ struct testrec seek_tests[] = { { 15, test15, "Test file with unwritten extents, page after unwritten extent" }, { 16, test16, "Test file with unwritten extents, non-contiguous dirty pages" }, { 17, test17, "Test file with unwritten extents, data-hole-data inside page" }, + { 18, test18, "Test file with negative SEEK_{HOLE,DATA} offsets" }, };static int run_test (struct testrec *tr)
tests/generic/702 new file +70 -0
70 lines not on this page · raw message
tests/generic/702.out new file +2 -0
@@ -0,0 +1,2 @@ +QA output created by 702 +Silence is golden
tests/generic/group +1 -0
@@ -449,4 +449,5 @@ 444 auto quick acl 445 auto quick rw 446 auto quick rw dangerous +702 auto quick rw 931 auto quick clone
Quoted 2 lines · Darrick J. Wong
Check that we get
-ENXIOif 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.
Quoted 31 lines
Signed-off-by Darrick J. Wong <[email protected]>--- 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.outsrc/seek_sanity_test.c +12
-0@@ -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++;
src/seek_sanity_test.c static int huge_file_test(int fd, int testnum, off_t filsz) · line 298
Quoted 10 lines
src/seek_sanity_test.c +10
-0+ } + + 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
Quoted 62 lines · Eryu Guan
Quoted 2 lines · Darrick J. Wong
Check that we get
-ENXIOif 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.Quoted 31 lines
Signed-off-by Darrick J. Wong <[email protected]>--- 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.outsrc/seek_sanity_test.c +12
-0@@ -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++;src/seek_sanity_test.c static int huge_file_test(int fd, int testnum, off_t filsz) · line 298
Quoted 10 lines
src/seek_sanity_test.c +10
-0+ } + + 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; }
Quoted 5 lines
And test reports "succ" or "FAIL" as what other subtests do
18. Test file with negative SEEK_{HOLE,DATA} offsets
18.01SEEK_HOLEexpected -1 or -1, got 0. FAIL
18.02SEEK_DATAexpected -1 with errno -6, got -1. FAIL
Sure, will change and resend.
--D
Quoted 7 lines
Thanks,
Eryu
--
To unsubscribe from this list: send the line "unsubscribe linux-xfs" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html