All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/6] fstests: start factoring test setup boilerplate
@ 2018-06-27  8:20 Dave Chinner
  2018-06-27  8:20 ` [PATCH 1/8] fstests: generic test setup preamble Dave Chinner
                   ` (8 more replies)
  0 siblings, 9 replies; 28+ messages in thread
From: Dave Chinner @ 2018-06-27  8:20 UTC (permalink / raw)
  To: fstests

Hi folks,

These patches start the long process of factoring out most of the
test setup boilerplate in each test. The first patch introduces the
generic test setup include file, and the patches that follow start
the process of converting tests over to use it.

Making infrastructure changes to fstests is hard because of the
sheer number of tests. Abstracting out things like test setup will
make it much easier in future to improve the test setup
infrstructure as we won't need to modify every test to make the
change. We only have to do the hard work once.

There is still some boiler plate in the preamble, but it is reduced
significantly and only contains things that individual tests should
be allowed to influence. i.e. the full output file and a cleanup
function that is called on exit.

I've also replaced the test success suffix - instead of this boiler
plate at the end of each test:

# success, all done
status=0
exit

This has been replaced with a single call to _success, which does
all the things necessary for the test harness to know the test has
exited successfully.

As an initial pass I've convert all the test directories with a
small number of tests, and converted the first handful of tests in
each of the major test directories. This is a slow process because
it's mostly manual as every second test has some unique variation
that makes automated replacement somewhat difficult.

As such, I've really only scratched the surface - this patchset
changes over about 60 tests, and there are about 1200 more tests to
convert. As such, my focus is going to be converting the generic
tests first - this is the biggest chunk of the work that
needs to be done.

Given there is still a large amount of conversion work to do, I
would appreciate it if people regularly contributing to the other
large test dirs (mainly overlay, btrfs, ext4 and xfs) would consider
devoting an hour or two to converting some of those tests to the new
setup preamble. The more people who do a bit, the faster the
conversion will go and the better it will be for everyone.

Comments, thoughts?

-Dave.



^ permalink raw reply	[flat|nested] 28+ messages in thread

* [PATCH 1/8] fstests: generic test setup preamble
  2018-06-27  8:20 [PATCH 0/6] fstests: start factoring test setup boilerplate Dave Chinner
@ 2018-06-27  8:20 ` Dave Chinner
  2018-06-27 11:07   ` Amir Goldstein
  2018-06-27  8:20 ` [PATCH 2/8] tests: convert various test dirs to " Dave Chinner
                   ` (7 subsequent siblings)
  8 siblings, 1 reply; 28+ messages in thread
From: Dave Chinner @ 2018-06-27  8:20 UTC (permalink / raw)
  To: fstests

From: Dave Chinner <dchinner@redhat.com>

So many tests chop random bits out of the mandaotry test setup
preamble which leads to subtle problems and stray files being dumped
all over the place. Create a common test preamble with hooks for
local cleanup functions so we can prevent this in future.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 common/setup_test | 31 +++++++++++++++++++++++++++++++
 new               | 35 ++++++++---------------------------
 soak              | 19 +++++++------------
 3 files changed, 46 insertions(+), 39 deletions(-)
 create mode 100644 common/setup_test

diff --git a/common/setup_test b/common/setup_test
new file mode 100644
index 000000000000..f25ed11c2306
--- /dev/null
+++ b/common/setup_test
@@ -0,0 +1,31 @@
+# SPDX-License-Identifier: GPL-2.0
+#
+# common test setup preamble
+# test specific cleanup is done via the cleanup() function now.
+
+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_test; exit \$status" 0 1 2 3 15
+
+_cleanup_test()
+{
+	# call local test cleanup function first, then cleanup tmp files
+	cleanup
+	cd /
+	rm -f $tmp.*
+}
+
+_success()
+{
+	status=0
+	exit
+}
+
+# get standard environment, filters and checks
+. ./common/rc
+. ./common/filter
diff --git a/new b/new
index 2bb8ce5055c1..1f11fdad1b8c 100755
--- a/new
+++ b/new
@@ -9,12 +9,11 @@
 iam=new
 . ./common/test_names
 
-trap "rm -f /tmp/$$.; exit" 0 1 2 3 15
 
-_cleanup()
-{
-    :
+_cleanup() {
+	rm -f /tmp/$$.
 }
+trap "_cleanup; exit" 0 1 2 3 15
 
 SRC_GROUPS=`find tests -not -path tests -type d -printf "%f "`
 usage()
@@ -153,31 +152,15 @@ cat <<End-of-File >$tdir/$id
 #
 # what am I here for?
 #
-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.*
-}
+. common/setup_test
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# test exit cleanup goes here
+cleanup() { :; }
 
 # remove previous \$seqres.full before test
 rm -f \$seqres.full
 
-# real QA test starts here
-
-# Modify as appropriate.
+# include test specific environments here
 _supported_fs generic
 _supported_os Linux
 _require_test
@@ -189,9 +172,7 @@ exit
 #echo
 #echo "If failure, check \$seqres.full (this) and \$seqres.full.ok (reference)"
 
-# success, all done
-status=0
-exit
+_success
 End-of-File
 
 sleep 2		# latency to read messages to this point
diff --git a/soak b/soak
index d5c4229ad6e7..3a9c4daa622e 100755
--- a/soak
+++ b/soak
@@ -3,21 +3,16 @@
 # Copyright (c) 2000-2002 Silicon Graphics, Inc.  All Rights Reserved.
 #
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+. common/setup_test
 
-tmp=/tmp/$$
-seq=soak
-status=1	# failure is the default!
-
-_cleanup()
-{
-    echo "        *** umount"
-    _scratch_unmount >/dev/null 2>&1
+# test exit cleanup goes here
+cleanup() {
+	echo "        *** umount"
+	_scratch_unmount >/dev/null 2>&1
 }
 
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
 ROOT="."
 LOG="$ROOT/soak.log"
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 2/8] tests: convert various test dirs to setup preamble
  2018-06-27  8:20 [PATCH 0/6] fstests: start factoring test setup boilerplate Dave Chinner
  2018-06-27  8:20 ` [PATCH 1/8] fstests: generic test setup preamble Dave Chinner
@ 2018-06-27  8:20 ` Dave Chinner
  2018-06-27 10:34   ` Amir Goldstein
  2018-06-27  8:20 ` [PATCH 3/8] shared: use new test " Dave Chinner
                   ` (6 subsequent siblings)
  8 siblings, 1 reply; 28+ messages in thread
From: Dave Chinner @ 2018-06-27  8:20 UTC (permalink / raw)
  To: fstests

From: Dave Chinner <dchinner@redhat.com>

Convert all the test dirs with a very small number of tests in one
go.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 tests/cifs/001  | 25 +++++++------------------
 tests/f2fs/001  | 25 +++++++------------------
 tests/nfs/001   | 28 +++++++---------------------
 tests/ocfs2/001 | 29 +++++++----------------------
 tests/perf/001  | 30 +++++++++++++-----------------
 tests/udf/102   | 29 ++++++++---------------------
 6 files changed, 49 insertions(+), 117 deletions(-)

diff --git a/tests/cifs/001 b/tests/cifs/001
index 193103bf8877..5bfc6ae46c92 100755
--- a/tests/cifs/001
+++ b/tests/cifs/001
@@ -6,27 +6,17 @@
 #
 # Sanity test for server-side copies initiated via CIFS_IOC_COPYCHUNK_FILE
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-
-_cleanup()
-{
-	rm -f $tmp.*
+# test exit cleanup goes here
+cleanup() {
 	rm -rf $TEST_DIR/$$
 }
 
-trap "_cleanup ; exit \$status" 0 1 2 3 15
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs cifs
 _supported_os Linux
 _require_cloner
@@ -49,5 +39,4 @@ for i in `seq 1 10`; do
 	diff $TEST_DIR/$$/src/${i} $TEST_DIR/$$/dest/${i}
 done
 
-status=0
-exit
+_success
diff --git a/tests/f2fs/001 b/tests/f2fs/001
index f9cd2cf089a3..c23c1cc6da36 100755
--- a/tests/f2fs/001
+++ b/tests/f2fs/001
@@ -15,25 +15,15 @@
 # In ext4, up to 132 bytes of data can be stored in 256 bytes-sized inode.
 # In f2fs, up to 3.4KB of data can be embedded into 4KB-sized inode block.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    cd /
-    rm -f $tmp.*
-}
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
+# include test specific environments here
 _supported_fs f2fs
 _supported_os Linux
 _require_scratch
@@ -65,5 +55,4 @@ hexdump -C $testfile
 rm $testfile
 rm $dummyfile
 
-status=0
-exit
+_success
diff --git a/tests/nfs/001 b/tests/nfs/001
index d7a79cb07d83..ca5d96093bf9 100755
--- a/tests/nfs/001
+++ b/tests/nfs/001
@@ -9,29 +9,17 @@
 # ERANGE. Upstream commit ed92d8c137b7 ("NFSv4: fix getacl ERANGE for some ACL
 # buffer sizes") fixed this bug.
 #
-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.* $acltest.*
-}
+. common/setup_test
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# test exit cleanup goes here
+cleanup() {
+	rm -f $acltest.*
+}
 
 # remove previous $seqres.full before test
 rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs nfs
 _supported_os Linux
 _require_test_nfs_version 4
@@ -57,6 +45,4 @@ $NFS4_SETFACL_PROG -S $acltest.list $acltest.file
 $NFS4_GETFACL_PROG $acltest.file >>$seqres.full 2>&1
 $NFS4_GETFACL_PROG $acltest.file | wc -l
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/ocfs2/001 b/tests/ocfs2/001
index af304b8281a3..ad4ed58cd875 100755
--- a/tests/ocfs2/001
+++ b/tests/ocfs2/001
@@ -6,34 +6,21 @@
 #
 # Ensure that reflink works correctly with inline-data files.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1    # failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    cd /
-    rm -rf $tmp.*
-}
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# include test specific environments here
 . ./common/reflink
-
-# real QA test starts here
 _supported_os Linux
 _supported_fs ocfs2
 _require_scratch_reflink
 _require_cp_reflink
 
-rm -f $seqres.full
-
 echo "Format and mount"
 _scratch_mkfs --fs-features=local,unwritten,refcount,inline-data > $seqres.full 2>&1
 tunefs.ocfs2 --query '%H' $SCRATCH_DEV | grep -q 'inline-data' || \
@@ -69,6 +56,4 @@ echo "Verify the whole mess"
 _scratch_cycle_mount
 md5sum $testdir/file* | _filter_scratch
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/perf/001 b/tests/perf/001
index 5a6d9b29cb93..b28081eb1872 100755
--- a/tests/perf/001
+++ b/tests/perf/001
@@ -6,30 +6,26 @@
 #
 # Buffered random write performance test.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-fio_config=$tmp.fio
-fio_results=$tmp.json
-status=1	# failure is the default!
-trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-. ./common/perf
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
+. ./common/perf
 _supported_fs generic
 _supported_os Linux
 _require_scratch
 _require_block_device $SCRATCH_DEV
 _require_fio_results
 
-rm -f $seqres.full
+echo "Silence is golden"
+
+fio_config=$tmp.fio
+fio_results=$tmp.json
 
 _size=$((16 * $LOAD_FACTOR))
 cat >$fio_config <<EOF
@@ -60,5 +56,5 @@ $FIO_PROG --output-format=json --output=$fio_results $fio_config
 _scratch_unmount
 cat $fio_results >> $seqres.full
 _fio_results_compare $seq $fio_results
-echo "Silence is golden"
-status=0; exit
+
+_success
diff --git a/tests/udf/102 b/tests/udf/102
index acfa85c30387..e3ea7da75f64 100755
--- a/tests/udf/102
+++ b/tests/udf/102
@@ -7,28 +7,17 @@
 # This tests mkfs_udf/mkudffs and the device detection code
 # Modified from UDFQA test 031.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    rm -f $tmp.*
-    cd /
-}
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
-_supported_fs udf 
+# include test specific environments here
+_supported_fs udf
 _supported_os Linux
-
 _require_scratch
 _setup_udf_scratchdir
 
@@ -37,6 +26,4 @@ _check_udf_filesystem $SCRATCH_DEV
 
 echo "Finished"
 
-# success, all done
-status=0
-exit
+_success
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 3/8] shared: use new test setup preamble
  2018-06-27  8:20 [PATCH 0/6] fstests: start factoring test setup boilerplate Dave Chinner
  2018-06-27  8:20 ` [PATCH 1/8] fstests: generic test setup preamble Dave Chinner
  2018-06-27  8:20 ` [PATCH 2/8] tests: convert various test dirs to " Dave Chinner
@ 2018-06-27  8:20 ` Dave Chinner
  2018-06-27 10:56   ` Amir Goldstein
  2018-06-27  8:20 ` [PATCH 4/8] generic: convert some tests to new " Dave Chinner
                   ` (5 subsequent siblings)
  8 siblings, 1 reply; 28+ messages in thread
From: Dave Chinner @ 2018-06-27  8:20 UTC (permalink / raw)
  To: fstests

From: Dave Chinner <dchinner@redhat.com>

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 tests/shared/001 | 33 ++++++++++-----------------------
 tests/shared/002 | 40 ++++++++++++++--------------------------
 tests/shared/003 | 35 ++++++++++-------------------------
 tests/shared/004 | 27 +++++++--------------------
 tests/shared/005 | 30 ++++++++----------------------
 tests/shared/006 | 35 +++++++++++------------------------
 tests/shared/007 | 30 +++++++++---------------------
 tests/shared/032 | 26 +++++++++-----------------
 tests/shared/272 | 34 ++++++++++++++--------------------
 tests/shared/289 | 31 +++++++------------------------
 tests/shared/298 | 48 ++++++++++++++++++++++--------------------------
 11 files changed, 121 insertions(+), 248 deletions(-)

diff --git a/tests/shared/001 b/tests/shared/001
index bde6e1987d90..80caa30e7f71 100755
--- a/tests/shared/001
+++ b/tests/shared/001
@@ -9,31 +9,19 @@
 #
 # 721e3eb ext4: lock i_mutex when truncating orphan inodes
 #
-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
-
-# real QA test starts here
+. common/setup_test
+
+# test exit cleanup goes here
+cleanup() { :; }
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
 _supported_fs ext2 ext3 ext4
 _supported_os Linux
 _require_scratch
 
-rm -f $seqres.full
 echo "Silence is golden"
 
 _scratch_mkfs_sized $((16*1024*1024)) >>$seqres.full 2>&1
@@ -52,5 +40,4 @@ debugfs -w -R "set_super_value last_orphan $inode" $SCRATCH_DEV \
 # mount again to truncate orphan inode, _check_dmesg will catch the WARNING
 _scratch_mount
 
-status=0
-exit
+_success
diff --git a/tests/shared/002 b/tests/shared/002
index 30ece3370601..ac7352bffc44 100755
--- a/tests/shared/002
+++ b/tests/shared/002
@@ -10,43 +10,32 @@
 # fsync log/journal is replayed, the xattrs still exist and with the correct
 # values.
 #
+# We create a lot of xattrs for a single file. Only btrfs and xfs are currently
+# able to store such a large mount of xattrs per file, other filesystems such
+# as ext3/4 and f2fs for example, fail with ENOSPC even if we attempt to add
+# less than 1000 xattrs with very small values.
+#
 # This test is motivated by a bug found in btrfs.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-
-_cleanup()
-{
+# test exit cleanup goes here
+cleanup() {
 	_cleanup_flakey
-	rm -f $tmp.*
 }
-trap "_cleanup; exit \$status" 0 1 2 3 15
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
 . ./common/dmflakey
 . ./common/attr
-
-# real QA test starts here
-
-# We create a lot of xattrs for a single file. Only btrfs and xfs are currently
-# able to store such a large mount of xattrs per file, other filesystems such
-# as ext3/4 and f2fs for example, fail with ENOSPC even if we attempt to add
-# less than 1000 xattrs with very small values.
-_supported_fs btrfs xfs
 _supported_os Linux
+_supported_fs btrfs xfs
 _require_scratch
 _require_dm_target flakey
 _require_attrs
 
-rm -f $seqres.full
-
 _scratch_mkfs >> $seqres.full 2>&1
 _require_metadata_journaling $SCRATCH_DEV
 _init_flakey
@@ -94,5 +83,4 @@ for ((i = 1; i <= $num_xattrs; i++)); do
 	echo
 done
 
-status=0
-exit
+_success
diff --git a/tests/shared/003 b/tests/shared/003
index 761b9691d4cc..23501b274101 100755
--- a/tests/shared/003
+++ b/tests/shared/003
@@ -11,34 +11,21 @@
 #
 # Also test on ext2/3.
 #
-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
-
-# real QA test starts here
+. common/setup_test
+
+# test exit cleanup goes here
+cleanup() { :; }
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
 _supported_fs ext2 ext3 ext4
 _supported_os Linux
 
 # nofsck as we modify sb via debugfs
 _require_scratch_nocheck
 
-# remove previous $seqres.full before test
-rm -f $seqres.full
 echo "Silence is golden"
 
 _scratch_mkfs >>$seqres.full 2>&1
@@ -50,6 +37,4 @@ debugfs -w -R "feature +needs_recovery" $SCRATCH_DEV \
 # mount with noload option
 _try_scratch_mount "-o noload" >>$seqres.full 2>&1
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/shared/004 b/tests/shared/004
index 3021c85d51eb..d5fe835ea8a3 100755
--- a/tests/shared/004
+++ b/tests/shared/004
@@ -7,31 +7,20 @@
 # Regression test for commit:
 # c9eb13a ext4: fix hang when processing corrupted orphaned inode list
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-	cd /
-	rm -f $tmp.*
-}
-
-# get standard environment, filters and checks
-. ./common/rc
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs ext2 ext3 ext4
 _supported_os Linux
 _require_scratch
 _require_command "$DEBUGFS_PROG" debugfs
 
-# remove previous $seqres.full before test
-rm -f $seqres.full
 echo "Silence is golden"
 
 # Although the bug only happens when last_orphan is set to 5
@@ -44,6 +33,4 @@ for i in {1..10}; do
 	_scratch_unmount
 done
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/shared/005 b/tests/shared/005
index 67940dd0d0fc..e9df81a67ce8 100755
--- a/tests/shared/005
+++ b/tests/shared/005
@@ -13,33 +13,21 @@
 # So, create this malformed inode and try a buffered append to make
 # sure we catch this situation.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-PIDS=""
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-	rm -f $tmp.*
-}
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
-_supported_os Linux
+# include test specific environments here
 _supported_fs ext2 ext3 ext4
+_supported_os Linux
 _require_scratch_nocheck
 _disable_dmesg_check
 _require_command "$DEBUGFS_PROG"
 
-rm -f $seqres.full
-
 echo "Format and mount"
 _scratch_mkfs  >> $seqres.full 2>&1
 _scratch_mount
@@ -60,6 +48,4 @@ _scratch_mount
 dd if=/dev/zero of=$testdir/a bs=512 count=1 oflag=append conv=notrunc >> $seqres.full 2>&1 || echo "Write did not succeed (ok)."
 sync
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/shared/006 b/tests/shared/006
index aa65e9a29e7b..d7a8cd9c6b6b 100755
--- a/tests/shared/006
+++ b/tests/shared/006
@@ -9,20 +9,18 @@
 # Also a regression test for xfsprogs commit
 # d586858 xfs_repair: fix sibling pointer tests in verify_dir2_path()
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    cd /
-    rm -f $tmp.*
-}
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
+_supported_fs ext4 ext3 ext2 xfs
+_supported_os Linux
+_require_scratch
 
 create_file()
 {
@@ -37,17 +35,7 @@ create_file()
 	done
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
 
-# real QA test starts here
-_supported_fs ext4 ext3 ext2 xfs
-_supported_os Linux
-
-_require_scratch
-
-rm -f $seqres.full
 echo "Silence is golden"
 
 _scratch_mkfs_sized $((1024 * 1024 * 1024)) >>$seqres.full 2>&1
@@ -77,5 +65,4 @@ rm -rf $SCRATCH_MNT/testdir
 echo "Inode status after deleting all test files" >>$seqres.full
 $DF_PROG -i $SCRATCH_MNT >>$seqres.full
 
-status=0
-exit
+_success
diff --git a/tests/shared/007 b/tests/shared/007
index 65cb5273b6a0..a552c1aba3aa 100755
--- a/tests/shared/007
+++ b/tests/shared/007
@@ -13,32 +13,22 @@
 # So, create this malformed inode and try a dio append to make sure we
 # catch this situation.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-PIDS=""
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
-
-_cleanup()
-{
-	rm -f $tmp.*
-}
+# test exit cleanup goes here
+cleanup() { :; }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
-_supported_os Linux
+# include test specific environments here
 _supported_fs ext2 ext3 ext4
+_supported_os Linux
 _require_scratch_nocheck
 _disable_dmesg_check
 _require_command "$DEBUGFS_PROG"
 
-rm -f $seqres.full
+PIDS=""
 
 echo "Format and mount"
 _scratch_mkfs  >> $seqres.full 2>&1
@@ -62,6 +52,4 @@ _scratch_mount
 dd if=/dev/zero of=$testdir/a bs=512 count=1 oflag=direct,append conv=notrunc >> $seqres.full 2>&1 || echo "Write did not succeed (ok)."
 sync
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/shared/032 b/tests/shared/032
index 3b0263b2ce78..ef0dc936b31e 100755
--- a/tests/shared/032
+++ b/tests/shared/032
@@ -6,34 +6,28 @@
 #
 # cross check mkfs detection of foreign filesystems
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
-rm -f $seqres.full
+# test exit cleanup goes here
+cleanup() { :; }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs xfs btrfs
 _supported_os Linux
-
 _require_scratch_nocheck
 _require_no_large_scratch_dev
 
+echo "Silence is golden."
+
 # mkfs.btrfs did not have overwrite detection at first
 if [ "$FSTYP" == "btrfs" ]; then
 	grep -q 'force overwrite' `echo $MKFS_BTRFS_PROG | awk '{print $1}'` || \
 		_notrun "Installed mkfs.btrfs does not support -f option"
 fi
 
-echo "Silence is golden."
 for fs in `echo ${MKFS_PROG}.* | sed -e "s:${MKFS_PROG}.::g"`
 do
 	preop=""	# for special input needs
@@ -75,6 +69,4 @@ do
 	fi
 done
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/shared/272 b/tests/shared/272
index b94dfc3c3d87..5c694308ae6b 100755
--- a/tests/shared/272
+++ b/tests/shared/272
@@ -6,21 +6,23 @@
 #
 # Test data journaling flag switch for a single file  
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
+_supported_fs ext3 ext4
+_supported_os Linux
+_require_scratch
+_exclude_scratch_mount_option dax
 
 # ext3 and ext4 don't support direct IO in journalling mode
 write_opt_list="iflag=noatime conv=notrunc conv=fsync"
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
 _workout()
 {
 	echo "Switch data journalling mode. Silence is golden."
@@ -32,7 +34,6 @@ _workout()
 		idx=$((idx + 1))
 		for chattr_opt in $chattr_opt_list
 		do
-		    
 			echo "OP write_opt: $write_opt 4M, \
 chattr_opt: $chattr_opt" >>$seqres.full
 			dd if=/dev/zero of=$SCRATCH_MNT/file.$idx \
@@ -63,13 +64,6 @@ chattr_opt: $chattr_opt" >>$seqres.full
 	done
 }
 
-# real QA test starts here
-_supported_fs ext3 ext4
-_supported_os Linux
-_require_scratch
-_exclude_scratch_mount_option dax
-
-rm -f $seqres.full
 _scratch_mkfs_sized $((64 * 1024 * 1024)) >> $seqres.full 2>&1
 _scratch_mount
 
@@ -86,5 +80,5 @@ if ! _scratch_unmount; then
 	exit
 fi
 echo "Check filesystem"
-status=0
-exit
+
+_success
diff --git a/tests/shared/289 b/tests/shared/289
index 94b644302b2d..7466fc2726f2 100755
--- a/tests/shared/289
+++ b/tests/shared/289
@@ -6,34 +6,19 @@
 #
 # Test overhead & df output for extN filesystems
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    cd /
-    rm -f $tmp.*
-}
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-
-# real QA test starts here
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# Modify as appropriate.
+# include test specific environments here
 _supported_fs ext2 ext3 ext4
 _supported_os Linux
 _require_scratch
 
-rm -f $seqres.full
-
 _scratch_mkfs >> $seqres.full 2>&1
 
 # Get the honest truth about block counts straight from metadata on disk
@@ -79,6 +64,4 @@ _within_tolerance "minix f_blocks" $MINIX_F_BLOCKS $TOTAL_BLOCKS 0 -v
 # bsd should be within ... we'll say 1% for some slop
 _within_tolerance "bsd f_blocks" $BSD_F_BLOCKS $(($TOTAL_BLOCKS-$OVERHEAD)) 1% -v
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/shared/298 b/tests/shared/298
index e7b7b233de45..fc2d090a2f66 100755
--- a/tests/shared/298
+++ b/tests/shared/298
@@ -6,15 +6,22 @@
 #
 # Test that filesystem sends discard requests only on free blocks
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() {
+	$UMOUNT_PROG $loop_dev &> /dev/null
+	_destroy_loop_device $loop_dev
+	if [ $status -eq 0 ]; then
+		rm $img_file
+		rm -rf $workdir
+	fi
+}
 
-. ./common/rc
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
+# include test specific environments here
 _supported_fs ext4 xfs
 _supported_os Linux
 _require_test
@@ -24,15 +31,8 @@ _require_xfs_io_command "fiemap"
 _require_fs_space $TEST_DIR 307200
 [ "$FSTYP" = "ext4" ] && _require_dumpe2fs
 
-_cleanup()
-{
-	$UMOUNT_PROG $loop_dev &> /dev/null
-	_destroy_loop_device $loop_dev
-	if [ $status -eq 0 ]; then
-		rm -rf $tmp
-		rm $img_file
-	fi
-}
+workdir=$TEST_DIR/$$
+mkdir -p $workdir
 
 get_holes()
 {
@@ -70,7 +70,7 @@ merge_ranges()
 	file1=$1
 	file2=$2
 
-	tmp_file=$tmp/sectors.tmp
+	tmp_file=$workdir/sectors.tmp
 
 	cat $file1 $file2 | sort -n > $tmp_file
 
@@ -101,19 +101,16 @@ merge_ranges()
 	rm $tmp_file
 }
 
-here=`pwd`
-tmp=`mktemp -d`
-
 img_file=$TEST_DIR/$$.fs
 dd if=/dev/zero of=$img_file bs=1M count=300 &> /dev/null
 
 loop_dev=$(_create_loop_device $img_file)
-loop_mnt=$tmp/loop_mnt
+loop_mnt=$workdir/loop_mnt
 
-fiemap_ref="$tmp/reference"
-fiemap_after="$tmp/after"
-free_sectors="$tmp/free_sectors"
-merged_sectors="$tmp/merged_free_sectors"
+fiemap_ref="$workdir/reference"
+fiemap_after="$workdir/after"
+free_sectors="$workdir/free_sectors"
+merged_sectors="$workdir/merged_free_sectors"
 
 mkdir $loop_mnt
 
@@ -173,5 +170,4 @@ while read line; do
 done < $fiemap_after
 echo "done."
 
-status=0
-exit
+_success
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 4/8] generic: convert some tests to new setup preamble
  2018-06-27  8:20 [PATCH 0/6] fstests: start factoring test setup boilerplate Dave Chinner
                   ` (2 preceding siblings ...)
  2018-06-27  8:20 ` [PATCH 3/8] shared: use new test " Dave Chinner
@ 2018-06-27  8:20 ` Dave Chinner
  2018-06-27 11:08   ` Amir Goldstein
  2018-07-07 11:28   ` Eryu Guan
  2018-06-27  8:21 ` [PATCH 5/8] btrfs: " Dave Chinner
                   ` (4 subsequent siblings)
  8 siblings, 2 replies; 28+ messages in thread
