File: test_runner.sh

package info (click to toggle)
libbfio 20160108-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 8,924 kB
  • ctags: 3,014
  • sloc: ansic: 97,641; sh: 12,271; makefile: 728; sed: 134
file content (133 lines) | stat: -rwxr-xr-x 3,238 bytes parent folder | download | duplicates (2)
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#!/bin/bash
#
# Script to run an executable for testing.
#
# When CHECK_WITH_VALGRIND is set to a non-empty value the executable
# is run with valgrind, otherwise it is run without.
#
# When CHECK_WITH_GDB is set to a non-empty value the executable
# is run with gdb, otherwise it is run without.
#
# Copyright (C) 2009-2016, Joachim Metz <joachim.metz@gmail.com>
#
# Refer to AUTHORS for acknowledgements.
#
# This software is free software: you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This software is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this software.  If not, see <http://www.gnu.org/licenses/>.
#

EXIT_SUCCESS=0;
EXIT_FAILURE=1;
EXIT_IGNORE=77;

if test $# -le 0;
then
	echo "Missing arguments";

	exit ${EXIT_FAILURE};
fi

EXECUTABLE=$1;

shift

if ! test -x ${EXECUTABLE};
then
	echo "Invalid executable: ${EXECUTABLE}";

	exit ${EXIT_FAILURE};
fi

if ! test -d "tmp";
then
	echo "Missing tmp directory.";

	exit ${EXIT_FAILURE};
fi

# Check if the executable needs to run with valgrind or gdb
if ! test -z ${CHECK_WITH_VALGRIND} || ! test -z ${CHECK_WITH_GDB};
then
	# Check if the executable is a libtool shell script or a binary.
	# Use the binary in combination with valgrind otherwise the shell binary is also tested.
	file -bi ${EXECUTABLE} | sed 's/;.*$//' | grep "text/x-shellscript" > /dev/null 2>&1;

	echo ${EXECUTABLE} | grep 'tools' > /dev/null 2>&1;

	if test $? -eq 0;
	then
		LIBRARY=`dirname ${EXECUTABLE} | sed 's?.*/\(.*\)tools$?lib\1?'`;
	else
		LIBRARY=`basename ${EXECUTABLE} | sed 's/^\(.*\)_test_.*$/lib\1/'`;
	fi

	if test $? -eq 0;
	then
		DIRNAME=`dirname ${EXECUTABLE}`;
		BASENAME=`basename ${EXECUTABLE}`;
		EXECUTABLE="${DIRNAME}/.libs/${BASENAME}";

		if ! test -x ${EXECUTABLE};
		then
			echo "Unable to find executable: ${EXECUTABLE}";

			exit ${EXIT_FAILURE};
		fi

		file -bi ${EXECUTABLE} | sed 's/;.*$//' | grep "application/x-executable" > /dev/null 2>&1;

		if test $? -ne 0;
		then
			echo "Invalid executable: ${EXECUTABLE}";

			exit ${EXIT_FAILURE};
		fi
	fi

	if ! test -z ${CHECK_WITH_VALGRIND};
	then
		IFS="
"; LD_LIBRARY_PATH="../${LIBRARY}/.libs/" valgrind --tool=memcheck --leak-check=full --track-origins=yes --show-reachable=yes --log-file=tmp/valgrind.log ${EXECUTABLE} $*;
	else
		IFS="
"; LD_LIBRARY_PATH="../${LIBRARY}/.libs/" gdb -ex r --args ${EXECUTABLE} $*;
	fi

	EXIT_RESULT=$?;

	if ! test -z ${CHECK_WITH_VALGRIND};
	then
		if test ${EXIT_RESULT} -eq 0;
		then
			grep "All heap blocks were freed -- no leaks are possible" tmp/valgrind.log > /dev/null 2>&1;

			if test $? -ne 0;
			then
				echo "Memory leakage detected.";

				cat tmp/valgrind.log;

				EXIT_RESULT=${EXIT_FAILURE};
			fi
		fi
		rm -f tmp/valgrind.log;
	fi
else
	IFS="
"; ${EXECUTABLE} $*;

	EXIT_RESULT=$?;
fi

exit ${EXIT_RESULT};