3 # This file and its contents are supplied under the terms of the
4 # Common Development and Distribution License ("CDDL"), version 1.0.
5 # You may only use this file in accordance with the terms of version
8 # A full copy of the text of the CDDL should have accompanied this
9 # source. A copy of the CDDL is also available via the Internet at
10 # http://www.illumos.org/license/CDDL.
14 # Copyright (c) 2016 by Delphix. All rights reserved.
17 .
$STF_SUITE/include
/libtest.shlib
19 ZCP_ROOT
=$STF_SUITE/tests
/functional
/channel_program
21 # <exitcode> <expected error string> <zfs program args>
22 # e.g. log_program 0 $POOL foo.zcp arg1 arg2
27 typeset expecterror
=$1
29 typeset cmdargs
=$@ tmpout
=$
(mktemp
) tmperr
=$
(mktemp
) tmpin
=$
(mktemp
)
31 # Expected output/error filename is the same as the .zcp name
33 if [[ $2 != "-" ]]; then
37 log_note
"running: zfs program $cmdargs:"
39 tee $tmpin | zfs program
$cmdargs >$tmpout 2>$tmperr
42 log_note
"input:\n$(cat $tmpin)"
43 log_note
"output:\n$(cat $tmpout)"
44 log_note
"error:\n$(cat $tmperr)"
45 # verify correct return value
46 if [[ $ret -ne $expectexit ]]; then
47 log_fail
"return mismatch: expected $expectexit, got $ret"
51 # Check the output or reported error for successful or error returns,
53 if [[ -f "$basename.out" ]] && [[ $expectexit -eq 0 ]]; then
55 outdiff
=$
(diff "$basename.out" "$tmpout")
56 [[ $?
-ne 0 ]] && log_fail
"Output mismatch. Expected:\n" \
57 "$(cat $basename.out)\nBut got:$(cat $tmpout)\n" \
60 elif [[ -f "$basename.err" ]] && [[ $expectexit -ne 0 ]]; then
62 outdiff
=$
(diff "$basename.err" "$tmperr")
63 [[ $?
-ne 0 ]] && log_fail
"Error mismatch. Expected:\n" \
64 "$(cat $basename.err)\nBut got:$(cat $tmpout)\n" \
67 elif [[ -n $expecterror ]] && [[ $expectexit -ne 0 ]]; then
69 grep -q "$expecterror" $tmperr || \
70 log_fail
"Error mismatch. Expected to contain:\n" \
71 "$expecterror\nBut got:$(cat $tmpout)\n"
73 elif [[ $expectexit -ne 0 ]]; then
75 # If there's no expected output, error reporting is allowed to
76 # vary, but ensure that we didn't fail silently.
78 [[ -z "$(cat $tmperr)" ]] && \
79 log_fail
"error with no stderr output"
85 function log_must_program
90 function log_mustnot_program
95 function log_mustnot_checkerror_program
97 typeset expecterror
=$1
99 log_program
1 "$expecterror" "$@"