sd: remove 'ssd' driver support
[unleashed/tickless.git] / usr / src / lib / libshell / common / tests / shtests
blob645d290574a43ec25a64f14abbf03ee7f191f914
1 # This program runs ksh regression tests
2 # shtests [ name=value ... ] [ --all | --compile ] [ --time ] [ a.sh b.sh ... ]
4 timesensitive='*@(options|sigchld|subshell).sh'
6 unset DISPLAY ENV FIGNORE HISTFILE
7 LANG=C
8 LC_ALL=C
9 compile=1
10 script=1
11 time=1
12 vmalloc_options=abort
13 while   :
14 do      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
40 done
41 if      [[ $VMALLOC_OPTIONS ]]
42 then    vmalloc_options=$VMALLOC_OPTIONS
43 else    VMALLOC_OPTIONS=$vmalloc_options
45 [[ $VMALLOC_OPTIONS ]] || timesensitive=.
46 export LANG LC_ALL PATH PWD SHELL VMALLOC_OPTIONS
47 PWD=`pwd`
48 SHELL=${SHELL-ksh}
49 case $0 in
50 /*)     d=`dirname $0`;;
51 */*)    d=$PWD/`dirname $0`;;
52 *)      d=$PWD;;
53 esac
54 case $SHELL in
55 /*)     ;;
56 */*)    SHELL=$d/$SHELL;;
57 *)      SHELL=$(whence $SHELL);;
58 esac
59 PATH=/bin:/usr/bin
60 if      [[ -d /usr/ucb ]]
61 then    PATH=$PATH:/usr/ucb
63 PATH=$PATH:$d
64 if      [[ $INSTALLROOT && -r $INSTALLROOT/bin/.paths ]]
65 then    PATH=$INSTALLROOT/bin:$PATH
67 if      [[ $compile ]]
68 then    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
78 typeset -A tests
79 for i in ${*-*.sh}
80 do      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
115 done
116 if      [[ $compile ]]
117 then    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