From: Dave Chinner @ 2018-06-27  8:20 UTC (permalink / raw)
  To: fstests

From: Dave Chinner <dchinner@redhat.com>

Small initial batch to demonstrate conversion.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 tests/generic/001 | 49 +++++++++++++++++------------------------------
 tests/generic/002 | 25 +++++++-----------------
 tests/generic/003 | 30 ++++++++---------------------
 tests/generic/004 | 32 +++++++++----------------------
 tests/generic/005 | 44 ++++++++++++++++--------------------------
 tests/generic/006 | 34 ++++++++++++--------------------
 tests/generic/007 | 29 ++++++++--------------------
 tests/generic/008 | 27 +++++++++-----------------
 tests/generic/009 | 28 +++++++++------------------
 9 files changed, 97 insertions(+), 201 deletions(-)

diff --git a/tests/generic/001 b/tests/generic/001
index 046e54e374a4..58ef45ed7102 100755
--- a/tests/generic/001
+++ b/tests/generic/001
@@ -15,25 +15,29 @@
 # config has one line per file with filename and byte size, else use
 # the default one below.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# test exit cleanup goes here
+cleanup() {
+    if $done_cleanup ; then
+	:
+    elif [ $status -eq 0 ]; then
+	$verbose && echo "cleanup"
+	cd /
+	rm -rf $TEST_DIR/$$
+	done_cleanup=true
+    fi
+}
 
-tmp=/tmp/$$
-here=`pwd`
-status=1
-done_cleanup=false
-trap "_cleanup; rm -f $tmp.*; exit \$status" 0 1 2 3 15
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs generic
 _supported_os Linux
 _require_test
 
+done_cleanup=false
 verbose=true
 verify=$here/verify_fill
 
@@ -260,25 +264,9 @@ _check()
     $verbose && echo
 }
 
-_cleanup()
-{
-    # cleanup
-    #
-    if $done_cleanup
-    then
-	:
-    elif [ $status -eq 0 ]
-    then
-	$verbose && echo "cleanup"
-	cd /
-	rm -rf $TEST_DIR/$$
-	done_cleanup=true
-    fi
-}
-
 rm -f $seqres.full
 status=0
-_cleanup
+cleanup
 status=1
 done_cleanup=false
 
@@ -299,5 +287,4 @@ do
     fi
 done
 
-status=0
-exit
+_success
diff --git a/tests/generic/002 b/tests/generic/002
index 8242ea907c1b..9943a077fe6b 100755
--- a/tests/generic/002
+++ b/tests/generic/002
@@ -6,31 +6,20 @@
 #
 # simple inode link count test for a regular file
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# test exit cleanup goes here
+cleanup() { :; }
 
-tmp=/tmp/$$
-here=`pwd`
-status=0	# success is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
 
-_cleanup()
-{
-    rm -f $tmp.*
-}
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs generic
 _supported_os Linux
 _require_test
 
-rm -f $seqres.full
-
 echo "Silence is goodness ..."
 
 # ensure target directory exists
@@ -62,4 +51,4 @@ do
 done
 
 # success, all done
-exit
+_success
diff --git a/tests/generic/003 b/tests/generic/003
index 767d70593c3f..d928b9392686 100755
--- a/tests/generic/003
+++ b/tests/generic/003
@@ -9,34 +9,22 @@
 # never updated on read-only subvolumes. (Regression test for bug fixed
 # with commit 93fd63c2f001ca6797c6b15b696a484b165b4800)
 #
-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 -rf $tmp.*
-}
+. common/setup_test
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# test exit cleanup goes here
+cleanup() { :; }
 
-# real QA test starts here
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
+# include test specific environments here
 _supported_fs generic
 _supported_os Linux
 _require_scratch
 _require_atime
 _require_relatime
 
