[xfstests PATCH] generic/693: add basic change attr test

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 <jlayton@xxxxxxxxxx>
---
 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!

diff --git a/common/rc b/common/rc
index 197c94157025..b9cb47f99016 100644
--- a/common/rc
+++ b/common/rc
@@ -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
 
 ################################################################################
diff --git a/tests/generic/693 b/tests/generic/693
new file mode 100755
index 000000000000..fa92931d2ac8
--- /dev/null
+++ b/tests/generic/693
@@ -0,0 +1,138 @@
+#! /bin/bash
+# SPDX-License-Identifier: GPL-2.0
+# Copyright (c) 2021, Jeff Layton <jlayton@xxxxxxxxxx>
+#
+# 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?
+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
+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
+exit
diff --git a/tests/generic/693.out b/tests/generic/693.out
new file mode 100644
index 000000000000..89ad553d911c
--- /dev/null
+++ b/tests/generic/693.out
@@ -0,0 +1 @@
+QA output created by 693
-- 
2.37.2




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux