svn commit: r292357 - projects/zfsd/head/tests/sys/cddl/zfs/include
Alan Somers
asomers at FreeBSD.org
Wed Dec 16 20:05:30 UTC 2015
Author: asomers
Date: Wed Dec 16 20:05:29 2015
New Revision: 292357
URL: https://svnweb.freebsd.org/changeset/base/292357
Log:
Add several more subroutines for test logging.
- log_debug: Only print the string if $STF_DEBUG is set.
- log_mustbe: Like log_must, but the first argument specifies the
required exit code; since its behavior differs from log_must in
certain ways that assume a success exit code of zero, it is not used
by log_must.
- log_cmd: Log the given command and its exit code, but let the caller
decide how to deal with the returned exit code.
- log_onfail: Like log_cmd, but only logs on failure.
Submitted by: Will
Sponsored by: Spectra Logic Corp
Modified:
projects/zfsd/head/tests/sys/cddl/zfs/include/logapi.kshlib
Modified: projects/zfsd/head/tests/sys/cddl/zfs/include/logapi.kshlib
==============================================================================
--- projects/zfsd/head/tests/sys/cddl/zfs/include/logapi.kshlib Wed Dec 16 19:55:53 2015 (r292356)
+++ projects/zfsd/head/tests/sys/cddl/zfs/include/logapi.kshlib Wed Dec 16 20:05:29 2015 (r292357)
@@ -33,6 +33,15 @@
. ${STF_SUITE}/include/stf.shlib
+#
+# Send a debug message to stderr, if $STF_DEBUG set.
+#
+function log_debug
+{
+ [ -z "$STF_DEBUG" ] && return
+ echo "$*" >&2
+}
+
# Output an assertion
#
# $@ - assertion text
@@ -61,6 +70,18 @@ function log_must
(( $? != 0 )) && log_fail
}
+# Execute a command that must exit $1
+#
+# $@ - command to execute
+function log_mustbe
+{
+ typeset exitcode_wanted=$1
+ shift
+
+ log_cmd "$@"
+ (( $? != $exitcode_wanted )) && log_fail
+}
+
# Execute a negative test and exit $STF_FAIL if test passes
#
# $@ - command to execute
@@ -71,6 +92,17 @@ function log_mustnot
(( $? != 0 )) && log_fail
}
+# Execute a command that should only be logged if it fails.
+#
+# $@ - command to execute
+function log_onfail
+{
+ eval $@
+ typeset status=$?
+ [ $status -eq 0 ] && return
+ _printerror "$@" "unexpectedly exited $status"
+}
+
# Execute and print command with status where success equals non-zero result
# or output includes expected keyword
#
@@ -135,6 +167,23 @@ function log_neg
return $ret
}
+# Execute and print command; unconditionally return its exit code.
+# Useful for code that needs to do more specialized exit status filtering.
+function log_cmd
+{
+ typeset logfile="$TMPDIR/log.$$"
+
+ while [[ -e $logfile ]]; do
+ logfile="$logfile.$$"
+ done
+
+ "$@" 2>$logfile
+ typeset status=$?
+ _printline "EXECUTED (exited $status): $@"
+ _recursive_output $logfile "false"
+ return $status
+}
+
# Execute and print command with status where success equals zero result
#
# $@ command to execute
More information about the svn-src-projects
mailing list