3 # The regression-test driver script. This used to be explicit in the
4 # makefile before we regrouped the regression tests by stable and unstable
7 # Requires GNU date extensions
8 # Should return an empty blank string if tose are not present.
9 starttime=`date +"%s" 2>/dev/null`
11 # We need to have the build directory in $GPSD_HOME to find the new gpsd
12 if [ "`dirname $0`" = "." ]; then
15 GPSD_HOME=`dirname $0`
18 # Arrange to call a gpsfake in the source directory without fuss.
19 if [ -z ${PYTHON} ]; then
22 # For an explanation of what we define here, see the comment on
23 # PYTHON_DISTUTILS_LIBDIR/PYTHON_DISTUTILS_SCRIPTDIR in configure.ac
24 py_libdir=`pwd`/build/`${PYTHON} -c 'import distutils.util; import sys; print("lib.%s-%s" %(distutils.util.get_platform(), sys.version[0:3]))'`
25 py_scriptdir=`pwd`/build/`${PYTHON} -c 'import sys; print("scripts-%s" %(sys.version[0:3], ))'`
26 if [ -d ${py_libdir} ] && [ -d ${py_scriptdir} ]; then
27 PYTHONPATH=${py_libdir}
30 PATH=${py_scriptdir}:${PATH}
37 while getopts cstrbuvo opt
40 c) testing=clientlib ;; # Can be 'daemon'
41 s) mode=regress ;; # Run regression tests
42 t) opts="-b $opts" mode=regress ;; # Run regression tests w/baton
43 r) mode=superraw ;; # Run superraw regressions (r=2 mode)
44 b) mode=build ;; # Rebuild regression check files
45 u) opts="$opts -u" ;; # Force UDP
46 v) mode=view ;; # View result of generating a check file
47 o) opts="$opts $OPTARG" ;; # Pass options to gpsfake
50 shift $(($OPTIND - 1))
52 # Enables us to turn debugging up high without screwing up the diff checks
53 # First and Second filter out gpsd log messages.
54 # Third filters out gps.py verbose loggging
55 # Fourth filters out WATCH responses
56 # Fifth filters out DEVICE responses
57 # Sixth filters out VERSION responses
58 # Seventh filters out device fields
59 GPSFILTER="sed -e /^gpsd:/d -e /^gpsfake/d -e /GPS-DATA/d -e /WATCH/d -e /DEVICE/d -e /VERSION/d -e s/,\"device\":[^,}]*//"
61 # Use ALTFILTER to set up custom filtering when a regression test fails
62 # This example filters out altitude and some fields computed by gpsd's error
63 # modeling - these are fragile in the prsence of changes to the fix-buffering
64 # logic. Note that as the last attribute mode needs to be handled differently.
65 #ALTFILTER="-e s/\"alt\":[^,]*,// -e s/\"ep[vhs]\":[-+0-9.]*// -e s/,\"mode\":[^}]*//"
69 # Only twirl the baton on a tty, avoids junk in transcripts.
77 echo "Testing the $testing..." >&2
78 errors=0; total=0; notfound=0;
82 trap 'rm -f ${TMP}/test-$$.chk; exit $errors' EXIT HUP INT TERM
84 daemon) gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} ${ALTFILTER} >${TMP}/test-$$.chk ;;
85 clientlib) $GPSD_HOME/libgps -b <${f} >${TMP}/test-$$.chk ;;
89 trap 'rm -f ${TMP}/test-$$.chk ${TMP}/testout-$$.chk ${TMP}/testin-$$.chk ${TMP}/diff-$$; exit $errors' EXIT HUP INT TERM
90 sed -n <${f}.chk >${TMP}/testin-$$.chk ${ALTFILTER} -e 'p';
91 sed -n <${TMP}/test-$$.chk >${TMP}/testout-$$.chk ${ALTFILTER} -e 'p';
92 diff -ub ${TMP}/testin-$$.chk ${TMP}/testout-$$.chk >${TMP}/diff-$$;
94 diff -ub ${f}.chk ${TMP}/test-$$.chk >${TMP}/diff-$$;
96 if test -s ${TMP}/diff-$$ ; then
97 errors=`expr $errors + 1`;
100 rm -f ${TMP}/test-$$.chk ${TMP}/testout-$$.chk ${TMP}/testin-$$.chk ${TMP}/diff-$$
102 echo "*** No check log $f.chk exists"
103 notfound=`expr $notfound + 1`;
105 total=`expr $total + 1`;
107 if test $errors -gt 0; then
108 echo "Regression test FAILED: $errors errors in $total tests total ($notfound not found).";
111 echo "Regression test successful: no errors in $total tests ($notfound not found).";
116 echo "Testing super-raw mode..." >&2
118 gpsfake -s 38400 -1 -p $opts -r '{"class":"WATCH","enable":False,"raw":2}' $opts ${f} \
119 | ./devtools/striplog -1 >${TMP}/test1-$$.chk;
120 ./devtools/striplog <${f} >${TMP}/test2-$$.chk;
121 cmp ${TMP}/test[12]-$$.chk;
122 done; rm ${TMP}/test[12]-$$.chk
125 echo "Rebuilding $testing regressions..." >&2
128 daemon) gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} >${f}.chk;;
129 clientlib) $GPSD_HOME/libgps -b <${f} >${f}.chk ;;
135 echo "Viewing..." >&2
138 daemon) gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} ;;
139 clientlib) $GPSD_HOME/libgps -b <${f} ;;
146 # See starttime above
147 endtime=`date +"%s" 2>/dev/null`
149 if [ "$starttime" -a "$endtime" ]
151 echo -n "Elapsed time: "
152 echo "scale=2; ${endtime} - ${starttime}" | bc