regress-driver 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. #!/bin/sh
  2. #
  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
  5. # drivers.
  6. # Without GNU date extensions, %N won't expand and we only get 1sec precision
  7. starttime=`date +"%s * 1000000000 + %N" | sed '/+ N/s///' 2>/dev/null`
  8. # We need to have the build directory in $GPSD_HOME to find the new gpsd
  9. if [ "`dirname $0`" = "." ]; then
  10. GPSD_HOME=`pwd`
  11. else
  12. GPSD_HOME=`dirname $0`
  13. fi
  14. # sed may choke on binary data with some LANG settings
  15. unset LANG
  16. # Arrange to call a gpsfake in the source directory without fuss.
  17. if [ -z ${PYTHON} ]; then
  18. PYTHON="python"
  19. fi
  20. # Define the directories we ask setup.py to install the
  21. # modules/extensions and scripts to. The way chosen here reproduces
  22. # the internal behaviour of distutils. Unfortunately distutils does
  23. # not export the pre-defined/configured directories, so we have to
  24. # define them on our own. For default installations of distutils the
  25. # chosen values here will match what distutils uses.
  26. py_libdir=`pwd`/build/`${PYTHON} -c 'import distutils.util; import sys; print("lib.%s-%s" %(distutils.util.get_platform(), sys.version[0:3]))'`
  27. py_scriptdir=`pwd`/build/`${PYTHON} -c 'import sys; print("scripts-%s" %(sys.version[0:3], ))'`
  28. if [ -d ${py_libdir} ] && [ -d ${py_scriptdir} ]; then
  29. PYTHONPATH=${py_libdir}
  30. export PYTHONPATH
  31. PATH=${py_scriptdir}:${PATH}
  32. fi
  33. export GPSD_HOME PATH
  34. # Use a non-default value of the SHM key to avoid colliding with
  35. # production instances. Value must be legal for strtol(3);
  36. # this is the default key plus one.
  37. export GPSD_SHM_KEY=0x47505345
  38. mode=regress
  39. testing=daemon
  40. opts=""
  41. logfile=""
  42. help="0"
  43. baton=false
  44. quiet=false
  45. quieter=false
  46. while getopts cl:sStbuvo:qQh opt
  47. do
  48. case $opt in
  49. c) testing=clientlib ;; # 'client' rather than the daemon
  50. l) logfile=$OPTARG ;; # Logfile to save diffs to
  51. s) mode=regress ;; # Run regression tests
  52. S) mode=slowregress ;; # Run regression tests with big delays
  53. t) baton=true mode=regress ;; # Run regression tests w/baton
  54. b) mode=build ;; # Rebuild regression check files
  55. u) opts="$opts -u" ;; # Force UDP
  56. v) mode=view ;; # View result of generating a check file
  57. o) opts="$opts $OPTARG" ;; # Pass options to gpsfake
  58. q) quiet=true ;; # Suppress header/trailer messages
  59. Q) quiet=true; quieter=true ;; # Suppress all success chatter
  60. h) help="1" ;;
  61. esac
  62. done
  63. shift $(($OPTIND - 1))
  64. if [ $help -eq "1" ]
  65. then
  66. echo
  67. echo
  68. echo "Regression test driver script"
  69. echo "-h - this help"
  70. echo "-c - test with 'client' rather than the daemon"
  71. echo "-l <filename> - where to log diffs to"
  72. echo "-s - run regression tests"
  73. echo "-S - run regression tests with realistic timing delays"
  74. echo "-t <ots> - Run regression tests w/baton"
  75. echo "-b - Rebuild regression check files"
  76. echo "-u - Force UDP"
  77. echo "-v - view result of generating a check file"
  78. echo "-o <opt> - Pass options to gpsfake"
  79. echo "-q - Suppress header/trailer messages"
  80. echo "-Q - Suppress all success chatter"
  81. echo
  82. exit 0
  83. fi
  84. # Enables us to turn debugging up high without screwing up the diff checks
  85. # First and Second filter out gpsd log messages.
  86. # Third filters out gps.py verbose loggging
  87. # Fourth filters out WATCH responses
  88. # Fifth filters out DEVICE responses
  89. # Sixth filters out VERSION responses
  90. # Seventh filters out device fields
  91. GPSFILTER="sed -e /^gpsd:/d -e /^gpsfake/d -e /GPS-DATA/d -e /WATCH/d -e /DEVICE/d -e /VERSION/d -e s/,\"device\":[^,}]*//"
  92. # Use ALTFILTER to set up custom filtering when a regression test fails
  93. # This example filters out altitude and some fields computed by gpsd's error
  94. # modeling - these are fragile in the presence of changes to the fix-buffering
  95. # logic. Note that as the last attribute mode needs to be handled differently.
  96. #ALTFILTER="-e s/\"alt\":[^,]*,// -e s/\"ep[vhs]\":[-+0-9.]*// -e s/,\"mode\":[^}]*//"
  97. TMP=`mktemp -d -t gpsd-test-XXXXXXXXXXXXXX`
  98. # Only twirl the baton on a tty, avoids junk in transcripts.
  99. if [ -t 0 ]
  100. then
  101. baton=false
  102. fi
  103. if [ $baton = true ]
  104. then
  105. opts="$opts -b"
  106. fi
  107. if [ $mode = slowregress ]
  108. then
  109. opts="$opts -S"
  110. fi
  111. if [ $quieter = true ]
  112. then
  113. opts="$opts -q"
  114. fi
  115. case $mode in
  116. regress|slowregress)
  117. [ $quiet = true ] || echo "Testing the $testing..." >&2
  118. errors=0; total=0; notfound=0;error_list="";
  119. for f in $*; do
  120. if [ -r $f.chk ]
  121. then
  122. trap 'rm -f ${TMP}/test-$$.chk; exit $errors' EXIT HUP INT TERM
  123. case $testing in
  124. daemon) TMPDIR=${TMP} ${PYTHON} ${PYTHON_COVERAGE} ${GPSD_HOME}/gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} ${ALTFILTER} >${TMP}/test-$$.chk ;;
  125. clientlib) ${GPSD_HOME}/tests/test_libgps -b <${f} >${TMP}/test-$$.chk ;;
  126. esac
  127. if [ "${ALTFILTER}" ]
  128. then
  129. trap 'rm -f ${TMP}/test-$$.chk ${TMP}/testout-$$.chk ${TMP}/testin-$$.chk ${TMP}/diff-$$; exit $errors' EXIT HUP INT TERM
  130. sed -n <${f}.chk >${TMP}/testin-$$.chk ${ALTFILTER} -e 'p';
  131. sed -n <${TMP}/test-$$.chk >${TMP}/testout-$$.chk ${ALTFILTER} -e 'p';
  132. diff -ub ${TMP}/testin-$$.chk ${TMP}/testout-$$.chk >${TMP}/diff-$$;
  133. else
  134. diff -ub ${f}.chk ${TMP}/test-$$.chk >${TMP}/diff-$$;
  135. fi
  136. if test -s ${TMP}/diff-$$ ; then
  137. errors=`expr $errors + 1`;
  138. error_list="$error_list \"${f}\""
  139. if ! test -s ${TMP}/test-$$.chk ; then
  140. echo " Output missing for ${f}" >${TMP}/diff-$$
  141. fi
  142. if [ -z "$logfile" ]
  143. then
  144. cat ${TMP}/diff-$$
  145. else
  146. cat ${TMP}/diff-$$ >>$logfile
  147. fi
  148. fi;
  149. rm -f ${TMP}/test-$$.chk ${TMP}/testout-$$.chk ${TMP}/testin-$$.chk ${TMP}/diff-$$
  150. else
  151. echo "*** No check log $f.chk exists"
  152. notfound=`expr $notfound + 1`;
  153. fi
  154. total=`expr $total + 1`;
  155. done;
  156. if test $errors -gt 0; then
  157. echo "Regression test FAILED: $errors errors in $total tests total ($notfound not found).";
  158. echo "The following test Failed:"
  159. echo "================================================================"
  160. for err in $error_list
  161. do
  162. echo $err
  163. done
  164. echo "================================================================"
  165. status=1;
  166. else
  167. if [ $quiet = true ] && [ $total -eq 1 ] && [ $notfound -eq 0 ]
  168. then
  169. [ $quieter = true ] || echo "Regression test $1 successful"
  170. else
  171. echo "Regression test successful: no errors in $total tests ($notfound not found).";
  172. fi
  173. status=0;
  174. fi
  175. ;;
  176. build)
  177. [ $quiet = true ] || echo "Rebuilding $testing regressions..." >&2
  178. for f in $*; do
  179. case $testing in
  180. daemon) ${PYTHON} ${PYTHON_COVERAGE} ${GPSD_HOME}/gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} >${f}.chk;;
  181. clientlib) ${GPSD_HOME}/test_libgps -b <${f} >${f}.chk ;;
  182. esac
  183. done
  184. status=0
  185. ;;
  186. view)
  187. [ $quiet = true ] || echo "Viewing..." >&2
  188. for f in $*; do
  189. case $testing in
  190. daemon) ${PYTHON} ${PYTHON_COVERAGE} ${GPSD_HOME}/gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} ;;
  191. clientlib) ${GPSD_HOME}/tests/test_libgps -b <${f} ;;
  192. esac
  193. done
  194. status=0
  195. ;;
  196. esac
  197. # See starttime above
  198. endtime=`date +"%s * 1000000000 + %N" | sed '/+ N/s///' 2>/dev/null`
  199. if [ $quiet = false ] && [ "$starttime" -a "$endtime" ]
  200. then
  201. # Avoid using -n here since some shells don't support it.
  202. echo "Elapsed time:" \
  203. $(echo "scale=2; (${endtime} - ${starttime}) / 1000000000" | bc) >&2
  204. fi
  205. rm -fr ${TMP}
  206. exit $status