[PATCH 7/7] Adds functions for tests to call environment setup/cleaning

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



This patch adds two functions into common/rc. These two functions are
called by tests to setup and clean environment. They have a single
argument - a target directory. So everything required in a test to
support environments is to call _require_environment $target after
requireing test or scratch dir, and then call the clean function at
the end.

Specific environment name is taken from variables exported by check
script.

Calling of the cleaning function is not critical as before setup,
cleaning is called automatically.

Signed-off-by: Jan Ťulák <jtulak@xxxxxxxxxx>
---
 common/rc | 49 +++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 49 insertions(+)

diff --git a/common/rc b/common/rc
index d5e3aff..14dbb1f 100644
--- a/common/rc
+++ b/common/rc
@@ -1037,6 +1037,55 @@ _supported_os()
     _notrun "not suitable for this OS: $HOSTOS"
 }
 
+_require_environment()
+{
+	target="$1"
+	if [ "$target" = "" ];then
+		1>&2 echo "Target directory for environment can't be empty! Aborting."
+		exit 1
+	fi
+
+	if [ "$env" != "" -a "$env" != "none" ];then
+		prepare_method="prepare-once"
+		if $env_force;then
+			prepare_method="prepare-always"
+		fi
+		bash ./environments/$env $prepare_method $target 
+		sts=$?
+		if [ "$sts" != 0 ]; then
+			echo "       [skipped]"
+			1>&2 echo "Failed to prepare environment $env "\
+				" (will skip the test)!"
+			1>&2 echo ""
+			exit 1
+		fi
+	fi
+}
+
+
+
+_environment_clean()
+{
+	target="$1"
+	if [ "$target" = "" ];then
+		1>&2 echo "Target directory for environment cleaning can't be empty!"\
+		" Aborting."
+		exit 1
+	fi
+	# Clean environment if there was some
+	# and the next environment is different.
+	# The variables are exported from check script.
+	if [ "$env" != "" -a "$env" != "none" -a "$env" != "$env_next" ];then
+		bash ./environments/$env clean $target
+		sts=$?
+		if [ "$sts" != "0" ];then
+			1>&2 echo "An error happened when cleaning environment $env!"
+			1>&2 echo ""
+		fi
+	fi
+
+}
+
 # this test needs a scratch partition - check we're ok & unmount it
 # No post-test check of the device is required. e.g. the test intentionally
 # finishes the test with the filesystem in a corrupt state
-- 
1.9.3

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




[Index of Archives]     [Linux Filesystems Development]     [Linux NFS]     [Linux NILFS]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]

  Powered by Linux