-rm -f $seqres.full
+echo "Silence is golden"
 
 _stat() {
 	stat -c "%x;%y;%z" $1
@@ -189,6 +177,4 @@ _compare_stat_times NNN "$file3_stat_before_ro_mount" \
 
 # success, all done
 _scratch_unmount
-echo "Silence is golden"
-status=0
-exit
+_success
diff --git a/tests/generic/004 b/tests/generic/004
index 156d68aee19f..a4d3d5d9d32e 100755
--- a/tests/generic/004
+++ b/tests/generic/004
@@ -6,35 +6,23 @@
 #
 # Test O_TMPFILE opens, and linking them back into the namespace.
 #
-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 ${testfile}
+. common/setup_test
+
+# test exit cleanup goes here
+cleanup() {
+	rm -f ${testfile}
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs generic
 _supported_os Linux
-
 _require_test
 _require_xfs_io_command "-T"
 _require_xfs_io_command "flink"
 
-rm -f $seqres.full
-
 testfile="${TEST_DIR}/tst-tmpfile-flink"
 
 # test creating a r/w tmpfile, do I/O and link it into the namespace
@@ -49,6 +37,4 @@ rm ${testfile}
 # test creating a r/o tmpfile.  Should fail
 $XFS_IO_PROG -Tr ${TEST_DIR} -c "close" 2>&1 | _filter_test_dir
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/generic/005 b/tests/generic/005
index 118fca20ed5d..ceff4117319e 100755
--- a/tests/generic/005
+++ b/tests/generic/005
@@ -9,28 +9,29 @@
 #
 # Note: On Linux, ELOOP limit used to be 32 but changed to 8, and lately
 # its become 5.  Who knows what it might be next.
-# 
+#
 # What we are looking for here is: no panic due to blowing the stack;
 # and that the ELOOP error code is returned at some point (the actual
 # limit point is unimportant, just checking that we do hit it).
-# 
-
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+#
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=0	# success is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() {
+    rm -f $TEST_DIR/symlink_{0,1,2,3,4}{0,1,2,3,4,5,6,7,8,9}
+    rm -f $TEST_DIR/symlink_self empty_file
 
-_cleanup()
-{
-    cd $TEST_DIR
-    rm -f symlink_{0,1,2,3,4}{0,1,2,3,4,5,6,7,8,9} symlink_self empty_file
-    cd /
 }
 
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
+_supported_fs generic
+_supported_os Linux
+_require_test
+_require_test_symlinks
+
 _touch()
 {
     touch $@ 2>&1 | grep -q 'Too many levels of symbolic links'
@@ -41,17 +42,6 @@ _touch()
     fi
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-
-# real QA test starts here
-_supported_fs generic
-_require_test
-_require_test_symlinks
-
-_supported_os Linux
-
 cd $TEST_DIR
 
 o=empty_file
@@ -72,4 +62,4 @@ echo "*** touch recusive symlinks"
 echo ""
 _touch symlink_self
 
-exit
+_success
diff --git a/tests/generic/006 b/tests/generic/006
index ba99324a5846..9511aeb0b026 100755
--- a/tests/generic/006
+++ b/tests/generic/006
@@ -6,22 +6,21 @@
 #
 # permname
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=0	# success is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
-
-_cleanup()
-{
-    cd /
-    rm -f $tmp.*
+# test exit cleanup goes here
+cleanup() {
     rm -rf $TEST_DIR/permname.$$
 }
 
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
+_supported_fs generic
+_supported_os Linux
+_require_test
+
 _count()
 {
     $AWK_PROG '
@@ -31,15 +30,6 @@ _count()
     '
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-
-# real QA test starts here
-_supported_fs generic
-_supported_os Linux
-_require_test
-
 mkdir $TEST_DIR/permname.$$
 
 echo ""
@@ -58,4 +48,4 @@ cd $TEST_DIR/permname.$$/b
 $here/src/permname -c 4 -l 6 -p 4 || echo "permname returned $?"
 find . | _count
 
-exit
+_success
diff --git a/tests/generic/007 b/tests/generic/007
index 9780e12e9e69..7a40418cdd56 100755
--- a/tests/generic/007
+++ b/tests/generic/007
@@ -9,32 +9,21 @@
 # and checks that error codes make sense with its
 # memory of the files created.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=0	# success is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
-
-_cleanup()
-{
-    cd /
-    rm -f $tmp.*
-    rm -rf $TEST_DIR/$seq
+# test exit cleanup goes here
+cleanup() {
+	rm -rf $TEST_DIR/$seq
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs generic
 _supported_os Linux
 _require_test
 
-status=1 # default failure 
 sourcefile=$tmp.nametest
 seed=1
 iterations=100000
@@ -53,6 +42,4 @@ mkdir $TEST_DIR/$seq
 cd $TEST_DIR/$seq
 $here/src/nametest -l $sourcefile -s $seed -i $iterations -z
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/generic/008 b/tests/generic/008
index 7d86c602a241..386c59d2e106 100755
--- a/tests/generic/008
+++ b/tests/generic/008
@@ -9,25 +9,18 @@
 # Primarily tests page boundries and boundries that are
 #  off-by-one to ensure we're only tossing what's expected
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-. ./common/punch
-
-# real QA test starts here
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# Modify as appropriate.
+# include test specific environments here
+. ./common/punch
+_supported_fs generic
 _supported_os Linux
-
 _require_xfs_io_command "fzero"
 _require_test
 
@@ -38,6 +31,4 @@ _test_block_boundaries 2048 fzero _filter_xfs_io_unique $testfile
 _test_block_boundaries 4096 fzero _filter_xfs_io_unique $testfile
 _test_block_boundaries 65536 fzero _filter_xfs_io_unique $testfile
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/generic/009 b/tests/generic/009
index fa6ef4664c66..124e502b23f0 100755
--- a/tests/generic/009
+++ b/tests/generic/009
@@ -6,32 +6,22 @@
 #
 # Test fallocate FALLOC_FL_ZERO_RANGE
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    rm -f $tmp.*
-}
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-trap "_cleanup ; exit \$status" 0 1 2 3 15
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# include test specific environments here
 . ./common/punch
-
-# real QA test starts here
+_supported_fs generic
 _supported_os Linux
+_require_test
 _require_xfs_io_command "fzero"
 _require_xfs_io_command "fiemap"
 _require_xfs_io_command "falloc"
-_require_test
 
 testfile=$TEST_DIR/009.$$
 
@@ -61,4 +51,4 @@ _test_generic_punch -k falloc fzero fzero fiemap _filter_fiemap $testfile
 # Delayed allocation multi zero range tests
 _test_generic_punch -d -k falloc fzero fzero fiemap _filter_fiemap $testfile
 
-status=0 ; exit
+_success
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 5/8] btrfs: convert some tests to new setup preamble
  2018-06-27  8:20 [PATCH 0/6] fstests: start factoring test setup boilerplate Dave Chinner
                   ` (3 preceding siblings ...)
  2018-06-27  8:20 ` [PATCH 4/8] generic: convert some tests to new " Dave Chinner
@ 2018-06-27  8:21 ` Dave Chinner
  2018-06-27 11:30   ` Amir Goldstein
  2018-07-07 11:22   ` Eryu Guan
  2018-06-27  8:21 ` [PATCH 6/8] ext4: " Dave Chinner
                   ` (3 subsequent siblings)
  8 siblings, 2 replies; 28+ messages in thread
From: Dave Chinner @ 2018-06-27  8:21 UTC (permalink / raw)
  To: fstests

From: Dave Chinner <dchinner@redhat.com>

Small initial batch to demonstrate conversion.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 tests/btrfs/001 | 25 ++++++----------------
 tests/btrfs/002 | 28 ++++++++----------------
 tests/btrfs/003 | 41 ++++++++++++++---------------------
 tests/btrfs/004 | 24 ++++++---------------
 tests/btrfs/005 | 51 +++++++++++++++++--------------------------
 tests/btrfs/006 | 30 ++++++--------------------
 tests/btrfs/007 | 57 +++++++++++++++++++------------------------------
 tests/btrfs/008 | 30 +++++++++-----------------
 tests/btrfs/009 | 29 +++++++------------------
 9 files changed, 105 insertions(+), 210 deletions(-)

diff --git a/tests/btrfs/001 b/tests/btrfs/001
index b13a2470a0ed..771971135937 100755
--- a/tests/btrfs/001
+++ b/tests/btrfs/001
@@ -6,27 +6,16 @@
 #
 # Test btrfs's subvolume and snapshot support
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    rm -f $tmp.*
-}
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-trap "_cleanup ; exit \$status" 0 1 2 3 15
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# include test specific environments here
 . ./common/filter.btrfs
-
-# real QA test starts here
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
@@ -90,4 +79,4 @@ _scratch_cycle_mount
 echo "List root dir"
 ls $SCRATCH_MNT
 
-status=0 ; exit
+_success
diff --git a/tests/btrfs/002 b/tests/btrfs/002
index 87e21c02f68c..5d6b106bc090 100755
--- a/tests/btrfs/002
+++ b/tests/btrfs/002
@@ -6,29 +6,21 @@
 #
 # Extented btrfs snapshot test cases
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    rm -f $tmp.*
-}
-
-trap "_cleanup ; exit \$status" 0 1 2 3 15
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
+# include test specific environments here
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
 
+echo "Silence is golden"
+
 _scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed"
 _scratch_mount
 
@@ -169,6 +161,4 @@ _save_checksum $SNAPNAME $tmp.$tname.sum
 _verify_checksum $SNAPNAME $tmp.$tname.sum
 
 _scratch_unmount || _fail "unmount failed"
-
-echo "Silence is golden"
-status=0; exit
+_success
diff --git a/tests/btrfs/003 b/tests/btrfs/003
index 22aa57aad0b9..dac7ed919711 100755
--- a/tests/btrfs/003
+++ b/tests/btrfs/003
@@ -6,31 +6,20 @@
 #
 # btrfs vol tests
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
-
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-dev_removed=0
-removed_dev_htl=""
-trap "_cleanup; exit \$status" 0 1 2 3 15
-
-_cleanup()
-{
-    cd /
-    rm -f $tmp.*
-    if [ $dev_removed == 1 ]; then
-	_scratch_unmount
-	_devmgt_add "${removed_dev_htl}"
-    fi
+. common/setup_test
+
+# test exit cleanup goes here
+cleanup() {
+	if [ $dev_removed == 1 ]; then
+		_scratch_unmount
+		_devmgt_add "${removed_dev_htl}"
+	fi
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
+# include test specific environments here
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
@@ -38,7 +27,10 @@ _require_scratch_dev_pool 4
 _require_deletable_scratch_dev_pool
 _require_command "$WIPEFS_PROG" wipefs
 
-rm -f $seqres.full
+echo "Silence is golden"
+
+dev_removed=0
+removed_dev_htl=""
 
 # Test cases related to raid in btrfs
 _test_raid0()
@@ -172,5 +164,4 @@ _test_add
 _test_replace
 _test_remove
 
-echo "Silence is golden"
-status=0; exit
+_success
diff --git a/tests/btrfs/004 b/tests/btrfs/004
index 3f61a8f46140..99dd1f768d81 100755
--- a/tests/btrfs/004
+++ b/tests/btrfs/004
@@ -9,28 +9,18 @@
 # run filefrag to get the extent mapping and follow the backrefs.
 # We check to end up back at the original file with the correct offset.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1
-noise_pid=0
-
-_cleanup()
-{
+# test exit cleanup goes here
+cleanup() {
 	rm $tmp.running
 	wait
-	rm -f $tmp.*
 }
-trap "_cleanup; exit \$status" 0 1 2 3 15
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
@@ -39,7 +29,7 @@ _require_btrfs_command inspect-internal logical-resolve
 _require_btrfs_command inspect-internal inode-resolve
 _require_command "$FILEFRAG_PROG" filefrag
 
-rm -f $seqres.full
+noise_pid=0
 
 FILEFRAG_FILTER='
 	if (/blocks? of (\d+) bytes/) {
diff --git a/tests/btrfs/005 b/tests/btrfs/005
index 15af46783298..4cebb57fbaba 100755
--- a/tests/btrfs/005
+++ b/tests/btrfs/005
@@ -6,22 +6,26 @@
 #
 # Btrfs Online defragmentation tests
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
-here="`pwd`"
-tmp=/tmp/$$
-cnt=119
-filesize=48000
+. common/setup_test
 
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    cd /
-    rm -f $tmp.*
-}
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
+. ./common/defrag
+_supported_fs btrfs
+_supported_os Linux
+_require_scratch
+
+_scratch_mkfs >/dev/null 2>&1
+_scratch_mount
+_require_defrag
+
+cnt=119
+filesize=48000
 
 _create_file()
 {
@@ -111,22 +115,6 @@ _rundefrag()
 	_check_scratch_fs
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-. ./common/defrag
-
-# real QA test starts here
-_supported_fs btrfs
-_supported_os Linux
-_require_scratch
-
-rm -f $seqres.full
-
-_scratch_mkfs >/dev/null 2>&1
-_scratch_mount
-_require_defrag
-
 echo "defrag object | defragment range | defragment compress"
 echo "a single file | default | off"
 _rundefrag 1 1 1
@@ -155,5 +143,4 @@ _rundefrag 2 1 1
 echo "a filesystem | default | off"
 _rundefrag 3 1 1
 
-status=0
-exit
+_success
diff --git a/tests/btrfs/006 b/tests/btrfs/006
index 3edbb25a72a8..8eed1a2a1221 100755
--- a/tests/btrfs/006
+++ b/tests/btrfs/006
@@ -7,35 +7,21 @@
 # run basic btrfs information commands in various ways
 # sanity tests: filesystem show, label, sync, and device stats
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "== QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    cd /
-    rm -f $tmp.*
-}
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# get standard environment, filters and checks
-. ./common/rc
+# include test specific environments here
 . ./common/filter.btrfs
-
-# real QA test starts here
-
-# Modify as appropriate.
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
 _require_scratch_dev_pool
 
-rm -f $seqres.full
-
 FIRST_POOL_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
 LAST_POOL_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $NF}'`
 TOTAL_DEVS=`echo $SCRATCH_DEV_POOL | wc -w`
@@ -83,6 +69,4 @@ $BTRFS_UTIL_PROG device stats $LAST_POOL_DEV | \
     sed -e "s,$LAST_POOL_DEV,LAST_POOL_DEV,g" | \
     _filter_spaces
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/btrfs/007 b/tests/btrfs/007
index 09f2f011bc77..50ead03acf31 100755
--- a/tests/btrfs/007
+++ b/tests/btrfs/007
@@ -9,37 +9,23 @@
 # (incr) and send both snapshots to a temp file. Remake the file
 # system and receive from the files. Check both states with fssum.
 #
-# creator
-owner=list.btrfs@jan-o-sch.net
+. common/setup_test
 
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+# test exit cleanup goes here
+cleanup() { :; }
 
-tmp=`mktemp -d`
-status=1
-
-_cleanup()
-{
-	echo "*** unmount"
-	_scratch_unmount 2>/dev/null
-	rm -f $tmp.*
-}
-trap "_cleanup; exit \$status" 0 1 2 3 15
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
+_supported_fs generic
+_supported_os Linux
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
 _require_fssum
 _require_seek_data_hole
 
-rm -f $seqres.full
-
 workout()
 {
 	fsz=$1
@@ -57,18 +43,18 @@ workout()
 
 	_run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr
 
-	echo "# $BTRFS_UTIL_PROG send $SCRATCH_MNT/base > $tmp/base.snap" \
+	echo "# $BTRFS_UTIL_PROG send $SCRATCH_MNT/base > $tmp.base.snap" \
 		>> $seqres.full
-	$BTRFS_UTIL_PROG send $SCRATCH_MNT/base > $tmp/base.snap 2>> $seqres.full \
+	$BTRFS_UTIL_PROG send $SCRATCH_MNT/base > $tmp.base.snap 2>> $seqres.full \
 		|| _fail "failed: '$@'"
 	echo "# $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base\
-		$SCRATCH_MNT/incr > $tmp/incr.snap" >> $seqres.full
+		$SCRATCH_MNT/incr > $tmp.incr.snap" >> $seqres.full
 	$BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base \
-		$SCRATCH_MNT/incr > $tmp/incr.snap 2>> $seqres.full \
+		$SCRATCH_MNT/incr > $tmp.incr.snap 2>> $seqres.full \
 		|| _fail "failed: '$@'"
 
-	run_check $FSSUM_PROG -A -f -w $tmp/base.fssum $SCRATCH_MNT/base
-	run_check $FSSUM_PROG -A -f -w $tmp/incr.fssum -x $SCRATCH_MNT/incr/base \
+	run_check $FSSUM_PROG -A -f -w $tmp.base.fssum $SCRATCH_MNT/base
+	run_check $FSSUM_PROG -A -f -w $tmp.incr.fssum -x $SCRATCH_MNT/incr/base \
 		$SCRATCH_MNT/incr
 
 	_scratch_unmount >/dev/null 2>&1
@@ -78,11 +64,11 @@ workout()
 		|| _fail "size=$fsz mkfs failed"
 	_scratch_mount "-o noatime"
 
-	_run_btrfs_util_prog receive $SCRATCH_MNT < $tmp/base.snap
-	run_check $FSSUM_PROG -r $tmp/base.fssum $SCRATCH_MNT/base
+	_run_btrfs_util_prog receive $SCRATCH_MNT < $tmp.base.snap
+	run_check $FSSUM_PROG -r $tmp.base.fssum $SCRATCH_MNT/base
 
-	_run_btrfs_util_prog receive $SCRATCH_MNT < $tmp/incr.snap
-	run_check $FSSUM_PROG -r $tmp/incr.fssum $SCRATCH_MNT/incr
+	_run_btrfs_util_prog receive $SCRATCH_MNT < $tmp.incr.snap
+	run_check $FSSUM_PROG -r $tmp.incr.fssum $SCRATCH_MNT/incr
 }
 
 echo "*** test send / receive"
@@ -91,7 +77,8 @@ fssize=`expr 2000 \* 1024 \* 1024`
 ops=200
 
 workout $fssize $ops
-
+echo "*** unmount"
+_scratch_unmount 2>/dev/null
 echo "*** done"
-status=0
-exit
+
+_success
diff --git a/tests/btrfs/008 b/tests/btrfs/008
index e7609de47580..288f6b97fdc0 100755
--- a/tests/btrfs/008
+++ b/tests/btrfs/008
@@ -6,37 +6,27 @@
 #
 # btrfs send ENOENT regression test, from a user report on linux-btrfs
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-tmp_dir=send_temp_$seq
-
-status=1	# failure is the default!
-
-_cleanup()
-{
+# test exit cleanup goes here
+cleanup() {
 	$BTRFS_UTIL_PROG subvolume delete $TEST_DIR/$tmp_dir/send/snapshots/backup2 > /dev/null 2>&1
 	$BTRFS_UTIL_PROG subvolume delete $TEST_DIR/$tmp_dir/send/snapshots/backup3 > /dev/null 2>&1
 	$BTRFS_UTIL_PROG subvolume delete $TEST_DIR/$tmp_dir/send > /dev/null 2>&1
 	rm -rf $TEST_DIR/$tmp_dir
-	rm -f $tmp.*
 }
 
-trap "_cleanup ; exit \$status" 0 1 2 3 15
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs btrfs
 _supported_os Linux
 _require_test
 _require_scratch
 
+echo "Silence is golden"
+
 _scratch_mkfs > /dev/null 2>&1
 
 #receive needs to be able to setxattrs, including the selinux context, if we use
@@ -46,6 +36,7 @@ export SELINUX_MOUNT_OPTIONS=""
 
 _scratch_mount
 
+tmp_dir=send_temp_$seq
 mkdir $TEST_DIR/$tmp_dir
 $BTRFS_UTIL_PROG subvolume create $TEST_DIR/$tmp_dir/send \
 	> $seqres.full 2>&1 || _fail "failed subvol create"
@@ -66,5 +57,4 @@ $BTRFS_UTIL_PROG send -f $TEST_DIR/$tmp_dir/blah $work_dir/snapshots/backup3 \
 $BTRFS_UTIL_PROG receive -vvvv -f $TEST_DIR/$tmp_dir/blah $SCRATCH_MNT \
 	>> $seqres.full 2>&1 || _fail "receive failed"
 
-echo "Silence is golden"
-status=0 ; exit
+_success
diff --git a/tests/btrfs/009 b/tests/btrfs/009
index 8b6e864f3ea8..3c11ba94921f 100755
--- a/tests/btrfs/009
+++ b/tests/btrfs/009
@@ -6,32 +6,20 @@
 #
 # Regression test to make sure we can't delete the default subvol
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
+# test exit cleanup goes here
+cleanup() { :; }
 
-status=1	# failure is the default!
-
-_cleanup()
-{
-	rm -f $tmp.*
-}
-
-trap "_cleanup ; exit \$status" 0 1 2 3 15
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs btrfs
 _supported_os Linux
 _require_scratch
 
-rm -f $seqres.full
+echo "Silence is golden"
 
 _scratch_mkfs > /dev/null 2>&1
 _scratch_mount
@@ -45,5 +33,4 @@ $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/newvol >> $seqres.full 2>&1
 _scratch_unmount
 _try_scratch_mount || _fail "mount should have succeeded"
 
-echo "Silence is golden"
-status=0 ; exit
+_success
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 6/8] ext4: convert some tests to new setup preamble
  2018-06-27  8:20 [PATCH 0/6] fstests: start factoring test setup boilerplate Dave Chinner
                   ` (4 preceding siblings ...)
  2018-06-27  8:21 ` [PATCH 5/8] btrfs: " Dave Chinner
@ 2018-06-27  8:21 ` Dave Chinner
  2018-06-27 11:34   ` Amir Goldstein
  2018-07-07 11:25   ` Eryu Guan
  2018-06-27  8:21 ` [PATCH 7/8] overlay: " Dave Chinner
                   ` (2 subsequent siblings)
  8 siblings, 2 replies; 28+ messages in thread
From: Dave Chinner @ 2018-06-27  8:21 UTC (permalink / raw)
  To: fstests

From: Dave Chinner <dchinner@redhat.com>

Small initial batch to demonstrate conversion.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 tests/ext4/001 | 26 +++++++-------------------
 tests/ext4/002 | 41 +++++++++++++----------------------------
 tests/ext4/003 | 25 +++++++------------------
 tests/ext4/004 | 46 ++++++++++++++++------------------------------
 tests/ext4/005 | 29 +++++++----------------------
 tests/ext4/006 | 38 +++++++++++++-------------------------
 tests/ext4/007 | 34 ++++++++++------------------------
 tests/ext4/008 | 28 +++++++---------------------
 tests/ext4/009 | 34 ++++++++++------------------------
 9 files changed, 90 insertions(+), 211 deletions(-)

diff --git a/tests/ext4/001 b/tests/ext4/001
index bf2d16b42b3c..deba9128d833 100755
--- a/tests/ext4/001
+++ b/tests/ext4/001
@@ -6,28 +6,16 @@
 #
 # Test fallocate FALLOC_FL_ZERO_RANGE
 #
-seqfull=$0
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    rm -f $tmp.*
-}
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-trap "_cleanup ; exit \$status" 0 1 2 3 15
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# include test specific environments here
 . ./common/punch
-
-# real QA test starts here
 _supported_fs ext4
 _supported_os Linux
 _require_xfs_io_command "fzero"
@@ -50,4 +38,4 @@ _test_generic_punch -k falloc fzero fzero fiemap _filter_fiemap $testfile
 # Delayed allocation multi zero range tests
 _test_generic_punch -d -k falloc fzero fzero fiemap _filter_fiemap $testfile
 
-status=0 ; exit
+_success
diff --git a/tests/ext4/002 b/tests/ext4/002
index c4fb3bde8ce1..c1324dc04609 100755
--- a/tests/ext4/002
+++ b/tests/ext4/002
@@ -26,26 +26,24 @@
 #
 # Ref: http://thread.gmane.org/gmane.comp.file-systems.ext4/20682
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1        # failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
+_supported_fs ext4
+_supported_os Linux
+_require_xfs_io_command "falloc"
+_require_test
 
 # Test specific macros.
 BIT_NOT_SET=0   # inode flag - 0x400000 bit is not set.
 BIT_SET=1       # inode flag - 0x400000 bit is set.
 
-# Generic test cleanup function.
-_cleanup()
-{
-  cd /
-  rm -f $tmp.*
-}
-
 # Ext4 uses the EOFBLOCKS_FL bit when fallocating blocks with KEEP_SIZE
 # enabled. The only time this bit should be set is when extending the allocated
 # blocks further than what the i_size represents. In the situations wherein the
@@ -97,18 +95,6 @@ _check_ext4_eof_flag()
   fi
 }
 
-# Get standard environment, filters and checks.
-. ./common/rc
-. ./common/filter
-
-# Prerequisites for the test run.
-_supported_fs ext4
-_supported_os Linux
-_require_xfs_io_command "falloc"
-_require_test
-
-# Real QA test starts here.
-rm -f $seqres.full
 
 # Remove any leftover files from last run.
 rm -f ${TEST_DIR}/test_?
@@ -162,5 +148,4 @@ ${XFS_IO_PROG} -f -d                    \
     ${TEST_DIR}/test_6 | _filter_xfs_io_unique
 _check_ext4_eof_flag test_6 ${BIT_NOT_SET}
 
-status=0
-exit ${status}
+_success
diff --git a/tests/ext4/003 b/tests/ext4/003
index 19fe4b4c1f7d..7e5dfca9468e 100755
--- a/tests/ext4/003
+++ b/tests/ext4/003
@@ -8,30 +8,20 @@
 # b5b6077 ext4: fix wrong assert in ext4_mb_normalize_request()
 # This testcase checks whether this bug has been fixed.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    _scratch_unmount
-}
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs ext4
 _supported_os Linux
-
 _require_scratch
 _require_scratch_ext4_feature "bigalloc"
 
-rm -f $seqres.full
-
 $MKFS_EXT4_PROG -F -O bigalloc -C 65536  -g 256 $SCRATCH_DEV 512m \
 	>> $seqres.full 2>&1
 _scratch_mount
@@ -39,5 +29,4 @@ _scratch_mount
 $XFS_IO_PROG -f -c "pwrite 0 256m -b 1M" $SCRATCH_MNT/testfile 2>&1 | \
 	_filter_xfs_io
 
-status=0
-exit
+_success
diff --git a/tests/ext4/004 b/tests/ext4/004
index e34aaa517b61..775afed4bc2c 100755
--- a/tests/ext4/004
+++ b/tests/ext4/004
@@ -6,26 +6,26 @@
 #
 # Test "dump | restore"(as opposed to a tape)
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
-
-_cleanup()
-{
-	cd /
-	rm -f $tmp.*
+# test exit cleanup goes here
+cleanup() {
 	# remove the generated data, which is much and meaningless.
 	rm -rf $restore_dir
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
+_supported_fs ext4
+_supported_os Linux
+_require_test
+_require_scratch
+_require_command "$DUMP_PROG" dump
+_require_command "$RESTORE_PROG" restore
+
+echo "Silence is golden"
 
 dump_dir=$SCRATCH_MNT/dump_restore_dir
 restore_dir=$TEST_DIR/dump_restore_dir
@@ -49,19 +49,6 @@ workout()
 	rm -rf restoresymtable
 }
 
-# real QA test starts here
-_supported_fs ext4
-_supported_os Linux
-
-_require_test
-_require_scratch
-
-_require_command "$DUMP_PROG" dump
-_require_command "$RESTORE_PROG" restore
-
-rm -f $seqres.full
-echo "Silence is golden"
-
 _scratch_mkfs_sized $((512 * 1024 * 1024)) >> $seqres.full 2>&1
 _scratch_mount
 rm -rf $restore_dir $TEST_DIR/restoresymtable
@@ -69,5 +56,4 @@ rm -rf $restore_dir $TEST_DIR/restoresymtable
 workout
 diff -r $dump_dir $restore_dir
 
-status=0
-exit
+_success
diff --git a/tests/ext4/005 b/tests/ext4/005
index db37c2eaa51e..a1e3f08eb1f4 100755
--- a/tests/ext4/005
+++ b/tests/ext4/005
@@ -11,33 +11,20 @@
 # ext4: be more strict when migrating to non-extent based file
 # ext4: correctly migrate a file with a hole at the beginning
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-	cd /
-	rm -f $tmp.*
-}
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs ext4
 _supported_os Linux
 _require_scratch
 _require_command "$CHATTR_PROG" chattr
 
-rm -f $seqres.full
-
 echo "Silence is golden"
 
 _scratch_mkfs >>$seqres.full 2>&1
@@ -63,6 +50,4 @@ $CHATTR_PROG -e $testfile >>$seqres.full 2>&1
 # results in i_blocks corruption
 $XFS_IO_PROG -c "pwrite 0 4k" $testfile >>$seqres.full 2>&1
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/ext4/006 b/tests/ext4/006
index 63e42f58906f..3881090efa51 100755
--- a/tests/ext4/006
+++ b/tests/ext4/006
@@ -8,40 +8,30 @@
 # the kernel reacts, how e2fsck fares in fixing the mess, and then
 # try more kernel accesses to see if it really fixed things.
 #
-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.*
-}
+. common/setup_test
+
+# test exit cleanup goes here
+cleanup() { :; }
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# get standard environment, filters and checks
+# include test specific environments here
 . ./common/rc
 . ./common/filter
 . ./common/attr
 . ./common/populate
 . ./common/fuzzy
-
-if [ ! -x "$(which e2fuzz)" ]; then
-	_notrun "Couldn't find e2fuzz"
-fi
-
-# real QA test starts here
 _supported_fs ext4
 _supported_os Linux
-
 _require_scratch
 _require_attrs
 _require_populate_commands
 
+if [ ! -x "$(which e2fuzz)" ]; then
+	_notrun "Couldn't find e2fuzz"
+fi
+
 repair_scratch() {
 	fsck_pass="$1"
 
@@ -75,7 +65,6 @@ repair_scratch() {
 	return 1
 }
 
-rm -f $seqres.full
 echo "See interesting results in $seqres.full" | sed -e "s,$RESULT_DIR,RESULT_DIR,g"
 SRCDIR=`pwd`
 test -z "${FUZZ_ARGS}" && FUZZ_ARGS="-b 32 -v"
@@ -144,5 +133,4 @@ if [ "$(wc -l < "$ROUND2_LOG")" -ne 8 ]; then
 fi
 echo "finished fuzzing" | tee -a "$seqres.full"
 
-status=0
-exit
+_success
diff --git a/tests/ext4/007 b/tests/ext4/007
index b7f7c6ce517e..be81135b18fa 100755
--- a/tests/ext4/007
+++ b/tests/ext4/007
@@ -7,35 +7,22 @@
 # Create and populate an ext4 filesystem, corrupt the primary superblock, then
 # see how the kernel and e2fsck deal with it.
 #
-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
-. ./common/attr
+. common/setup_test
+
+# test exit cleanup goes here
+cleanup() { :; }
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
+. ./common/attr
 _supported_fs ext4
 _supported_os Linux
-
 _require_scratch
 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
 _require_attrs
 
-rm -f $seqres.full
 TESTDIR="${SCRATCH_MNT}/scratchdir"
 TESTFILE="${TESTDIR}/testfile"
 
@@ -103,5 +90,4 @@ umount "${SCRATCH_MNT}"
 echo "+ check fs (2)"
 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
 
-status=0
-exit
+_success
diff --git a/tests/ext4/008 b/tests/ext4/008
index c553760dd333..6f35511bd366 100755
--- a/tests/ext4/008
+++ b/tests/ext4/008
@@ -7,35 +7,22 @@
 # Create and populate an ext4 filesystem, corrupt a group descriptor, then
 # see how the kernel and e2fsck deal with it.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    cd /
-    #rm -f $tmp.*
-}
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# include test specific environments here
 . ./common/attr
-
-# real QA test starts here
 _supported_fs ext4
 _supported_os Linux
-
 _require_scratch
 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
 _require_attrs
 
-rm -f $seqres.full
 TESTDIR="${SCRATCH_MNT}/scratchdir"
 TESTFILE="${TESTDIR}/testfile"
 
@@ -84,5 +71,4 @@ umount "${SCRATCH_MNT}"
 echo "+ check fs (2)"
 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
 
-status=0
-exit
+_success
diff --git a/tests/ext4/009 b/tests/ext4/009
index 9a2cd0f3c669..94da5e91900a 100755
--- a/tests/ext4/009
+++ b/tests/ext4/009
@@ -7,36 +7,23 @@
 # Create and populate an ext4 filesystem, corrupt a block bitmap, then
 # see how the kernel and e2fsck deal with it.
 #
-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
-. ./common/attr
+. common/setup_test
+
+# test exit cleanup goes here
+cleanup() { :; }
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
+. ./common/attr
 _supported_fs ext4
 _supported_os Linux
-
 _require_xfs_io_command "falloc"
 _require_scratch
 test -n "${FORCE_FUZZ}" || _require_scratch_ext4_crc
 _require_attrs
 
-rm -f $seqres.full
 TESTDIR="${SCRATCH_MNT}/scratchdir"
 TESTFILE="${TESTDIR}/testfile"
 
@@ -94,5 +81,4 @@ umount "${SCRATCH_MNT}"
 echo "+ check fs (2)"
 e2fsck -fn "${SCRATCH_DEV}" >> $seqres.full 2>&1 || _fail "fsck should not fail"
 
-status=0
-exit
+_success
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 7/8] overlay: convert some tests to new setup preamble
  2018-06-27  8:20 [PATCH 0/6] fstests: start factoring test setup boilerplate Dave Chinner
                   ` (5 preceding siblings ...)
  2018-06-27  8:21 ` [PATCH 6/8] ext4: " Dave Chinner
@ 2018-06-27  8:21 ` Dave Chinner
  2018-06-27 11:37   ` Amir Goldstein
  2018-06-27  8:21 ` [PATCH 8/8] xfs: " Dave Chinner
  2018-06-28  5:59 ` [PATCH 0/6] fstests: start factoring test setup boilerplate Eryu Guan
  8 siblings, 1 reply; 28+ messages in thread
From: Dave Chinner @ 2018-06-27  8:21 UTC (permalink / raw)
  To: fstests

From: Dave Chinner <dchinner@redhat.com>

Small initial batch to demonstrate conversion.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 tests/overlay/001 | 26 +++++---------------------
 tests/overlay/002 | 26 +++++---------------------
 tests/overlay/003 | 31 +++++++------------------------
 tests/overlay/004 | 26 +++++---------------------
 tests/overlay/005 | 32 ++++++++------------------------
 tests/overlay/006 | 27 ++++++---------------------
 tests/overlay/007 | 26 ++++++--------------------
 tests/overlay/008 | 27 ++++++---------------------
 tests/overlay/009 | 29 ++++++++---------------------
 9 files changed, 56 insertions(+), 194 deletions(-)

diff --git a/tests/overlay/001 b/tests/overlay/001
index ade7a73a6cb2..4f2131ac0b49 100755
--- a/tests/overlay/001
+++ b/tests/overlay/001
@@ -9,29 +9,15 @@
 # Kernel commit 0480334fa604 ("ovl: use O_LARGEFILE in ovl_copy_up()")
 # fixed bug when copying up large file from lower dir.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-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
+# test exit cleanup goes here
+cleanup() { :; }
 
 # remove previous $seqres.full before test
 rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs overlay
 _supported_os Linux
 _require_scratch
@@ -60,6 +46,4 @@ for f in $SCRATCH_MNT/*; do
 	$XFS_IO_PROG -c "open" $f >>$seqres.full
 done
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/overlay/002 b/tests/overlay/002
index dd96cf0d3ab4..c677db1c6ffe 100755
--- a/tests/overlay/002
+++ b/tests/overlay/002
@@ -11,29 +11,15 @@
 # memory access) when the lower or upper directory belonged to a btrfs file
 # system.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-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
+# test exit cleanup goes here
+cleanup() { :; }
 
 # remove previous $seqres.full before test
 rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs overlay
 _supported_os Linux
 _require_scratch
@@ -52,6 +38,4 @@ _scratch_mount
 # This should work and not result in a crash.
 $XFS_IO_PROG -c "pwrite 0 64k" -c "fsync" $SCRATCH_MNT/foobar | _filter_xfs_io
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/overlay/003 b/tests/overlay/003
index 878ecbe7e974..5f753546242d 100755
--- a/tests/overlay/003
+++ b/tests/overlay/003
@@ -12,35 +12,21 @@
 # prevents mounting overlayfs like this since v4.6-rc1.
 # No harm to keep this test as a sanity check.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-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
+# test exit cleanup goes here
+cleanup() { :; }
 
 # remove previous $seqres.full before test
 rm -f $seqres.full
 
-# real QA test starts here
-
-# Modify as appropriate.
+# include test specific environments here
 _supported_fs overlay
 _supported_os Linux
 _require_scratch
 
+echo "Silence is golden"
+
 # Remove all files from previous tests
 _scratch_mkfs
 
@@ -77,7 +63,4 @@ ls ${SCRATCH_MNT}/
 # unmount overlayfs but not base fs
 $UMOUNT_PROG $SCRATCH_MNT
 
-echo "Silence is golden"
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/overlay/004 b/tests/overlay/004
index 216df203fe50..03115bb8ffd8 100755
--- a/tests/overlay/004
+++ b/tests/overlay/004
@@ -6,29 +6,15 @@
 #
 # Test file copy up on overlayfs by changing mode bits.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-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
+# test exit cleanup goes here
+cleanup() { :; }
 
 # remove previous $seqres.full before test
 rm -f $seqres.full
 
-# Modify as appropriate.
+# include test specific environments here
 _supported_fs overlay
 _supported_os Linux
 _require_scratch
@@ -78,6 +64,4 @@ $UMOUNT_PROG $SCRATCH_MNT
 stat -c %a ${upperdir}/attr_file1
 ls ${upperdir}/
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/overlay/005 b/tests/overlay/005
index 902eda18c8fe..13733c8ee50d 100755
--- a/tests/overlay/005
+++ b/tests/overlay/005
@@ -8,35 +8,20 @@
 # when unmount the underlying fs.
 # Kernel commit ab79efab0 fixed this issue.
 #
-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.*
+. common/setup_test
+
+# test exit cleanup goes here
+cleanup() {
 	_destroy_loop_device $fs_loop_dev
 	_destroy_loop_device $upper_loop_dev
 	rm -f $lower_img
 	rm -f $upper_img
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-
 # remove previous $seqres.full before test
 rm -f $seqres.full
 
-# real QA test starts here
-
-# Modify as appropriate.
+# include test specific environments here
 _supported_fs overlay
 _supported_os Linux
 # Use non-default scratch underlying overlay dirs, we need to check
@@ -44,6 +29,8 @@ _supported_os Linux
 _require_scratch_nocheck
 _require_loop
 
+echo "Silence is golden"
+
 # Remove all files from previous tests
 _scratch_mkfs
 
@@ -96,7 +83,4 @@ _overlay_check_scratch_dirs $lowerd $upperd $workd
 $UMOUNT_PROG ${OVL_BASE_SCRATCH_MNT}/uppermnt
 $UMOUNT_PROG ${OVL_BASE_SCRATCH_MNT}/lowermnt
 
-# success, all done
-echo "Silence is golden"
-status=0
-exit
+_success
diff --git a/tests/overlay/006 b/tests/overlay/006
index 72aa451a3c0b..ab48d70c36e7 100755
--- a/tests/overlay/006
+++ b/tests/overlay/006
@@ -10,28 +10,15 @@
 # Upstream commit 45d117389696 ("ovl: ignore lower entries when checking purity
 # of non-directory entries") fixed the issue
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-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
+# test exit cleanup goes here
+cleanup() { :; }
 
+# remove previous $seqres.full before test
 rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs overlay
 _supported_os Linux
 _require_scratch
@@ -57,6 +44,4 @@ rm $SCRATCH_MNT/uppertestdir/lowertestfile
 # no file no whiteout file in upptestdir
 ls $SCRATCH_MNT/uppertestdir
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/overlay/007 b/tests/overlay/007
index 5dffc83276bb..1f9366dd8ed4 100755
--- a/tests/overlay/007
+++ b/tests/overlay/007
@@ -9,29 +9,17 @@
 # Upstream commit ce9113bbcbf4 ("ovl: fix getcwd() failure after unsuccessful
 # rmdir") fixed this issue
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
-
-_cleanup()
-{
-	cd /
-	rm -f $tmp.*
+# test exit cleanup goes here
+cleanup() {
 	rm -rf $TEST_DIR/$seq
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-
+# remove previous $seqres.full before test
 rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs overlay
 _supported_os Linux
 _require_test
@@ -46,6 +34,4 @@ rmdir ../$seq >>$seqres.full 2>&1
 # getcwd should return the correct current dir
 pwd | _filter_test_dir
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/overlay/008 b/tests/overlay/008
index 29fa509bd8cf..a12bc792ee08 100755
--- a/tests/overlay/008
+++ b/tests/overlay/008
@@ -10,28 +10,15 @@
 # This upstream kernel patch fixed the issue
 # d0e13f5 ovl: fix uid/gid when creating over whiteout
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-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
+# test exit cleanup goes here
+cleanup() { :; }
 
+# remove previous $seqres.full before test
 rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs overlay
 _supported_os Linux
 _require_scratch
@@ -65,6 +52,4 @@ rm -f $SCRATCH_MNT/testfile
 _user_do "mkdir $SCRATCH_MNT/testfile"
 stat -c %U:%G-%F $SCRATCH_MNT/testfile
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/overlay/009 b/tests/overlay/009
index 7fe25f2da172..d9e37313bbe8 100755
--- a/tests/overlay/009
+++ b/tests/overlay/009
@@ -9,32 +9,21 @@
 # This is fixed by kernel commit named as
 # ovl: fix dentry leak for default_permissions
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-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
+# test exit cleanup goes here
+cleanup() { :; }
 
+# remove previous $seqres.full before test
 rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs overlay
 _supported_os Linux
 _require_scratch
 
+echo "Silence is golden"
+
 # Remove all files from previous tests
 _scratch_mkfs
 
@@ -48,6 +37,4 @@ _scratch_mount -o default_permissions
 cat $SCRATCH_MNT/testfile
 
 # overlay will be unmounted by test harness and kernel BUG if dentry leaked
-echo "Silence is golden"
-status=0
-exit
+_success
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* [PATCH 8/8] xfs: convert some tests to new setup preamble
  2018-06-27  8:20 [PATCH 0/6] fstests: start factoring test setup boilerplate Dave Chinner
                   ` (6 preceding siblings ...)
  2018-06-27  8:21 ` [PATCH 7/8] overlay: " Dave Chinner
@ 2018-06-27  8:21 ` Dave Chinner
  2018-06-27 11:42   ` Amir Goldstein
  2018-06-28  5:59 ` [PATCH 0/6] fstests: start factoring test setup boilerplate Eryu Guan
  8 siblings, 1 reply; 28+ messages in thread
From: Dave Chinner @ 2018-06-27  8:21 UTC (permalink / raw)
  To: fstests

From: Dave Chinner <dchinner@redhat.com>

Small initial batch to demonstrate conversion.

Signed-off-by: Dave Chinner <dchinner@redhat.com>
---
 tests/xfs/001 | 38 ++++++++++++--------------------------
 tests/xfs/002 | 35 ++++++++++-------------------------
 tests/xfs/003 | 19 ++++++++-----------
 tests/xfs/004 | 43 ++++++++++++++-----------------------------
 tests/xfs/005 | 30 +++++++-----------------------
 tests/xfs/006 | 27 ++++++---------------------
 tests/xfs/007 | 30 +++++++-----------------------
 tests/xfs/008 | 42 +++++++++++++++---------------------------
 tests/xfs/009 | 46 +++++++++++++++++++---------------------------
 9 files changed, 98 insertions(+), 212 deletions(-)

diff --git a/tests/xfs/001 b/tests/xfs/001
index ac86c3b1e484..fc61d6e8b284 100755
--- a/tests/xfs/001
+++ b/tests/xfs/001
@@ -8,20 +8,19 @@
 # write the value 0, each bit and finally the entry beyond the maximum legal
 # value. Also makes sure a core write and hex input still work.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    cd /
-    rm -f $tmp.*
-}
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
+_supported_fs xfs
+_supported_os Linux
+_require_scratch_nocheck
+_require_xfs_mkfs_crc
 
 _do_bit_test()
 {
@@ -39,18 +38,6 @@ _do_bit_test()
 	echo
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-
-# real QA test starts here
-
-# Modify as appropriate.
-_supported_fs xfs
-_supported_os Linux
-_require_scratch_nocheck
-_require_xfs_mkfs_crc
-
 _scratch_mkfs -m crc=0 >/dev/null 2>&1
 _scratch_mount
 
@@ -79,5 +66,4 @@ _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen 0xa5"
 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen 0"
 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen #5a5a"
 _scratch_xfs_db -x -c "inode $FILE_INO" -c "write core.gen #a5a5"
-status=0
-exit
+_success
diff --git a/tests/xfs/002 b/tests/xfs/002
index bd1c0a7a07f9..f64408afb3c1 100755
--- a/tests/xfs/002
+++ b/tests/xfs/002
@@ -13,26 +13,15 @@
 # for further explanation.  (NB: while the commit log was good, the
 # patch had a bug which was subsequently fixed)
 #
-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
-
-# Modify as appropriate.
+. common/setup_test
+
+# test exit cleanup goes here
+cleanup() { :; }
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
 _supported_fs xfs
 _supported_os Linux
 _require_scratch_nocheck
@@ -41,8 +30,6 @@ _require_no_large_scratch_dev
 # So we can explicitly turn it _off_:
 _require_xfs_mkfs_crc
 
-rm -f $seqres.full
-
 _scratch_mkfs_xfs -m crc=0 -d size=128m >> $seqres.full 2>&1 || _fail "mkfs failed"
 
 # Scribble past a couple V4 secondary superblocks to populate sb_crc
@@ -56,6 +43,4 @@ _scratch_mount
 # This should pass
 $XFS_GROWFS_PROG $SCRATCH_MNT >> $seqres.full 2>&1 || _fail "growfs failed"
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/xfs/003 b/tests/xfs/003
index 1ce3e5ce71a1..ca24e2be40cf 100755
--- a/tests/xfs/003
+++ b/tests/xfs/003
@@ -6,20 +6,15 @@
 #
 # exercise xfs_db bug #784078
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# test exit cleanup goes here
+cleanup() { :; }
 
-tmp=/tmp/$$
-here=`pwd`
-status=0	# success is the default!
-trap "rm -f $tmp.*; exit \$status" 0 1 2 3 15
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
 _supported_fs xfs
 _supported_os Linux
 _require_test
@@ -67,3 +62,5 @@ test_done
 echo "=== TEST 7 ==="
 xfs_db -r -c 'ring' $TEST_DEV
 test_done
+
+_success
diff --git a/tests/xfs/004 b/tests/xfs/004
index bf03583d7382..040133efc195 100755
--- a/tests/xfs/004
+++ b/tests/xfs/004
@@ -6,21 +6,19 @@
 #
 # exercise xfs_db bug #789674 and other freesp functionality
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=0
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-	_scratch_unmount
-	rm -f $tmp.*
-	exit $status
-}
-trap "_cleanup" 0 1 2 3 15
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
+_supported_fs xfs
+_supported_os Linux
+_require_scratch
+_require_no_large_scratch_dev
 
 _populate_scratch()
 {
@@ -36,19 +34,6 @@ _populate_scratch()
 	_scratch_mount				# and then remount
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-
-# real QA test starts here
-_supported_fs xfs
-_supported_os Linux
-
-_require_scratch
-_require_no_large_scratch_dev
-
-rm -f $seqres.full
-
 _populate_scratch
 
 eval `$DF_PROG -P --block-size=512 $SCRATCH_MNT 2>&1 \
@@ -84,7 +69,7 @@ then
 	echo "Error: $SCRATCH_DEV: freesp mismatch: $ans"
 	echo "xfs_db output ..."
 	cat $tmp.xfs_db
-	status=1
+	exit
 fi
 
 # check the 'pct' field from freesp command is good
@@ -103,7 +88,7 @@ then
 	echo "Error: $SCRATCH_DEV: pct mismatch: $ans (expected 100)"
 	echo "xfs_db output ..."
 	cat $tmp.xfs_db
-	status=1
+	exit
 fi
 
-exit
+_success
diff --git a/tests/xfs/005 b/tests/xfs/005
index ab7712232933..3f4a608a4e62 100755
--- a/tests/xfs/005
+++ b/tests/xfs/005
@@ -10,34 +10,20 @@
 # inadvertently caused primary SB CRC failures to not error out, this
 # is a regression test for that fix.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    cd /
-    rm -f $tmp.*
-}
-
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# Modify as appropriate.
+# include test specific environments here
 _supported_fs xfs
 _supported_os Linux
-
 _require_scratch_nocheck
 _require_xfs_mkfs_crc
 
-rm -f $seqres.full
-
 _scratch_mkfs_xfs -m crc=1 >> $seqres.full 2>&1 || _fail "mkfs failed"
 
 # Zap the crc.  xfs_db updates the CRC post-write, so poke it directly
@@ -46,6 +32,4 @@ $XFS_IO_PROG -c "pwrite 224 4" -c fsync $SCRATCH_DEV | _filter_xfs_io
 # should FAIL, the crc is bad; golden output contains mount failure
 _try_scratch_mount 2>&1 | _filter_error_mount
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/xfs/006 b/tests/xfs/006
index 2ee066200e20..57c3898caa37 100755
--- a/tests/xfs/006
+++ b/tests/xfs/006
@@ -7,31 +7,18 @@
 # Test xfs' "fail at unmount" error handling configuration. Stop
 # XFS from retrying to writeback forever at unmount.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
-
-_cleanup()
-{
-	cd /
-	rm -f $tmp.*
+# test exit cleanup goes here
+cleanup() {
 	_dmerror_cleanup
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-. ./common/dmerror
-
 # remove previous $seqres.full before test
 rm -f $seqres.full
 
-# real QA test starts here
+# include test specific environments here
+. ./common/dmerror
 _supported_fs xfs
 _supported_os Linux
 _require_scratch
@@ -83,6 +70,4 @@ _dmerror_load_working_table
 _dmerror_mount
 _dmerror_unmount
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/xfs/007 b/tests/xfs/007
index 7e965a642be5..59808e219efa 100755
--- a/tests/xfs/007
+++ b/tests/xfs/007
@@ -6,35 +6,21 @@
 #
 # Test to verify Q_XQUOTARM functionality.
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=1	# failure is the default!
-trap "_cleanup; exit \$status" 0 1 2 3 15
+# test exit cleanup goes here
+cleanup() { :; }
 
-_cleanup()
-{
-    cd /
-    rm -f $tmp.*
-}
+# remove previous $seqres.full before test
+rm -f $seqres.full
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
+# include test specific environments here
 . ./common/quota
-
-# Modify as appropriate.
 _supported_fs xfs
 _supported_os Linux
-
 _require_scratch
 _require_xfs_quota
 
-rm -f $seqres.full
-
 _scratch_mkfs_xfs | _filter_mkfs > /dev/null 2> $tmp.mkfs
 . $tmp.mkfs
 
@@ -83,6 +69,4 @@ _qmount
 _require_prjquota $SCRATCH_DEV
 do_test uquotino $PQUOTINO up
 
-# success, all done
-status=0
-exit
+_success
diff --git a/tests/xfs/008 b/tests/xfs/008
index 968a80528eec..51d5e5c50d96 100755
--- a/tests/xfs/008
+++ b/tests/xfs/008
@@ -6,32 +6,29 @@
 #
 # randholes test
 #
-seq=`basename $0`
-seqres=$RESULT_DIR/$seq
-echo "QA output created by $seq"
+. common/setup_test
 
-here=`pwd`
-tmp=/tmp/$$
-status=0	# success is the default!
-pgsize=`$here/src/feature -s`
-trap "_cleanup; exit \$status" 0 1 2 3 15
-
-_cleanup()
-{
-    rm -f $tmp.*
-    rm -rf $TEST_DIR/randholes.$$.*
+# test exit cleanup goes here
+cleanup() {
+	rm -rf $TEST_DIR/randholes.$$.*
 }
 
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
+_supported_fs xfs
+_supported_os Linux
+_require_test
+
+pgsize=`$here/src/feature -s`
+
 _filter()
 {
     sed -e "s/-b $pgsize/-b PGSIZE/g" \
 	-e "s/-l .* -c/-l FSIZE -c/g"
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-
 _do_test()
 {
     _n="$1"
@@ -64,17 +61,9 @@ _do_test()
         echo "$_n - output from bmap:"                      >>$seqres.full
         echo "--------------------------------------"       >>$seqres.full
         xfs_bmap -vvv $out                                  >>$seqres.full
-        status=1
     fi
 }
 
-# real QA test starts here
-_supported_fs xfs
-_supported_os Linux
-_require_test
-
-rm -f $seqres.full
-
 # Note on special numbers here.
 #
 # We are trying to create roughly 50 or 100 holes in a file
@@ -95,5 +84,4 @@ _do_test 5 100 "-d -l `expr 400 \* $pgsize` -c 100 -b $pgsize"
 
 # todo: realtime.
 
-# success, all done
-exit
+_success
diff --git a/tests/xfs/009 b/tests/xfs/009
index 68f63798cee3..6225d602d5f7 100755
--- a/tests/xfs/009
+++ b/tests/xfs/009
@@ -6,24 +6,25 @@
 #
 # XFS allocator test (preallocation - allocp, resvsp ,etc)
 #
-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
+. common/setup_test
+
+# test exit cleanup goes here
+cleanup() { :; }
+
+# remove previous $seqres.full before test
+rm -f $seqres.full
+
+# include test specific environments here
+_supported_fs xfs
+_supported_os Linux
+_require_scratch
+
+_supported_fs generic
+_supported_os Linux
+
 # This isn't really related to fs block size, it's just what
 # alloc uses for the "block" unit in it's input parameters...
 bsize=4096
-
-_cleanup()
-{
-    echo "*** unmount"
-    _scratch_unmount
-}
-
 _block_filter()
 {
    sed \
@@ -54,16 +55,6 @@ _filesize()
     ls -l $1 | $AWK_PROG '{print "filesize = " $5}'
 }
 
-# get standard environment, filters and checks
-. ./common/rc
-. ./common/filter
-
-# real QA test starts here
-_supported_fs xfs
-_supported_os Linux
-
-_require_scratch
-
 _init
 out=$SCRATCH_MNT/$$.tmp
 
@@ -167,5 +158,6 @@ EOF
 
 _filesize $out
 
-status=0
-exit
+echo "*** unmount"
+_scratch_unmount
+_success
-- 
2.17.0


^ permalink raw reply related	[flat|nested] 28+ messages in thread

* Re: [PATCH 2/8] tests: convert various test dirs to setup preamble
  2018-06-27  8:20 ` [PATCH 2/8] tests: convert various test dirs to " Dave Chinner
@ 2018-06-27 10:34   ` Amir Goldstein
  2018-06-27 14:03     ` Dave Chinner
  0 siblings, 1 reply; 28+ messages in thread
From: Amir Goldstein @ 2018-06-27 10:34 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 11:20 AM, Dave Chinner <david@fromorbit.com> wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> Convert all the test dirs with a very small number of tests in one
> go.
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> ---
[...]

> -rm -f $seqres.full
> +echo "Silence is golden"
> +
> +fio_config=$tmp.fio
> +fio_results=$tmp.json
>
>  _size=$((16 * $LOAD_FACTOR))
>  cat >$fio_config <<EOF
> @@ -60,5 +56,5 @@ $FIO_PROG --output-format=json --output=$fio_results $fio_config
>  _scratch_unmount
>  cat $fio_results >> $seqres.full
>  _fio_results_compare $seq $fio_results
> -echo "Silence is golden"
> -status=0; exit
> +
> +_success

I realize that without status=0 test will not pass, but it always
annoys me that echo "Silence is golden" before the end of the test.

How about _success_silent to further reduce the boilerplate echo
"Silence is golden"?

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 3/8] shared: use new test setup preamble
  2018-06-27  8:20 ` [PATCH 3/8] shared: use new test " Dave Chinner
@ 2018-06-27 10:56   ` Amir Goldstein
  2018-06-27 14:27     ` Dave Chinner
  0 siblings, 1 reply; 28+ messages in thread
From: Amir Goldstein @ 2018-06-27 10:56 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 11:20 AM, Dave Chinner <david@fromorbit.com> wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> ---
[...]
> diff --git a/tests/shared/298 b/tests/shared/298
> index e7b7b233de45..fc2d090a2f66 100755
> --- a/tests/shared/298
> +++ b/tests/shared/298
> @@ -6,15 +6,22 @@
>  #
>  # Test that filesystem sends discard requests only on free blocks
>  #
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> +. common/setup_test
>
> -status=1       # failure is the default!
> -trap "_cleanup; exit \$status" 0 1 2 3 15
> +# test exit cleanup goes here
> +cleanup() {
> +       $UMOUNT_PROG $loop_dev &> /dev/null
> +       _destroy_loop_device $loop_dev
> +       if [ $status -eq 0 ]; then
> +               rm $img_file
> +               rm -rf $workdir
> +       fi
> +}
>
> -. ./common/rc
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>
> +# include test specific environments here
>  _supported_fs ext4 xfs
>  _supported_os Linux
>  _require_test
> @@ -24,15 +31,8 @@ _require_xfs_io_command "fiemap"
>  _require_fs_space $TEST_DIR 307200
>  [ "$FSTYP" = "ext4" ] && _require_dumpe2fs
>
> -_cleanup()
> -{
> -       $UMOUNT_PROG $loop_dev &> /dev/null
> -       _destroy_loop_device $loop_dev
> -       if [ $status -eq 0 ]; then
> -               rm -rf $tmp
> -               rm $img_file
> -       fi
> -}
> +workdir=$TEST_DIR/$$
> +mkdir -p $workdir

:-/ I don't like this s/tmp/workdir conversion and don't like the idea
of having to do the same thing for 16 btrfs tests + 1 generic test.
IIUC, you changed the test from using tmpdir under $here to
tmpdir under $TEST_DIR. Why not change it to tmpdir under /tmp?

Only change you will need to do is:
-tmp=`mktemp -d`
+mkdir -p $tmp

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 1/8] fstests: generic test setup preamble
  2018-06-27  8:20 ` [PATCH 1/8] fstests: generic test setup preamble Dave Chinner
@ 2018-06-27 11:07   ` Amir Goldstein
  0 siblings, 0 replies; 28+ messages in thread
From: Amir Goldstein @ 2018-06-27 11:07 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 11:20 AM, Dave Chinner <david@fromorbit.com> wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> So many tests chop random bits out of the mandaotry test setup
> preamble which leads to subtle problems and stray files being dumped
> all over the place. Create a common test preamble with hooks for
> local cleanup functions so we can prevent this in future.
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> ---
>  common/setup_test | 31 +++++++++++++++++++++++++++++++
>  new               | 35 ++++++++---------------------------
>  soak              | 19 +++++++------------
>  3 files changed, 46 insertions(+), 39 deletions(-)
>  create mode 100644 common/setup_test
>
> diff --git a/common/setup_test b/common/setup_test
> new file mode 100644
> index 000000000000..f25ed11c2306
> --- /dev/null
> +++ b/common/setup_test
> @@ -0,0 +1,31 @@
> +# SPDX-License-Identifier: GPL-2.0
> +#
> +# common test setup preamble
> +# test specific cleanup is done via the cleanup() function now.
> +
> +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_test; exit \$status" 0 1 2 3 15
> +
> +_cleanup_test()
> +{
> +       # call local test cleanup function first, then cleanup tmp files
> +       cleanup
> +       cd /
> +       rm -f $tmp.*
> +}
> +
> +_success()
> +{
> +       status=0
> +       exit
> +}
> +
> +# get standard environment, filters and checks
> +. ./common/rc
> +. ./common/filter
> diff --git a/new b/new
> index 2bb8ce5055c1..1f11fdad1b8c 100755
> --- a/new
> +++ b/new
> @@ -9,12 +9,11 @@
>  iam=new
>  . ./common/test_names
>
> -trap "rm -f /tmp/$$.; exit" 0 1 2 3 15
>
> -_cleanup()
> -{
> -    :
> +_cleanup() {
> +       rm -f /tmp/$$.
>  }
> +trap "_cleanup; exit" 0 1 2 3 15
>

1. that looks like a bug in 'new' cleanup.
    should be rm -f /tmp/$$.* (or /tmp/$$.group)
2. if we are going with convention that local cleanup is
    without _, may as well stick with this convention here as well
    even though we are not sourcing setup_test

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 4/8] generic: convert some tests to new setup preamble
  2018-06-27  8:20 ` [PATCH 4/8] generic: convert some tests to new " Dave Chinner
@ 2018-06-27 11:08   ` Amir Goldstein
  2018-07-07 11:28   ` Eryu Guan
  1 sibling, 0 replies; 28+ messages in thread
From: Amir Goldstein @ 2018-06-27 11:08 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 11:20 AM, Dave Chinner <david@fromorbit.com> wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> Small initial batch to demonstrate conversion.
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> ---

Looks fine.

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 5/8] btrfs: convert some tests to new setup preamble
  2018-06-27  8:21 ` [PATCH 5/8] btrfs: " Dave Chinner
@ 2018-06-27 11:30   ` Amir Goldstein
  2018-06-27 14:34     ` Dave Chinner
  2018-07-07 11:22   ` Eryu Guan
  1 sibling, 1 reply; 28+ messages in thread
From: Amir Goldstein @ 2018-06-27 11:30 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 11:21 AM, Dave Chinner <david@fromorbit.com> wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> Small initial batch to demonstrate conversion.
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> ---
[...]
> diff --git a/tests/btrfs/007 b/tests/btrfs/007
> index 09f2f011bc77..50ead03acf31 100755
> --- a/tests/btrfs/007
> +++ b/tests/btrfs/007
> @@ -9,37 +9,23 @@
>  # (incr) and send both snapshots to a temp file. Remake the file
>  # system and receive from the files. Check both states with fssum.
>  #
> -# creator
> -owner=list.btrfs@jan-o-sch.net
> +. common/setup_test
>
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> +# test exit cleanup goes here
> +cleanup() { :; }
>
> -tmp=`mktemp -d`
> -status=1
> -
> -_cleanup()
> -{
> -       echo "*** unmount"
> -       _scratch_unmount 2>/dev/null
> -       rm -f $tmp.*
> -}

Bug in existing test - it does not cleanup $tmp.

> -trap "_cleanup; exit \$status" 0 1 2 3 15
> -
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>
> -# real QA test starts here
> +# include test specific environments here
> +_supported_fs generic
> +_supported_os Linux
>  _supported_fs btrfs
>  _supported_os Linux
>  _require_scratch
>  _require_fssum
>  _require_seek_data_hole
>
> -rm -f $seqres.full
> -
>  workout()
>  {
>         fsz=$1
> @@ -57,18 +43,18 @@ workout()
>
>         _run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr
>
> -       echo "# $BTRFS_UTIL_PROG send $SCRATCH_MNT/base > $tmp/base.snap" \
> +       echo "# $BTRFS_UTIL_PROG send $SCRATCH_MNT/base > $tmp.base.snap" \
>                 >> $seqres.full
> -       $BTRFS_UTIL_PROG send $SCRATCH_MNT/base > $tmp/base.snap 2>> $seqres.full \
> +       $BTRFS_UTIL_PROG send $SCRATCH_MNT/base > $tmp.base.snap 2>> $seqres.full \
>                 || _fail "failed: '$@'"
>         echo "# $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base\
> -               $SCRATCH_MNT/incr > $tmp/incr.snap" >> $seqres.full
> +               $SCRATCH_MNT/incr > $tmp.incr.snap" >> $seqres.full
>         $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base \
> -               $SCRATCH_MNT/incr > $tmp/incr.snap 2>> $seqres.full \
> +               $SCRATCH_MNT/incr > $tmp.incr.snap 2>> $seqres.full \
>                 || _fail "failed: '$@'"
>
> -       run_check $FSSUM_PROG -A -f -w $tmp/base.fssum $SCRATCH_MNT/base
> -       run_check $FSSUM_PROG -A -f -w $tmp/incr.fssum -x $SCRATCH_MNT/incr/base \
> +       run_check $FSSUM_PROG -A -f -w $tmp.base.fssum $SCRATCH_MNT/base
> +       run_check $FSSUM_PROG -A -f -w $tmp.incr.fssum -x $SCRATCH_MNT/incr/base \
>                 $SCRATCH_MNT/incr
>
>         _scratch_unmount >/dev/null 2>&1
> @@ -78,11 +64,11 @@ workout()
>                 || _fail "size=$fsz mkfs failed"
>         _scratch_mount "-o noatime"
>
> -       _run_btrfs_util_prog receive $SCRATCH_MNT < $tmp/base.snap
> -       run_check $FSSUM_PROG -r $tmp/base.fssum $SCRATCH_MNT/base
> +       _run_btrfs_util_prog receive $SCRATCH_MNT < $tmp.base.snap
> +       run_check $FSSUM_PROG -r $tmp.base.fssum $SCRATCH_MNT/base
>
> -       _run_btrfs_util_prog receive $SCRATCH_MNT < $tmp/incr.snap
> -       run_check $FSSUM_PROG -r $tmp/incr.fssum $SCRATCH_MNT/incr
> +       _run_btrfs_util_prog receive $SCRATCH_MNT < $tmp.incr.snap
> +       run_check $FSSUM_PROG -r $tmp.incr.fssum $SCRATCH_MNT/incr
>  }
>

This is better than the s/tmp/workdir conversion in shared/298, but
yet easier is to do:

cleanup() { rm -rf $tmp }

-tmp=`mktemp -d`
+mkdir -p $tmp

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 6/8] ext4: convert some tests to new setup preamble
  2018-06-27  8:21 ` [PATCH 6/8] ext4: " Dave Chinner
@ 2018-06-27 11:34   ` Amir Goldstein
  2018-07-07 11:25   ` Eryu Guan
  1 sibling, 0 replies; 28+ messages in thread
From: Amir Goldstein @ 2018-06-27 11:34 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 11:21 AM, Dave Chinner <david@fromorbit.com> wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> Small initial batch to demonstrate conversion.
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> ---

Looks fine.

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 7/8] overlay: convert some tests to new setup preamble
  2018-06-27  8:21 ` [PATCH 7/8] overlay: " Dave Chinner
@ 2018-06-27 11:37   ` Amir Goldstein
  0 siblings, 0 replies; 28+ messages in thread
From: Amir Goldstein @ 2018-06-27 11:37 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 11:21 AM, Dave Chinner <david@fromorbit.com> wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> Small initial batch to demonstrate conversion.
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> ---

Looks fine.

I can convert the rest of overlayfs tests once this batch is merged.

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 8/8] xfs: convert some tests to new setup preamble
  2018-06-27  8:21 ` [PATCH 8/8] xfs: " Dave Chinner
@ 2018-06-27 11:42   ` Amir Goldstein
  0 siblings, 0 replies; 28+ messages in thread
From: Amir Goldstein @ 2018-06-27 11:42 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 11:21 AM, Dave Chinner <david@fromorbit.com> wrote:
> From: Dave Chinner <dchinner@redhat.com>
>
> Small initial batch to demonstrate conversion.
>
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> ---

Looks fine.

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 2/8] tests: convert various test dirs to setup preamble
  2018-06-27 10:34   ` Amir Goldstein
@ 2018-06-27 14:03     ` Dave Chinner
  0 siblings, 0 replies; 28+ messages in thread
From: Dave Chinner @ 2018-06-27 14:03 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: fstests

On Wed, Jun 27, 2018 at 01:34:07PM +0300, Amir Goldstein wrote:
> On Wed, Jun 27, 2018 at 11:20 AM, Dave Chinner <david@fromorbit.com> wrote:
> > From: Dave Chinner <dchinner@redhat.com>
> >
> > Convert all the test dirs with a very small number of tests in one
> > go.
> >
> > Signed-off-by: Dave Chinner <dchinner@redhat.com>
> > ---
> [...]
> 
> > -rm -f $seqres.full
> > +echo "Silence is golden"
> > +
> > +fio_config=$tmp.fio
> > +fio_results=$tmp.json
> >
> >  _size=$((16 * $LOAD_FACTOR))
> >  cat >$fio_config <<EOF
> > @@ -60,5 +56,5 @@ $FIO_PROG --output-format=json --output=$fio_results $fio_config
> >  _scratch_unmount
> >  cat $fio_results >> $seqres.full
> >  _fio_results_compare $seq $fio_results
> > -echo "Silence is golden"
> > -status=0; exit
> > +
> > +_success
> 
> I realize that without status=0 test will not pass, but it always
> annoys me that echo "Silence is golden" before the end of the test.

That's because it's supposed to be at the start of the test,
documenting the fact that any output from the test is expected to
cause it to fail. That's generally important to know before you get
ot the last line of the test code....

> How about _success_silent to further reduce the boilerplate echo
> "Silence is golden"?

No.  Removing "silence is golden" (and all the variations that have
crept in over the years) and replacing them with
_success_silent can be mostly scripted once everything
has first been converted to call _success. IMO that's a relatively easy followup
patchset, and it's precisely what this initial conversion is supposed to
enable us to do. i.e. make codebase wide setup/completion
maintenance much easier to perform.

So let's not make the hard part of converting 1260 tests to common
setup infrastructure any harder than it already is going to be by
adding lots of other random cleanups into it as well.....

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 3/8] shared: use new test setup preamble
  2018-06-27 10:56   ` Amir Goldstein
@ 2018-06-27 14:27     ` Dave Chinner
  2018-06-27 14:43       ` Amir Goldstein
  0 siblings, 1 reply; 28+ messages in thread
From: Dave Chinner @ 2018-06-27 14:27 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: fstests

On Wed, Jun 27, 2018 at 01:56:29PM +0300, Amir Goldstein wrote:
> On Wed, Jun 27, 2018 at 11:20 AM, Dave Chinner <david@fromorbit.com> wrote:
> > From: Dave Chinner <dchinner@redhat.com>
> >
> > Signed-off-by: Dave Chinner <dchinner@redhat.com>
> > ---
> [...]
> > diff --git a/tests/shared/298 b/tests/shared/298
> > index e7b7b233de45..fc2d090a2f66 100755
> > --- a/tests/shared/298
> > +++ b/tests/shared/298
> > @@ -6,15 +6,22 @@
> >  #
> >  # Test that filesystem sends discard requests only on free blocks
> >  #
> > -seq=`basename $0`
> > -seqres=$RESULT_DIR/$seq
> > -echo "QA output created by $seq"
> > +. common/setup_test
> >
> > -status=1       # failure is the default!
> > -trap "_cleanup; exit \$status" 0 1 2 3 15
> > +# test exit cleanup goes here
> > +cleanup() {
> > +       $UMOUNT_PROG $loop_dev &> /dev/null
> > +       _destroy_loop_device $loop_dev
> > +       if [ $status -eq 0 ]; then
> > +               rm $img_file
> > +               rm -rf $workdir
> > +       fi
> > +}
> >
> > -. ./common/rc
> > +# remove previous $seqres.full before test
> > +rm -f $seqres.full
> >
> > +# include test specific environments here
> >  _supported_fs ext4 xfs
> >  _supported_os Linux
> >  _require_test
> > @@ -24,15 +31,8 @@ _require_xfs_io_command "fiemap"
> >  _require_fs_space $TEST_DIR 307200
> >  [ "$FSTYP" = "ext4" ] && _require_dumpe2fs
> >
> > -_cleanup()
> > -{
> > -       $UMOUNT_PROG $loop_dev &> /dev/null
> > -       _destroy_loop_device $loop_dev
> > -       if [ $status -eq 0 ]; then
> > -               rm -rf $tmp
> > -               rm $img_file
> > -       fi
> > -}
> > +workdir=$TEST_DIR/$$
> > +mkdir -p $workdir
> 
> :-/ I don't like this s/tmp/workdir conversion and don't like the idea
> of having to do the same thing for 16 btrfs tests + 1 generic test.

Too bad, we're going to have to do that.

> IIUC, you changed the test from using tmpdir under $here to
> tmpdir under $TEST_DIR.

Yes, because the usages of $tmp in this test (and all those other
ones, too) is completely broken.  You do realise that $here points
at the xfstests source directory, and so tests like this are dumping
crap in the source dir you run xfstests out of?

That's the sort of crap I'm trying to get rid of by moving to a
common setup - no test should *ever* be writing to $here. They
write temporary files the test needs to either /tmp
(i.e. $tmp) or TEST_DIR. Redfining $tmp to whatever you want
breaks assumptions in the infrastructure, and that's precisely the
problems I'm trying to fix.

And that means we've got to do the hard work of fixing the crappy
tests that have accumulated over the years. The btrfs stuff is
simple to fix - there's 15+ years of technical debt in the old xfs
and generic tests that I'm going to have to wade through to make
this conversion work. I don't like having to do this but if we want
to make things better then we have to fix them.

> Why not change it to tmpdir under /tmp?
> Only change you will need to do is:
> -tmp=`mktemp -d`
> +mkdir -p $tmp

Because the test is creating image files in $tmp, and we've had
problems in the past with tests running the root filesystems out of
space because they put too much shit in /tmp or dump crap in $here.
TEST_DIR is supposed to be used at the work dir for things like this
- we're trying to exercises the filesystem we are testing, not the
root filesystem that hosts the fstests installation.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 5/8] btrfs: convert some tests to new setup preamble
  2018-06-27 11:30   ` Amir Goldstein
@ 2018-06-27 14:34     ` Dave Chinner
  2018-06-27 14:48       ` Amir Goldstein
  0 siblings, 1 reply; 28+ messages in thread
From: Dave Chinner @ 2018-06-27 14:34 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: fstests

On Wed, Jun 27, 2018 at 02:30:13PM +0300, Amir Goldstein wrote:
> On Wed, Jun 27, 2018 at 11:21 AM, Dave Chinner <david@fromorbit.com> wrote:
> > From: Dave Chinner <dchinner@redhat.com>
> >
> > Small initial batch to demonstrate conversion.
> >
> > Signed-off-by: Dave Chinner <dchinner@redhat.com>
> > ---
> [...]
> > diff --git a/tests/btrfs/007 b/tests/btrfs/007
> > index 09f2f011bc77..50ead03acf31 100755
> > --- a/tests/btrfs/007
> > +++ b/tests/btrfs/007
> > @@ -9,37 +9,23 @@
> >  # (incr) and send both snapshots to a temp file. Remake the file
> >  # system and receive from the files. Check both states with fssum.
> >  #
> > -# creator
> > -owner=list.btrfs@jan-o-sch.net
> > +. common/setup_test
> >
> > -seq=`basename $0`
> > -seqres=$RESULT_DIR/$seq
> > -echo "QA output created by $seq"
> > +# test exit cleanup goes here
> > +cleanup() { :; }
> >
> > -tmp=`mktemp -d`
> > -status=1
> > -
> > -_cleanup()
> > -{
> > -       echo "*** unmount"
> > -       _scratch_unmount 2>/dev/null
> > -       rm -f $tmp.*
> > -}
> 
> Bug in existing test - it does not cleanup $tmp.

Yup, because it creates a non-standard $tmp but then uses code that
assumes that tmp is the standard name prefix definition, not a
directory.  This is exactly the sort of bug I'm trying to eradicate.

And, FWIW, because the test is only using tmp files, it doesn't need
to use TEST_DIR to store them so no need for a working directory to
be defined.

> cleanup() { rm -rf $tmp }
> 
> -tmp=`mktemp -d`
> +mkdir -p $tmp

Again, no. $tmp is not a directory and there's infrastructure that
assumes it is not a directory.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 3/8] shared: use new test setup preamble
  2018-06-27 14:27     ` Dave Chinner
@ 2018-06-27 14:43       ` Amir Goldstein
  2018-06-27 22:07         ` Dave Chinner
  0 siblings, 1 reply; 28+ messages in thread
From: Amir Goldstein @ 2018-06-27 14:43 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 5:27 PM, Dave Chinner <david@fromorbit.com> wrote:
> On Wed, Jun 27, 2018 at 01:56:29PM +0300, Amir Goldstein wrote:
>> On Wed, Jun 27, 2018 at 11:20 AM, Dave Chinner <david@fromorbit.com> wrote:
>> > From: Dave Chinner <dchinner@redhat.com>
>> >
>> > Signed-off-by: Dave Chinner <dchinner@redhat.com>
>> > ---
>> [...]
>> > diff --git a/tests/shared/298 b/tests/shared/298
>> > index e7b7b233de45..fc2d090a2f66 100755
>> > --- a/tests/shared/298
>> > +++ b/tests/shared/298
>> > @@ -6,15 +6,22 @@
>> >  #
>> >  # Test that filesystem sends discard requests only on free blocks
>> >  #
>> > -seq=`basename $0`
>> > -seqres=$RESULT_DIR/$seq
>> > -echo "QA output created by $seq"
>> > +. common/setup_test
>> >
>> > -status=1       # failure is the default!
>> > -trap "_cleanup; exit \$status" 0 1 2 3 15
>> > +# test exit cleanup goes here
>> > +cleanup() {
>> > +       $UMOUNT_PROG $loop_dev &> /dev/null
>> > +       _destroy_loop_device $loop_dev
>> > +       if [ $status -eq 0 ]; then
>> > +               rm $img_file
>> > +               rm -rf $workdir
>> > +       fi
>> > +}
>> >
>> > -. ./common/rc
>> > +# remove previous $seqres.full before test
>> > +rm -f $seqres.full
>> >
>> > +# include test specific environments here
>> >  _supported_fs ext4 xfs
>> >  _supported_os Linux
>> >  _require_test
>> > @@ -24,15 +31,8 @@ _require_xfs_io_command "fiemap"
>> >  _require_fs_space $TEST_DIR 307200
>> >  [ "$FSTYP" = "ext4" ] && _require_dumpe2fs
>> >
>> > -_cleanup()
>> > -{
>> > -       $UMOUNT_PROG $loop_dev &> /dev/null
>> > -       _destroy_loop_device $loop_dev
>> > -       if [ $status -eq 0 ]; then
>> > -               rm -rf $tmp
>> > -               rm $img_file
>> > -       fi
>> > -}
>> > +workdir=$TEST_DIR/$$
>> > +mkdir -p $workdir
>>
>> :-/ I don't like this s/tmp/workdir conversion and don't like the idea
>> of having to do the same thing for 16 btrfs tests + 1 generic test.
>
> Too bad, we're going to have to do that.
>
>> IIUC, you changed the test from using tmpdir under $here to
>> tmpdir under $TEST_DIR.
>
> Yes, because the usages of $tmp in this test (and all those other
> ones, too) is completely broken.  You do realise that $here points
> at the xfstests source directory, and so tests like this are dumping
> crap in the source dir you run xfstests out of?
>

Yes, I did not mean that $here was a good location for tmp files.
Anyway I double checked what directory mktemp -d defaults to and it is
/tmp, not $here.
"...If TEMPLATE is not specified, use tmp.XXXXXXXXXX, and
       --tmpdir is implied"
--tmpdir is implied means /tmp/
and indeed this is what those tests do, at least with version of mktemp
on my machine.

>
>> Why not change it to tmpdir under /tmp?
>> Only change you will need to do is:
>> -tmp=`mktemp -d`
>> +mkdir -p $tmp
>
> Because the test is creating image files in $tmp, and we've had
> problems in the past with tests running the root filesystems out of
> space because they put too much shit in /tmp or dump crap in $here.
> TEST_DIR is supposed to be used at the work dir for things like this
> - we're trying to exercises the filesystem we are testing, not the
> root filesystem that hosts the fstests installation.
>

I see. It might be better though to make this fix in a separate patch
and keeping the conversion patch to the minimal change I suggested.

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 5/8] btrfs: convert some tests to new setup preamble
  2018-06-27 14:34     ` Dave Chinner
@ 2018-06-27 14:48       ` Amir Goldstein
  0 siblings, 0 replies; 28+ messages in thread
