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 2012 (c), Joyent, Inc.
24 mt_arg0
=$
(basename $0)
38 [[ -z "$msg" ]] ||
echo "$msg" 2>&1
40 Usage: $mt_arg0 [ -o dir ] [ -k ] [ -m executable ] [ -a | test ... ]
42 -o dir Sets 'dir' as the output directory
43 -a Runs all tests, ignores tests passed in
44 -k Keep output from all tests, not just failures
53 [[ -z "$msg" ]] && msg
="failed"
54 echo "$mt_arg0: $msg" >&2
60 mt_outdir
="$mt_outdir/$mt_arg0.$$"
61 mkdir
-p $mt_outdir || fatal
"failed to make output dir $mt_outdir"
67 local expect base ext exe
command odir res reason input
69 [[ -z "$name" ]] && fail
"missing test to run"
73 odir
="$mt_outdir/current"
74 [[ -z "$ext" ]] && fatal
"found test without ext: $name"
75 [[ -z "$expect" ]] && fatal
"found test without prefix: $name"
79 command="$mt_ksh $name"
87 # This is the file format for checking output against.
92 echo "skipping test $name (unknown extensino)"
97 echo "Executing test $name ... \c"
98 mkdir
-p "$odir" >/dev
/null || fatal
"can't make output directory"
99 if [[ -z "$input" ]]; then
100 MDB
=$mt_mdb $command > "$odir/stdout" 2>"$odir/stderr"
103 MDB
=$mt_mdb $command < $input > "$odir/stdout" 2>"$odir/stderr"
107 if [[ -f "$name.out" ]] && ! diff "$name.out" "$odir/stdout" >/dev
/null
; then
108 cp $name.out
$odir/$base.out
109 reason
="stdout mismatch"
110 elif [[ "$expect" == "tst" && $res -ne 0 ]]; then
111 reason
="test exited $res, not zero"
112 elif [[ "$expect" == "err" && $res -eq 0 ]]; then
113 reason
="test exited $res, not non-zero"
116 if [[ -n "$reason" ]]; then
119 mv "$odir" "$mt_outdir/failure.$mt_tfail" || fatal \
120 "failed to move test output directory"
121 cp "$name" "$mt_outdir/failure.$mt_tfail/test" || fatal \
122 "failed to copy test into output directory"
126 mv "$odir" "$mt_outdir/success.$mt_tsuc" || fatal \
127 "failed to move test directory"
137 tests
=$
(find .
-type f
-name '[tst,err]*.*.[ksh,mdb]*')
147 mtest target: $mt_mdb
148 output directory: $mt_outdir
154 [[ -n "$mt_keep" ]] && return
155 rm -rf "$mt_outdir"/success.
* || fatal \
156 "failed to remove successful test cases"
157 if [[ $mt_tfail -eq 0 ]]; then
158 rmdir "$mt_outdir" || fatal \
159 "failed to remove test output directory"
171 Tests passed: $mt_tsuc
172 Tests failed: $mt_tfail
176 if [[ $mt_tfail -eq 0 ]]; then
177 echo "Congrats, mdb isn't completely broken, the tests pass".
179 echo "Some tests failed, you have some work to do."
183 while getopts ":ahko:m:" c $@
; do
201 usage
"option requires an argument -- $OPTARG"
204 usage
"invalid option -- $OPTARG"
211 [[ -z "$mt_all" && $# == 0 ]] && usage
"no tests to run"
213 [[ -x "$mt_mdb" ]] || fatal
"unable to execute mdb binary: $mt_mdb"
215 [[ -z "$mt_outdir" ]] && mt_outdir
=/var
/tmp
220 if [[ ! -z "$mt_all" ]]; then
224 [[ -f $t ]] || fatal
"cannot find test $t"
233 # Exit 1 if we have tests that return non-zero