regress-driver 8.6 KB

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