xref: /titanic_50/usr/src/lib/libshell/common/tests/shtests (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
1da2e3ebdSchin# This program runs ksh regression tests
27c2fbfb3SApril Chin# shtests [ name=value ... ] [ --all | --compile ] [ --time ] [ a.sh b.sh ... ]
3da2e3ebdSchin
434f9b3eeSRoland Mainztimesensitive='*@(options|sigchld|subshell).sh'
534f9b3eeSRoland Mainz
634f9b3eeSRoland Mainzunset DISPLAY ENV FIGNORE HISTFILE
7da2e3ebdSchinLANG=C
8da2e3ebdSchinLC_ALL=C
97c2fbfb3SApril Chincompile=1
107c2fbfb3SApril Chinscript=1
11da2e3ebdSchintime=1
12*3e14f97fSRoger A. Faulknervmalloc_options=abort
13da2e3ebdSchinwhile	:
14da2e3ebdSchindo	case $1 in
157c2fbfb3SApril Chin	-a|--a*)compile=2
167c2fbfb3SApril Chin		script=2
177c2fbfb3SApril Chin		;;
187c2fbfb3SApril Chin	-c|--c*)compile=2
197c2fbfb3SApril Chin		script=
207c2fbfb3SApril Chin		;;
217c2fbfb3SApril Chin	-s|--s*)compile=
227c2fbfb3SApril Chin		script=2
237c2fbfb3SApril Chin		;;
247c2fbfb3SApril Chin	-t|--not*)time=
257c2fbfb3SApril Chin		;;
26*3e14f97fSRoger A. Faulkner	-v|--nov*)vmalloc_options=
277c2fbfb3SApril Chin		;;
287c2fbfb3SApril Chin	-*)	echo $0: $1: invalid option >&2
297c2fbfb3SApril Chin		exit 2
307c2fbfb3SApril Chin		;;
31da2e3ebdSchin	*=*)	n=${1%%=*}
32da2e3ebdSchin		v=${1#*=}
33da2e3ebdSchin		eval $n=\'$v\'
34da2e3ebdSchin		export $n
35da2e3ebdSchin		;;
36da2e3ebdSchin	*)	break
37da2e3ebdSchin		;;
38da2e3ebdSchin	esac
39da2e3ebdSchin	shift
40da2e3ebdSchindone
41*3e14f97fSRoger A. Faulknerif	[[ $VMALLOC_OPTIONS ]]
42*3e14f97fSRoger A. Faulknerthen	vmalloc_options=$VMALLOC_OPTIONS
43*3e14f97fSRoger A. Faulknerelse	VMALLOC_OPTIONS=$vmalloc_options
447c2fbfb3SApril Chinfi
45*3e14f97fSRoger A. Faulkner[[ $VMALLOC_OPTIONS ]] || timesensitive=.
46*3e14f97fSRoger A. Faulknerexport LANG LC_ALL PATH PWD SHELL VMALLOC_OPTIONS
47da2e3ebdSchinPWD=`pwd`
48da2e3ebdSchinSHELL=${SHELL-ksh}
49da2e3ebdSchincase $0 in
50da2e3ebdSchin/*)	d=`dirname $0`;;
51da2e3ebdSchin*/*)	d=$PWD/`dirname $0`;;
52da2e3ebdSchin*)	d=$PWD;;
53da2e3ebdSchinesac
54da2e3ebdSchincase $SHELL in
55da2e3ebdSchin/*)	;;
56da2e3ebdSchin*/*)	SHELL=$d/$SHELL;;
57da2e3ebdSchin*)	SHELL=$(whence $SHELL);;
58da2e3ebdSchinesac
59da2e3ebdSchinPATH=/bin:/usr/bin
60da2e3ebdSchinif	[[ -d /usr/ucb ]]
61da2e3ebdSchinthen	PATH=$PATH:/usr/ucb
62da2e3ebdSchinfi
63da2e3ebdSchinPATH=$PATH:$d
64da2e3ebdSchinif	[[ $INSTALLROOT && -r $INSTALLROOT/bin/.paths ]]
65da2e3ebdSchinthen	PATH=$INSTALLROOT/bin:$PATH
66da2e3ebdSchinfi
677c2fbfb3SApril Chinif	[[ $compile ]]
687c2fbfb3SApril Chinthen	SHCOMP=${SHCOMP:-shcomp}
697c2fbfb3SApril Chin	if	whence $SHCOMP > /dev/null
7034f9b3eeSRoland Mainz	then	tmp=$(mktemp -dt) || { echo mktemp -dt failed >&2; exit 1; }
7134f9b3eeSRoland Mainz		trap "cd /; rm -rf $tmp" EXIT
727c2fbfb3SApril Chin	elif	[[ $compile != 1 ]]
737c2fbfb3SApril Chin	then	echo $0: --compile: $SHCOMP not found >&2
747c2fbfb3SApril Chin		exit 1
757c2fbfb3SApril Chin	else	compile=
76da2e3ebdSchin	fi
777c2fbfb3SApril Chinfi
787c2fbfb3SApril Chintypeset -A tests
797c2fbfb3SApril Chinfor i in ${*-*.sh}
80*3e14f97fSRoger A. Faulknerdo	if	[[ ! -r $i ]]
81*3e14f97fSRoger A. Faulkner	then	echo $0: $i: not found >&2
82*3e14f97fSRoger A. Faulkner		continue
83*3e14f97fSRoger A. Faulkner	fi
84*3e14f97fSRoger A. Faulkner	t=$(grep -c err_exit $i)
857c2fbfb3SApril Chin	if	(( $t > 2 ))
867c2fbfb3SApril Chin	then	(( t = $t - 2 ))
877c2fbfb3SApril Chin	fi
887c2fbfb3SApril Chin	tests[$i]=$t
89da2e3ebdSchin	T=test
90da2e3ebdSchin	if	(( $t != 1 ))
91da2e3ebdSchin	then	T=${T}s
92da2e3ebdSchin	fi
93da2e3ebdSchin	E=error
947c2fbfb3SApril Chin	if	[[ $script ]]
957c2fbfb3SApril Chin	then	echo test $i begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"}
9634f9b3eeSRoland Mainz		if	[[ $i == $timesensitive ]]
97*3e14f97fSRoger A. Faulkner		then	VMALLOC_OPTIONS=
9834f9b3eeSRoland Mainz		fi
99da2e3ebdSchin		if	$SHELL $i
100da2e3ebdSchin		then	echo test $i passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 ${E}s ]"
101da2e3ebdSchin		else	e=$?
1027c2fbfb3SApril Chin			if	(( e > 256 ))
1037c2fbfb3SApril Chin			then	e=1
1047c2fbfb3SApril Chin				E=signal
1057c2fbfb3SApril Chin			fi
106da2e3ebdSchin			if	(( $e != 1 ))
107da2e3ebdSchin			then	E=${E}s
108da2e3ebdSchin			fi
109da2e3ebdSchin			echo test $i failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $e $E ]"
110da2e3ebdSchin		fi
11134f9b3eeSRoland Mainz		if	[[ $i == $timesensitive ]]
112*3e14f97fSRoger A. Faulkner		then	VMALLOC_OPTIONS=$vmalloc_options
11334f9b3eeSRoland Mainz		fi
1147c2fbfb3SApril Chin	fi
115da2e3ebdSchindone
1167c2fbfb3SApril Chinif	[[ $compile ]]
1177c2fbfb3SApril Chinthen	for i in ${*-*.sh}
118*3e14f97fSRoger A. Faulkner	do	if	[[ ! -r $i ]]
119*3e14f97fSRoger A. Faulkner		then	continue
120*3e14f97fSRoger A. Faulkner		fi
121*3e14f97fSRoger A. Faulkner		t=${tests[$i]}
1227c2fbfb3SApril Chin		T=test
1237c2fbfb3SApril Chin		if	(( $t != 1 ))
1247c2fbfb3SApril Chin		then	T=${T}s
1257c2fbfb3SApril Chin		fi
1267c2fbfb3SApril Chin		o=${i##*/}
1277c2fbfb3SApril Chin		o=shcomp-${o%.sh}.ksh
1287c2fbfb3SApril Chin		echo test $o begins ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"}
1297c2fbfb3SApril Chin		E=error
1307c2fbfb3SApril Chin		if	$SHCOMP $i > $tmp/$o
13134f9b3eeSRoland Mainz		then	if	[[ $i == $timesensitive ]]
132*3e14f97fSRoger A. Faulkner			then	VMALLOC_OPTIONS=
13334f9b3eeSRoland Mainz			fi
13434f9b3eeSRoland Mainz			if	$SHELL $tmp/$o
1357c2fbfb3SApril Chin			then	echo test $o passed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} "[ $t $T 0 ${E}s ]"
1367c2fbfb3SApril Chin			else	e=$?
1377c2fbfb3SApril Chin				if	(( e > 256 ))
1387c2fbfb3SApril Chin				then	e=1
1397c2fbfb3SApril Chin					E=signal
1407c2fbfb3SApril Chin				fi
1417c2fbfb3SApril Chin				if	(( $e != 1 ))
1427c2fbfb3SApril Chin				then	E=${E}s
1437c2fbfb3SApril Chin				fi
1447c2fbfb3SApril Chin				echo test $o failed ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T $e $E ]"
1457c2fbfb3SApril Chin			fi
14634f9b3eeSRoland Mainz			if	[[ $i == $timesensitive ]]
147*3e14f97fSRoger A. Faulkner			then	VMALLOC_OPTIONS=$vmalloc_options
14834f9b3eeSRoland Mainz			fi
1497c2fbfb3SApril Chin		else	e=$?
1507c2fbfb3SApril Chin			t=1
1517c2fbfb3SApril Chin			T=test
1527c2fbfb3SApril Chin			echo test $o failed to compile ${time:+"at $(date +%Y-%m-%d+%H:%M:%S)"} with exit code $e "[ $t $T 1 $E ]"
1537c2fbfb3SApril Chin		fi
1547c2fbfb3SApril Chin	done
1557c2fbfb3SApril Chinfi
156