Skip to contentSkip to conversation

xfstests: Add first statx test

PATCH In review David Howells 3 participants 11 messages Mar 30, 2017 – Mar 31, 2017 VFS

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 xfstests: Add first statx test

Add a statx test that does the following:

(1) Creates one each of the various types of file object and creates a hard link to the regular file.

Note that the creation of an AF_UNIX socket is done with netcat in a bash coprocessing thread. This might be best done with another in-house helper to avoid a dependency on nc.

(2) Notes the clock time before creating the file.

(3) Invokes the C test program included in this patch after the creation, handing it the clock time from (2) and providing a selection of invariants to check.

The patch also creates a C[*] test program to do the actual stat checking. The test program then does the following:

(1) Compares the output of statx() to that of fstatat().

(2) Optionally compares the timestamps to see that they're sensibly ordered with respect to the saved clock time[**] and each other.

(3) Optionally compares selected stats to values specified on the command line.

(4) Optionally compares the stats to those of another file, requiring them to be the same (hard link checking).

For example:

        ./src/stat_test /dev/null \
               0.0 \
               stx_type=char \
               stx_rdev_major=3 \
               stx_rdev_minor=8 \
               stx_nlink=1

[*] Note that it proved much easier to do this in C than trying to do it in
shell script and trying parsing the output of xfs_io. Using xfs_io has other pitfalls also: it wants to *open* the file, even if the file is not an appropriate type for this or does not grant permission to do so. I can get around this by opening O_PATH, but then xfs_io fails to handle XFS files because it wants to issue ioctls on every fd it opens.

[**] It turns out they may be *before* the clock time. This would seem to
indicate a bug in the kernel's time-tracking system.

---
 src/Makefile          |    2 
 src/stat_test.c       |  666 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/statx.h           |  166 ++++++++++++
 tests/generic/420     |  221 ++++++++++++++++
 tests/generic/420.out |   12 
 tests/generic/group   |    1 
 6 files changed, 1067 insertions(+), 1 deletion(-)
src/Makefile +1 -1
index a7f27f0..7dc53e9 100644
@@ -22,7 +22,7 @@ LINUX_TARGETS = xfsctl bstat t_mtab getdevicesize preallo_rw_pattern_reader \
 	seek_copy_test t_readdir_1 t_readdir_2 fsync-tester nsexec cloner \
 	renameat2 t_getcwd e4compact test-nextquota punch-alternating \
 	attr-list-by-handle-cursor-test listxattr dio-interleaved t_dir_type \
-	dio-invalidate-cache
+	dio-invalidate-cache stat_test
 
 SUBDIRS =
 
src/stat_test.c new file +666 -0

666 lines not on this page · raw message

src/statx.h new file +166 -0

166 lines not on this page · raw message

tests/generic/420 new file +221 -0

221 lines not on this page · raw message

tests/generic/420.out new file +12 -0
new file mode 100644
index 0000000..e2956a6
@@ -0,0 +1,12 @@
+QA output created by 420
+Test statx on a fifo
+Test statx on a chardev
+Test statx on a directory
+Test statx on a blockdev
+Test statx on a file
+20+0 records in
+20+0 records out
+Test statx on a symlink
+Test statx on an AF_UNIX socket
+Test a hard link to a file
+Success
tests/generic/group +1 -0
index 0781f35..c420998 100644
@@ -422,3 +422,4 @@
 417 auto quick shutdown log
 418 auto rw
 419 auto quick encrypt
+420 other
#1 lore raw

[ + cc: fstests ]

Quoted 15 lines · David Howells

Add a statx test that does the following:

(1) Creates one each of the various types of file object and creates a hard link to the regular file.

Note that the creation of an AF_UNIX socket is done with netcat in a bash coprocessing thread. This might be best done with another in-house helper to avoid a dependency on nc.

(2) Notes the clock time before creating the file.

(3) Invokes the C test program included in this patch after the creation, handing it the clock time from (2) and providing a selection of invariants to check.

Quoted 8 lines

The patch also creates a C[*] test program to do the actual stat checking. The test program then does the following:

(1) Compares the output of statx() to that of fstatat().

