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

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