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.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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. CMP="${CMP-cmp}"
  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 [ $use_valgrind -eq 1 ] ; then
  77. eval valgrind --tool=memcheck \
  78. --trace-children=yes \
  79. --demangle=yes \
  80. --log-file="${TEST_OUTPUT}.vg.out" \
  81. --leak-check=full \
  82. --show-reachable=yes \
  83. --run-libc-freeres=yes \
  84. "\"${top_builddir}/${TEST_COMMAND}\"" \"\$@\" ${REDIR_OUTPUT}
  85. err=$?
  86. else
  87. eval "\"${top_builddir}/${TEST_COMMAND}"\" \"\$@\" ${REDIR_OUTPUT}
  88. err=$?
  89. fi
  90. if [ $err -ne 0 ] ; then
  91. echo "ERROR: \"${TEST_COMMAND} $@\" exited with non-zero exit status: $err" 1>&2
  92. fi
  93. if [ $use_valgrind -eq 1 ] ; then
  94. if ! tail -1 "${TEST_OUTPUT}.vg.out" | grep -q "ERROR SUMMARY: 0 errors" ; then
  95. echo "ERROR: valgrind found errors during execution:" 1>&2
  96. cat "${TEST_OUTPUT}.vg.out"
  97. err=1
  98. fi
  99. fi
  100. if ! "$CMP" -s "${top_builddir}/${TEST_OUTPUT}.expected" "${TEST_OUTPUT}.out" ; then
  101. echo "ERROR: \"${TEST_COMMAND} $@\" (${TEST_OUTPUT}) failed (set VERBOSE=1 to see full output):" 1>&2
  102. (cd "${CURDIR}" ; set -x ; diff "${top_builddir}/${TEST_OUTPUT}.expected" "$testsubdir/${TEST_OUTPUT}.out")
  103. echo "cp \"$testsubdir/${TEST_OUTPUT}.out\" \"${top_builddir}/${TEST_OUTPUT}.expected\"" 1>&2
  104. err=1
  105. fi
  106. return $err
  107. }