(2) Optionally compares the timestamps to see that they're sensibly ordered with respect to the saved clock time[**] and each other.

I suggest that instead of comparing to absolute timestamp value compare to a timestamp of the cmp file.
This will also solve you the problem of gettimeofday() vs. kernel_time and will also open up the possibility of adding more interesting tests later on (e.g. make sure that mtime of file A >= atime of file B).

Quoted 16 lines

(3) Optionally compares selected stats to values specified on the command line.

(4) Optionally compares the stats to those of another file, requiring them to be the same (hard link checking).

For example:

        ./src/stat_test /dev/null \
               0.0 \
               stx_type=char \
               stx_rdev_major=3 \
               stx_rdev_minor=8 \
               stx_nlink=1
Quoted 7 lines

[*] Note that it proved much easier to do this in C than trying to do it in
shell script and trying parsing the output of xfs_io. Using xfs_io has other pitfalls also: it wants to *open* the file, even if the file is not an appropriate type for this or does not grant permission to do so. I can get around this by opening O_PATH, but then xfs_io fails to handle XFS files because it wants to issue ioctls on every fd it opens.

IMO, you reached the correct solution :)
Minor nits below.

Quoted 5 lines

[**] It turns out they may be *before* the clock time. This would seem to
indicate a bug in the kernel's time-tracking system.

---

[...]

src/stat_test.c line 128

Quoted 10 lines
src/stat_test.c new file +10 -0
+
+static __attribute__((noreturn))
+void format(void)
+{
+       fprintf(stderr, "usage: %s [-v] [-m<mask>] <testfile> <origintime> [checks]\n",
+               prog);
+       fprintf(stderr, "\t<mask> can be basic, all or a number; all is the default\n");
+       fprintf(stderr, "checks is a list of zero or more of:\n");
+       fprintf(stderr, "\tts-order -- check the timestamp order after init\n");
+       fprintf(stderr, "\tts=<a>,<b> -- timestamp a <= b, where a and b are one of 'Oabcm'\n");

How about ABCMabcm,
where ABCM are timestamps of cmp file

Quoted 6 lines
src/stat_test.c new file +6 -0
+       fprintf(stderr, "\tcmp=<file> -- check that the specified file has identical stats\n");
+       fprintf(stderr, "\tstx_<field>=<val> -- statx field value check\n");
+       fprintf(stderr, "\t\t(for stx_type, fifo char dir, block, file, sym, sock can be used)\n");
+       exit(2);
+}
+

[...]

tests/generic/420 line 209

Quoted 4 lines
tests/generic/420 new file +4 -0
+
+if [ $failed = 1 ]
+then
+    echo "Test script failed"

That's not really needed

tests/generic/420 line 213

Quoted 4 lines
tests/generic/420 new file +4 -0
+    exit
+fi
+
+echo "Success"

And neither is this.

tests/generic/420 line 220

Quoted 7 lines
tests/generic/420 new file +7 -0
+
+# optional stuff if your test has verbose output to help resolve problems
+#echo
+#echo "If failure, check $seqres.full (this) and $seqres.full.ok (reference)"
+
+# success, all done
+status=0

status=fail will do the trick.

Quoted 24 lines
(quoted diff) +1 -0
+exit
tests/generic/420.out new file +12 -0
new file mode 100644
index 0000000..e2956a6
@@ -0,0 +1,12 @@
+QA output created by 420
+Test statx on a fifo
+Test statx on a chardev
+Test statx on a directory
+Test statx on a blockdev
+Test statx on a file
+20+0 records in
+20+0 records out
+Test statx on a symlink
+Test statx on an AF_UNIX socket
+Test a hard link to a file
+Success
tests/generic/group +0 -0
index 0781f35..c420998 100644

tests/generic/group line 425

Quoted 4 lines
tests/generic/group +1 -0
@@ -422,3 +422,4 @@
 417 auto quick shutdown log
 418 auto rw
 419 auto quick encrypt
+420 other

Since your test takes a few seconds, you should add it to auto, quick groups I don't know what this 'other' group is about.

Amir.

#2 lore raw
Quoted 68 lines · Amir Goldstein

[ + cc: fstests ]

