]>
git.proxmox.com Git - mirror_zfs.git/blob - tests/test-runner/include/logapi.shlib
5 # The contents of this file are subject to the terms of the
6 # Common Development and Distribution License (the "License").
7 # You may not use this file except in compliance with the License.
9 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 # or http://www.opensolaris.org/os/licensing.
11 # See the License for the specific language governing permissions
12 # and limitations under the License.
14 # When distributing Covered Code, include this CDDL HEADER in each
15 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 # If applicable, add the following below this CDDL HEADER, with the
17 # fields enclosed by brackets "[]" replaced with your own identifying
18 # information: Portions Copyright [yyyy] [name of copyright owner]
24 # Copyright 2007 Sun Microsystems, Inc. All rights reserved.
25 # Use is subject to license terms.
27 # Copyright (c) 2012 by Delphix. All rights reserved.
30 .
${STF_TOOLS}/include
/stf.shlib
38 _printline ASSERTION
: "$@"
50 # Execute and print command with status where success equals non-zero result
52 # $@ - command to execute
54 # return 0 if command fails, otherwise return 1
58 log_neg_expect
"" "$@"
62 # Execute a positive test and exit $STF_FAIL is test fails
64 # $@ - command to execute
69 (( $?
!= 0 )) && log_fail
72 # Execute a negative test and exit $STF_FAIL if test passes
74 # $@ - command to execute
79 (( $?
!= 0 )) && log_fail
82 # Execute a negative test with keyword expected, and exit
83 # $STF_FAIL if test passes
85 # $1 - keyword expected
86 # $2-$@ - command to execute
88 function log_mustnot_expect
91 (( $?
!= 0 )) && log_fail
94 # Execute and print command with status where success equals non-zero result
95 # or output includes expected keyword
97 # $1 - keyword expected
98 # $2-$@ - command to execute
100 # return 0 if command fails, or the output contains the keyword expected,
103 function log_neg_expect
106 typeset logfile
="/tmp/log.$$"
111 while [[ -e $logfile ]]; do
112 logfile
="$logfile.$$"
120 if (( $status == 0 )); then
122 _printerror
"$@" "unexpectedly exited $status"
124 elif (( $status == 127 )); then
126 _printerror
"$@" "unexpectedly exited $status (File not found)"
127 # bus error - core dump
128 elif (( $status == 138 )); then
130 _printerror
"$@" "unexpectedly exited $status (Bus Error)"
131 # segmentation violation - core dump
132 elif (( $status == 139 )); then
134 _printerror
"$@" "unexpectedly exited $status (SEGV)"
136 $out |
$EGREP -i "internal error|assertion failed" \
138 # internal error or assertion failed
139 if (( $?
== 0 )); then
141 _printerror
"$@" "internal error or assertion failure" \
143 elif [[ -n $expect ]] ; then
144 $out |
$GREP -i "$expect" > /dev
/null
2>&1
145 if (( $?
== 0 )); then
149 _printerror
"$@" "unexpectedly exited $status"
155 if (( $ret == 0 )); then
156 [[ -n $LOGAPI_DEBUG ]] && print $
($out)
157 _printsuccess
"$@" "exited $status"
160 _recursive_output
$logfile "false"
164 # Execute and print command with status where success equals zero result
166 # $@ command to execute
168 # return command exit status
173 typeset logfile
="/tmp/log.$$"
175 while [[ -e $logfile ]]; do
176 logfile
="$logfile.$$"
183 if (( $status != 0 )) ; then
185 _printerror
"$@" "exited $status"
187 $out |
$EGREP -i "internal error|assertion failed" \
189 # internal error or assertion failed
190 if [[ $?
-eq 0 ]]; then
192 _printerror
"$@" "internal error or assertion failure" \
196 [[ -n $LOGAPI_DEBUG ]] && print $
($out)
200 _recursive_output
$logfile "false"
204 # Set an exit handler
206 # $@ - function(s) to perform on exit
217 # Perform cleanup and exit $STF_PASS
223 _endlog
$STF_PASS "$@"
226 # Perform cleanup and exit $STF_FAIL
232 _endlog
$STF_FAIL "$@"
235 # Perform cleanup and exit $STF_UNRESOLVED
239 function log_unresolved
241 _endlog
$STF_UNRESOLVED "$@"
244 # Perform cleanup and exit $STF_NOTINUSE
248 function log_notinuse
250 _endlog
$STF_NOTINUSE "$@"
253 # Perform cleanup and exit $STF_UNSUPPORTED
257 function log_unsupported
259 _endlog
$STF_UNSUPPORTED "$@"
262 # Perform cleanup and exit $STF_UNTESTED
266 function log_untested
268 _endlog
$STF_UNTESTED "$@"
271 # Perform cleanup and exit $STF_UNINITIATED
275 function log_uninitiated
277 _endlog
$STF_UNINITIATED "$@"
280 # Perform cleanup and exit $STF_NORESULT
284 function log_noresult
286 _endlog
$STF_NORESULT "$@"
289 # Perform cleanup and exit $STF_WARNING
295 _endlog
$STF_WARNING "$@"
298 # Perform cleanup and exit $STF_TIMED_OUT
302 function log_timed_out
304 _endlog
$STF_TIMED_OUT "$@"
307 # Perform cleanup and exit $STF_OTHER
313 _endlog
$STF_OTHER "$@"
320 # Perform cleanup and exit
323 # $2-$n - message text
327 typeset logfile
="/tmp/log.$$"
328 _recursive_output
$logfile
330 if [[ -n $_CLEANUP ]] ; then
331 typeset cleanup
=$_CLEANUP
333 log_note
"Performing local cleanup via log_onexit ($cleanup)"
338 (( ${#@} > 0 )) && _printline
"$@"
342 # Output a formatted line
351 # Output an error message
357 _printline ERROR
: "$@"
360 # Output a success message
364 function _printsuccess
366 _printline SUCCESS
: "$@"
369 # Output logfiles recursively
372 # $2 - indicate whether output the start file itself, default as yes.
374 function _recursive_output
#logfile
378 while [[ -e $logfile ]]; do
379 if [[ -z $2 ||
$logfile != $1 ]]; then
383 logfile
="$logfile.$$"