xref: /netbsd-src/external/bsd/unbound/dist/testdata/02-unittest.tdir/02-unittest.test (revision 7cd94d692f099dff0c03996f61fd7a476e40159b)
1# #-- 02-unittest.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 unittest; $MAKE lock-verify)
11
12if test -f $PRE/unbound_do_valgrind_in_test; then
13	do_valgrind=yes
14else
15	do_valgrind=no
16fi
17VALGRIND_FLAGS="--leak-check=full --show-leak-kinds=all"
18
19if test $do_valgrind = "yes"; then
20	echo "valgrind yes"
21	echo
22	tmpout=/tmp/tmpout.$$
23	if (cd $PRE; valgrind $VALGRIND_FLAGS ./unittest >$tmpout 2>&1); then
24		echo "unit test worked."
25	else
26		echo "unit test failed."
27		exit 1
28	fi
29	if grep "All heap blocks were freed -- no leaks are possible" $tmpout; then
30		:  # clean
31	else
32		cat $tmpout
33		echo "Memory leaked in unittest"
34		grep "in use at exit" $tmpout
35		exit 1
36	fi
37	if grep "ERROR SUMMARY: 0 errors from 0 contexts" $tmpout; then
38		:  # clean
39	else
40		cat $tmpout
41		echo "Errors in unittest"
42		grep "ERROR SUMMARY" $tmpout
43		exit 1
44	fi
45	rm -f $tmpout
46else
47	# without valgrind
48	if (cd $PRE; ./unittest); then
49		echo "unit test worked."
50	else
51		echo "unit test failed."
52		exit 1
53	fi
54fi
55if test -f $PRE/ublocktrace.0; then
56	if (cd $PRE; ./lock-verify ublocktrace.*); then
57		echo "lock-verify test worked."
58	else
59		echo "lock-verify test failed."
60		exit 1
61	fi
62fi
63exit 0
64