forked from json-c/json-c
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test-defs.sh
executable file
·114 lines (94 loc) · 2.63 KB
/
test-defs.sh
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
#! /bin/sh
# Make sure srcdir is an absolute path. Supply the variable
# if it does not exist. We want to be able to run the tests
# stand-alone!!
#
srcdir=${srcdir-.}
if test ! -d $srcdir ; then
echo "test-defs.sh: installation error" 1>&2
exit 1
fi
# Use absolute paths
case "$srcdir" in
/* | [A-Za-z]:\\*) ;;
*) srcdir=`\cd $srcdir && pwd` ;;
esac
case "$top_builddir" in
/* | [A-Za-z]:\\*) ;;
*) top_builddir=`\cd ${top_builddir-..} && pwd` ;;
esac
progname=`echo "$0" | sed 's,^.*/,,'`
testname=`echo "$progname" | sed 's,-.*$,,'`
testsubdir=${testsubdir-testSubDir}
# User can set VERBOSE to cause output redirection
case "$VERBOSE" in
[Nn]|[Nn][Oo]|0|"")
VERBOSE=0
exec > /dev/null 2>&1
;;
[Yy]|[Yy][Ee][Ss])
VERBOSE=1
;;
esac
rm -rf "$testsubdir/$progname" > /dev/null 2>&1
mkdir -p "$testsubdir/$progname"
cd "$testsubdir/$progname" \
|| { echo "Cannot make or change into $testsubdir/$progname"; exit 1; }
echo "=== Running test $progname"
CMP="${CMP-cmp}"
use_valgrind=${USE_VALGRIND-1}
valgrind_path=$(which valgrind 2> /dev/null)
if [ -z "${valgrind_path}" -o ! -x "${valgrind_path}" ] ; then
use_valgrind=0
fi
#
# This is a common function to check the results of a test program
# that is intended to generate consistent output across runs.
#
# ${top_builddir} must be set to the top level build directory.
#
# Output will be written to the current directory.
#
# It must be passed the name of the test command to run, which must be present
# in the ${top_builddir} directory.
#
# It will compare the output of running that against <name of command>.expected
#
run_output_test()
{
TEST_COMMAND="$1"
REDIR_OUTPUT="> \"${TEST_COMMAND}.out\""
if [ $VERBOSE -gt 1 ] ; then
REDIR_OUTPUT="| tee \"${TEST_COMMAND}.out\""
fi
if [ $use_valgrind -eq 1 ] ; then
eval valgrind --tool=memcheck \
--trace-children=yes \
--demangle=yes \
--log-file=vg.out \
--leak-check=full \
--show-reachable=yes \
--run-libc-freeres=yes \
"\"${top_builddir}/${TEST_COMMAND}\"" ${REDIR_OUTPUT}
err=$?
else
eval "\"${top_builddir}/${TEST_COMMAND}"\" ${REDIR_OUTPUT}
err=$?
fi
if [ $err -ne 0 ] ; then
echo "ERROR: ${TEST_COMMAND} exited with non-zero exit status: $err" 1>&2
fi
if [ $use_valgrind -eq 1 ] ; then
if ! tail -1 "vg.out" | grep -q "ERROR SUMMARY: 0 errors" ; then
echo "ERROR: valgrind found errors during execution:" 1>&2
cat vg.out
err=1
fi
fi
if ! "$CMP" -s "${top_builddir}/${TEST_COMMAND}.expected" "${TEST_COMMAND}.out" ; then
echo "ERROR: ${TEST_COMMAND} failed:" 1>&2
diff "${top_builddir}/${TEST_COMMAND}.expected" "${TEST_COMMAND}.out" 1>&2
err=1
fi
return $err
}