From: Amir Goldstein @ 2018-06-27 14:48 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 5:34 PM, Dave Chinner <david@fromorbit.com> wrote:
> On Wed, Jun 27, 2018 at 02:30:13PM +0300, Amir Goldstein wrote:
>> On Wed, Jun 27, 2018 at 11:21 AM, Dave Chinner <david@fromorbit.com> wrote:
>> > From: Dave Chinner <dchinner@redhat.com>
>> >
>> > Small initial batch to demonstrate conversion.
>> >
>> > Signed-off-by: Dave Chinner <dchinner@redhat.com>
>> > ---
>> [...]
>> > diff --git a/tests/btrfs/007 b/tests/btrfs/007
>> > index 09f2f011bc77..50ead03acf31 100755
>> > --- a/tests/btrfs/007
>> > +++ b/tests/btrfs/007
>> > @@ -9,37 +9,23 @@
>> >  # (incr) and send both snapshots to a temp file. Remake the file
>> >  # system and receive from the files. Check both states with fssum.
>> >  #
>> > -# creator
>> > -owner=list.btrfs@jan-o-sch.net
>> > +. common/setup_test
>> >
>> > -seq=`basename $0`
>> > -seqres=$RESULT_DIR/$seq
>> > -echo "QA output created by $seq"
>> > +# test exit cleanup goes here
>> > +cleanup() { :; }
>> >
>> > -tmp=`mktemp -d`
>> > -status=1
>> > -
>> > -_cleanup()
>> > -{
>> > -       echo "*** unmount"
>> > -       _scratch_unmount 2>/dev/null
>> > -       rm -f $tmp.*
>> > -}
>>
>> Bug in existing test - it does not cleanup $tmp.
>
> Yup, because it creates a non-standard $tmp but then uses code that
> assumes that tmp is the standard name prefix definition, not a
> directory.  This is exactly the sort of bug I'm trying to eradicate.
>
> And, FWIW, because the test is only using tmp files, it doesn't need
> to use TEST_DIR to store them so no need for a working directory to
> be defined.
>
>> cleanup() { rm -rf $tmp }
>>
>> -tmp=`mktemp -d`
>> +mkdir -p $tmp
>
> Again, no. $tmp is not a directory and there's infrastructure that
> assumes it is not a directory.
>

