xref: /netbsd-src/external/bsd/unbound/dist/testdata/03-testbound.tdir/03-testbound.test (revision ae87de8892f277bece3527c15b186ebcfa188227)
1# #-- 03-testbound.test --#
2# source the master var file when it's there
3[ -f ../.tpkg.var.master ] && source ../.tpkg.var.master
4# use .tpkg.var.test for in test variable passing
5[ -f .tpkg.var.test ] && source .tpkg.var.test
6
7. ../common.sh
8PRE="../.."
9get_make
10(cd $PRE ; $MAKE testbound)
11exitval=0
12# quiet="" to make verbose
13
14if test -f $PRE/unbound_do_valgrind_in_test; then
15	do_valgrind=yes
16else
17	do_valgrind=no
18fi
19VALGRIND_FLAGS="--leak-check=full --show-leak-kinds=all"
20# valgrind mode for debug
21#if grep "staticexe=-static" $PRE/Makefile >/dev/null 2>&1; then
22#	if test -x "`which valgrind`"; then
23#		do_valgrind=yes
24#	fi
25#fi
26
27# self-test (unit test of testbound)
28if test $do_valgrind = "yes"; then
29	echo "valgrind yes"
30	echo
31	if (valgrind $VALGRIND_FLAGS $PRE/testbound -s >tmpout 2>&1;); then
32		echo "selftest   OK  "
33	else
34		echo "selftest FAILED"
35		exit 1
36	fi
37	if grep "All heap blocks were freed -- no leaks are possible" tmpout; then
38		:  # clean
39	else
40		cat tmpout
41		echo "Memory leaked in selftest"
42		grep "in use at exit" tmpout
43		exit 1
44	fi
45	if grep "ERROR SUMMARY: 0 errors from 0 contexts" tmpout; then
46		:  # clean
47	else
48		cat tmpout
49		echo "Errors in selftest"
50		grep "ERROR SUMMARY" tmpout
51		exit 1
52	fi
53else
54	if ($PRE/testbound -s >/dev/null 2>&1;); then
55		echo "selftest   OK  "
56	else
57		echo "selftest FAILED"
58		exit 1
59	fi
60fi
61
62
63# the .crpl are not always supported and need checking for SHA256 and GOST
64# support.
65# the .rpl should work on any system (portable).
66for input in $PRE/testdata/*.rpl $PRE/testdata/*.crpl; do
67	header=`grep SCENARIO_BEGIN $input | head -1 | sed -e 's/SCENARIO_BEGIN //'`
68	cleaninput=`echo $input | sed -e "s?$PRE/testdata/??"`
69
70	# detect if SHA256 is needed
71	if echo $cleaninput | grep sha2 >/dev/null 2>&1; then
72		if $PRE/testbound -2 >/dev/null 2>&1; then
73			: # the SHA256 is supported
74		else
75			continue
76		fi
77	fi
78
79	# detect if GOST is needed
80	if echo $cleaninput | grep gost >/dev/null 2>&1; then
81		if $PRE/testbound -g >/dev/null 2>&1; then
82			: # GOST is supported
83		else
84			continue
85		fi
86	fi
87
88	# detect if CLIENT_SUBNET is needed
89	if echo $cleaninput | grep subnet >/dev/null 2>&1; then
90		if $PRE/testbound -c >/dev/null 2>&1; then
91			: # CLIENT_SUBNET is supported
92		else
93			continue
94		fi
95	fi
96
97	# detect if IPSECMOD is needed
98	if echo $cleaninput | grep ipsecmod >/dev/null 2>&1; then
99		if $PRE/testbound -i >/dev/null 2>&1; then
100			: # IPSECMOD is supported
101		else
102			continue
103		fi
104	fi
105
106	if test $do_valgrind = "yes"; then
107		echo
108		if (valgrind $VALGRIND_FLAGS $PRE/testbound -p $input >tmpout 2>&1;); then
109			echo "  OK   $cleaninput: $header"
110		else
111			echo "FAILED $cleaninput: $header"
112			exitval=1
113		fi
114		if grep "All heap blocks were freed -- no leaks are possible" tmpout; then
115			:  # clean
116		else
117			grep "^==" tmpout
118			echo "Memory leaked in $cleaninput"
119			grep "in use at exit" tmpout
120			exitval=1
121		fi
122		if grep "ERROR SUMMARY: 0 errors from 0 contexts" tmpout; then
123			:  # clean
124		else
125			grep "^==" tmpout
126			echo "Errors in $cleaninput"
127			grep "ERROR SUMMARY" tmpout
128			exitval=1
129		fi
130	else
131		# do valgrind=no
132		if ($PRE/testbound -p $input >/dev/null 2>&1;); then
133			echo "  OK   $cleaninput: $header"
134		else
135			echo "FAILED $cleaninput: $header"
136			exitval=1
137		fi
138	fi
139	if test -f ublocktrace.0; then
140        	if $PRE/lock-verify ublocktrace.*; then
141                	#echo "lock-verify test $input worked."
142			i=i
143        	else
144                	echo "lock-verify test $input failed."
145			exitval=1
146        	fi
147	fi
148done
149exit $exitval
150