diff mbox

[3/8] shared: use new test setup preamble

Message ID 20180627082103.9662-4-david@fromorbit.com (mailing list archive)
State New, archived
Headers show

Commit Message

Dave Chinner June 27, 2018, 8:20 a.m. UTC
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(-)

Comments

Amir Goldstein June 27, 2018, 10:56 a.m. UTC | #1
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.
--
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
Dave Chinner June 27, 2018, 2:27 p.m. UTC | #2
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.
Amir Goldstein June 27, 2018, 2:43 p.m. UTC | #3
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.
--
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
Dave Chinner June 27, 2018, 10:07 p.m. UTC | #4
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.
Amir Goldstein June 28, 2018, 4:12 a.m. UTC | #5
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.
--
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
diff mbox

Patch

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