Ok, I see the logic in that argument.
16 more mktemp tests to go...

Thanks,
Amir.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 3/8] shared: use new test setup preamble
  2018-06-27 14:43       ` Amir Goldstein
@ 2018-06-27 22:07         ` Dave Chinner
  2018-06-28  4:12           ` Amir Goldstein
  0 siblings, 1 reply; 28+ messages in thread
From: Dave Chinner @ 2018-06-27 22:07 UTC (permalink / raw)
  To: Amir Goldstein; +Cc: fstests

On Wed, Jun 27, 2018 at 05:43:06PM +0300, Amir Goldstein wrote:
> On Wed, Jun 27, 2018 at 5:27 PM, Dave Chinner <david@fromorbit.com> wrote:
> > On Wed, Jun 27, 2018 at 01:56:29PM +0300, Amir Goldstein wrote:
> >> On Wed, Jun 27, 2018 at 11:20 AM, Dave Chinner <david@fromorbit.com> wrote:
> > Because the test is creating image files in $tmp, and we've had
> > problems in the past with tests running the root filesystems out of
> > space because they put too much shit in /tmp or dump crap in $here.
> > TEST_DIR is supposed to be used at the work dir for things like this
> > - we're trying to exercises the filesystem we are testing, not the
> > root filesystem that hosts the fstests installation.
> >
> 
> I see. It might be better though to make this fix in a separate patch
> and keeping the conversion patch to the minimal change I suggested.

We can't make the conversion patch as you suggested because it's
/doesn't fix the broken usage of $tmp/. That's the intent of this
whole conversion - to fix these bugs by converting to common setup
code. So we need to fix the bugs as we convert them, not slap a
band-aid over them and then have to come back and fix them later (if
we remember which of the many, many tests need fixing!).

Again, lets not ake this conversion harder than it needs to be by
trying to split hairs over how individual bugs are fixed. There are
/hundreds of bugs/ that need to be fixed during this conversion
- the cost of separating them out is prohibitive, and it makes no
sense to add more change management time and overhead to an
already resource intensive conversion process.

Cheers,

Dave.
-- 
Dave Chinner
david@fromorbit.com

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 3/8] shared: use new test setup preamble
  2018-06-27 22:07         ` Dave Chinner
