[v3] generic/430: add copy in same file test
diff mbox series

Message ID 20190904130134.7842-1-yin-jianhong@163.com
State New
Headers show
Series
  • [v3] generic/430: add copy in same file test
Related show

Commit Message

Jianhong.Yin Sept. 4, 2019, 1:01 p.m. UTC
now xfstests has not cover the senario that copy in same file
related bug:
 copy_file_range return "Invalid argument" when copy in the same file
 https://bugzilla.kernel.org/show_bug.cgi?id=202935

step1:
 copy whole file to itself, and compare with original file.
step2:
 copy whole file to end of itself, and compare the two halves with the original file
step3:
 recover from original file.

Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
---

this is a base function test, I don't think we should add a new
test for it like 553 554, so add it in generic/430
what do you think?

 tests/generic/430     | 12 ++++++++++++
 tests/generic/430.out |  4 ++++
 2 files changed, 16 insertions(+)

Comments

Zorro Lang Sept. 5, 2019, 1:46 a.m. UTC | #1
On Wed, Sep 04, 2019 at 09:01:34PM +0800, Jianhong.Yin wrote:
> now xfstests has not cover the senario that copy in same file
> related bug:
>  copy_file_range return "Invalid argument" when copy in the same file
>  https://bugzilla.kernel.org/show_bug.cgi?id=202935
> 
> step1:
>  copy whole file to itself, and compare with original file.
> step2:
>  copy whole file to end of itself, and compare the two halves with the original file
> step3:
>  recover from original file.
> 
> Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
> ---
> 
> this is a base function test, I don't think we should add a new
> test for it like 553 554, so add it in generic/430
> what do you think?
> 
>  tests/generic/430     | 12 ++++++++++++
>  tests/generic/430.out |  4 ++++
>  2 files changed, 16 insertions(+)
> 
> diff --git a/tests/generic/430 b/tests/generic/430
> index 1b11f60d..4ce0ee26 100755
> --- a/tests/generic/430
> +++ b/tests/generic/430
> @@ -6,6 +6,7 @@
>  #
>  # Tests vfs_copy_file_range():
>  #   - Copy a file
> +#   - Copy in same file
>  #   - Copy beginning of original to new file
>  #   - Copy middle of original to a new file
>  #   - Copy end of original to new file
> @@ -52,6 +53,17 @@ cmp $testdir/file $testdir/copy
>  echo "Original md5sums:"
>  md5sum $testdir/{file,copy} | _filter_test_dir
>  
> +fsize=$(stat -c %s $testdir/copy)

I don't think you need to do `stat` to get the file size, due to this case
has definite fixed file size (5000 bytes). If it fails to write 5000 bytes,
the case should be failed for something wrong.

> +echo "Copy in same file"
> +$XFS_IO_PROG    -c "copy_range -l $fsize $testdir/copy" "$testdir/copy"
> +cmp $testdir/file $testdir/copy
> +$XFS_IO_PROG    -c "copy_range -l $fsize -d $fsize $testdir/copy" "$testdir/copy"
> +cmp -n $fsize $testdir/file $testdir/copy
> +cmp -i 0:$fsize $testdir/file $testdir/copy

I think test once on same file is enough, but I don't have objection if you and
maintainer preper twice.

> +$XFS_IO_PROG -f -c "copy_range $testdir/file" "$testdir/copy"
> +echo "md5sums after copying in same file and recover:"
> +md5sum $testdir/{file,copy} | _filter_test_dir

This test base on an implicit operation that xfs_io copy_range command always
truncates target file to 0 before doing copy_file_range, if there's not
-l or -d or -s specified.

So I think if you'd like to do this test, I prefer truncating $testdir/copy
by an explicit operation (e.g: use -t option, or -c 'truncate 0', or even
rm -f $testdir/copy).

And as above, I don't think this test is necessary, but I don't have objection
if you and maintainer preper that.