Quoted 15 lines · David Howells

Add a statx test that does the following:

(1) Creates one each of the various types of file object and creates a hard link to the regular file.

Note that the creation of an AF_UNIX socket is done with netcat in a bash coprocessing thread. This might be best done with another in-house helper to avoid a dependency on nc.

(2) Notes the clock time before creating the file.

(3) Invokes the C test program included in this patch after the creation, handing it the clock time from (2) and providing a selection of invariants to check.

Quoted 8 lines

The patch also creates a C[*] test program to do the actual stat checking. The test program then does the following:

(1) Compares the output of statx() to that of fstatat().

(2) Optionally compares the timestamps to see that they're sensibly ordered with respect to the saved clock time[**] and each other.

I suggest that instead of comparing to absolute timestamp value compare to a timestamp of the cmp file.
This will also solve you the problem of gettimeofday() vs. kernel_time and will also open up the possibility of adding more interesting tests later on (e.g. make sure that mtime of file A >= atime of file B).

Quoted 16 lines

(3) Optionally compares selected stats to values specified on the command line.

(4) Optionally compares the stats to those of another file, requiring them to be the same (hard link checking).

For example:

        ./src/stat_test /dev/null \
               0.0 \
               stx_type=char \
               stx_rdev_major=3 \
               stx_rdev_minor=8 \
               stx_nlink=1
Quoted 7 lines

[*] Note that it proved much easier to do this in C than trying to do it in
shell script and trying parsing the output of xfs_io. Using xfs_io has other pitfalls also: it wants to *open* the file, even if the file is not an appropriate type for this or does not grant permission to do so. I can get around this by opening O_PATH, but then xfs_io fails to handle XFS files because it wants to issue ioctls on every fd it opens.

IMO, you reached the correct solution :)
Minor nits below.

Quoted 5 lines

[**] It turns out they may be *before* the clock time. This would seem to
indicate a bug in the kernel's time-tracking system.

---

[...]

Quoted 16 lines

src/stat_test.c line 128

Quoted 10 lines
src/stat_test.c new file +10 -0
+
+static __attribute__((noreturn))
+void format(void)
+{
+       fprintf(stderr, "usage: %s [-v] [-m<mask>] <testfile> <origintime> [checks]\n",
+               prog);
+       fprintf(stderr, "\t<mask> can be basic, all or a number; all is the default\n");
+       fprintf(stderr, "checks is a list of zero or more of:\n");
+       fprintf(stderr, "\tts-order -- check the timestamp order after init\n");
+       fprintf(stderr, "\tts=<a>,<b> -- timestamp a <= b, where a and b are one of 'Oabcm'\n");

How about ABCMabcm,
where ABCM are timestamps of cmp file

Quoted 2 lines
src/stat_test.c new file +2 -0
+       fprintf(stderr, "\tcmp=<file> -- check that the specified file has identical stats\n");
+       fprintf(stderr, "\tstx_<field>=<val> -- statx field value check\n");

And maybe use the flag "stx_<field>" (without =<val>) to indicate 'compare statx field
with that of the cmp file'.
So instead of having an all on nothing 'check that the specified file has identical stats'
tests could be more specific than that.
And maybe a '-a' flag for 'compare all stats'.

Quoted 64 lines
Quoted 4 lines
src/stat_test.c new file +4 -0
+       fprintf(stderr, "\t\t(for stx_type, fifo char dir, block, file, sym, sock can be used)\n");
+       exit(2);
+}
+

[...]

tests/generic/420 line 209

Quoted 4 lines
tests/generic/420 new file +4 -0
+
+if [ $failed = 1 ]
+then
+    echo "Test script failed"

That's not really needed

tests/generic/420 line 213

Quoted 4 lines
tests/generic/420 new file +4 -0
+    exit
+fi
+
+echo "Success"

And neither is this.

tests/generic/420 line 220

Quoted 7 lines
tests/generic/420 new file +7 -0
+
+# optional stuff if your test has verbose output to help resolve problems
+#echo
+#echo "If failure, check $seqres.full (this) and $seqres.full.ok (reference)"
+
+# success, all done
+status=0

status=fail will do the trick.