@ 2018-06-28  4:12           ` Amir Goldstein
  0 siblings, 0 replies; 28+ messages in thread
From: Amir Goldstein @ 2018-06-28  4:12 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Thu, Jun 28, 2018 at 1:07 AM, Dave Chinner <david@fromorbit.com> wrote:
> On Wed, Jun 27, 2018 at 05:43:06PM +0300, Amir Goldstein wrote:
>> On Wed, Jun 27, 2018 at 5:27 PM, Dave Chinner <david@fromorbit.com> wrote:
>> > On Wed, Jun 27, 2018 at 01:56:29PM +0300, Amir Goldstein wrote:
>> >> On Wed, Jun 27, 2018 at 11:20 AM, Dave Chinner <david@fromorbit.com> wrote:
>> > Because the test is creating image files in $tmp, and we've had
>> > problems in the past with tests running the root filesystems out of
>> > space because they put too much shit in /tmp or dump crap in $here.
>> > TEST_DIR is supposed to be used at the work dir for things like this
>> > - we're trying to exercises the filesystem we are testing, not the
>> > root filesystem that hosts the fstests installation.
>> >
>>
>> I see. It might be better though to make this fix in a separate patch
>> and keeping the conversion patch to the minimal change I suggested.
>
> We can't make the conversion patch as you suggested because it's
> /doesn't fix the broken usage of $tmp/. That's the intent of this
> whole conversion - to fix these bugs by converting to common setup
> code. So we need to fix the bugs as we convert them, not slap a
> band-aid over them and then have to come back and fix them later (if
> we remember which of the many, many tests need fixing!).
>
> Again, lets not ake this conversion harder than it needs to be by
> trying to split hairs over how individual bugs are fixed. There are
> /hundreds of bugs/ that need to be fixed during this conversion
> - the cost of separating them out is prohibitive, and it makes no
> sense to add more change management time and overhead to an
> already resource intensive conversion process.
>

No worries. I'll stick to validating correctness in review.
I realize how agonizing this conversion task can be.

Cheers,
Amir.

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 0/6] fstests: start factoring test setup boilerplate
  2018-06-27  8:20 [PATCH 0/6] fstests: start factoring test setup boilerplate Dave Chinner
                   ` (7 preceding siblings ...)
  2018-06-27  8:21 ` [PATCH 8/8] xfs: " Dave Chinner
@ 2018-06-28  5:59 ` Eryu Guan
  8 siblings, 0 replies; 28+ messages in thread
