1# This program runs ksh regression tests 2# shtests [ name=value ... ] [ --all | --compile ] [ --time ] [ a.sh b.sh ... ] 3 4timesensitive='*@(options|sigchld|subshell).sh' 5 6unset DISPLAY ENV FIGNORE HISTFILE 7LANG=C 8LC_ALL=C 9compile=1 10script=1 11time=1 12vmalloc_options=abort 13while : 14do case $1 in 15 -a|--a*)compile=2 16 script=2 17 ;; 18 -c|--c*)compile=2 19 script= 20 ;; 21 -s|--s*)compile= 22 script=2 23 ;; 24 -t|--not*)time= 25 ;; 26 -v|--nov*)vmalloc_options= 27 ;; 28 -*) echo $0: $1: invalid option >&2 29 exit 2 30 ;; 31 *=*) n=${1%%=*} 32 v=${1#*=} 33 eval $n=\'$v\' 34 export $n 35 ;; 36 *) break 37 ;; 38 esac 39 shift 40done 41if [[ $VMALLOC_OPTIONS ]] 42then vmalloc_options=$VMALLOC_OPTIONS 43else VMALLOC_OPTIONS=$vmalloc_options 44fi 45[[ $VMALLOC_OPTIONS ]] || timesensitive=. 46export LANG LC_ALL PATH PWD SHELL VMALLOC_OPTIONS 47PWD=`pwd` 48SHELL=${SHELL-ksh} 49case $0 in 50/*) d=`dirname $0`;; 51*/*) d=$PWD/`dirname $0`;; 52*) d=$PWD;; 53esac 54case $SHELL in 55/*) ;; 56*/*) SHELL=$d/$SHELL;; 57*) SHELL=$(whence $SHELL);; 58esac 59PATH=/bin:/usr/bin 60if [[ -d /usr/ucb ]] 61then PATH=$PATH:/usr/ucb 62fi 63PATH=$PATH:$d 64if [[ $INSTALLROOT && -r $INSTALLROOT/bin/.paths ]] 65then PATH=$INSTALLROOT/bin:$PATH 66fi 67if [[ $compile ]] 68then SHCOMP=${SHCOMP:-shcomp} 69 if whence $SHCOMP > /dev/null 70 then tmp=$(mktemp -dt) || { echo mktemp -dt failed >&2; exit 1; } 71 trap "cd /; rm -rf $tmp" EXIT 72 elif [[ $compile != 1 ]] 73 then echo $0: --compile: $SHCOMP not found >&2 74 exit 1 75 else compile= 76 fi 77fi 78typeset -A tests 79for i in ${*-*.sh} 80do if [[ ! -r $i ]] 81 then echo $0: $i: not found >&2 82 continue 83 fi 84 t=$(grep -c err_exit $i) 85 if (( $t > 2 )) 86 then (( t = $t - 2 )) 87 fi 88 tests[$i]=$t 89 T=test 90 if (( $t != 1 )) 91 then T=${T}s 92 fi 93 E=error 94 if [[ $script ]] 95 then echo test $i begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} 96 if [[ $i == $timesensitive ]] 97 then VMALLOC_OPTIONS= 98 fi 99 if $SHELL $i 100 then echo test $i passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 ${E}s ]" 101 else e=$? 102 if (( e > 256 )) 103 then e=1 104 E=signal 105 fi 106 if (( $e != 1 )) 107 then E=${E}s 108 fi 109 echo test $i failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $e $E ]" 110 fi 111 if [[ $i == $timesensitive ]] 112 then VMALLOC_OPTIONS=$vmalloc_options 113 fi 114 fi 115done 116if [[ $compile ]] 117then for i in ${*-*.sh} 118 do if [[ ! -r $i ]] 119 then continue 120 fi 121 t=${tests[$i]} 122 T=test 123 if (( $t != 1 )) 124 then T=${T}s 125 fi 126 o=${i##*/} 127 o=shcomp-${o%.sh}.ksh 128 echo test $o begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} 129 E=error 130 if $SHCOMP $i > $tmp/$o 131 then if [[ $i == $timesensitive ]] 132 then VMALLOC_OPTIONS= 133 fi 134 if $SHELL $tmp/$o 135 then echo test $o passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 ${E}s ]" 136 else e=$? 137 if (( e > 256 )) 138 then e=1 139 E=signal 140 fi 141 if (( $e != 1 )) 142 then E=${E}s 143 fi 144 echo test $o failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $e $E ]" 145 fi 146 if [[ $i == $timesensitive ]] 147 then VMALLOC_OPTIONS=$vmalloc_options 148 fi 149 else e=$? 150 t=1 151 T=test 152 echo test $o failed to compile ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T 1 $E ]" 153 fi 154 done 155fi 156