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 2.7 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  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. progname=`echo "$0" | sed 's,^.*/,,'`
  21. testname=`echo "$progname" | sed 's,-.*$,,'`
  22. testsubdir=${testsubdir-testSubDir}
  23. # User can set VERBOSE to cause output redirection
  24. case "$VERBOSE" in
  25. [Nn]|[Nn][Oo]|0|"")
  26. VERBOSE=0
  27. exec > /dev/null 2>&1
  28. ;;
  29. [Yy]|[Yy][Ee][Ss])
  30. VERBOSE=1
  31. ;;
  32. esac
  33. rm -rf "$testsubdir/$progname" > /dev/null 2>&1
  34. mkdir -p "$testsubdir/$progname"
  35. cd "$testsubdir/$progname" \
  36. || { echo "Cannot make or change into $testsubdir/$progname"; exit 1; }
  37. echo "=== Running test $progname"
  38. CMP="${CMP-cmp}"
  39. use_valgrind=${USE_VALGRIND-1}
  40. valgrind_path=$(which valgrind 2> /dev/null)
  41. if [ -z "${valgrind_path}" -o ! -x "${valgrind_path}" ] ; then
  42. use_valgrind=0
  43. fi
  44. #
  45. # This is a common function to check the results of a test program
  46. # that is intended to generate consistent output across runs.
  47. #
  48. # ${top_builddir} must be set to the top level build directory.
  49. #
  50. # Output will be written to the current directory.
  51. #
  52. # It must be passed the name of the test command to run, which must be present
  53. # in the ${top_builddir} directory.
  54. #
  55. # It will compare the output of running that against <name of command>.expected
  56. #
  57. run_output_test()
  58. {
  59. TEST_COMMAND="$1"
  60. REDIR_OUTPUT="> \"${TEST_COMMAND}.out\""
  61. if [ $VERBOSE -gt 1 ] ; then
  62. REDIR_OUTPUT="| tee \"${TEST_COMMAND}.out\""
  63. fi
  64. if [ $use_valgrind -eq 1 ] ; then
  65. eval valgrind --tool=memcheck \
  66. --trace-children=yes \
  67. --demangle=yes \
  68. --log-file=vg.out \
  69. --leak-check=full \
  70. --show-reachable=yes \
  71. --run-libc-freeres=yes \
  72. "\"${top_builddir}/${TEST_COMMAND}\"" ${REDIR_OUTPUT}
  73. err=$?
  74. else
  75. eval "\"${top_builddir}/${TEST_COMMAND}"\" ${REDIR_OUTPUT}
  76. err=$?
  77. fi
  78. if [ $err -ne 0 ] ; then
  79. echo "ERROR: ${TEST_COMMAND} exited with non-zero exit status: $err" 1>&2
  80. fi
  81. if [ $use_valgrind -eq 1 ] ; then
  82. if ! tail -1 "vg.out" | grep -q "ERROR SUMMARY: 0 errors" ; then
  83. echo "ERROR: valgrind found errors during execution:" 1>&2
  84. cat vg.out
  85. err=1
  86. fi
  87. fi
  88. if ! "$CMP" -s "${top_builddir}/${TEST_COMMAND}.expected" "${TEST_COMMAND}.out" ; then
  89. echo "ERROR: ${TEST_COMMAND} failed:" 1>&2
  90. diff "${top_builddir}/${TEST_COMMAND}.expected" "${TEST_COMMAND}.out" 1>&2
  91. err=1
  92. fi
  93. return $err
  94. }