xref: /openbsd/regress/lib/libc/asr/regress.subr (revision 264ca280)
1#!/bin/sh
2#	$OpenBSD: regress.subr,v 1.2 2013/03/28 09:36:03 eric Exp $
3
4TOTAL=0
5FAIL=0
6OK=0
7
8EXT0=.std
9EXT1=.asr
10EFLAG=-ee
11
12set -e
13
14fail()
15{
16	echo "*** ERROR: $@"
17	exit 1
18}
19
20regress()
21{
22	local out;
23	local _cmd=$1;
24	local _bin0=/bin/$_cmd$EXT0
25	local _bin1=/bin/$_cmd$EXT1
26	shift;
27
28	TOTAL=$((TOTAL+1))
29
30	# XXX with user "bin"
31	test -x $_RUNDIR$_bin0 || fail $_RUNDIR$_bin0 not executable
32	test -x $_RUNDIR$_bin1 || fail $_RUNDIR$_bin1 not executable
33
34	out=/tmp/asr_regress
35
36	echo -n $_cmd $EFLAG $@ "."
37
38	set +e
39	chroot -u bin "$_RUNDIR" $_bin0 $EFLAG $@ > $out.0
40	echo -n .
41	chroot -u bin "$_RUNDIR" $_bin1 $EFLAG $@ > $out.1
42	echo -n ". "
43
44	diff -u $out.0 $out.1 > $out.diff
45	set -e
46	if test -s $out.diff; then
47		FAIL=$((FAIL+1))
48		echo fail
49		echo "*** FAIL (env=$REGRESSENV)" $_cmd $EFLAG $@ >> $REG
50		tail -n +3 $out.diff >> $REG
51		echo >> $REG
52	else
53		OK=$((OK+1))
54		echo ok
55		echo "OK (env=$REGRESSENV)" $_cmd $EFLAG $@ >> $OUT
56		cat $out.0 >> $OUT
57		echo >> $OUT
58	fi
59	rm $out.diff $out.0 $out.1
60}
61
62regress_setenv()
63{
64	local _name="$1"
65
66	echo "===> using env $_name"
67
68	cp /etc/hosts $_RUNDIR/etc/
69	cp /etc/resolv.conf $_RUNDIR/etc/
70	cp /etc/protocols $_RUNDIR/etc/
71	cp /etc/networks $_RUNDIR/etc/
72
73	case $_name in
74	empty)
75		rm -f $_RUNDIR/etc/*
76		;;
77	local)
78		;;
79	file)
80		grep -v lookup /etc/resolv.conf > $_RUNDIR/etc/resolv.conf
81		echo "lookup file" >> $_RUNDIR/etc/resolv.conf
82		;;
83	bind)
84		grep -v lookup /etc/resolv.conf > $_RUNDIR/etc/resolv.conf
85		echo "lookup bind" >> $_RUNDIR/etc/resolv.conf
86		;;
87	*)
88		fail unknown env $_name
89		;;
90	esac
91	REGRESSENV=$_name
92}
93
94regress_digest()
95{
96	echo
97	cat $REG
98	echo "===>" run=$TOTAL fail=$FAIL
99}
100
101
102# needed for chroot
103test "$(id -u)" -ne 0 && fail need root privileges to run this script
104
105# we really really want to avoid erasing /etc later
106test "$RUNDIR" || fail RUNDIR is not set
107_RUNDIR=$(readlink -fn ${RUNDIR})
108test "$_RUNDIR" == / && fail RUNDIR is root dir: $RUNDIR
109
110OUT=$_RUNDIR/output.log
111REG=$_RUNDIR/regress.log
112ETC=$_RUNDIR/etc
113
114echo -n > $REG
115echo -n > $OUT
116