public inbox for fstests@vger.kernel.org
 help / color / mirror / Atom feed
From: Dave Chinner <david@fromorbit.com>
To: fstests@vger.kernel.org
Subject: [PATCH 1/8] fstests: generic test setup preamble
Date: Wed, 27 Jun 2018 18:20:56 +1000	[thread overview]
Message-ID: <20180627082103.9662-2-david@fromorbit.com> (raw)
In-Reply-To: <20180627082103.9662-1-david@fromorbit.com>

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


  reply	other threads:[~2018-06-27  8:21 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-27  8:20 [PATCH 0/6] fstests: start factoring test setup boilerplate Dave Chinner
2018-06-27  8:20 ` Dave Chinner [this message]
2018-06-27 11:07   ` [PATCH 1/8] fstests: generic test setup preamble 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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20180627082103.9662-2-david@fromorbit.com \
    --to=david@fromorbit.com \
    --cc=fstests@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox