1#!/bin/sh
2
3unset LANG LANGUAGE
4unset LC_COLLATE
5unset LC_CTYPE
6unset LC_MONETARY
7unset LC_MESSAGES
8unset LC_NUMERIC
9unset LC_TIME
10unset LC_ALL
11
12TOPDIR=`pwd`
13
14if test ! -x ash; then
15	if test ! -x ../../busybox; then
16		echo "Can't run tests. Put ash binary into this directory (`pwd`)"
17		exit 1
18	fi
19	echo "No ./ash - creating a link to ../../busybox"
20	ln -s ../../busybox ash
21fi
22if test ! -f .config; then
23	if test ! -f ../../.config; then
24		echo "Missing .config file"
25		exit 1
26	fi
27	cp ../../.config . || exit 1
28fi
29
30eval $(sed -e '/^#/d' -e '/^$/d' -e 's:^:export :' .config)
31
32test -x printenv || gcc -O2 -o printenv printenv.c || exit $?
33test -x recho    || gcc -O2 -o recho    recho.c    || exit $?
34test -x zecho    || gcc -O2 -o zecho    zecho.c    || exit $?
35
36PATH="`pwd`:$PATH" # for ash and recho/zecho/printenv
37export PATH
38
39THIS_SH="`pwd`/ash"
40export THIS_SH
41
42do_test()
43{
44	test -d "$1" || return 0
45	d=${d%/}
46#	echo Running tests in directory "$1"
47	# $1 but with / replaced by # so that it can be used as filename part
48	noslash=`echo "$1" | sed 's:/:#:g'`
49	(
50	cd "$1" || { echo "cannot cd $1!"; exit 1; }
51	for x in run-*; do
52		test -f "$x" || continue
53		case "$x" in
54			"$0"|run-minimal|run-gprof) ;;
55			*.orig|*~) ;;
56			#*) echo $x ; sh $x ;;
57			*)
58			echo -n "$1/$x:"
59			sh "$x" >"$TOPDIR/$noslash-$x.fail" 2>&1 && \
60			{ { echo " ok"; rm "$TOPDIR/$noslash-$x.fail"; } || echo " fail"; }
61			;;
62		esac
63	done
64	# Many bash run-XXX scripts just do this,
65	# no point in duplication it all over the place
66	for x in *.tests; do
67		test -x "$x" || continue
68		name="${x%%.tests}"
69		test -f "$name.right" || continue
70#		echo Running test: "$x"
71		echo -n "$1/$x:"
72		{
73			"$THIS_SH" "./$x" 2>&1 | \
74				grep -va "^ash: using fallback suid method$" >"$name.xx"
75			diff -u "$name.xx" "$name.right" >"$TOPDIR/$noslash-$x.fail" \
76			&& rm -f "$name.xx" "$TOPDIR/$noslash-$x.fail"
77		} && echo " ok" || echo " fail"
78	done
79	)
80}
81
82# Main part of this script
83# Usage: run-all [directories]
84
85ret=0
86
87if [ $# -lt 1 ]; then
88	# All sub directories
89	modules=`ls -d ash-*`
90	# If you want to test ash against hush testsuite
91	# (have to copy hush_test dir to current dir first):
92	#modules=`ls -d ash-* hush_test/hush-*`
93
94	for module in $modules; do
95		do_test $module || ret=1
96	done
97else
98	while [ $# -ge 1 ]; do
99	if [ -d $1 ]; then
100		do_test $1 || ret=1
101	fi
102	shift
103	done
104fi
105
106exit ${ret}
107