#
# This file and its contents are supplied under the terms of the
# Common Development and Distribution License ("CDDL"), version 1.0.
# You may only use this file in accordance with the terms of version
# 1.0 of the CDDL.
#
# A full copy of the text of the CDDL should have accompanied this
# source. A copy of the CDDL is also available via the Internet at
#
#
# Copyright 2012 (c), Joyent, Inc.
#
#
# mdb test driver
#
unalias -a
#set -o xtrace
mt_tnum=0
mt_tfail=0
mt_tsuc=0
function usage
{
local msg="$*"
cat <<USAGE >&2
Usage: $mt_arg0 [ -o dir ] [ -k ] [ -m executable ] [ -a | test ... ]
-o dir Sets 'dir' as the output directory
-a Runs all tests, ignores tests passed in
-k Keep output from all tests, not just failures
-m mdb binary to test
USAGE
exit 2
}
function fatal
{
local msg="$*"
exit 1
}
function setup_outdir
{
mt_outdir="$mt_outdir/$mt_arg0.$$"
mkdir -p $mt_outdir || fatal "failed to make output dir $mt_outdir"
}
function run_single
{
local name=$1
odir="$mt_outdir/current"
"ksh")
;;
"mdb")
command="$mt_mdb"
;;
"out")
#
# This is the file format for checking output against.
#
return 0
;;
*)
echo "skipping test $name (unknown extensino)"
return 0
;;
esac
echo "Executing test $name ... \c"
res=$?
else
res=$?
fi
reason="stdout mismatch"
fi
echo "$reason"
"failed to move test output directory"
"failed to copy test into output directory"
else
echo "passed"
"failed to move test directory"
fi
}
function run_all
{
local tests t
run_single $t
done
}
function welcome
{
cat <<WELCOME
Starting tests...
mtest target: $mt_mdb
output directory: $mt_outdir
WELCOME
}
function cleanup
{
"failed to remove successful test cases"
"failed to remove test output directory"
fi
}
function goodbye
{
cat <<EOF
-------------
Results
-------------
Tests passed: $mt_tsuc
Tests failed: $mt_tfail
Tests ran: $mt_tnum
EOF
echo "Congrats, mdb isn't completely broken, the tests pass".
else
echo "Some tests failed, you have some work to do."
fi
}
while getopts ":ahko:m:" c $@; do
case "$c" in
a)
mt_all="y"
;;
k)
mt_keep="y"
;;
m)
;;
o)
;;
h)
;;
:)
;;
*)
;;
esac
done
if [[ ! -z "$mt_all" ]]; then
else
for t in $@; do
[[ -f $t ]] || fatal "cannot find test $t"
run_single $t
done
fi
#
# Exit 1 if we have tests that return non-zero
#