File: check_files.sh

package info (click to toggle)
pdfedit 0.4.5-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 15,220 kB
  • ctags: 17,436
  • sloc: cpp: 156,708; xml: 8,973; makefile: 1,003; sh: 704; ansic: 688; perl: 669; yacc: 589; python: 236; lisp: 51
file content (241 lines) | stat: -rwxr-xr-x 7,193 bytes parent folder | download
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
#!/bin/bash
# PDFedit - free program for PDF document manipulation.
# Copyright (C) 2006-2009  PDFedit team: Michal Hocko,
#                                        Jozef Misutka,
#                                        Martin Petricek
#                   Former team members: Miroslav Jahoda
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; version 2 of the License.
#
# This program 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 General Public License
# along with this program (in doc/LICENSE.GPL); if not, write to the 
# Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, 
# MA  02111-1307  USA
#
# Project is hosted on http://sourceforge.net/projects/pdfedit

###############################################################################
# Helper script for CPPUnit testing
#
# Primary goal of this script is to provide easy to review results from our
# CPPunit test cases and fast regression testings.
# Features:
# 	- runs only one test case at the time. This is especially useful when
#	  some of test cases fails/crashes, we can just log this issue and
#	  go on with other tests
#	- suppresses all output and redirects it to the log files (splitting
#	  standard and error outputs)
#	- enables auto detection of all test suites defined in CPPunit modules
#	- clean overview of results. There is list of all documents for which
#	  at least one test suite failed followed by detailed per file overview
#	  of failed suites
#	- enables fine grained control over test binary, its parameters, test
#	  suites to be checked and others (please run ./check_files.sh -h for
#	  more detailed information or look for examples).
#
# Examples:
# 1) We want to simply run all test suites from kernel test for all pdf 
#    documents in the testset directory (we are in pdfedit root tree):
#  
#	$ cd src/tests/kernel && \
#		$PDFEDIT_ROOT/check_files.sh $PDFEDIT_ROOT/testset/*.pdf
#
#    Same can be done like this from $PDFEDIT_ROOT
#	$ tools/check_files.sh -b src/tests/kernel/test_bin -d src/tests/kernel\
#		$PDFEDIT_ROOT/tests/*.pdf
#
# 2) We want to run specific test suits (lets say TEST_CPDF and TEST_STREAM)
#
#	$ cd src/tests/kernel && \
#		$PDFEDIT_ROOT/check_files.sh -t "TEST_CPDF TEST_STREAM" \
#		$PDFEDIT_ROOT/testset/*.pdf
#
#    Note that test suits have to be quoted for -t parameter.
#
# 3) We want to set debug level for test binary to have more information
#
#	$ cd src/tests/kernel && \
#		$PDFEDIT_ROOT/check_files.sh -p "-debug_level 5 -all" \
#		$PDFEDIT_ROOT/testset/*.pdf
#
#    Note that test binary parameters to be quoted for -p parameter.
#
# 4) We want to keep log files apart from current directory
#
#	$ [ -d /tmp/pdfedit.logs ] && mkdir /tmp/pdfedit.logs
#	$ cd src/tests/kernel && \
#		-l /tmp/pdfedit.logs \
#		$PDFEDIT_ROOT/testset/*.pdf
#
###############################################################################

print_help()
{
	echo "`basename $0` [-h] [-b test_binary] [-d dir_with_test|-t test_names] [-l log_dir] [-p test_params] test_doc+"
	echo where
	echo -e "\t-h\tPrints this help"
	echo -e "\t-b test_binary\tSpecifies CPPUNIT binary to run (./test_bin \n\
		by default)"
	echo -e "\t-d dir_with_test\tSpecifies directory with CPPUNIT modules. \n\
		This directory is searched for all defined test cases (*.cc and *.h
		files with CPPUNIT_TEST_SUITE_NAMED_REGISTRATION). Note that \n\
		this parameter is suppressed by -t test_names"
	echo -e "\t-t test_names\tSpecifies explicitly which test cases to run.\n\
		Note that more than one test cases have to be properly quoted. \n\
		This parameter also suppress -d parameter because it is more \n\
		specific on which test cases are run and thus we don't have to\n\
		search for them in CPPUNIT modules"
	echo -e "\t-l log_dir\tSpecifies directory where log files are placed.\n\
		Normally, all output is suppress during tests and standard output\n\
		is redirected to testdoc_testname.log and error to testdoc_testname.err\n\
		file placed in log_dir. Default value is current directory."
	echo -e "\t-p test_params\tSpecifies additional parameters for test binary.\n\
		This can be used for finer grained control over test binary \n\
		(how much verbose etc)"
	echo -e "\nAll other parameters are treated as documents to be tested.\n\
		If a parameter is not regular file, it is ignored."
	exit 0
}