Thanks,
Zorro

> +
>  echo "Copy beginning of original file"
>  $XFS_IO_PROG -f -c "copy_range -l 1000 $testdir/file" "$testdir/beginning"
>  cmp -n 1000 $testdir/file $testdir/beginning
> diff --git a/tests/generic/430.out b/tests/generic/430.out
> index 4b4ca75d..57584957 100644
> --- a/tests/generic/430.out
> +++ b/tests/generic/430.out
> @@ -3,6 +3,10 @@ Create the original file and then copy
>  Original md5sums:
>  e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/file
>  e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/copy
> +Copy in same file
> +md5sums after copying in same file and recover:
> +e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/file
> +e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/copy
>  Copy beginning of original file
>  md5sums after copying beginning:
>  e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/file
> -- 
> 2.21.0
>
Jianhong Yin Sept. 5, 2019, 1:50 a.m. UTC | #2
----- 原始邮件 -----
> 发件人: "Zorro Lang" <zlang@redhat.com>
> 收件人: "Jianhong.Yin" <yin-jianhong@163.com>
> 抄送: fstests@vger.kernel.org, jiyin@redhat.com
> 发送时间: 星期四, 2019年 9 月 05日 上午 9:46:06
> 主题: Re: [PATCH v3] generic/430: add copy in same file test
> 
> On Wed, Sep 04, 2019 at 09:01:34PM +0800, Jianhong.Yin wrote:
> > now xfstests has not cover the senario that copy in same file
> > related bug:
> >  copy_file_range return "Invalid argument" when copy in the same file
> >  https://bugzilla.kernel.org/show_bug.cgi?id=202935
> > 
> > step1:
> >  copy whole file to itself, and compare with original file.
> > step2:
> >  copy whole file to end of itself, and compare the two halves with the
> >  original file
> > step3:
> >  recover from original file.
> > 
> > Signed-off-by: Jianhong Yin <yin-jianhong@163.com>
> > ---
> > 
> > this is a base function test, I don't think we should add a new
> > test for it like 553 554, so add it in generic/430
> > what do you think?
> > 
> >  tests/generic/430     | 12 ++++++++++++
> >  tests/generic/430.out |  4 ++++
> >  2 files changed, 16 insertions(+)
> > 
> > diff --git a/tests/generic/430 b/tests/generic/430
> > index 1b11f60d..4ce0ee26 100755
> > --- a/tests/generic/430
> > +++ b/tests/generic/430
> > @@ -6,6 +6,7 @@
> >  #
> >  # Tests vfs_copy_file_range():
> >  #   - Copy a file
> > +#   - Copy in same file
> >  #   - Copy beginning of original to new file
> >  #   - Copy middle of original to a new file
> >  #   - Copy end of original to new file
> > @@ -52,6 +53,17 @@ cmp $testdir/file $testdir/copy
> >  echo "Original md5sums:"
> >  md5sum $testdir/{file,copy} | _filter_test_dir
> >  
> > +fsize=$(stat -c %s $testdir/copy)
> 
> I don't think you need to do `stat` to get the file size, due to this case
> has definite fixed file size (5000 bytes). If it fails to write 5000 bytes,
> the case should be failed for something wrong.
I don't think you are right, here.

> 
> > +echo "Copy in same file"
> > +$XFS_IO_PROG    -c "copy_range -l $fsize $testdir/copy" "$testdir/copy"
> > +cmp $testdir/file $testdir/copy
> > +$XFS_IO_PROG    -c "copy_range -l $fsize -d $fsize $testdir/copy"
> > "$testdir/copy"
> > +cmp -n $fsize $testdir/file $testdir/copy
> > +cmp -i 0:$fsize $testdir/file $testdir/copy
> 
> I think test once on same file is enough, but I don't have objection if you
> and
> maintainer preper twice.
> 
> > +$XFS_IO_PROG -f -c "copy_range $testdir/file" "$testdir/copy"
> > +echo "md5sums after copying in same file and recover:"
> > +md5sum $testdir/{file,copy} | _filter_test_dir
> 
> This test base on an implicit operation that xfs_io copy_range command always
> truncates target file to 0 before doing copy_file_range, if there's not
> -l or -d or -s specified.
> 
> So I think if you'd like to do this test, I prefer truncating $testdir/copy
> by an explicit operation (e.g: use -t option, or -c 'truncate 0', or even
> rm -f $testdir/copy).

