regress-driver 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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. mode=regress
  42. testing=daemon
  43. opts=""
  44. logfile=""
  45. help="0"
  46. baton=false
  47. quiet=false
  48. quieter=false
  49. while getopts cl:sStbuvo:qQh opt
  50. do
  51. case $opt in
  52. c) testing=clientlib ;; # 'client' rather than the daemon
  53. l) logfile=$OPTARG ;; # Logfile to save diffs to
  54. s) mode=regress ;; # Run regression tests
  55. S) mode=slowregress ;; # Run regression tests with big delays
  56. t) baton=true mode=regress ;; # Run regression tests w/baton
  57. b) mode=build ;; # Rebuild regression check files
  58. u) opts="$opts -u" ;; # Force UDP
  59. v) mode=view ;; # View result of generating a check file
  60. o) opts="$opts $OPTARG" ;; # Pass options to gpsfake
  61. q) quiet=true ;; # Suppress header/trailer messages
  62. Q) quiet=true; quieter=true ;; # Suppress all success chatter
  63. h) help="1" ;;
  64. esac
  65. done
  66. shift $(($OPTIND - 1))
  67. if [ $help -eq "1" ]
  68. then
  69. echo
  70. echo
  71. echo "Regression test driver script"
  72. echo "-h - this help"
  73. echo "-c - test with 'client' rather than the daemon"
  74. echo "-l <filename> - where to log diffs to"
  75. echo "-s - run regression tests"
  76. echo "-S - run regression tests with realistic timing delays"
  77. echo "-t <ots> - Run regression tests w/baton"
  78. echo "-b - Rebuild regression check files"
  79. echo "-u - Force UDP"
  80. echo "-v - view result of generating a check file"
  81. echo "-o <opt> - Pass options to gpsfake"
  82. echo "-q - Suppress header/trailer messages"
  83. echo "-Q - Suppress all success chatter"
  84. echo
  85. exit 0
  86. fi
  87. # Enables us to turn debugging up high without screwing up the diff checks
  88. # First and Second filter out gpsd log messages.
  89. # Third filters out gps.py verbose logging
  90. # Fourth filters out WATCH responses
  91. # Fifth filters out DEVICE responses
  92. # Sixth filters out VERSION responses
  93. # Seventh filters out device fields
  94. GPSFILTER="sed -e /^gpsd:/d -e /^gpsfake/d -e /GPS-DATA/d -e /WATCH/d -e /DEVICE/d -e /VERSION/d -e s/,\"device\":[^,}]*//"
  95. # Use ALTFILTER to set up custom filtering when a regression test fails
  96. # This example filters out altitude and some fields computed by gpsd's error
  97. # modeling - these are fragile in the presence of changes to the fix-buffering
  98. # logic. Note that as the last attribute mode needs to be handled differently.
  99. #ALTFILTER="-e s/\"alt\":[^,]*,// -e s/\"ep[vhs]\":[-+0-9.]*// -e s/,\"mode\":[^}]*//"
  100. TMP=`mktemp -d -t gpsd-test-XXXXXXXXXXXXXX`
  101. # Only twirl the baton on a tty, avoids junk in transcripts.
  102. if [ -t 0 ]
  103. then
  104. baton=false
  105. fi
  106. if [ $baton = true ]
  107. then
  108. opts="$opts -b"
  109. fi
  110. if [ $mode = slowregress ]
  111. then
  112. opts="$opts -S"
  113. fi
  114. if [ $quieter = true ]
  115. then
  116. opts="$opts -q"
  117. fi
  118. case $mode in
  119. regress|slowregress)
  120. [ $quiet = true ] || echo "Testing the $testing..." >&2
  121. errors=0; total=0; notfound=0;error_list="";
  122. for f in $*; do
  123. if [ -r $f.chk ]
  124. then
  125. trap 'rm -f ${TMP}/test-$$.chk; exit $errors' EXIT HUP INT TERM
  126. case $testing in
  127. daemon) TMPDIR=${TMP} ${PYTHON} ${PYTHON_COVERAGE} ${GPSD_HOME}/gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} ${ALTFILTER} >${TMP}/test-$$.chk ;;
  128. clientlib) ${GPSD_HOME}/tests/test_libgps -b <${f} >${TMP}/test-$$.chk ;;
  129. esac
  130. if [ "${ALTFILTER}" ]
  131. then
  132. trap 'rm -f ${TMP}/test-$$.chk ${TMP}/testout-$$.chk ${TMP}/testin-$$.chk ${TMP}/diff-$$; exit $errors' EXIT HUP INT TERM
  133. sed -n <${f}.chk >${TMP}/testin-$$.chk ${ALTFILTER} -e 'p';
  134. sed -n <${TMP}/test-$$.chk >${TMP}/testout-$$.chk ${ALTFILTER} -e 'p';
  135. diff -ub ${TMP}/testin-$$.chk ${TMP}/testout-$$.chk >${TMP}/diff-$$;
  136. else
  137. diff -ub ${f}.chk ${TMP}/test-$$.chk >${TMP}/diff-$$;
  138. fi
  139. if test -s ${TMP}/diff-$$ ; then
  140. errors=`expr $errors + 1`;
  141. error_list="$error_list \"${f}\""
  142. if ! test -s ${TMP}/test-$$.chk ; then
  143. echo " Output missing for ${f}" >${TMP}/diff-$$
  144. fi
  145. if [ -z "$logfile" ]
  146. then
  147. cat ${TMP}/diff-$$
  148. else
  149. cat ${TMP}/diff-$$ >>$logfile
  150. fi
  151. fi;
  152. rm -f ${TMP}/test-$$.chk ${TMP}/testout-$$.chk ${TMP}/testin-$$.chk ${TMP}/diff-$$
  153. else
  154. echo "*** No check log $f.chk exists"
  155. notfound=`expr $notfound + 1`;
  156. fi
  157. total=`expr $total + 1`;
  158. done;
  159. if test $errors -gt 0; then
  160. echo "Regression test FAILED: $errors errors in $total tests total ($notfound not found).";
  161. echo "The following test Failed:"
  162. echo "================================================================"
  163. for err in $error_list
  164. do
  165. echo $err
  166. done
  167. echo "================================================================"
  168. status=1;
  169. else
  170. if [ $quiet = true ] && [ $total -eq 1 ] && [ $notfound -eq 0 ]
  171. then
  172. [ $quieter = true ] || echo "Regression test $1 successful"
  173. else
  174. echo "Regression test successful: no errors in $total tests ($notfound not found).";
  175. fi
  176. status=0;
  177. fi
  178. ;;
  179. build)
  180. [ $quiet = true ] || echo "Rebuilding $testing regressions..." >&2
  181. for f in $*; do
  182. case $testing in
  183. daemon) ${PYTHON} ${PYTHON_COVERAGE} ${GPSD_HOME}/gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} >${f}.chk;;
  184. clientlib) ${GPSD_HOME}/test_libgps -b <${f} >${f}.chk ;;
  185. esac
  186. done
  187. status=0
  188. ;;
  189. view)
  190. [ $quiet = true ] || echo "Viewing..." >&2
  191. for f in $*; do
  192. case $testing in
  193. daemon) ${PYTHON} ${PYTHON_COVERAGE} ${GPSD_HOME}/gpsfake -s 38400 -1 -p $opts ${f} | ${GPSFILTER} ;;
  194. clientlib) ${GPSD_HOME}/tests/test_libgps -b <${f} ;;
  195. esac
  196. done
  197. status=0
  198. ;;
  199. esac
  200. # See starttime above
  201. endtime=`date +"%s * 1000000000 + %N" | sed '/+ N/s///' 2>/dev/null`
  202. if [ $quiet = false ] && [ "$starttime" -a "$endtime" ]
  203. then
  204. # Avoid using -n here since some shells don't support it.
  205. echo "Elapsed time:" \
  206. $(echo "scale=2; (${endtime} - ${starttime}) / 1000000000" | bc) >&2
  207. fi
  208. rm -fr ${TMP}
  209. exit $status
  210. # vim: set expandtab shiftwidth=4