#!/bin/sh # # The regression-test driver script. This used to be explicit in the # makefile before we regrouped the regression tests by stable and unstable # drivers. # Arrange to call a gpsfake in the source directory without fuss. if [ -z ${PYTHON} ]; then PYTHON="python" fi py_libdir=`pwd`/build/`${PYTHON} -c 'import distutils.util; import sys; print "lib.%s-%s" %(distutils.util.get_platform(), sys.version[0:3])'` py_scriptdir=`pwd`/build/`${PYTHON} -c 'import sys; print "scripts-%s" %(sys.version[0:3], )'` if [ -d ${py_libdir} ] && [ -d ${py_scriptdir} ]; then PYTHONPATH=${py_libdir} export PYTHONPATH PATH=${py_scriptdir}:${PATH} else PATH=`dirname $0`:${PATH} fi export PATH mode=regress testing=daemon opts="" while getopts cstrbvo opt do case $opt in c) testing=clientlib ;; # Can be 'daemon' s) mode=regress ;; # Run regression tests t) opts="-b $opts" mode=regress ;; # Run regression tests w/baton r) mode=superraw ;; # Run superraw regressions (r=2 mode) b) mode=build ;; # Rebuild regression check files v) mode=view ;; # View result of generating a check file o) opts="$opts $OPTARG" ;; # Pass options to gpsfake esac done shift $(($OPTIND - 1)) # Enables us to turn debugging up high without screwing up the diff checks # First and Second filter out gpsd log messages. # Third filters out gps.py verbose loggging # Fourth filters out WATCH responses # Fifth filters out DEVICE responses # Sixth filters out VERSION responses # Seventh filters out device fields GPSFILTER="sed -e /^gpsd:/d -e /^gpsfake/d -e /GPS-DATA/d -e /WATCH/d -e /DEVICE/d -e /VERSION/d -e s/,\"device\":[^,}]*//" # Use ALTFILTER to set up custom filtering when a regression test fails # This example filters out altitude and some fields computed by gpsd's error # modeling - these are fragile in the prsence of changes to the fix-buffering # logic. Note that as the last attribute mode needs to be handled differently. #ALTFILTER="-e s/\"alt\":[^,]*,// -e s/\"ep[vhs]\":[-+0-9.]*// -e s/,\"mode\":[^}]*//" TMP=/tmp # Only twirl the baton on a tty, avoids junk in transcripts. if [ -t 1 ] then opts="$opts -b" fi case $mode in regress) echo "Testing the $testing..." >&2 errors=0; total=0; notfound=0; for f in $*; do trap 'rm -f ${TMP}/test-$$.chk ${TMP}/test-whole-$$.chk ${TMP}/test-trunc-$$.chk ${TMP}/log-copy-$$.chk ${TMP}/diff-$$ ${TMP}/diff-$$-trunc; exit $errors' EXIT HUP INT TERM if [ -r $f.chk ] then case $testing in daemon) gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} ${ALTFILTER} >${TMP}/test-$$.chk ;; clientlib) libgps -b <${f} >${TMP}/test-$$.chk ;; esac sed -n <${f}.chk >${TMP}/log-copy-$$.chk ${ALTFILTER} -e 'p'; sed -n <${TMP}/test-$$.chk >${TMP}/test-whole-$$.chk ${ALTFILTER} -e 'p'; sed -n <${TMP}/test-$$.chk >${TMP}/test-trunc-$$.chk -e '$d' ${ALTFILTER} -e 'p'; diff -ub ${TMP}/log-copy-$$.chk ${TMP}/test-whole-$$.chk >${TMP}/diff-$$; diff -ub ${TMP}/log-copy-$$.chk ${TMP}/test-trunc-$$.chk >${TMP}/diff-$$-trunc; if test \( -s ${TMP}/diff-$$ \) -a \( -s ${TMP}/diff-$$-trunc \) ; then errors=`expr $errors + 1`; cat ${TMP}/diff-$$ fi; rm -f ${TMP}/test-$$.chk ${TMP}/test-whole-$$.chk ${TMP}/test-trunc-$$.chk ${TMP}/log-copy-$$.chk ${TMP}/diff-$$ ${TMP}/diff-$$-trunc else echo "*** No check log $f.chk exists" notfound=`expr $notfound + 1`; fi total=`expr $total + 1`; done; if test $errors -gt 0; then echo "Regression test FAILED: $errors errors in $total tests total ($notfound not found)."; exit 1; else echo "Regression test successful: no errors in $total tests ($notfound not found)."; exit 0; fi ;; superraw) echo "Testing super-raw mode..." >&2 for f in $*; do gpsfake -s 38400 -1 -p $opts -r '{"class":"WATCH","enable":False,"raw":2}' $opts ${f} \ | ./devtools/striplog -1 >${TMP}/test1-$$.chk; ./devtools/striplog <${f} >${TMP}/test2-$$.chk; cmp ${TMP}/test[12]-$$.chk; done; rm ${TMP}/test[12]-$$.chk ;; build) echo "Rebuilding $testing regressions..." >&2 for f in $*; do case $testing in daemon) gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} >${f}.chk;; clientlib) libgps -b <${f} >${f}.chk ;; esac done exit 0 ;; view) echo "Viewing..." >&2 for f in $*; do case $testing in daemon) gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} ;; clientlib) libgps -b <${f} ;; esac done exit 0 ;; esac