xref: /netbsd-src/external/mpl/dhcp/dist/keama/tests/runone.sh (revision aef5eb5f59cdfe8314f1b5f78ac04eb144e44010)
1#!/bin/sh
2
3#set -x
4
5if [ $# -ne 1 ]; then
6	echo "usage: $0 test-name" >&2
7	exit 1
8fi
9
10file=$1
11
12cd "$(dirname "$0")"
13
14isin=$(expr $file : ".*\.in*")
15iserr=$(expr $file : ".*\.err*")
16if [ \( $isin -eq 0 \) -a \( $iserr -eq 0 \) ]; then
17	full=$file.in*
18	if [ ! -f $full ]; then
19		full=$file.err*
20	fi
21else
22	full=$file
23fi
24
25if [ ! -f $full ]; then
26	echo "can't find $file" >&2
27	exit 1
28fi
29
30errcase=$(expr $full : ".*\.err*")
31
32trail=
33if [ $errcase -eq 0 ]; then
34	trail=$(expr $full : ".*\.in\(.\)")
35else
36	trail=$(expr $full : ".*\.err\(.\)")
37fi
38
39options=""
40dual=0
41hook=0
42
43case $trail in
44	'') dual=1;;
45	4) options="-4";;
46	6) options="-6";;
47	F) options="-4 -r fatal";;
48	P) options="-4 -r pass";;
49	d) options="-4 -D";;
50	D) options="-6 -D";;
51	n) options="-4 -N";;
52	N) options="-6 -N";;
53	l) options="-4 -l ${HOOK:-/path/}"; hook=1;;
54	L) options="-6 -l ${HOOK:-/path/}"; hook=1;;
55	*) echo "unrecognized trail '$trail' in '$full'" >&2; exit 1;;
56esac
57
58if [ $errcase -ne 0 ]; then
59	base=$(basename $full .err$trail)
60else
61	if [ $dual -ne 0 ]; then
62		echo "required trail ([45FP]) in '$full'" >&2
63		exit 1
64	fi
65	base=$(basename $full .in$trail)
66fi
67
68out=/tmp/$base.out$$
69expected=""
70if [ $errcase -ne 0 ]; then
71	expected=$base.msg
72else
73	expected=$base.out
74fi
75
76if [ $errcase -ne 0 ]; then
77	if [ $dual -eq 1 ]; then
78		../keama -4 -i $full >$out 2>&1
79		if [ $? -ne 255 ]; then
80			echo "$full -4 doesn't fail as expected" >&2
81			exit 1
82		fi
83		../keama -6 -i $full >$out 2>&1
84		if [ $? -ne 255 ]; then
85			echo "$full -6 doesn't fail as expected" >&2
86			exit 1
87		fi
88	else
89		../keama $options -i $full >$out 2>&1
90		if [ $? -ne 255 ]; then
91			echo "$full doesn't fail as expected" >&2
92			exit 1
93		fi
94	fi
95else
96	../keama $options -i  $full -o $out >&2
97	if [ $? -eq 255 ]; then
98		echo "$full raised an error" >&2
99		exit 1
100	fi
101fi
102
103if [ $hook -eq 1 ]; then
104    sed s,/path/,${HOOK:-/path/}, < ${expected}L > $expected
105fi
106
107if [ $errcase -ne 0 ]; then
108	cat $out | head -1 | diff --brief - $expected
109	if [ $? -ne 0 ]; then
110		echo "$full doesn't provide expected output" >&2
111		exit 1
112	fi
113else
114	diff --brief $out $expected
115	if [ $? -ne 0 ]; then
116		echo "$full doesn't provide expected output" >&2
117		exit 1
118	fi
119fi
120