# directory with test modules
TEST_DIR=./

# CPPUNIT binary
# can be overwritten by -b parameter
TEST_BIN="./test_bin"

# parameters for TEST_BIN
TEST_PARAMS=

# Documents to be tested
# Filled by files specified in command line
TEST_DOC=""

# Directory where to put result logs
# Can be overwritten by -l parameter
LOG_DIR=./

# Checks all used variables
check_vars()
{
	if [ ! -x "$TEST_BIN" ] 
	then
		echo "Test binary \"$TEST_BIN\" not found"
		exit 1
	fi

	if [ ! -d "$TEST_DIR" ] 
	then
		echo "test directory \"$TEST_DIR\" is not a directory"
		exit 1
	fi

	if [ ! -d "$LOG_DIR" ] 
	then
		echo "log directory \"$LOG_DIR\" is not a directory"
		exit 1
	fi
}

# Parse command line 
# files have precedence over parameters
while getopts hb:d:l:p:t: OPT
do
	case $OPT in
		h ) print_help ;;
		b ) TEST_BIN=$OPTARG 
		;;
		d ) TEST_DIR="$OPTARG/"
		;;
		l ) LOG_DIR="$OPTARG/"
		;;
		p ) TEST_PARAMS=$OPTARG;;
		t ) TEST_NAMES=$OPTARG;;
		* ) "Unrecognized parameter \"$param\" - ignoring" ;;
	esac
done

check_vars

# All parameters which are not recognized as options should
# be test documents
if [ $OPTIND -le $# ]
then
	shift $((OPTIND-1))
	for i in $*
	do
		if [ -f $i ]
		then	
			TEST_DOC="$TEST_DOC $i"
		else
			echo "\"$i\" is not a file - ignoring"
		fi
	done
fi

# get names of all registered (for CPPUNIT) tests
if [ -z "$TEST_NAMES" ]
then
	TEST_NAMES=`grep CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ${TEST_DIR}*.cc ${TEST_DIR}*.h | sed 's/.*\"\(.*\)\".*/\1/'`
fi

# for debugging
#echo TEST_BIN $TEST_BIN
#echo TEST_PARAMS $TEST_PARAMS
#echo TEST_DIR $TEST_DIR
#echo TEST_DOC $TEST_DOC
#echo TEST_NAMES $TEST_NAMES
#echo LOG_DIR $LOG_DIR

if [ -z "$TEST_DOC" ]
then
	echo "No test document specified"
	exit 0	
fi

# cumulative description of failed tests
# It has following format:
# document:testname\n
# for each failed test
FAILED_TESTS=""
for file_name in $TEST_DOC
do
	file_log_name=`basename ${file_name}`
	for test_name in $TEST_NAMES
	do
		$TEST_BIN $TEST_PARAMS $test_name $file_name \
			> ${LOG_DIR}${file_log_name}_${test_name}.log\
			2> ${LOG_DIR}${file_log_name}_${test_name}.err \
			|| FAILED_TESTS="${FAILED_TESTS}$file_name:$test_name\n"
	done
done

echo Failure summary:
if [ -z $FAILED_TESTS ]
then
	echo No failure
	exit 0
fi

echo -n Files: 
FILES=`echo -e $FAILED_TESTS | cut -d: -f1 | sort -u`
echo $FILES
echo -e "\nDetailed:"

for i in $FILES
do
	echo File:$i
	echo Tests:
	echo -e $FAILED_TESTS | grep $i | cut -d: -f2
	echo
done

# At least one error occurred
exit 1