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
|
#!/bin/sh
# Simple regression test suite for gpscorrelate
# Based on the test suite for gphoto2
# Dan Fandrich <dan@coneharvesters.com>
# We expect English text throughout the tests...
LANG=C
export LANG
LANGUAGE=C
export LANGUAGE
if [ "$1" = "-h" ] ; then
echo "Usage: $0 [-v] [-m]"
exit
fi
VERBOSECOMMAND=
if [ "$1" = "-v" ] ; then
shift
VERBOSECOMMAND='set -x ;'
fi
USEVALGRIND=
if [ "$1" = "-m" ] ; then
shift
USEVALGRIND=true
fi
test -z "$srcdir" && srcdir=`pwd`
DATADIR="$srcdir/data"
if [ ! -e "$DATADIR" ] ; then
echo Must run tests from the tests directory
exit 1
fi
STAGINGDIR="$srcdir/staging"
# Make all files in the staging area read only to prevent
# accidental modification
chmod a-w "$STAGINGDIR"/*
LOGDIR="`pwd`/log"
if [ -e "$LOGDIR" ] ; then
rm -f "$LOGDIR/"*
else
mkdir "$LOGDIR"
fi
if [ -n "$1" ] ; then
TESTLIST="$*"
else
TESTLIST="$DATADIR"/*.param
fi
POSTCOMMAND=
# Clean up on test abort
trap 'eval $POSTCOMMAND; exit 1' INT HUP TERM
FAILEDTESTS=0
for TEST in $TESTLIST ; do
echo ''
# These variables are unlikely to be needed in the test parameters file
TESTNAME=`echo "$TEST" | sed -e 's@^.*data/@@' -e 's/\..*$//'`
RESULTFILE="$DATADIR/$TESTNAME.result"
# Initialize variables that can be used within the test parameters file
PROGRAM='../gpscorrelate'
if [ -n "$USEVALGRIND" ] ; then
PROGRAM="valgrind --error-exitcode=126 --tool=memcheck --leak-check=yes --num-callers=30 --log-file=$LOGDIR/$TESTNAME-valgrind.log $PROGRAM"
fi
OUTFILE="$LOGDIR/$TESTNAME.out"
ERRFILE="$LOGDIR/$TESTNAME.err"
# Initialize variables that must be set for each test
TITLE=
COMMAND=
PRECOMMAND=
POSTCOMMAND=
SEDCOMMAND=
RESULTCODE=0
SKIP=
# Load the test parameters, which can override the above
if [ ! -e "$TEST" ] ; then
echo "Test $TESTNAME FAILED: invalid test parameter file $TEST"
FAILEDTESTS=$(($FAILEDTESTS + 1))
continue
fi
. "$TEST"
if [ -n "$SKIP" ] ; then
echo "*** Skipping \"$TITLE\" test"
continue
fi
echo "*** Running \"$TITLE\" test"
# Clean up from previous tests
rm -f "$OUTFILE" "$ERRFILE"
# Run a pre-test command
if ! eval $PRECOMMAND ; then
echo "Test $TESTNAME FAILED: pre test command failure"
FAILEDTESTS=$(($FAILEDTESTS + 1))
# Unconditionally run post command to clean up
eval $POSTCOMMAND
POSTCOMMAND=
continue
fi
#eval echo `echo "$COMMAND" | sed -e 's/>/\\\\>/g' -e "s/'/\\\\'/g" -e 's/\"/\\\\"/g'`
eval $VERBOSECOMMAND $COMMAND
EXITCODE=$?
set +x
if [ $EXITCODE -ne "$RESULTCODE" ] ; then
echo "Test $TESTNAME FAILED: got exit $EXITCODE, expected $RESULTCODE"
# Don't abort now--run the post-test command to clean up first
FAILEDTESTS=$(($FAILEDTESTS + 1))
if [ -n "$VERBOSECOMMAND" ] ; then
test -e "$ERRFILE" && cat "$ERRFILE"
test -e "$OUTFILE" && echo "Command output was:" && cat "$OUTFILE"
fi
fi
# Run a post-test command
if ! eval $POSTCOMMAND ; then
POSTCOMMAND=
echo "Test $TESTNAME FAILED: post test command failure"
FAILEDTESTS=$(($FAILEDTESTS + 1))
continue
fi
POSTCOMMAND=
if [ $EXITCODE -ne "$RESULTCODE" ] ; then
# Delayed exit
continue
fi
# In case this is running on Windows, delete any CR characters in the output
# to eliminate any difference from the expected file.
mv -f "$OUTFILE" "$OUTFILE".orig
tr -d '\r' < "$OUTFILE.orig" > "$OUTFILE"
if [ -n "$SEDCOMMAND" ] ; then
mv -f "$OUTFILE" "$OUTFILE".orig
# Need sed to parse extended regular expressions
sed -E "$SEDCOMMAND" < "$OUTFILE.orig" > "$OUTFILE"
fi
# Older versions of exiv2 (e.g. 0.15-0.18) have slightly different whitespace
# and handle the GPS IFD tag differently. This alternate comparison program
# can be used in place of "cmp" to relax the comparison and use such a
# version:
# ! diff -I GPSTag -qw
if ! cmp "$RESULTFILE" "$OUTFILE" >/dev/null ; then
echo "Test $TESTNAME FAILED: unexpected output"
test -n "$VERBOSECOMMAND" && diff -u "$RESULTFILE" "$OUTFILE"
FAILEDTESTS=$(($FAILEDTESTS + 1))
continue
fi
echo "Test $TESTNAME PASSED"
done
echo ''
if [ $FAILEDTESTS -eq 0 ] ; then
echo All tests have PASSED
else
echo "$FAILEDTESTS test(s) have FAILED"
test -z "$VERBOSECOMMAND" && echo "Run with -v to see details"
fi
# Set the exit code
test "$FAILEDTESTS" -eq 0
|