Path: blob/main/cddl/usr.sbin/dtrace/tests/tools/dtest.sh
105171 views
#!/bin/sh12usage()3{4cat >&2 <<__EOF__5A harness for test cases in the DTrace test suite.67usage: $(basename $0) <testfile>8__EOF__9exit 110}1112gettag()13{14local tag1516tag=$(basename $1)17tag=${tag#*.}18tag=${tag%%[a-z.]*}19echo $tag20}2122runtest()23{24local dflags exe exstatus pid retval status2526exstatus=027retval=02829case $TFILE in30drp.DTRACEDROP_*.d|err.*.d|tst.*.d)31case $TFILE in32drp.DTRACEDROP_*.d)33dflags="-x droptags"34tag=$(gettag "$TFILE")35;;36err.D_*.d)37exstatus=138dflags="-x errtags"39tag=$(gettag "$TFILE")40;;41err.*.d)42exstatus=143;;44esac4546exe=${TFILE%.*}.exe47if [ -f "$exe" -a -x "$exe" ]; then48./$exe &49pid=$!50dflags="$dflags ${pid}"51fi5253dtrace -C -s "${TFILE}" $dflags >$STDOUT 2>$STDERR54status=$?5556if [ $status -ne $exstatus ]; then57ERRMSG="dtrace exited with status ${status}, expected ${exstatus}"58retval=159elif [ -n "${tag}" ] && ! grep -Fq " [${tag}] " ${STDERR}; then60ERRMSG="dtrace's error output did not contain expected tag ${tag}"61retval=162fi6364if [ -n "$pid" ]; then65kill -0 $pid >/dev/null 2>&1 && kill -9 $pid >/dev/null 2>&166wait67fi68;;69err.*.ksh|tst.*.ksh)70expr "$TFILE" : 'err.*' >/dev/null && exstatus=17172tst=$TFILE ksh -p "$TFILE" /usr/sbin/dtrace >$STDOUT 2>$STDERR73status=$?7475if [ $status -ne $exstatus ]; then76ERRMSG="script exited with status ${status}, expected ${exstatus}"77retval=178fi79;;80*)81ERRMSG="unexpected test file name $TFILE"82retval=183;;84esac8586if [ $retval -eq 0 ] && \87head -n 1 $STDOUT | grep -q -E '^#!/.*ksh$'; then88ksh -p $STDOUT89retval=$?90fi9192return $retval93}9495[ $# -eq 1 ] || usage9697readonly STDERR=$(mktemp)98readonly STDOUT=$(mktemp)99readonly TFILE=$(basename $1)100readonly EXOUT=${TFILE}.out101102kldload -n dtrace_test103cd $(dirname $1)104runtest105RESULT=$?106107if [ $RESULT -eq 0 -a -f $EXOUT -a -r $EXOUT ] && \108! cmp $STDOUT $EXOUT >/dev/null 2>&1; then109ERRMSG="test output mismatch"110RESULT=1111fi112113if [ $RESULT -ne 0 ]; then114echo "test $TFILE failed: $ERRMSG" >&2115if [ $(stat -f '%z' $STDOUT) -gt 0 ]; then116cat >&2 <<__EOF__117test stdout:118--119$(cat $STDOUT)120--121test stdout diff:122--123$(diff -u $EXOUT $STDOUT)124--125__EOF__126fi127if [ $(stat -f '%z' $STDERR) -gt 0 ]; then128cat >&2 <<__EOF__129test stderr:130--131$(cat $STDERR)132--133__EOF__134fi135fi136137rm -f $STDERR $STDOUT138exit $RESULT139140141