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.

167 lines
3.3KB

  1. #!/bin/sh
  2. ### cross format waypoint check ###
  3. PNAME=${PNAME:-./gpsbabel}
  4. REFGPX="reference/expertgps.gpx" # reference file for all tests
  5. EXCL="ozi vitosmt" # exclude formats from test
  6. CAPS=""
  7. TEMPDIR=/tmp/gb-testw
  8. CATALOG=/tmp/gb-testw.done
  9. LOGFILE=/tmp/gb-testw.log
  10. # options
  11. vg=0
  12. prep=0
  13. function log_entry()
  14. {
  15. touch $LOGFILE
  16. echo "-----------------------------------------------------------------------" >> ${LOGFILE}
  17. date >> ${LOGFILE}
  18. echo "$*" >> ${LOGFILE}
  19. }
  20. function try_run() # command line
  21. {
  22. local CMD="$*"
  23. local RES=0
  24. [ $vg -ne 0 ] && CMD="valgrind -q $CMD"
  25. ${CMD} > $TEMPDIR/.result 2>&1
  26. RES=$?
  27. if [ $RES -ne 0 -o -s $TEMPDIR/.result ]; then
  28. if [ $RES -ne 0 ]; then
  29. echo " -- Uhps --"
  30. echo "-----------------------------------------------------------------------"
  31. test -s $TEMPDIR/.result && cat $TEMPDIR/.result
  32. echo "-----------------------------------------------------------------------"
  33. else
  34. echo ""
  35. fi
  36. log_entry "cmd($RES): $CMD"
  37. test -s $TEMPDIR/.result && cat $TEMPDIR/.result >> ${LOGFILE}
  38. return 1
  39. else
  40. return 0
  41. fi
  42. }
  43. function STAGE_1 () # format
  44. {
  45. local FMT=$1
  46. local CMD1 CMD2
  47. echo "$CAPS" |
  48. while read type caps format comment; do
  49. for i in $EXCL; do
  50. if [ "$format" = "$i" ]; then
  51. caps="------"
  52. fi
  53. done
  54. grep "$FMT & $format" ${CATALOG} > /dev/null && continue
  55. echo -n "testing \"$FMT\" with \"$format\" "
  56. case $caps in
  57. -w*)
  58. echo -n "*"
  59. CMD1="${PNAME} -i $FMT -f $TEMPDIR/$FMT -o $format -F $TEMPDIR/$FMT.$format"
  60. try_run "${CMD1}" || continue
  61. ;;
  62. rw*)
  63. echo -n "*"
  64. CMD1="${PNAME} -i $FMT -f $TEMPDIR/$FMT -o $format -F $TEMPDIR/$FMT.$format"
  65. try_run "${CMD1}" || continue
  66. echo -n "*"
  67. CMD2="${PNAME} -i $format -f $TEMPDIR/$FMT.$format -o $FMT -F $TEMPDIR/$FMT.$format.$FMT"
  68. try_run "${CMD2}" || continue
  69. ;;
  70. esac
  71. echo "*"
  72. echo "$FMT & $format" >> $CATALOG
  73. done
  74. return 0
  75. }
  76. function STAGE_0 ()
  77. {
  78. echo "$CAPS" |
  79. while read type caps format comment; do
  80. for i in $EXCL; do
  81. if [ "$format" = "$i" ]; then
  82. caps="------"
  83. fi
  84. done
  85. case $caps in
  86. rw*)
  87. CMD="${PNAME} -i gpx -f $REFGPX -x nuketypes,routes,tracks -o $format -F $TEMPDIR/$format"
  88. try_run "${CMD}" || continue
  89. STAGE_1 $format || exit 1
  90. ;;
  91. esac
  92. case $caps in
  93. -w*)
  94. CMD="${PNAME} -i gpx -f $REFGPX -x nuketypes,routes,tracks -o $format -F $TEMPDIR/$format"
  95. try_run "${CMD}" || continue
  96. ;;
  97. esac
  98. done
  99. rm -f $TEMPDIR/.result
  100. }
  101. rm -rf $TEMPDIR > /dev/null
  102. mkdir -p $TEMPDIR > /dev/null
  103. while [ $# -gt 0 ]; do
  104. case $1 in
  105. -s|--start) # remove catalog. run the full test.
  106. rm -f $CATALOG
  107. ;;
  108. -v|--valgrind)
  109. vg=1
  110. ;;
  111. -p|--prepare) # prepare for valgrind check.
  112. prep=1
  113. ;;
  114. -c|--clean)
  115. trap "rm -fr $TEMPDIR; exit 1" 0 1 2 3 15
  116. ;;
  117. -r|--reference)
  118. shift
  119. REFGPX=$1
  120. ;;
  121. esac
  122. shift
  123. done
  124. if [ $prep -ne 0 ]; then
  125. test -s Makefile && make clean
  126. CFLAGS="-O0" ./configure || exit 1 # -O0 is suggested by vg.
  127. make || exit 1
  128. echo "All fine. You can do now a 'testw -v'"
  129. exit 0
  130. fi
  131. if test ! -s $REFGPX; then
  132. echo "GPX reference \"$REFGPX\" doesn't exist!"
  133. exit 1
  134. fi
  135. touch $CATALOG
  136. log_entry "testw started."
  137. echo "Catalog: $CATALOG" >> $LOGFILE
  138. CAPS=`${PNAME} -^2 | grep "^file"`
  139. STAGE_0