From: Eryu Guan @ 2018-06-28  5:59 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 06:20:55PM +1000, Dave Chinner wrote:
> Hi folks,
> 
> These patches start the long process of factoring out most of the
> test setup boilerplate in each test. The first patch introduces the
> generic test setup include file, and the patches that follow start
> the process of converting tests over to use it.
> 
> Making infrastructure changes to fstests is hard because of the
> sheer number of tests. Abstracting out things like test setup will
> make it much easier in future to improve the test setup
> infrstructure as we won't need to modify every test to make the
> change. We only have to do the hard work once.
> 
> There is still some boiler plate in the preamble, but it is reduced
> significantly and only contains things that individual tests should
> be allowed to influence. i.e. the full output file and a cleanup
> function that is called on exit.
> 
> I've also replaced the test success suffix - instead of this boiler
> plate at the end of each test:
> 
> # success, all done
> status=0
> exit
> 
> This has been replaced with a single call to _success, which does
> all the things necessary for the test harness to know the test has
> exited successfully.
> 
> As an initial pass I've convert all the test directories with a
> small number of tests, and converted the first handful of tests in
> each of the major test directories. This is a slow process because
> it's mostly manual as every second test has some unique variation
> that makes automated replacement somewhat difficult.

Sounds good to me. I'll continue commit in new tests using old template
until this patchset goes in. Once these patches are upstream, all new
tests should use new template, I'll convert the pending new tests on
commit or ask the author to do so.

> 
> As such, I've really only scratched the surface - this patchset
> changes over about 60 tests, and there are about 1200 more tests to
> convert. As such, my focus is going to be converting the generic
> tests first - this is the biggest chunk of the work that
> needs to be done.
> 
> Given there is still a large amount of conversion work to do, I
> would appreciate it if people regularly contributing to the other
> large test dirs (mainly overlay, btrfs, ext4 and xfs) would consider
> devoting an hour or two to converting some of those tests to the new
> setup preamble. The more people who do a bit, the faster the
> conversion will go and the better it will be for everyone.

Agreed. And manual conversion also means all the converted tests need
careful review and testings, I'll take some time reviewing & testing
this first batch.

Thanks a lot for doing the hard work in converting the tests!

Eryu

> 
> Comments, thoughts?
> 
> -Dave.
> 
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 5/8] btrfs: convert some tests to new setup preamble
  2018-06-27  8:21 ` [PATCH 5/8] btrfs: " Dave Chinner
  2018-06-27 11:30   ` Amir Goldstein
@ 2018-07-07 11:22   ` Eryu Guan
  1 sibling, 0 replies; 28+ messages in thread
From: Eryu Guan @ 2018-07-07 11:22 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 06:21:00PM +1000, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
> 
> Small initial batch to demonstrate conversion.
> 
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> ---
>  tests/btrfs/001 | 25 ++++++----------------
>  tests/btrfs/002 | 28 ++++++++----------------
>  tests/btrfs/003 | 41 ++++++++++++++---------------------
>  tests/btrfs/004 | 24 ++++++---------------
>  tests/btrfs/005 | 51 +++++++++++++++++--------------------------
>  tests/btrfs/006 | 30 ++++++--------------------
>  tests/btrfs/007 | 57 +++++++++++++++++++------------------------------
>  tests/btrfs/008 | 30 +++++++++-----------------
>  tests/btrfs/009 | 29 +++++++------------------
>  9 files changed, 105 insertions(+), 210 deletions(-)
> 
> diff --git a/tests/btrfs/001 b/tests/btrfs/001
> index b13a2470a0ed..771971135937 100755
> --- a/tests/btrfs/001
> +++ b/tests/btrfs/001
> @@ -6,27 +6,16 @@
>  #
>  # Test btrfs's subvolume and snapshot support
>  #
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> +. common/setup_test
>  
> -here=`pwd`
> -tmp=/tmp/$$
> -status=1	# failure is the default!
> +# test exit cleanup goes here
> +cleanup() { :; }
>  
> -_cleanup()
> -{
> -    rm -f $tmp.*
> -}
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>  
> -trap "_cleanup ; exit \$status" 0 1 2 3 15
> -
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> +# include test specific environments here
>  . ./common/filter.btrfs
> -
> -# real QA test starts here
>  _supported_fs btrfs
>  _supported_os Linux
>  _require_scratch
> @@ -90,4 +79,4 @@ _scratch_cycle_mount
>  echo "List root dir"
>  ls $SCRATCH_MNT
>  
> -status=0 ; exit
> +_success
> diff --git a/tests/btrfs/002 b/tests/btrfs/002
> index 87e21c02f68c..5d6b106bc090 100755
> --- a/tests/btrfs/002
> +++ b/tests/btrfs/002
> @@ -6,29 +6,21 @@
>  #
>  # Extented btrfs snapshot test cases
>  #
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> +. common/setup_test
>  
> -here=`pwd`
> -tmp=/tmp/$$
> -status=1	# failure is the default!
> +# test exit cleanup goes here
> +cleanup() { :; }
>  
> -_cleanup()
> -{
> -    rm -f $tmp.*
> -}
> -
> -trap "_cleanup ; exit \$status" 0 1 2 3 15
> -
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>  
> +# include test specific environments here
>  _supported_fs btrfs
>  _supported_os Linux
>  _require_scratch
>  
> +echo "Silence is golden"
> +
>  _scratch_mkfs > /dev/null 2>&1 || _fail "mkfs failed"
>  _scratch_mount
>  
> @@ -169,6 +161,4 @@ _save_checksum $SNAPNAME $tmp.$tname.sum
>  _verify_checksum $SNAPNAME $tmp.$tname.sum
>  
>  _scratch_unmount || _fail "unmount failed"
> -
> -echo "Silence is golden"
> -status=0; exit
> +_success
> diff --git a/tests/btrfs/003 b/tests/btrfs/003
> index 22aa57aad0b9..dac7ed919711 100755
> --- a/tests/btrfs/003
> +++ b/tests/btrfs/003
> @@ -6,31 +6,20 @@
>  #
>  # btrfs vol tests
>  #
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> -
> -here=`pwd`
> -tmp=/tmp/$$
> -status=1	# failure is the default!
> -dev_removed=0
> -removed_dev_htl=""
> -trap "_cleanup; exit \$status" 0 1 2 3 15
> -
> -_cleanup()
> -{
> -    cd /
> -    rm -f $tmp.*
> -    if [ $dev_removed == 1 ]; then
> -	_scratch_unmount
> -	_devmgt_add "${removed_dev_htl}"
> -    fi
> +. common/setup_test
> +
> +# test exit cleanup goes here
> +cleanup() {
> +	if [ $dev_removed == 1 ]; then
> +		_scratch_unmount
> +		_devmgt_add "${removed_dev_htl}"
> +	fi
>  }
>  
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>  
> +# include test specific environments here
>  _supported_fs btrfs
>  _supported_os Linux
>  _require_scratch
> @@ -38,7 +27,10 @@ _require_scratch_dev_pool 4
>  _require_deletable_scratch_dev_pool
>  _require_command "$WIPEFS_PROG" wipefs
>  
> -rm -f $seqres.full
> +echo "Silence is golden"
> +
> +dev_removed=0
> +removed_dev_htl=""
>  
>  # Test cases related to raid in btrfs
>  _test_raid0()
> @@ -172,5 +164,4 @@ _test_add
>  _test_replace
>  _test_remove
>  
> -echo "Silence is golden"
> -status=0; exit
> +_success
> diff --git a/tests/btrfs/004 b/tests/btrfs/004
> index 3f61a8f46140..99dd1f768d81 100755
> --- a/tests/btrfs/004
> +++ b/tests/btrfs/004
> @@ -9,28 +9,18 @@
>  # run filefrag to get the extent mapping and follow the backrefs.
>  # We check to end up back at the original file with the correct offset.
>  #
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> +. common/setup_test
>  
> -here=`pwd`
> -tmp=/tmp/$$
> -status=1
> -noise_pid=0
> -
> -_cleanup()
> -{
> +# test exit cleanup goes here
> +cleanup() {
>  	rm $tmp.running
>  	wait
> -	rm -f $tmp.*
>  }
> -trap "_cleanup; exit \$status" 0 1 2 3 15
>  
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>  
> -# real QA test starts here
> +# include test specific environments here
>  _supported_fs btrfs
>  _supported_os Linux
>  _require_scratch
> @@ -39,7 +29,7 @@ _require_btrfs_command inspect-internal logical-resolve
>  _require_btrfs_command inspect-internal inode-resolve
>  _require_command "$FILEFRAG_PROG" filefrag
>  
> -rm -f $seqres.full
> +noise_pid=0
>  
>  FILEFRAG_FILTER='
>  	if (/blocks? of (\d+) bytes/) {
> diff --git a/tests/btrfs/005 b/tests/btrfs/005
> index 15af46783298..4cebb57fbaba 100755
> --- a/tests/btrfs/005
> +++ b/tests/btrfs/005
> @@ -6,22 +6,26 @@
>  #
>  # Btrfs Online defragmentation tests
>  #
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> -here="`pwd`"
> -tmp=/tmp/$$
> -cnt=119
> -filesize=48000
> +. common/setup_test
>  
> -status=1	# failure is the default!
> -trap "_cleanup; exit \$status" 0 1 2 3 15
> +# test exit cleanup goes here
> +cleanup() { :; }
>  
> -_cleanup()
> -{
> -    cd /
> -    rm -f $tmp.*
> -}
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
> +
> +# include test specific environments here
> +. ./common/defrag
> +_supported_fs btrfs
> +_supported_os Linux
> +_require_scratch
> +
> +_scratch_mkfs >/dev/null 2>&1
> +_scratch_mount
> +_require_defrag
> +
> +cnt=119
> +filesize=48000
>  
>  _create_file()
>  {
> @@ -111,22 +115,6 @@ _rundefrag()
>  	_check_scratch_fs
>  }
>  
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> -. ./common/defrag
> -
> -# real QA test starts here
> -_supported_fs btrfs
> -_supported_os Linux
> -_require_scratch
> -
> -rm -f $seqres.full
> -
> -_scratch_mkfs >/dev/null 2>&1
> -_scratch_mount
> -_require_defrag
> -
>  echo "defrag object | defragment range | defragment compress"
>  echo "a single file | default | off"
>  _rundefrag 1 1 1
> @@ -155,5 +143,4 @@ _rundefrag 2 1 1
>  echo "a filesystem | default | off"
>  _rundefrag 3 1 1
>  
> -status=0
> -exit
> +_success
> diff --git a/tests/btrfs/006 b/tests/btrfs/006
> index 3edbb25a72a8..8eed1a2a1221 100755
> --- a/tests/btrfs/006
> +++ b/tests/btrfs/006
> @@ -7,35 +7,21 @@
>  # run basic btrfs information commands in various ways
>  # sanity tests: filesystem show, label, sync, and device stats
>  #
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "== QA output created by $seq"

This test uses a customized .out file header (the leading "== "), the
.out file should be updated too when converting to the new setup
preamble.

> +. common/setup_test
>  
> -here=`pwd`
> -tmp=/tmp/$$
> -status=1	# failure is the default!
> -trap "_cleanup; exit \$status" 0 1 2 3 15
> +# test exit cleanup goes here
> +cleanup() { :; }
>  
> -_cleanup()
> -{
> -    cd /
> -    rm -f $tmp.*
> -}
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>  
> -# get standard environment, filters and checks
> -. ./common/rc
> +# include test specific environments here
>  . ./common/filter.btrfs
> -
> -# real QA test starts here
> -
> -# Modify as appropriate.
>  _supported_fs btrfs
>  _supported_os Linux
>  _require_scratch
>  _require_scratch_dev_pool
>  
> -rm -f $seqres.full
> -
>  FIRST_POOL_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $1}'`
>  LAST_POOL_DEV=`echo $SCRATCH_DEV_POOL | awk '{print $NF}'`
>  TOTAL_DEVS=`echo $SCRATCH_DEV_POOL | wc -w`
> @@ -83,6 +69,4 @@ $BTRFS_UTIL_PROG device stats $LAST_POOL_DEV | \
>      sed -e "s,$LAST_POOL_DEV,LAST_POOL_DEV,g" | \
>      _filter_spaces
>  
> -# success, all done
> -status=0
> -exit
> +_success
> diff --git a/tests/btrfs/007 b/tests/btrfs/007
> index 09f2f011bc77..50ead03acf31 100755
> --- a/tests/btrfs/007
> +++ b/tests/btrfs/007
> @@ -9,37 +9,23 @@
>  # (incr) and send both snapshots to a temp file. Remake the file
>  # system and receive from the files. Check both states with fssum.
>  #
> -# creator
> -owner=list.btrfs@jan-o-sch.net
> +. common/setup_test
>  
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> +# test exit cleanup goes here
> +cleanup() { :; }
>  
> -tmp=`mktemp -d`
> -status=1
> -
> -_cleanup()
> -{
> -	echo "*** unmount"

Originally _cleanup was called on exit, so this "umount" message was the
last message printed, but...

> -	_scratch_unmount 2>/dev/null
> -	rm -f $tmp.*
> -}
> -trap "_cleanup; exit \$status" 0 1 2 3 15
> -
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>  
> -# real QA test starts here
> +# include test specific environments here
> +_supported_fs generic
> +_supported_os Linux
>  _supported_fs btrfs
>  _supported_os Linux
>  _require_scratch
>  _require_fssum
>  _require_seek_data_hole
>  
> -rm -f $seqres.full
> -
>  workout()
>  {
>  	fsz=$1
> @@ -57,18 +43,18 @@ workout()
>  
>  	_run_btrfs_util_prog subvolume snapshot -r $SCRATCH_MNT $SCRATCH_MNT/incr
>  
> -	echo "# $BTRFS_UTIL_PROG send $SCRATCH_MNT/base > $tmp/base.snap" \
> +	echo "# $BTRFS_UTIL_PROG send $SCRATCH_MNT/base > $tmp.base.snap" \
>  		>> $seqres.full
> -	$BTRFS_UTIL_PROG send $SCRATCH_MNT/base > $tmp/base.snap 2>> $seqres.full \
> +	$BTRFS_UTIL_PROG send $SCRATCH_MNT/base > $tmp.base.snap 2>> $seqres.full \
>  		|| _fail "failed: '$@'"
>  	echo "# $BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base\
> -		$SCRATCH_MNT/incr > $tmp/incr.snap" >> $seqres.full
> +		$SCRATCH_MNT/incr > $tmp.incr.snap" >> $seqres.full
>  	$BTRFS_UTIL_PROG send -p $SCRATCH_MNT/base \
> -		$SCRATCH_MNT/incr > $tmp/incr.snap 2>> $seqres.full \
> +		$SCRATCH_MNT/incr > $tmp.incr.snap 2>> $seqres.full \
>  		|| _fail "failed: '$@'"
>  
> -	run_check $FSSUM_PROG -A -f -w $tmp/base.fssum $SCRATCH_MNT/base
> -	run_check $FSSUM_PROG -A -f -w $tmp/incr.fssum -x $SCRATCH_MNT/incr/base \
> +	run_check $FSSUM_PROG -A -f -w $tmp.base.fssum $SCRATCH_MNT/base
> +	run_check $FSSUM_PROG -A -f -w $tmp.incr.fssum -x $SCRATCH_MNT/incr/base \
>  		$SCRATCH_MNT/incr
>  
>  	_scratch_unmount >/dev/null 2>&1
> @@ -78,11 +64,11 @@ workout()
>  		|| _fail "size=$fsz mkfs failed"
>  	_scratch_mount "-o noatime"
>  
> -	_run_btrfs_util_prog receive $SCRATCH_MNT < $tmp/base.snap
> -	run_check $FSSUM_PROG -r $tmp/base.fssum $SCRATCH_MNT/base
> +	_run_btrfs_util_prog receive $SCRATCH_MNT < $tmp.base.snap
> +	run_check $FSSUM_PROG -r $tmp.base.fssum $SCRATCH_MNT/base
>  
> -	_run_btrfs_util_prog receive $SCRATCH_MNT < $tmp/incr.snap
> -	run_check $FSSUM_PROG -r $tmp/incr.fssum $SCRATCH_MNT/incr
> +	_run_btrfs_util_prog receive $SCRATCH_MNT < $tmp.incr.snap
> +	run_check $FSSUM_PROG -r $tmp.incr.fssum $SCRATCH_MNT/incr
>  }
>  
>  echo "*** test send / receive"
> @@ -91,7 +77,8 @@ fssize=`expr 2000 \* 1024 \* 1024`
>  ops=200
>  
>  workout $fssize $ops
> -
> +echo "*** unmount"
> +_scratch_unmount 2>/dev/null
>  echo "*** done"

