You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

284 lines
7.2KB

  1. #!/bin/bash
  2. set -e
  3. ### cross format read/(write) test ###
  4. PNAME=${PNAME:-./gpsbabel}
  5. BASEPATH=`dirname $0`
  6. REFGPX="${BASEPATH}/reference/expertgps.gpx" # reference file for all tests
  7. EXCL="exif ozi vitosmt xol navigonwpt gopal" # exclude formats from test
  8. CAPS=""
  9. TEMPDIR=${GBTEMP:-/tmp}/gb-test-all
  10. CATALOG=${GBTEMP:-/tmp}/gb-test-all.done
  11. LOGFILE=${GBTEMP:-/tmp}/gb-test-all.log
  12. RNDFILE=${GBTEMP:-/tmp}/gb-random.gpx
  13. # options
  14. vg=0
  15. prep=0
  16. tally=0
  17. judge=0
  18. function tally_log()
  19. {
  20. local exceptions=`grep '^cmd([0-9]*)\*[*]*:' $LOGFILE | wc -l`
  21. local onlyunexpected=`grep '^cmd([0-9]*)\*:' $LOGFILE | wc -l`
  22. local nonfatals=`grep '^cmd([0-9]*)\*\*:' $LOGFILE | wc -l`
  23. local fatals=`grep '^cmd([0-9]*)\*\*\*:' $LOGFILE | wc -l`
  24. local totals=`grep '^cmd([0-9]*)[*]*:' $LOGFILE | wc -l`
  25. echo "Fatal Error Cases:"
  26. grep '^cmd([0-9]*)\*\*\*:' $LOGFILE || true
  27. echo ""
  28. echo Error Summary:
  29. echo "tests with errors and/or unexpected output: $exceptions"
  30. echo " tests without error but with unexpected output: $onlyunexpected"
  31. echo " tests with non-fatal errors: $nonfatals"
  32. echo " tests with fatal errors: $fatals"
  33. echo "total tests: $totals"
  34. if [ $fatals -gt 0 ]; then
  35. return 1
  36. else
  37. return 0
  38. fi
  39. }
  40. function log_entry()
  41. {
  42. touch $LOGFILE
  43. echo "-----------------------------------------------------------------------" >> ${LOGFILE}
  44. date >> ${LOGFILE}
  45. echo "$*" >> ${LOGFILE}
  46. }
  47. function try_run() # command line
  48. {
  49. local CMD="$*"
  50. local RES=0
  51. local SEVERITY=""
  52. [ $vg -ne 0 ] && CMD="valgrind -q $CMD"
  53. ${CMD} > $TEMPDIR/.result 2>&1
  54. RES=$?
  55. if [ $RES -ne 0 -o -s $TEMPDIR/.result ]; then
  56. if [ $RES -ne 0 ]; then
  57. echo " -- Signal $RES --"
  58. if [ -s $TEMPDIR/.result ]; then
  59. echo "---------------------------output-follows------------------------------"
  60. cat $TEMPDIR/.result
  61. echo "-----------------------------------------------------------------------"
  62. fi
  63. else
  64. echo " -- unexpected output exists, see $LOGFILE --"
  65. fi
  66. if [ $RES -gt 128 ]; then
  67. SEVERITY="***"
  68. elif [ $RES -gt 0 ]; then
  69. SEVERITY="**"
  70. else
  71. SEVERITY="*"
  72. fi
  73. log_entry "cmd($RES)$SEVERITY: $CMD"
  74. test -s $TEMPDIR/.result && cat $TEMPDIR/.result >> ${LOGFILE}
  75. return 1
  76. else
  77. log_entry "cmd($RES): $CMD"
  78. return 0
  79. fi
  80. }
  81. function STAGE_1 () # type format
  82. {
  83. local TYP=$1
  84. local FMT=$2
  85. local CMD1 CMD2 IFILE OFILE
  86. echo "$CAPS" |
  87. while read type caps format comment; do
  88. for i in $EXCL; do
  89. if [ "$format" == "$i" ]; then
  90. caps="------"
  91. fi
  92. done
  93. grep "$TYP: $FMT & $format" ${CATALOG} > /dev/null && continue
  94. echo -n "testing "
  95. case $TYP in
  96. w)
  97. echo -n "waypoints"
  98. caps=${caps:0:2}
  99. ;;
  100. t)
  101. echo -n "tracks"
  102. caps=${caps:2:2}
  103. ;;
  104. r)
  105. echo -n "routes"
  106. caps=${caps:4:2}
  107. ;;
  108. esac
  109. echo -n ": \"$FMT\" with \"$format\" "
  110. IFILE=$TEMPDIR/$TYP-$FMT
  111. OFILE=$TEMPDIR/$TYP-$FMT.$format
  112. case $caps in
  113. -w)
  114. echo -n "*"
  115. CMD1="${PNAME} -$TYP -i $FMT -f $IFILE -o $format -F $OFILE"
  116. try_run "${CMD1}" || continue
  117. ;;
  118. rw)
  119. echo -n "*"
  120. CMD1="${PNAME} -$TYP -i $FMT -f $IFILE -o $format -F $OFILE"
  121. try_run "${CMD1}" || continue
  122. echo -n "*"
  123. CMD2="${PNAME} -$TYP -i $format -f $OFILE -o $FMT -F $OFILE.$FMT"
  124. try_run "${CMD2}" || continue
  125. ;;
  126. esac
  127. echo "*"
  128. echo "$TYP: $FMT & $format" >> $CATALOG
  129. done
  130. return 0
  131. }
  132. function STAGE_0 ()
  133. {
  134. echo "$CAPS" |
  135. while read type caps format comment; do
  136. for i in $EXCL; do
  137. if [ "$format" == "$i" ]; then
  138. caps="------"
  139. fi
  140. done
  141. case ${caps:0:2} in
  142. rw)
  143. CMD="${PNAME} -i gpx -f $REFGPX -x nuketypes,routes,tracks -o $format -F $TEMPDIR/w-$format"
  144. try_run "${CMD}" || continue
  145. STAGE_1 "w" $format || exit 1
  146. ;;
  147. -w)
  148. CMD="${PNAME} -i gpx -f $REFGPX -x nuketypes,routes,tracks -o $format -F $TEMPDIR/w-$format"
  149. try_run "${CMD}" || continue
  150. ;;
  151. esac
  152. case ${caps:2:2} in
  153. rw)
  154. CMD="${PNAME} -t -i gpx -f $REFGPX -x nuketypes,waypoints,routes -x track,fix=2D -o $format -F $TEMPDIR/t-$format"
  155. try_run "${CMD}" || continue
  156. STAGE_1 "t" $format || exit 1
  157. ;;
  158. -w)
  159. CMD="${PNAME} -t -i gpx -f $REFGPX -x nuketypes,waypoints,routes -x track,fix=2D -o $format -F $TEMPDIR/t-$format"
  160. try_run "${CMD}" || continue
  161. ;;
  162. esac
  163. case ${caps:4:2} in
  164. rw)
  165. CMD="${PNAME} -r -i gpx -f $REFGPX -x nuketypes,waypoints,tracks -o $format -F $TEMPDIR/r-$format"
  166. try_run "${CMD}" || continue
  167. STAGE_1 "r" $format || exit 1
  168. ;;
  169. -w)
  170. CMD="${PNAME} -r -i gpx -f $REFGPX -x nuketypes,waypoints,tracks -o $format -F $TEMPDIR/r-$format"
  171. try_run "${CMD}" || continue
  172. ;;
  173. esac
  174. done
  175. rm -f $TEMPDIR/.result
  176. }
  177. while [ $# -gt 0 ]; do
  178. case $1 in
  179. -s|--start) # remove catalog. run the full test.
  180. rm -f $CATALOG
  181. ;;
  182. -v|--valgrind)
  183. vg=1
  184. ;;
  185. -p|--prepare) # prepare for valgrind check.
  186. prep=1
  187. ;;
  188. -c|--clean)
  189. trap "rm -fr $TEMPDIR; exit 1" 0 1 2 3 15
  190. ;;
  191. -n|--random)
  192. ${PNAME} -i random -w -f - -i random,points=48 -r -f - -i random,points=120 -t -f - -o gpx,gpxver=1.1 -F $RNDFILE
  193. REFGPX=$RNDFILE
  194. ;;
  195. -r|--reference)
  196. shift
  197. REFGPX=$1
  198. ;;
  199. -j|--judge) # implies tallying so we have something to judge.
  200. tally=1
  201. judge=1
  202. ;;
  203. -J|--rejudge) # re-judge a previous run and exit without running more tests.
  204. tally=1
  205. judge=1
  206. tally_log
  207. exit $?
  208. ;;
  209. -t|--tally)
  210. tally=1
  211. ;;
  212. -T|--retally) # re-tally a previous run and exit without running more tests.
  213. tally=1
  214. tally_log
  215. exit 0
  216. ;;
  217. -W|--wipe) # clean up files and exit
  218. rm -rf $TEMPDIR > /dev/null
  219. rm -f $CATALOG
  220. rm -f $LOGFILE
  221. rm -f $RNDFILE
  222. exit 0
  223. ;;
  224. esac
  225. shift
  226. done
  227. if [ $prep -ne 0 ]; then
  228. test -s Makefile && make clean
  229. CFLAGS="-O0" ./configure || exit 1 # -O0 is suggested by vg.
  230. make || exit 1
  231. echo "All fine. You can do now a 'test-all -v'"
  232. exit 0
  233. fi
  234. if test ! -s $REFGPX; then
  235. echo "GPX reference \"$REFGPX\" doesn't exist!"
  236. exit 1
  237. fi
  238. rm -rf $TEMPDIR > /dev/null
  239. mkdir -p $TEMPDIR > /dev/null
  240. rm -f $LOGFILE
  241. touch $LOGFILE
  242. touch $CATALOG
  243. log_entry "test-all started."
  244. echo "Catalog: $CATALOG" >> $LOGFILE
  245. CAPS=`${PNAME} -^2 | grep "^file"`
  246. STAGE_0
  247. if [ $tally -ne 0 ]; then
  248. tally_log
  249. judgement=$?
  250. if [ $judge -ne 0 ]; then
  251. exit $judgement
  252. fi
  253. fi
  254. exit 0