generic/693: add basic change attr test
PATCH 1/1 generic/693: add basic change attr test
Now that we have the ability to query the change attribute in userland, test that the filesystems implement it correctly. Fetch the change attribute before and after various operations and validate that it changes (or doesn't change) as expected.
--- common/rc | 17 ++++++ tests/generic/693 | 138 ++++++++++++++++++++++++++++++++++++++++++ tests/generic/693.out | 1 + 3 files changed, 156 insertions(+) create mode 100755 tests/generic/693 create mode 100644 tests/generic/693.out
Please look and make sure I'm not missing other operations that we should be testing here!
common/rc +17 -0
@@ -5052,6 +5052,23 @@ hexdump() _fail "Use _hexdump(), please!" } +_require_change_attr () +{ + + _mask=$($XFS_IO_PROG -f -c "statx -m 0x2000 -r" $TEST_DIR/change_attr_test.$$ \ + | grep "^stat.mask" | cut -d' ' -f 3) + rm -f $TEST_DIR/change_attr_test.$$ + if [ $(( ${_mask}&0x2000 )) -eq 0 ]; then + _notrun "$FSTYP does not support inode change attribute" + fi +} + +_get_change_attr () +{ + $XFS_IO_PROG -r -c "statx -m 0x2000 -r" $1 | grep '^stat.change_attr' | \ + cut -d' ' -f3 +} + init_rc ################################################################################
tests/generic/693 new file +138 -0
138 lines not on this page · raw message
tests/generic/693.out new file +1 -0
@@ -0,0 +1 @@ +QA output created by 693
Signature · 1 line
2.37.2
Hi Jeff,
Thanks for the patch!
Quoted 82 lines · Jeff Layton
Now that we have the ability to query the change attribute in userland, test that the filesystems implement it correctly. Fetch the change attribute before and after various operations and validate that it changes (or doesn't change) as expected.
Signed-off-by Jeff Layton <[email protected]>--- common/rc | 17 ++++++ tests/generic/693 | 138 ++++++++++++++++++++++++++++++++++++++++++ tests/generic/693.out | 1 + 3 files changed, 156 insertions(+) create mode 100755 tests/generic/693 create mode 100644 tests/generic/693.outPlease look and make sure I'm not missing other operations that we should be testing here!
common/rc +17
-0@@ -5052,6 +5052,23 @@ hexdump() _fail "Use _hexdump(), please!" } +_require_change_attr () +{ + + _mask=$($XFS_IO_PROG -f -c "statx -m 0x2000 -r" $TEST_DIR/change_attr_test.$$ \ + | grep "^stat.mask" | cut -d' ' -f 3) + rm -f $TEST_DIR/change_attr_test.$$ + if [ $(( ${_mask}&0x2000 )) -eq 0 ]; then + _notrun "$FSTYP does not support inode change attribute" + fi +} + +_get_change_attr () +{ + $XFS_IO_PROG -r -c "statx -m 0x2000 -r" $1 | grep '^stat.change_attr' | \ + cut -d' ' -f3 +} + init_rc ################################################################################tests/generic/693 new file +30
-0@@ -0,0 +1,138 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021, Jeff Layton <[email protected]> +# +# FS QA Test No. 693 +# +# Test the behavior of the inode change attribute +# +. ./common/preamble +_begin_fstest auto quick rw + +# Import common functions. +. ./common/filter + +# real QA test starts here +_supported_fs generic +_require_test +_require_change_attr + +# from the stat.h header file +UTIME_OMIT=1073741822 + +testdir="$TEST_DIR/test_iversion_dir.$$" +testfile="$testdir/test_iversion_file.$$" + +mkdir $testdir + +# DIRECTORY TESTS +################# +# Does dir change attr change on a create?
tests/generic/693 line 40
Quoted 10 lines
tests/generic/693 new file +10
-0+old=$(_get_change_attr $testdir) +touch $testfile +new=$(_get_change_attr $testdir) +if [ $old = $new ]; then + _fail "Change attr of dir did not change after create!" +fi + +# on a hardlink? +old=$new +ln $testfile $testdir/linky
We may need to clean up these temporary testing files.
Other parts look good to me.
Regards~
Quoted 108 lines
tests/generic/693 new file +98
-0+new=$(_get_change_attr $testdir) +if [ $old = $new ]; then + _fail "Change attr of dir did not change after hardlink!" +fi + +# on an unlink? +old=$new +rm -f $testfile +new=$(_get_change_attr $testdir) +if [ $old = $new ]; then + _fail "Change attr of dir did not change after unlink!" +fi + +# on a rename (within same dir) +old=$new +mv $testdir/linky $testfile +new=$(_get_change_attr $testdir) +if [ $old = $new ]; then + _fail "Change attr of dir did not change after rename!" +fi + +# on a mknod +old=$new +mknod $testdir/pipe p +new=$(_get_change_attr $testdir) +if [ $old = $new ]; then + _fail "Change attr of dir did not change after mknod!" +fi + + +# REGULAR FILE TESTS +#################### +# ensure change_attr changes after a write +old=$(_get_change_attr $testfile) +$XFS_IO_PROG -c "pwrite -W -q 0 32" $testfile +new=$(_get_change_attr $testfile) +if [ $old = $new ]; then + _fail "Change attr did not change after write!" +fi + +# ensure it doesn't change after a sync +old=$new +sync +new=$(_get_change_attr $testfile) +if [ $old != $new ]; then + _fail "Change attr changed after sync!" +fi + +# ensure change_attr does not change after read +old=$new +cat $testfile > /dev/null +new=$(_get_change_attr $testfile) +if [ $old != $new ]; then + _fail "Change attr changed after read!" +fi + +# ensure it changes after truncate +old=$new +truncate --size 0 $testfile +new=$(_get_change_attr $testfile) +if [ $old = $new ]; then + _fail "Change attr did not change after truncate!" +fi + +# ensure it changes after only atime update +old=$new +$XFS_IO_PROG -c "utimes 1 1 $UTIME_OMIT $UTIME_OMIT" $testfile +new=$(_get_change_attr $testfile) +if [ $old = $new ]; then + _fail "Change attr did not change after atime update!" +fi + +# ensure it changes after utimes atime/mtime update +old=$new +$XFS_IO_PROG -c "utimes 1 1 1 1" $testfile +new=$(_get_change_attr $testfile) +if [ $old = $new ]; then + _fail "Change attr did not change after mtime update!" +fi + +# after setting xattr +old=$new +setfattr -n user.foo -v bar $testfile +new=$(_get_change_attr $testfile) +if [ $old = $new ]; then + _fail "Change attr did not change after setxattr!" +fi + +# after removing xattr +old=$new +setfattr -x user.foo $testfile +new=$(_get_change_attr $testfile) +if [ $old = $new ]; then + _fail "Change attr did not change after rmxattr!" +fi + +status=0 +exittests/generic/693.out new file +1
-1@@ -0,0 +1 @@ +QA output created by 693 --2.37.2
Thanks for having a look. I should probably have marked this as an RFC patch. The infrastructure for this is still being debated on the mailing lists. Until that's settled we won't want to merge this.
Cheers,
Jeff
Quoted 212 lines · Murphy Zhou
Hi Jeff,
Thanks for the patch!
Quoted 82 lines · Jeff Layton
Now that we have the ability to query the change attribute in userland, test that the filesystems implement it correctly. Fetch the change attribute before and after various operations and validate that it changes (or doesn't change) as expected.
Signed-off-by Jeff Layton <[email protected]>--- common/rc | 17 ++++++ tests/generic/693 | 138 ++++++++++++++++++++++++++++++++++++++++++ tests/generic/693.out | 1 + 3 files changed, 156 insertions(+) create mode 100755 tests/generic/693 create mode 100644 tests/generic/693.outPlease look and make sure I'm not missing other operations that we should be testing here!
common/rc +17
-0@@ -5052,6 +5052,23 @@ hexdump() _fail "Use _hexdump(), please!" } +_require_change_attr () +{ + + _mask=$($XFS_IO_PROG -f -c "statx -m 0x2000 -r" $TEST_DIR/change_attr_test.$$ \ + | grep "^stat.mask" | cut -d' ' -f 3) + rm -f $TEST_DIR/change_attr_test.$$ + if [ $(( ${_mask}&0x2000 )) -eq 0 ]; then + _notrun "$FSTYP does not support inode change attribute" + fi +} + +_get_change_attr () +{ + $XFS_IO_PROG -r -c "statx -m 0x2000 -r" $1 | grep '^stat.change_attr' | \ + cut -d' ' -f3 +} + init_rc ################################################################################tests/generic/693 new file +30
-0@@ -0,0 +1,138 @@ +#! /bin/bash +# SPDX-License-Identifier: GPL-2.0 +# Copyright (c) 2021, Jeff Layton <[email protected]> +# +# FS QA Test No. 693 +# +# Test the behavior of the inode change attribute +# +. ./common/preamble +_begin_fstest auto quick rw + +# Import common functions. +. ./common/filter + +# real QA test starts here +_supported_fs generic +_require_test +_require_change_attr + +# from the stat.h header file +UTIME_OMIT=1073741822 + +testdir="$TEST_DIR/test_iversion_dir.$$" +testfile="$testdir/test_iversion_file.$$" + +mkdir $testdir + +# DIRECTORY TESTS +################# +# Does dir change attr change on a create?tests/generic/693 line 40
Quoted 10 lines
tests/generic/693 new file +10
-0+old=$(_get_change_attr $testdir) +touch $testfile +new=$(_get_change_attr $testdir) +if [ $old = $new ]; then + _fail "Change attr of dir did not change after create!" +fi + +# on a hardlink? +old=$new +ln $testfile $testdir/linkyWe may need to clean up these temporary testing files.
Other parts look good to me.
Regards~
Quoted 108 lines
tests/generic/693 new file +98
-0+new=$(_get_change_attr $testdir) +if [ $old = $new ]; then + _fail "Change attr of dir did not change after hardlink!" +fi + +# on an unlink? +old=$new +rm -f $testfile +new=$(_get_change_attr $testdir) +if [ $old = $new ]; then + _fail "Change attr of dir did not change after unlink!" +fi + +# on a rename (within same dir) +old=$new +mv $testdir/linky $testfile +new=$(_get_change_attr $testdir) +if [ $old = $new ]; then + _fail "Change attr of dir did not change after rename!" +fi + +# on a mknod +old=$new +mknod $testdir/pipe p +new=$(_get_change_attr $testdir) +if [ $old = $new ]; then + _fail "Change attr of dir did not change after mknod!" +fi + + +# REGULAR FILE TESTS +#################### +# ensure change_attr changes after a write +old=$(_get_change_attr $testfile) +$XFS_IO_PROG -c "pwrite -W -q 0 32" $testfile +new=$(_get_change_attr $testfile) +if [ $old = $new ]; then + _fail "Change attr did not change after write!" +fi + +# ensure it doesn't change after a sync +old=$new +sync +new=$(_get_change_attr $testfile) +if [ $old != $new ]; then + _fail "Change attr changed after sync!" +fi + +# ensure change_attr does not change after read +old=$new +cat $testfile > /dev/null +new=$(_get_change_attr $testfile) +if [ $old != $new ]; then + _fail "Change attr changed after read!" +fi + +# ensure it changes after truncate +old=$new +truncate --size 0 $testfile +new=$(_get_change_attr $testfile) +if [ $old = $new ]; then + _fail "Change attr did not change after truncate!" +fi + +# ensure it changes after only atime update +old=$new +$XFS_IO_PROG -c "utimes 1 1 $UTIME_OMIT $UTIME_OMIT" $testfile +new=$(_get_change_attr $testfile) +if [ $old = $new ]; then + _fail "Change attr did not change after atime update!" +fi + +# ensure it changes after utimes atime/mtime update +old=$new +$XFS_IO_PROG -c "utimes 1 1 1 1" $testfile +new=$(_get_change_attr $testfile) +if [ $old = $new ]; then + _fail "Change attr did not change after mtime update!" +fi + +# after setting xattr +old=$new +setfattr -n user.foo -v bar $testfile +new=$(_get_change_attr $testfile) +if [ $old = $new ]; then + _fail "Change attr did not change after setxattr!" +fi + +# after removing xattr +old=$new +setfattr -x user.foo $testfile +new=$(_get_change_attr $testfile) +if [ $old = $new ]; then + _fail "Change attr did not change after rmxattr!" +fi + +status=0 +exittests/generic/693.out new file +1
-1@@ -0,0 +1 @@ +QA output created by 693 --2.37.2
Signature · 1 line
Jeff Layton <[email protected]>