dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / test / zfs-tests / tests / functional / channel_program / channel_common.kshlib
blobf3097940f98c8321dbae8558ab8bf7af4477ff9b
1 #!/bin/ksh
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
6 # 1.0 of the CDDL.
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
23 function log_program
25 typeset expectexit=$1
26 shift
27 typeset expecterror=$1
28 shift
29 typeset cmdargs=$@ tmpout=$(mktemp) tmperr=$(mktemp) tmpin=$(mktemp)
31 # Expected output/error filename is the same as the .zcp name
32 typeset basename
33 if [[ $2 != "-" ]]; then
34 basename=${2%.*}
37 log_note "running: zfs program $cmdargs:"
39 tee $tmpin | zfs program $cmdargs >$tmpout 2>$tmperr
40 typeset ret=$?
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,
52 # respectively.
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" \
58 "Diff:\n$outdiff"
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" \
65 "Diff:\n$outdiff"
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"
82 rm $tmpout $tmperr
85 function log_must_program
87 log_program 0 "" "$@"
90 function log_mustnot_program
92 log_program 1 "" "$@"
95 function log_mustnot_checkerror_program
97 typeset expecterror=$1
98 shift
99 log_program 1 "$expecterror" "$@"