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

test-defs.sh 3.2 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. #!/bin/sh
  2. # Make sure srcdir is an absolute path. Supply the variable
  3. # if it does not exist. We want to be able to run the tests
  4. # stand-alone!!
  5. #
  6. srcdir=${srcdir-.}
  7. if test ! -d $srcdir ; then
  8. echo "test-defs.sh: installation error" 1>&2
  9. exit 1
  10. fi
  11. # Use absolute paths
  12. case "$srcdir" in
  13. /* | [A-Za-z]:\\*) ;;
  14. *) srcdir=`\cd $srcdir && pwd` ;;
  15. esac
  16. case "$top_builddir" in
  17. /* | [A-Za-z]:\\*) ;;
  18. *) top_builddir=`\cd ${top_builddir-..} && pwd` ;;
  19. esac
  20. top_builddir=${top_builddir}/tests
  21. progname=`echo "$0" | sed 's,^.*/,,'`
  22. testname=`echo "$progname" | sed 's,-.*$,,'`
  23. testsubdir=${testsubdir-testSubDir}
  24. testsubdir=${testsubdir}/${progname}
  25. # User can set VERBOSE to cause output redirection
  26. case "$VERBOSE" in
  27. [Nn]|[Nn][Oo]|0|"")
  28. VERBOSE=0
  29. exec > /dev/null
  30. ;;
  31. [Yy]|[Yy][Ee][Ss])
  32. VERBOSE=1
  33. ;;
  34. esac
  35. rm -rf "$testsubdir" > /dev/null 2>&1
  36. mkdir -p "$testsubdir"
  37. CURDIR=$(pwd)
  38. cd "$testsubdir" \
  39. || { echo "Cannot make or change into $testsubdir"; exit 1; }
  40. echo "=== Running test $progname"
  41. DIFF="${DIFF-diff}"
  42. use_valgrind=${USE_VALGRIND-1}
  43. valgrind_path=$(which valgrind 2> /dev/null)
  44. if [ -z "${valgrind_path}" -o ! -x "${valgrind_path}" ] ; then
  45. use_valgrind=0
  46. fi
  47. #
  48. # This is a common function to check the results of a test program
  49. # that is intended to generate consistent output across runs.
  50. #
  51. # ${top_builddir} must be set to the top level build directory.
  52. #
  53. # Output will be written to the current directory.
  54. #
  55. # It must be passed the name of the test command to run, which must be present
  56. # in the ${top_builddir} directory.
  57. #
  58. # It will compare the output of running that against <name of command>.expected
  59. #
  60. run_output_test()
  61. {
  62. if [ "$1" = "-o" ] ; then
  63. TEST_OUTPUT="$2"
  64. shift
  65. shift
  66. fi
  67. TEST_COMMAND="$1"
  68. shift
  69. if [ -z "${TEST_OUTPUT}" ] ; then
  70. TEST_OUTPUT=${TEST_COMMAND}
  71. fi
  72. REDIR_OUTPUT="> \"${TEST_OUTPUT}.out\""
  73. if [ $VERBOSE -gt 1 ] ; then
  74. REDIR_OUTPUT="| tee \"${TEST_OUTPUT}.out\""
  75. fi
  76. if [ -f ${top_builddir}/${TEST_COMMAND}.exe ]; then
  77. TEST_COMMAND=${TEST_COMMAND}.exe
  78. fi
  79. if [ $use_valgrind -eq 1 ] ; then
  80. eval valgrind --tool=memcheck \
  81. --trace-children=yes \
  82. --demangle=yes \
  83. --log-file="${TEST_OUTPUT}.vg.out" \
  84. --leak-check=full \
  85. --show-reachable=yes \
  86. --run-libc-freeres=yes \
  87. "\"${top_builddir}/${TEST_COMMAND}\"" \"\$@\" ${REDIR_OUTPUT}
  88. err=$?
  89. else
  90. eval "\"${top_builddir}/${TEST_COMMAND}"\" \"\$@\" ${REDIR_OUTPUT}
  91. err=$?
  92. fi
  93. if [ $err -ne 0 ] ; then
  94. echo "ERROR: \"${TEST_COMMAND} $@\" exited with non-zero exit status: $err" 1>&2
  95. fi
  96. if [ $use_valgrind -eq 1 ] ; then
  97. if ! tail -1 "${TEST_OUTPUT}.vg.out" | grep -q "ERROR SUMMARY: 0 errors" ; then
  98. echo "ERROR: valgrind found errors during execution:" 1>&2
  99. cat "${TEST_OUTPUT}.vg.out"
  100. err=1
  101. fi
  102. fi
  103. if ! "$DIFF" -w "${top_builddir}/${TEST_OUTPUT}.expected" "${TEST_OUTPUT}.out" ; then
  104. echo "ERROR: \"${TEST_COMMAND} $@\" (${TEST_OUTPUT}) failed (set VERBOSE=1 to see full output):" 1>&2
  105. (cd "${CURDIR}" ; set -x ; diff -wu "${top_builddir}/${TEST_OUTPUT}.expected" "$testsubdir/${TEST_OUTPUT}.out")
  106. echo "cp \"$testsubdir/${TEST_OUTPUT}.out\" \"${top_builddir}/${TEST_OUTPUT}.expected\"" 1>&2
  107. err=1
  108. fi
  109. return $err
  110. }