shtests revision 3f54fd611f536639ec30dd53c48e5ec1897cc7d9
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync: ksh regression test harness :
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync
ca551aca153d6df494985b5281c573ba2e3eb474vboxsyncUSAGE_LICENSE="[-author?David Korn <dgk@research.att.com>][-author?Glenn Fowler <gsf@research.att.com>][-copyright?Copyright (c) 2000-2012 AT&T Intellectual Property][-license?http://www.eclipse.org/org/documents/epl-v10.html]"
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync
ca551aca153d6df494985b5281c573ba2e3eb474vboxsynccommand=shtests
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync
ca551aca153d6df494985b5281c573ba2e3eb474vboxsyncsetslocale='*@(locale).sh'
c7814cf6e1240a519cbec0441e033d0e2470ed00vboxsynctimesensitive='*@(options|sigchld|subshell).sh'
ca551aca153d6df494985b5281c573ba2e3eb474vboxsyncvalgrindflags='--xml=yes --log-file=/dev/null --track-origins=yes --read-var-info=yes'
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync
ca551aca153d6df494985b5281c573ba2e3eb474vboxsyncUSAGE=$'
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync[-s8?
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync@(#)$Id: shtests (AT&T Research) 2012-05-29 $
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync'$USAGE_LICENSE$'
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync[+NAME?shtests - ksh regression test harness]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync[+DESCRIPTION?\bshtests\b is the \bksh\b(1) regression test harness for
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync \b$SHELL\b or \bksh\b if \bSHELL\b is not defined and exported. If
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync none of the \b--posix --utf8 --compile\b options are specified then
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync all three are enabled.]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync[+INPUT FILES?\bshtests\b regression test files are shell scripts that
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync run in an environment controlled by \bshtests\b. An identification
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync message is printed before and after each test on the standard output.
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync The default environment settings are:]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync {
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync [+unset LANG]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync [+unset LC_ALL]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync [+LC_NUMERIC=C?\b.\b radix point assumed by all test scripts.]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync [+VMALLOC_OPTIONS=abort?\bvmalloc\b(1) arena checking enabled
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync with \babort(2)\b on error.]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync }
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync[c:compile?Run test scripts using \bshcomp\b(1).]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync[d:debug?Enable \bshtests\b execution trace.]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync[l:locale?Disable \b--utf8\b and run the \b--posix\b and \b--compile\b
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync tests, if enabled, in the locale of the caller. This may cause invalid
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync regressions, especially for locales where \b.\b is not the radix
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync point.]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync[p:posix?Run the test scripts in the posix/C locale.]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync[t!:time?Include the current date/time in the test identification
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync messages.]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync[u:utf8?Run the test scripts in the ast-specific C.UTF-8 locale.]
bd810d58866067df322ea7f4a4627d9bdebb70d3vboxsync[v!:vmalloc_options?Run tests with \bVMALLOC_OPTIONS=abort\b. Test
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync script names matching \b'$timesensitive$'\b are run with
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync \bVMALLOC_OPTIONS\b unset.]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync[V:valgrind?Set \b--novmalloc_options\b and run the test scripts with
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync \bvalgrind\b(1) on \bksh\b. If \b$SHELL-g\b exists and is executable
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync than it is used instead of \b$SHELL\b.]
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync[x:trace?Enable script execution trace.]
061bebe04c5bfa05ed733d2a1204389c2a0c96a8vboxsync
061bebe04c5bfa05ed733d2a1204389c2a0c96a8vboxsync[ test.sh ... ] [ name=value ... ]
7bcc9300d10d0bd2c659be811f360748ecbc8274vboxsync
7f3bb583c97fd6f88c66f0047f1cd465afffefb4vboxsync[+SEE ALSO?\bksh\b(1), \bregress\b(1), \brt\b(1)]
7f3bb583c97fd6f88c66f0047f1cd465afffefb4vboxsync'
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync
ca551aca153d6df494985b5281c573ba2e3eb474vboxsyncfunction usage
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync{
bd810d58866067df322ea7f4a4627d9bdebb70d3vboxsync OPTIND=0
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync getopts -a $command "$USAGE" OPT '--??long'
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync exit 2
96e64b6c6d22f40507ff9e6efcbf9750116a78c2vboxsync}
7f3bb583c97fd6f88c66f0047f1cd465afffefb4vboxsync
7f3bb583c97fd6f88c66f0047f1cd465afffefb4vboxsyncfunction valxml
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync{
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync typeset state=INIT data dir file fn line what
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync integer errors=0
061bebe04c5bfa05ed733d2a1204389c2a0c96a8vboxsync
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync #print === $1 ===; cat $1; print === ===
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync while read data
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync do case $state in
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync INIT) case $data in
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync '<error>')
d2e5354b92ecffb83d50e04ff040fa2e7bb8e24avboxsync state=ERROR
113e32cd5ad8ef067495b103da706e9494d30d37vboxsync ;;
a076b35761e36233a2a3ba16f77c77d7849170cavboxsync esac
a076b35761e36233a2a3ba16f77c77d7849170cavboxsync ;;
113e32cd5ad8ef067495b103da706e9494d30d37vboxsync ERROR) case $data in
bd810d58866067df322ea7f4a4627d9bdebb70d3vboxsync '<kind>'Leak*'</kind>')
bd810d58866067df322ea7f4a4627d9bdebb70d3vboxsync state=SKIP
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync ;;
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync '<kind>'*'</kind>')
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync state=KEEP
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync what=UNKNOWN
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync ;;
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync esac
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync ;;
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync FRAME) case $data in
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync '<dir>'*'</dir>')
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync dir=${data#'<dir>'}
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync dir=${dir%'</dir>'}
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync ;;
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync '<file>'*'</file>')
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync file=${data#'<file>'}
81b3101ea5e60964f67c97185bbd43dbf75c5ab5vboxsync file=${file%'</file>'}
81b3101ea5e60964f67c97185bbd43dbf75c5ab5vboxsync ;;
81b3101ea5e60964f67c97185bbd43dbf75c5ab5vboxsync '<fn>'*'</fn>')
ebc248f21b276416f76e20da3add001aff9fc30avboxsync fn=${data#'<fn>'}
ebc248f21b276416f76e20da3add001aff9fc30avboxsync fn=${fn%'</fn>'}
ebc248f21b276416f76e20da3add001aff9fc30avboxsync ;;
061bebe04c5bfa05ed733d2a1204389c2a0c96a8vboxsync '<line>'*'</line>')
061bebe04c5bfa05ed733d2a1204389c2a0c96a8vboxsync line=${data#'<line>'}
061bebe04c5bfa05ed733d2a1204389c2a0c96a8vboxsync line=${line%'</line>'}
061bebe04c5bfa05ed733d2a1204389c2a0c96a8vboxsync ;;
061bebe04c5bfa05ed733d2a1204389c2a0c96a8vboxsync '</frame>')
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync [[ $dir ]] && dir+=/
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync dir+=$file
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync [[ $dir ]] && dir+=:
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync [[ $line ]] && dir+=$line:
ca551aca153d6df494985b5281c573ba2e3eb474vboxsync [[ $fn ]] && dir+=$fn
[[ $dir ]] && echo $'\t '$dir
state=KEEP
;;
esac
;;
KEEP) case $data in
'<auxwhat>'*'</auxwhat>')
what=${data#'<auxwhat>'}
what=${what%'</auxwhat>'}
echo $'\t'"$what"
;;
'<frame>')
state=FRAME
dir=
file=
fn=
line=
;;
'<what>Syscall param mount(type) points to unaddressable byte(s)</what>')
state=SKIP
;;
'<what>'*'</what>')
(( errors++ ))
what=${data#'<what>'}
what=${what%'</what>'}
echo $'\n\t'"$what"
;;
'<xwhat>')
state=WHAT
;;
'</error>')
state=INIT
;;
esac
;;
SKIP) case $data in
'</error>')
state=INIT
;;
esac
;;
WHAT) case $data in
'<text>'*'</text>')
(( errors++ ))
what=${data#'<text>'}
what=${what%'</text>'}
echo $'\n\t'"$what"
;;
'</xwhat>')
state=KEEP
;;
esac
;;
esac
done < "$1"
(( errors )) && echo
return $errors
}
unset DISPLAY ENV FIGNORE HISTFILE
trap + PIPE # unadvertized -- set SIGPIPE to SIG_DFL #
integer compile=-1 posix=-1 utf8=-1
integer debug=0 locale=0 time=1
typeset vmalloc_options=abort trace= valgrind=
vmalloc_options= #XXX# until multi-region vmalloc trace fixed #XXX#
while getopts -a $command "$USAGE" OPT
do case $OPT in
c) if (( $OPTARG ))
then compile=2
else compile=0
fi
;;
d) debug=$OPTARG
;;
l) locale=$OPTARG
;;
p) posix=$OPTARG
;;
t) time=$OPTARG
;;
u) utf8=$OPTARG
;;
v) if (( OPTARG ))
then vmalloc_options=abort
else vmalloc_options=
fi
;;
V) valgrind="${VALGRIND:-valgrind} ${VALGRINDFLAGS:-$valgrindflags}"
vmalloc_options=
;;
x) trace=-x
;;
*) usage
;;
esac
done
shift $OPTIND-1
if (( debug )) || [[ $trace ]]
then export PS4=':$LINENO: '
if (( debug ))
then set -x
fi
fi
while [[ $1 == *=* ]]
do eval export "$1"
shift
done
if (( compile <= 0 && posix <= 0 && utf8 <= 0 ))
then (( compile )) && compile=1
(( posix )) && posix=1
(( utf8 )) && utf8=1
fi
(( compile < 0 )) && compile=0
(( posix < 0 )) && posix=0
(( utf8 < 0 )) && utf8=0
if (( locale ))
then utf8=0
if [[ $LC_ALL ]]
then export LANG=$LC_ALL
fi
else unset LANG LC_ALL
export LC_NUMERIC=C
fi
if [[ $VMALLOC_OPTIONS ]]
then vmalloc_options=$VMALLOC_OPTIONS
else VMALLOC_OPTIONS=$vmalloc_options
fi
[[ $VMALLOC_OPTIONS ]] || timesensitive=.
export PATH PWD SHCOMP SHELL VMALLOC_OPTIONS
PWD=$(pwd)
SHELL=${SHELL-ksh}
case $0 in
/*) d=$(dirname $0);;
*/*) d=$PWD/$(dirname $0);;
*) d=$PWD;;
esac
case $SHELL in
/*) ;;
*/*) SHELL=$d/$SHELL;;
*) SHELL=$(whence $SHELL);;
esac
PATH=/bin:/usr/bin
if [[ -d /usr/ucb ]]
then PATH=$PATH:/usr/ucb
fi
PATH=$PATH:$d
if [[ $INSTALLROOT && -r $INSTALLROOT/bin/.paths ]]
then PATH=$INSTALLROOT/bin:$PATH
fi
if [[ ${SHELL%/*} != $INSTALLROOT/bin ]]
then PATH=${SHELL%/*}:$PATH
fi
if [[ ! $SHCOMP ]]
then s=${SHELL:##*sh}
s=${SHELL:%/*}/shcomp$s
if [[ -x $s ]]
then SHCOMP=$s
elif [[ -x ${s%-g} ]]
then SHCOMP=${s%-g}
else SHCOMP=shcomp
fi
fi
if (( compile ))
then if whence $SHCOMP > /dev/null
then tmp=$(mktemp -dt) || { echo mktemp -dt failed >&2; exit 1; }
trap "cd /; rm -rf $tmp" EXIT
elif (( compile > 1 ))
then echo $0: --compile: $SHCOMP not found >&2
exit 1
else compile=0
fi
fi
if [[ $valgrind ]]
then if [[ -x $SHELL-g ]]
then SHELL=$SHELL-g
fi
if [[ ! $tmp ]]
then tmp=$(mktemp -dt) || { echo mktemp -dt failed >&2; exit 1; }
trap "cd /; rm -rf $tmp" EXIT
fi
valxml=$tmp/valgrind.xml
valgrind+=" --xml-file=$valxml"
fi
typeset -A tests
for i in ${*-*.sh}
do if [[ ! -r $i ]]
then echo $0: $i: not found >&2
continue
fi
t=$(grep -c err_exit $i)
if (( t > 2 ))
then (( t = t - 2 ))
fi
tests[$i]=$t
T=test
if (( t != 1 ))
then T=${T}s
fi
u=${i##*/}
u=${u%.sh}
if [[ $i == $timesensitive ]]
then VMALLOC_OPTIONS=
fi
if (( posix || utf8 ))
then locales=
(( posix )) && locales+=" ${LANG:-C}"
[[ $utf8 == 0 || $i == $setslocale ]] || locales+=" C.UTF-8"
for lang in $locales
do o=$u
if [[ $lang == C ]]
then lang=
else o="$o($lang)"
lang=LANG=$lang
fi
echo test $o begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"}
E=error
eval $lang \$valgrind \$SHELL \$trace \$i
e=$?
if [[ $valgrind ]]
then valxml $valxml
(( e += $? ))
fi
if (( e == 0 ))
then echo test $o passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 ${E}s ]"
else e=$?
if (( e != 1 ))
then E=${E}s
fi
echo test $o failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $e $E ]"
fi
done
fi
if (( compile ))
then c=$tmp/shcomp-$u.ksh
o="$u(shcomp)"
echo test $o begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"}
E=error
if $SHCOMP $i > $c
then if $valgrind $SHELL $trace $c
then echo test $o passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 ${E}s ]"
else e=$?
if (( e != 1 ))
then E=${E}s
fi
echo test $o failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $e $E ]"
fi
else e=$?
t=1
T=test
echo test $o failed to compile ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T 1 $E ]"
fi
if [[ $i == $timesensitive ]]
then VMALLOC_OPTIONS=$vmalloc_options
fi
fi
done