From owner-svn-src-projects@freebsd.org Wed Dec 16 20:05:30 2015 Return-Path: Delivered-To: svn-src-projects@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id B1D80A49A1F for ; Wed, 16 Dec 2015 20:05:30 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 696AF1892; Wed, 16 Dec 2015 20:05:30 +0000 (UTC) (envelope-from asomers@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id tBGK5TbK057324; Wed, 16 Dec 2015 20:05:29 GMT (envelope-from asomers@FreeBSD.org) Received: (from asomers@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id tBGK5TRo057323; Wed, 16 Dec 2015 20:05:29 GMT (envelope-from asomers@FreeBSD.org) Message-Id: <201512162005.tBGK5TRo057323@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: asomers set sender to asomers@FreeBSD.org using -f From: Alan Somers Date: Wed, 16 Dec 2015 20:05:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-projects@freebsd.org Subject: svn commit: r292357 - projects/zfsd/head/tests/sys/cddl/zfs/include X-SVN-Group: projects MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-projects@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: "SVN commit messages for the src " projects" tree" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Dec 2015 20:05:30 -0000 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