Yes, we are talking about this in linux-xfs channel:
 https://www.spinics.net/lists/linux-xfs/msg31327.html
 https://www.spinics.net/lists/linux-xfs/msg31292.html


patch v4 is comming.
> 
> And as above, I don't think this test is necessary, but I don't have
> objection
> if you and maintainer preper that.
> 
> Thanks,
> Zorro
> 
> > +
> >  echo "Copy beginning of original file"
> >  $XFS_IO_PROG -f -c "copy_range -l 1000 $testdir/file" "$testdir/beginning"
> >  cmp -n 1000 $testdir/file $testdir/beginning
> > diff --git a/tests/generic/430.out b/tests/generic/430.out
> > index 4b4ca75d..57584957 100644
> > --- a/tests/generic/430.out
> > +++ b/tests/generic/430.out
> > @@ -3,6 +3,10 @@ Create the original file and then copy
> >  Original md5sums:
> >  e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/file
> >  e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/copy
> > +Copy in same file
> > +md5sums after copying in same file and recover:
> > +e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/file
> > +e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/copy
> >  Copy beginning of original file
> >  md5sums after copying beginning:
> >  e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/file
> > --
> > 2.21.0
> > 
>

Patch
diff mbox series

diff --git a/tests/generic/430 b/tests/generic/430
index 1b11f60d..4ce0ee26 100755
--- a/tests/generic/430
+++ b/tests/generic/430
@@ -6,6 +6,7 @@ 
 #
 # Tests vfs_copy_file_range():
 #   - Copy a file
+#   - Copy in same file
 #   - Copy beginning of original to new file
 #   - Copy middle of original to a new file
 #   - Copy end of original to new file
@@ -52,6 +53,17 @@  cmp $testdir/file $testdir/copy
 echo "Original md5sums:"
 md5sum $testdir/{file,copy} | _filter_test_dir
 
+fsize=$(stat -c %s $testdir/copy)
+echo "Copy in same file"
+$XFS_IO_PROG    -c "copy_range -l $fsize $testdir/copy" "$testdir/copy"
+cmp $testdir/file $testdir/copy
+$XFS_IO_PROG    -c "copy_range -l $fsize -d $fsize $testdir/copy" "$testdir/copy"
+cmp -n $fsize $testdir/file $testdir/copy
+cmp -i 0:$fsize $testdir/file $testdir/copy
+$XFS_IO_PROG -f -c "copy_range $testdir/file" "$testdir/copy"
+echo "md5sums after copying in same file and recover:"
+md5sum $testdir/{file,copy} | _filter_test_dir
+
 echo "Copy beginning of original file"
 $XFS_IO_PROG -f -c "copy_range -l 1000 $testdir/file" "$testdir/beginning"
 cmp -n 1000 $testdir/file $testdir/beginning
diff --git a/tests/generic/430.out b/tests/generic/430.out
index 4b4ca75d..57584957 100644
--- a/tests/generic/430.out
+++ b/tests/generic/430.out
@@ -3,6 +3,10 @@  Create the original file and then copy
 Original md5sums:
 e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/file
 e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/copy
+Copy in same file
+md5sums after copying in same file and recover:
+e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/file
+e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/copy
 Copy beginning of original file
 md5sums after copying beginning:
 e11fbace556cba26bf0076e74cab90a3  TEST_DIR/test-430/file