Quoted 24 lines
(quoted diff) +1 -0
+exit
tests/generic/420.out new file +12 -0
new file mode 100644
index 0000000..e2956a6
@@ -0,0 +1,12 @@
+QA output created by 420
+Test statx on a fifo
+Test statx on a chardev
+Test statx on a directory
+Test statx on a blockdev
+Test statx on a file
+20+0 records in
+20+0 records out
+Test statx on a symlink
+Test statx on an AF_UNIX socket
+Test a hard link to a file
+Success
tests/generic/group +0 -0
index 0781f35..c420998 100644

tests/generic/group line 425

Quoted 4 lines
tests/generic/group +1 -0
@@ -422,3 +422,4 @@
 417 auto quick shutdown log
 418 auto rw
 419 auto quick encrypt
+420 other

Since your test takes a few seconds, you should add it to auto, quick groups I don't know what this 'other' group is about.

Amir.

#3 lore raw
Quoted 7 lines · Amir Goldstein

And maybe use the flag "stx_<field>" (without =<val>) to indicate 'compare statx field
with that of the cmp file'.
So instead of having an all on nothing 'check that the specified file has identical stats'
tests could be more specific than that.
And maybe a '-a' flag for 'compare all stats'.

Would comparing anything other than everything or just timestamps actually be of use, I wonder?

David

#4 lore raw
In reply to Amir Goldstein
Quoted 8 lines · Amir Goldstein
Quoted 2 lines

(2) Optionally compares the timestamps to see that they're sensibly ordered with respect to the saved clock time[**] and each other.

I suggest that instead of comparing to absolute timestamp value compare to a timestamp of the cmp file.
This will also solve you the problem of gettimeofday() vs. kernel_time and will also open up the possibility of adding more interesting tests later on (e.g. make sure that mtime of file A >= atime of file B).

The whole point was to compare to a preceding time to make sure the timestamp didn't go backwards - exactly as it can do:-/. Comparing to a reference file doesn't prove that unless you've checked the reference file...

Making use of more of a reference file's timestamps could be useful for other checks, though.

Quoted 4 lines
Quoted 1 line

+420 other

Since your test takes a few seconds, you should add it to auto, quick groups I don't know what this 'other' group is about.

I don't know either. Ask the 'new' script.

David

#5 lore raw
Quoted 46 lines · David Howells

Add a statx test that does the following:

(1) Creates one each of the various types of file object and creates a hard link to the regular file.

Note that the creation of an AF_UNIX socket is done with netcat in a bash coprocessing thread. This might be best done with another in-house helper to avoid a dependency on nc.

(2) Notes the clock time before creating the file.

(3) Invokes the C test program included in this patch after the creation, handing it the clock time from (2) and providing a selection of invariants to check.

The patch also creates a C[*] test program to do the actual stat checking. The test program then does the following:

(1) Compares the output of statx() to that of fstatat().

(2) Optionally compares the timestamps to see that they're sensibly ordered with respect to the saved clock time[**] and each other.

(3) Optionally compares selected stats to values specified on the command line.

(4) Optionally compares the stats to those of another file, requiring them to be the same (hard link checking).

For example:

        ./src/stat_test /dev/null \
               0.0 \
               stx_type=char \
               stx_rdev_major=3 \
               stx_rdev_minor=8 \
               stx_nlink=1

[*] Note that it proved much easier to do this in C than trying to do it in
shell script and trying parsing the output of xfs_io. Using xfs_io has other pitfalls also: it wants to *open* the file, even if the file is not an appropriate type for this or does not grant permission to do so. I can get around this by opening O_PATH, but then xfs_io fails to handle XFS files because it wants to issue ioctls on every fd it opens.

Quoted 4 lines

[**] It turns out they may be *before* the clock time. This would seem to
indicate a bug in the kernel's time-tracking system.

I haven't looked into the statx(2) tests deeply, I'll just comment from xfstests' perspective of view for now.

Quoted 8 lines
---
 src/Makefile          |    2 
 src/stat_test.c       |  666 ++++++++++++++++++++++++++++++++++++++++++++++++++
 src/statx.h           |  166 ++++++++++++
 tests/generic/420     |  221 ++++++++++++++++
 tests/generic/420.out |   12 
 tests/generic/group   |    1 
 6 files changed, 1067 insertions(+), 1 deletion(-)