.. now "umount" is printed before "done". The order in btrfs/007.out
should be updated too.

Thanks,
Eryu

> -status=0
> -exit
> +
> +_success
> diff --git a/tests/btrfs/008 b/tests/btrfs/008
> index e7609de47580..288f6b97fdc0 100755
> --- a/tests/btrfs/008
> +++ b/tests/btrfs/008
> @@ -6,37 +6,27 @@
>  #
>  # btrfs send ENOENT regression test, from a user report on linux-btrfs
>  #
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> +. common/setup_test
>  
> -here=`pwd`
> -tmp=/tmp/$$
> -tmp_dir=send_temp_$seq
> -
> -status=1	# failure is the default!
> -
> -_cleanup()
> -{
> +# test exit cleanup goes here
> +cleanup() {
>  	$BTRFS_UTIL_PROG subvolume delete $TEST_DIR/$tmp_dir/send/snapshots/backup2 > /dev/null 2>&1
>  	$BTRFS_UTIL_PROG subvolume delete $TEST_DIR/$tmp_dir/send/snapshots/backup3 > /dev/null 2>&1
>  	$BTRFS_UTIL_PROG subvolume delete $TEST_DIR/$tmp_dir/send > /dev/null 2>&1
>  	rm -rf $TEST_DIR/$tmp_dir
> -	rm -f $tmp.*
>  }
>  
> -trap "_cleanup ; exit \$status" 0 1 2 3 15
> -
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>  
> -# real QA test starts here
> +# include test specific environments here
>  _supported_fs btrfs
>  _supported_os Linux
>  _require_test
>  _require_scratch
>  
> +echo "Silence is golden"
> +
>  _scratch_mkfs > /dev/null 2>&1
>  
>  #receive needs to be able to setxattrs, including the selinux context, if we use
> @@ -46,6 +36,7 @@ export SELINUX_MOUNT_OPTIONS=""
>  
>  _scratch_mount
>  
> +tmp_dir=send_temp_$seq
>  mkdir $TEST_DIR/$tmp_dir
>  $BTRFS_UTIL_PROG subvolume create $TEST_DIR/$tmp_dir/send \
>  	> $seqres.full 2>&1 || _fail "failed subvol create"
> @@ -66,5 +57,4 @@ $BTRFS_UTIL_PROG send -f $TEST_DIR/$tmp_dir/blah $work_dir/snapshots/backup3 \
>  $BTRFS_UTIL_PROG receive -vvvv -f $TEST_DIR/$tmp_dir/blah $SCRATCH_MNT \
>  	>> $seqres.full 2>&1 || _fail "receive failed"
>  
> -echo "Silence is golden"
> -status=0 ; exit
> +_success
> diff --git a/tests/btrfs/009 b/tests/btrfs/009
> index 8b6e864f3ea8..3c11ba94921f 100755
> --- a/tests/btrfs/009
> +++ b/tests/btrfs/009
> @@ -6,32 +6,20 @@
>  #
>  # Regression test to make sure we can't delete the default subvol
>  #
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> +. common/setup_test
>  
> -here=`pwd`
> -tmp=/tmp/$$
> +# test exit cleanup goes here
> +cleanup() { :; }
>  
> -status=1	# failure is the default!
> -
> -_cleanup()
> -{
> -	rm -f $tmp.*
> -}
> -
> -trap "_cleanup ; exit \$status" 0 1 2 3 15
> -
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>  
> -# real QA test starts here
> +# include test specific environments here
>  _supported_fs btrfs
>  _supported_os Linux
>  _require_scratch
>  
> -rm -f $seqres.full
> +echo "Silence is golden"
>  
>  _scratch_mkfs > /dev/null 2>&1
>  _scratch_mount
> @@ -45,5 +33,4 @@ $BTRFS_UTIL_PROG subvolume delete $SCRATCH_MNT/newvol >> $seqres.full 2>&1
>  _scratch_unmount
>  _try_scratch_mount || _fail "mount should have succeeded"
>  
> -echo "Silence is golden"
> -status=0 ; exit
> +_success
> -- 
> 2.17.0
> 
> --
> To unsubscribe from this list: send the line "unsubscribe fstests" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 6/8] ext4: convert some tests to new setup preamble
  2018-06-27  8:21 ` [PATCH 6/8] ext4: " Dave Chinner
  2018-06-27 11:34   ` Amir Goldstein
@ 2018-07-07 11:25   ` Eryu Guan
  1 sibling, 0 replies; 28+ messages in thread
From: Eryu Guan @ 2018-07-07 11:25 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 06:21:01PM +1000, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
> 
> Small initial batch to demonstrate conversion.
> 
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> ---
>  tests/ext4/001 | 26 +++++++-------------------
>  tests/ext4/002 | 41 +++++++++++++----------------------------
>  tests/ext4/003 | 25 +++++++------------------
>  tests/ext4/004 | 46 ++++++++++++++++------------------------------
>  tests/ext4/005 | 29 +++++++----------------------
>  tests/ext4/006 | 38 +++++++++++++-------------------------
>  tests/ext4/007 | 34 ++++++++++------------------------
>  tests/ext4/008 | 28 +++++++---------------------
>  tests/ext4/009 | 34 ++++++++++------------------------
>  9 files changed, 90 insertions(+), 211 deletions(-)
> 
> diff --git a/tests/ext4/001 b/tests/ext4/001
> index bf2d16b42b3c..deba9128d833 100755
> --- a/tests/ext4/001
> +++ b/tests/ext4/001
> @@ -6,28 +6,16 @@
>  #
>  # Test fallocate FALLOC_FL_ZERO_RANGE
>  #
> -seqfull=$0

This is needed and used by _link_out_file_named(), without defining it
test is unable to find .cfg file to do the .out file link.

How about making "seqfull" part of the test setup preamble?

Thanks,
Eryu

^ permalink raw reply	[flat|nested] 28+ messages in thread

* Re: [PATCH 4/8] generic: convert some tests to new setup preamble
  2018-06-27  8:20 ` [PATCH 4/8] generic: convert some tests to new " Dave Chinner
  2018-06-27 11:08   ` Amir Goldstein
@ 2018-07-07 11:28   ` Eryu Guan
  1 sibling, 0 replies; 28+ messages in thread
From: Eryu Guan @ 2018-07-07 11:28 UTC (permalink / raw)
  To: Dave Chinner; +Cc: fstests

On Wed, Jun 27, 2018 at 06:20:59PM +1000, Dave Chinner wrote:
> From: Dave Chinner <dchinner@redhat.com>
> 
> Small initial batch to demonstrate conversion.
> 
> Signed-off-by: Dave Chinner <dchinner@redhat.com>
> ---
>  tests/generic/001 | 49 +++++++++++++++++------------------------------
>  tests/generic/002 | 25 +++++++-----------------
>  tests/generic/003 | 30 ++++++++---------------------
>  tests/generic/004 | 32 +++++++++----------------------
>  tests/generic/005 | 44 ++++++++++++++++--------------------------
>  tests/generic/006 | 34 ++++++++++++--------------------
>  tests/generic/007 | 29 ++++++++--------------------
>  tests/generic/008 | 27 +++++++++-----------------
>  tests/generic/009 | 28 +++++++++------------------
>  9 files changed, 97 insertions(+), 201 deletions(-)
> 
> diff --git a/tests/generic/001 b/tests/generic/001
> index 046e54e374a4..58ef45ed7102 100755
> --- a/tests/generic/001
> +++ b/tests/generic/001
> @@ -15,25 +15,29 @@
>  # config has one line per file with filename and byte size, else use
>  # the default one below.
>  #
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> +. common/setup_test
>  
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> +# test exit cleanup goes here
> +cleanup() {
> +    if $done_cleanup ; then
> +	:
> +    elif [ $status -eq 0 ]; then
> +	$verbose && echo "cleanup"
> +	cd /
> +	rm -rf $TEST_DIR/$$
> +	done_cleanup=true
> +    fi
> +}
>  
> -tmp=/tmp/$$
> -here=`pwd`
> -status=1
> -done_cleanup=false
> -trap "_cleanup; rm -f $tmp.*; exit \$status" 0 1 2 3 15
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>  
> -# real QA test starts here
> +# include test specific environments here
>  _supported_fs generic
>  _supported_os Linux
>  _require_test
>  
> +done_cleanup=false
>  verbose=true
>  verify=$here/verify_fill
>  
> @@ -260,25 +264,9 @@ _check()
>      $verbose && echo
>  }
>  
> -_cleanup()
> -{
> -    # cleanup
> -    #
> -    if $done_cleanup
> -    then
> -	:
> -    elif [ $status -eq 0 ]
> -    then
> -	$verbose && echo "cleanup"
> -	cd /
> -	rm -rf $TEST_DIR/$$
> -	done_cleanup=true
> -    fi
> -}
> -
>  rm -f $seqres.full
>  status=0
> -_cleanup
> +cleanup
>  status=1
>  done_cleanup=false
>  
> @@ -299,5 +287,4 @@ do
>      fi
>  done
>  
> -status=0
> -exit
> +_success
> diff --git a/tests/generic/002 b/tests/generic/002
> index 8242ea907c1b..9943a077fe6b 100755
> --- a/tests/generic/002
> +++ b/tests/generic/002
> @@ -6,31 +6,20 @@
>  #
>  # simple inode link count test for a regular file
>  #
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> +. common/setup_test
>  
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> +# test exit cleanup goes here
> +cleanup() { :; }
>  
> -tmp=/tmp/$$
> -here=`pwd`
> -status=0	# success is the default!
> -trap "_cleanup; exit \$status" 0 1 2 3 15
>  
> -_cleanup()
> -{
> -    rm -f $tmp.*
> -}
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>  
> -# real QA test starts here
> +# include test specific environments here
>  _supported_fs generic
>  _supported_os Linux
>  _require_test
>  
> -rm -f $seqres.full
> -
>  echo "Silence is goodness ..."
>  
>  # ensure target directory exists
> @@ -62,4 +51,4 @@ do
>  done
>  
>  # success, all done
> -exit
> +_success
> diff --git a/tests/generic/003 b/tests/generic/003
> index 767d70593c3f..d928b9392686 100755
> --- a/tests/generic/003
> +++ b/tests/generic/003
> @@ -9,34 +9,22 @@
>  # never updated on read-only subvolumes. (Regression test for bug fixed
>  # with commit 93fd63c2f001ca6797c6b15b696a484b165b4800)
>  #
> -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 -rf $tmp.*
> -}
> +. common/setup_test
>  
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> +# test exit cleanup goes here
> +cleanup() { :; }
>  
> -# real QA test starts here
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>  
> +# include test specific environments here
>  _supported_fs generic
>  _supported_os Linux
>  _require_scratch
>  _require_atime
>  _require_relatime
>  
> -rm -f $seqres.full
> +echo "Silence is golden"
>  
>  _stat() {
>  	stat -c "%x;%y;%z" $1
> @@ -189,6 +177,4 @@ _compare_stat_times NNN "$file3_stat_before_ro_mount" \
>  
>  # success, all done
>  _scratch_unmount
> -echo "Silence is golden"
> -status=0
> -exit
> +_success
> diff --git a/tests/generic/004 b/tests/generic/004
> index 156d68aee19f..a4d3d5d9d32e 100755
> --- a/tests/generic/004
> +++ b/tests/generic/004
> @@ -6,35 +6,23 @@
>  #
>  # Test O_TMPFILE opens, and linking them back into the namespace.
>  #
> -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 ${testfile}
> +. common/setup_test
> +
> +# test exit cleanup goes here
> +cleanup() {
> +	rm -f ${testfile}
>  }
>  
> -# get standard environment, filters and checks
> -. ./common/rc
> -. ./common/filter
> +# remove previous $seqres.full before test
> +rm -f $seqres.full
>  
> -# real QA test starts here
> +# include test specific environments here
>  _supported_fs generic
>  _supported_os Linux
> -
>  _require_test
>  _require_xfs_io_command "-T"
>  _require_xfs_io_command "flink"
>  
> -rm -f $seqres.full
> -
>  testfile="${TEST_DIR}/tst-tmpfile-flink"
>  
>  # test creating a r/w tmpfile, do I/O and link it into the namespace
> @@ -49,6 +37,4 @@ rm ${testfile}
>  # test creating a r/o tmpfile.  Should fail
>  $XFS_IO_PROG -Tr ${TEST_DIR} -c "close" 2>&1 | _filter_test_dir
>  
> -# success, all done
> -status=0
> -exit
> +_success
> diff --git a/tests/generic/005 b/tests/generic/005
> index 118fca20ed5d..ceff4117319e 100755
> --- a/tests/generic/005
> +++ b/tests/generic/005
> @@ -9,28 +9,29 @@
>  #
>  # Note: On Linux, ELOOP limit used to be 32 but changed to 8, and lately
>  # its become 5.  Who knows what it might be next.
> -# 
> +#
>  # What we are looking for here is: no panic due to blowing the stack;
>  # and that the ELOOP error code is returned at some point (the actual
>  # limit point is unimportant, just checking that we do hit it).
> -# 
> -
> -seq=`basename $0`
> -seqres=$RESULT_DIR/$seq
> -echo "QA output created by $seq"
> +#
> +. common/setup_test
>  
> -here=`pwd`
> -tmp=/tmp/$$
> -status=0	# success is the default!
> -trap "_cleanup; exit \$status" 0 1 2 3 15
> +# test exit cleanup goes here
> +cleanup() {
> +    rm -f $TEST_DIR/symlink_{0,1,2,3,4}{0,1,2,3,4,5,6,7,8,9}
> +    rm -f $TEST_DIR/symlink_self empty_file

Looked like "empty_file" was not cleaned up, but it's removed correctly
because test cd'ed into $TEST_DIR. IMHO, it's better to remove
"empty_file" with full path name as all other files, really a minor
issue though.

Thanks,
Eryu

^ permalink raw reply	[flat|nested] 28+ messages in thread

end of thread, other threads:[~2018-07-07 11:28 UTC | newest]

Thread overview: 28+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-27  8:20 [PATCH 0/6] fstests: start factoring test setup boilerplate Dave Chinner
2018-06-27  8:20 ` [PATCH 1/8] fstests: generic test setup preamble Dave Chinner
2018-06-27 11:07   ` Amir Goldstein
2018-06-27  8:20 ` [PATCH 2/8] tests: convert various test dirs to " Dave Chinner
2018-06-27 10:34   ` Amir Goldstein
2018-06-27 14:03     ` Dave Chinner
2018-06-27  8:20 ` [PATCH 3/8] shared: use new test " Dave Chinner
2018-06-27 10:56   ` Amir Goldstein
2018-06-27 14:27     ` Dave Chinner
2018-06-27 14:43       ` Amir Goldstein
2018-06-27 22:07         ` Dave Chinner
2018-06-28  4:12           ` Amir Goldstein
2018-06-27  8:20 ` [PATCH 4/8] generic: convert some tests to new " Dave Chinner
2018-06-27 11:08   ` Amir Goldstein
2018-07-07 11:28   ` Eryu Guan
2018-06-27  8:21 ` [PATCH 5/8] btrfs: " Dave Chinner
2018-06-27 11:30   ` Amir Goldstein
2018-06-27 14:34     ` Dave Chinner
2018-06-27 14:48       ` Amir Goldstein
2018-07-07 11:22   ` Eryu Guan
2018-06-27  8:21 ` [PATCH 6/8] ext4: " Dave Chinner
2018-06-27 11:34   ` Amir Goldstein
2018-07-07 11:25   ` Eryu Guan
2018-06-27  8:21 ` [PATCH 7/8] overlay: " Dave Chinner
2018-06-27 11:37   ` Amir Goldstein
2018-06-27  8:21 ` [PATCH 8/8] xfs: " Dave Chinner
2018-06-27 11:42   ` Amir Goldstein
2018-06-28  5:59 ` [PATCH 0/6] fstests: start factoring test setup boilerplate Eryu Guan

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.