summaryrefslogtreecommitdiff
path: root/regress/lib/libc/asr/regress.subr
blob: 3e8cc0ebd5a66f7ef05db7c9654675fda2dd8f1b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#!/bin/sh
#	$OpenBSD: regress.subr,v 1.2 2013/03/28 09:36:03 eric Exp $

TOTAL=0
FAIL=0
OK=0

EXT0=.std
EXT1=.asr
EFLAG=-ee

set -e

fail()
{
	echo "*** ERROR: $@"
	exit 1
}

regress()
{
	local out;
	local _cmd=$1;
	local _bin0=/bin/$_cmd$EXT0
	local _bin1=/bin/$_cmd$EXT1
	shift;

	TOTAL=$((TOTAL+1))

	# XXX with user "bin"
	test -x $_RUNDIR$_bin0 || fail $_RUNDIR$_bin0 not executable
	test -x $_RUNDIR$_bin1 || fail $_RUNDIR$_bin1 not executable

	out=/tmp/asr_regress

	echo -n $_cmd $EFLAG $@ "."

	set +e
	chroot -u bin "$_RUNDIR" $_bin0 $EFLAG $@ > $out.0
	echo -n .
	chroot -u bin "$_RUNDIR" $_bin1 $EFLAG $@ > $out.1
	echo -n ". "

	diff -u $out.0 $out.1 > $out.diff
	set -e
	if test -s $out.diff; then
		FAIL=$((FAIL+1))
		echo fail
		echo "*** FAIL (env=$REGRESSENV)" $_cmd $EFLAG $@ >> $REG
		tail -n +3 $out.diff >> $REG
		echo >> $REG
	else
		OK=$((OK+1))
		echo ok
		echo "OK (env=$REGRESSENV)" $_cmd $EFLAG $@ >> $OUT
		cat $out.0 >> $OUT
		echo >> $OUT
	fi
	rm $out.diff $out.0 $out.1
}

regress_setenv()
{
	local _name="$1"

	echo "===> using env $_name"

	cp /etc/hosts $_RUNDIR/etc/
	cp /etc/resolv.conf $_RUNDIR/etc/
	cp /etc/protocols $_RUNDIR/etc/
	cp /etc/networks $_RUNDIR/etc/

	case $_name in
	empty)
		rm -f $_RUNDIR/etc/*
		;;
	local)
		;;
	file)
		grep -v lookup /etc/resolv.conf > $_RUNDIR/etc/resolv.conf
		echo "lookup file" >> $_RUNDIR/etc/resolv.conf
		;;
	bind)
		grep -v lookup /etc/resolv.conf > $_RUNDIR/etc/resolv.conf
		echo "lookup bind" >> $_RUNDIR/etc/resolv.conf
		;;
	*)
		fail unknown env $_name
		;;
	esac
	REGRESSENV=$_name
}

regress_digest()
{
	echo
	cat $REG
	echo "===>" run=$TOTAL fail=$FAIL
}


# needed for chroot
test "$(id -u)" -ne 0 && fail need root privileges to run this script

# we really really want to avoid erasing /etc later
test "$RUNDIR" || fail RUNDIR is not set
_RUNDIR=$(readlink -fn ${RUNDIR})
test "$_RUNDIR" == / && fail RUNDIR is root dir: $RUNDIR

OUT=$_RUNDIR/output.log
REG=$_RUNDIR/regress.log
ETC=$_RUNDIR/etc

echo -n > $REG
echo -n > $OUT