Need an entry in .gitignore for the new stat_test binary.

...

Quoted 48 lines
tests/generic/420 new file +42 -0
new file mode 100755
index 0000000..e9a6dda
@@ -0,0 +1,221 @@
+#! /bin/bash
+# FS QA Test 420
+#
+# Test the statx system call
+#
+#-----------------------------------------------------------------------
+# Copyright (c) 2017 Red Hat, Inc.  All Rights Reserved.
+# Written by David Howells ([email protected])
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License as
+# published by the Free Software Foundation.
+#
+# This program is distributed in the hope that it would be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write the Free Software Foundation,
+# Inc.,  51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+#-----------------------------------------------------------------------
+#
+
+seq=`basename $0`
+seqres=$RESULT_DIR/$seq
+echo "QA output created by $seq"
+
+here=`pwd`
+tmp=/tmp/$$
+status=1	# failure is the default!
+trap "_cleanup; exit \$status" 0 1 2 3 15
+
+_cleanup()
+{
+	cd /
+	rm -f $tmp.*
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter

tests/generic/420 line 52

Quoted 10 lines
tests/generic/420 new file +10 -0
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# real QA test starts here
+
+# Modify as appropriate.
+_supported_fs generic
+_supported_os Linux
+_require_test

_require_scratch is not called, but in the test $SCRATCH_MNT is used. So you need to either call "_require_scratch" here or use $TEST_DIR in the test. For this statx(2) test, I think test in $TEST_DIR would be sufficient.

TEST_DEV and TEST_DIR are mandatory in xfstests, while SCRATCH_DEV and SCRATCH_MNT are optional, so need to _require_scratch before using them.

tests/generic/420 line 53

Quoted 1 line
tests/generic/420 new file +1 -0
+_require_test_program "stat_test"

Also, we need to detect if the filesystem in test supports statx(2) or not, and call _notrun to exit immediately and skip the test, so test doesn't fail when running on older kernels where don't have statx support. e.g. a new _require rule like

_require_statx

Perhaps you can update src/stat_test so that it could perform statx(2) call on a give file and report the support status of statx syscall of the filesystem. e.g. common/rc::_require_seek_data_hole(), it runs "src/seek_sanity_test -t $testfile" to check statx support status.

tests/generic/420 line 64

Quoted 11 lines
tests/generic/420 new file +11 -0
+
+function check_stat () {
+    $here/src/stat_test $*
+}
+
+###############################################################################
+#
+# Check statx'ing of various types of object
+#
+###############################################################################
+failed=0

This is not needed, "status" is sufficient.

Quoted 8 lines
tests/generic/420 new file +8 -0
+
+echo "Test statx on a fifo"
+origin=`date +%s.%N`
+if mkfifo -m 0600 $SCRATCH_MNT/fifo
+then
+    check_stat $SCRATCH_MNT/fifo \
+	       $origin\
+	       ts_order \

tests/generic/420 line 82

Quoted 10 lines
tests/generic/420 new file +10 -0
+	       stx_type=fifo \
+	       stx_mode=0600 \
+	       stx_rdev_major=0 \
+	       stx_rdev_minor=0 \
+	       stx_nlink=1 \
+	|| failed=1
+else
+    echo "- mkfifo failed"
+    failed=1
+fi

No need to check if mkfifo's status (and all later similar commands like mkmod, mkdir, ln etc.). The test harness compares the test output with the predefined golden output file (420.out in this case) and fails the test if the output doesn't match. So any error message from mkfifo, mknod, mkdir commands will break golden image and fails the test.

And prefix or suffix the test file name with current test sequence number would be good, to avoid file name conflicts with test files from other tests.

So this could be simplified to:

echo "Test statx on a fifo"
origin=date +%s.%N
mkfifo -m 0600 $TEST_DIR/$seq-fifo
check_stat $TEST_DIR/$seq-fifo $origin ....

Quoted 98 lines
tests/generic/420 new file +98 -0
+
+echo "Test statx on a chardev"
+origin=`date +%s.%N`
+if mknod -m 0600 $SCRATCH_MNT/null c 1 3
+then
+    check_stat $SCRATCH_MNT/null \
+	       $origin \
+	       ts_order \
+	       stx_type=char \
+	       stx_mode=0600 \
+	       stx_rdev_major=1 \
+	       stx_rdev_minor=3 \
+	       stx_nlink=1 \
+	|| failed=1
+else
+    echo "- mknod failed"
+    failed=1
+fi
+
+echo "Test statx on a directory"
+origin=`date +%s.%N`
+if mkdir $SCRATCH_MNT/dir
+then
+    check_stat $SCRATCH_MNT/dir \
+	       $origin \
+	       ts_order \
+	       stx_type=dir \
+	       stx_mode=0755 \
+	       stx_rdev_major=0 \
+	       stx_rdev_minor=0 \
+	       stx_nlink=2 \
+	|| failed=1
+else
+    echo "- mkdir failed"
+    failed=1
+fi
+
+echo "Test statx on a blockdev"
+origin=`date +%s.%N`
+if mknod -m 0600 $SCRATCH_MNT/loopy b 7 123
+then
+    check_stat $SCRATCH_MNT/loopy \
+	       $origin \
+	       ts_order \
+	       stx_type=block \
+	       stx_mode=0600 \
+	       stx_rdev_major=7 \
+	       stx_rdev_minor=123 \
+	       stx_nlink=1 \
+	|| failed=1
+else
+    echo "- mknod failed"
+    failed=1
+fi
+
+echo "Test statx on a file"
+origin=`date +%s.%N`
+if dd if=/dev/zero of=$SCRATCH_MNT/file bs=1024 count=20
+then
+    check_stat $SCRATCH_MNT/file \
+	       $origin \
+	       ts_order \
+	       stx_type=file \
+	       stx_size=20480 \
+	       stx_rdev_major=0 \
+	       stx_rdev_minor=0 \
+	       stx_nlink=1 \
+	|| failed=1
+else
+    echo "- dd failed"
+    failed=1
+fi
+
+echo "Test statx on a symlink"
+origin=`date +%s.%N`
+if ln -s $SCRATCH_MNT/nowhere $SCRATCH_MNT/symlink
+then
+    check_stat $SCRATCH_MNT/symlink \
+	       $origin \
+	       ts_order \
+	       stx_type=sym \
+	       stx_rdev_major=0 \
+	       stx_rdev_minor=0 \
+	       stx_nlink=1 \
+	|| failed=1
+else
+    echo "- ln -s failed"
+    failed=1
+fi
+
+echo "Test statx on an AF_UNIX socket"
+origin=`date +%s.%N`
+if (coproc SERVER { nc -U -l $SCRATCH_MNT/sock </dev/null; };
+    nc -U $SCRATCH_MNT/sock </dev/null;
+    wait)
+then
+    check_stat $SCRATCH_MNT/sock \
+	       $origin \

tests/generic/420 line 190

Quoted 10 lines
tests/generic/420 new file +10 -0
+	       ts_order \
+	       stx_type=sock \
+	       stx_rdev_major=0 \
+	       stx_rdev_minor=0 \
+	       stx_nlink=1 \
+	|| failed=1
+else
+    echo "- nc failed"
+    failed=1
+fi

If nc is really needed, we should check the existence of it before starting the actual test, so test won't fail because of lack of nc command. i.e. define NC_PROG in common/config and call _require_command to check the existence of it. e.g.

common/config:
export NC_PROG="set_prog_path nc"

In this test, along with other _require rules:
_require_command "$NC_PROG" "nc"

Quoted 11 lines
tests/generic/420 new file +11 -0
+
+echo "Test a hard link to a file"
+origin=`date +%s.%N`
+if ln $SCRATCH_MNT/file $SCRATCH_MNT/link
+then
+    check_stat $SCRATCH_MNT/link \
+	       $origin \
+	       ts=O,c \
+	       cmp=$SCRATCH_MNT/file \
+	       stx_nlink=2 \
+	|| failed=1

tests/generic/420 line 211

Quoted 10 lines
tests/generic/420 new file +10 -0
+else
+    echo "- ln failed"
+    failed=1
+fi
+
+if [ $failed = 1 ]
+then
+    echo "Test script failed"
+    exit
+fi

This is not needed either.

Quoted 33 lines
tests/generic/420 new file +10 -0
+
+echo "Success"
+
+# optional stuff if your test has verbose output to help resolve problems
+#echo
+#echo "If failure, check $seqres.full (this) and $seqres.full.ok (reference)"
+
+# success, all done
+status=0
+exit
tests/generic/420.out new file +12 -0
new file mode 100644
index 0000000..e2956a6
@@ -0,0 +1,12 @@
+QA output created by 420
+Test statx on a fifo
+Test statx on a chardev
+Test statx on a directory
+Test statx on a blockdev
+Test statx on a file
+20+0 records in
+20+0 records out
+Test statx on a symlink
+Test statx on an AF_UNIX socket
+Test a hard link to a file
+Success
tests/generic/group +0 -0
index 0781f35..c420998 100644

tests/generic/group line 425

Quoted 4 lines
tests/generic/group +1 -0
@@ -422,3 +422,4 @@
 417 auto quick shutdown log
 418 auto rw
 419 auto quick encrypt
+420 other

I noticed you've already updated group to 'auto quick' :)

Thanks,
Eryu

#6 lore raw
Quoted 4 lines · Eryu Guan

Also, we need to detect if the filesystem in test supports statx(2) or not, and call _notrun to exit immediately and skip the test, so test doesn't fail when running on older kernels where don't have statx support. e.g. a new _require rule like

All filesystems support statx. What changes is whether they provide any extra data. What does matter is the kernel version (4.11-rc1 minimum).

Quoted 3 lines
Quoted 1 line

+failed=0

This is not needed, "status" is sufficient.

The script generated by new says:

status=1 # failure is the default!

I presume I'm allowed to change the default.

Quoted 2 lines

No need to check if mkfifo's status (and all later similar commands like mkmod, mkdir, ln etc.). ...

But there's no point doing the stat on them if they didn't succeed.

Quoted 4 lines

... The test harness compares the test output with the predefined golden output file (420.out in this case) and fails the test if the output doesn't match. So any error message from mkfifo, mknod, mkdir commands will break golden image and fails the test.

The status variable would be redundant then.

Quoted 3 lines

And prefix or suffix the test file name with current test sequence number would be good, to avoid file name conflicts with test files from other tests.

Do I increment this for each use? Or is it per call of the test script? Or is it the number of the script (ie. 420 in this case)?

Quoted 4 lines

If nc is really needed, we should check the existence of it before starting the actual test, so test won't fail because of lack of nc command. i.e. define NC_PROG in common/config and call _require_command to check the existence of it. e.g.

Then I run $NC_PROG rather than nc?

Quoted 7 lines

Review

Quoted 5 lines
(quoted diff) +5 -0
+if [ $failed = 1 ]
+then
+    echo "Test script failed"
+    exit
+fi

This is not needed either.

You're looking at version 1. This is gone in version 2.

Quoted 1 line

I noticed you've already updated group to 'auto quick' :)

Someone needs to fix ./new. Also it would be good if ./new either didn't require the suite to be built or explicitly said that the suite should be built before running if you run it without doing so first.

David

#7 lore raw
Quoted 9 lines · David Howells
Quoted 4 lines · Eryu Guan

Also, we need to detect if the filesystem in test supports statx(2) or not, and call _notrun to exit immediately and skip the test, so test doesn't fail when running on older kernels where don't have statx support. e.g. a new _require rule like

All filesystems support statx. What changes is whether they provide any extra data. What does matter is the kernel version (4.11-rc1 minimum).

xfstests is run not only with latest upstream kernel, but also with many distro kernels, like RHEL, by distro testers, where there's no statx syscall support at all (at this moment). So test should _notrun instead of failing there.

If not providing extra data will fail the test, we need to require the filesystem to be tested to provide such extra data too.

Quoted 10 lines
Quoted 4 lines
Quoted 2 lines

+failed=0

This is not needed, "status" is sufficient.

The script generated by new says:

status=1 # failure is the default!

I presume I'm allowed to change the default.

Yes, you can change the default simply by "status=0". But in xfstests we rarely do that, we usually set status=0 just before exit if everything went well.

Quoted 5 lines
Quoted 3 lines

No need to check if mkfifo's status (and all later similar commands like mkmod, mkdir, ln etc.). ...

But there's no point doing the stat on them if they didn't succeed.

Then just let statx(2) fail and complain about the missing file, the test fails anyway. The whole point is that with golden image matching, you don't have to check return value of every command, that's the methodology xfstests has adopted. And occasionally, exercising such error paths help find unexpected bugs too :)

Quoted 7 lines
Quoted 5 lines

... The test harness compares the test output with the predefined golden output file (420.out in this case) and fails the test if the output doesn't match. So any error message from mkfifo, mknod, mkdir commands will break golden image and fails the test.

The status variable would be redundant then.

Some tests can't rely on the golden image match, they rely on status variable. So test passes only if a) golden image matches, b) status=0

Quoted 7 lines
Quoted 4 lines

And prefix or suffix the test file name with current test sequence number would be good, to avoid file name conflicts with test files from other tests.

Do I increment this for each use? Or is it per call of the test script? Or is it the number of the script (ie. 420 in this case)?

There's a pre-defined $seq variable (as showed in my example, not included in this reply), you can just use $seq directly.

Quoted 7 lines
Quoted 5 lines

If nc is really needed, we should check the existence of it before starting the actual test, so test won't fail because of lack of nc command. i.e. define NC_PROG in common/config and call _require_command to check the existence of it. e.g.

Then I run $NC_PROG rather than nc?

Yes, that's perferred.

Quoted 9 lines
Quoted 8 lines

Review

Quoted 6 lines
(quoted diff) +5 -0
+if [ $failed = 1 ]
+then
+    echo "Test script failed"
+    exit
+fi

This is not needed either.

Quoted 7 lines

You're looking at version 1. This is gone in version 2.

Quoted 1 line

I noticed you've already updated group to 'auto quick' :)

Someone needs to fix ./new. Also it would be good if ./new either didn't require the suite to be built or explicitly said that the suite should be built before running if you run it without doing so first.

Yes, and the document really should be improved, so people could have an easy start with it.

Thanks,
Eryu

#8 lore raw
In reply to Eryu Guan
Quoted 4 lines · Eryu Guan

_require_scratch is not called, but in the test $SCRATCH_MNT is used. So you need to either call "_require_scratch" here or use $TEST_DIR in the test. For this statx(2) test, I think test in $TEST_DIR would be sufficient.

SCRATCH is cleaned between runs of ./check, but not this isn't so for TEST, right?

David

#9 lore raw
Quoted 11 lines · David Howells
Quoted 4 lines · Eryu Guan

_require_scratch is not called, but in the test $SCRATCH_MNT is used. So you need to either call "_require_scratch" here or use $TEST_DIR in the test. For this statx(2) test, I think test in $TEST_DIR would be sufficient.

SCRATCH is cleaned between runs of ./check, but not this isn't so for TEST, right?

David

Yes, TEST_DEV is supposed to be aging across tests, while SCRATCH_DEV is re-created in tests. But you need to clean it explicitly in the test by calling _scratch_mkfs, then mount it beforing writing anything to $SCRATCH_MNT.

So the usual steps to use SCRATCH_DEV/SCRATCH_MNT is:

# this makes sure we have SCRATCH_DEV/MNT configured and unmounts it
# if SCRATCH_DEV is still mounted, so you don't need to unmount it
_require_scratch
# create filesystem on SCRATCH_DEV and mount it at SCRATCH_MNT
_scratch_mkfs
_scratch_mount
...
# then you can write to SCRATCH_MNT
$XFS_IO_PROG -fc "pwrite 0 1M" $SCRATCH_MNT/testfile

Thanks,
Eryu

#10 lore raw
Quoted 3 lines · Eryu Guan
# create filesystem on SCRATCH_DEV and mount it at SCRATCH_MNT
_scratch_mkfs
_scratch_mount

This doesn't seem to be necessary; it's doing it automatically for me.

David