runtests.sh 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329
  1. #! /bin/sh
  2. # Copyright (C) 2001, 2002 by Martin Pool <mbp@samba.org>
  3. # Copyright (C) 2003, 2004, 2005, 2006 Wayne Davison
  4. # This program is free software; you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License version
  6. # 2 as published by the Free Software Foundation.
  7. #
  8. # This program is distributed in the hope that it will be useful, but
  9. # WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. # Lesser General Public License for more details.
  12. #
  13. # You should have received a copy of the GNU Lesser General Public
  14. # License along with this program; if not, write to the Free Software
  15. # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  16. # rsync top-level test script -- this invokes all the other more
  17. # detailed tests in order. This script can either be called by `make
  18. # check' or `make installcheck'. `check' runs against the copies of
  19. # the program and other files in the build directory, and
  20. # `installcheck' against the installed copy of the program.
  21. # In either case we need to also be able to find the source directory,
  22. # since we read test scripts and possibly other information from
  23. # there.
  24. # Whenever possible, informational messages are written to stdout and
  25. # error messages to stderr. They're separated out by the build farm
  26. # display scripts.
  27. # According to the GNU autoconf manual, the only valid place to set up
  28. # directory locations is through Make, since users are allowed to (try
  29. # to) change their mind on the Make command line. So, Make has to
  30. # pass in all the values we need.
  31. # For other configured settings we read ./config.sh, which tells us
  32. # about shell commands on this machine and similar things.
  33. # rsync_bin gives the location of the rsync binary. This is either
  34. # builddir/rsync if we're testing an uninstalled copy, or
  35. # install_prefix/bin/rsync if we're testing an installed copy. On the
  36. # build farm rsync will be installed, but into a scratch /usr.
  37. # srcdir gives the location of the source tree, which lets us find the
  38. # build scripts. At the moment we assume we are invoked from the
  39. # source directory.
  40. # This script must be invoked from the build directory.
  41. # A scratch directory, 'testtmp', is used in the build directory to
  42. # hold per-test subdirectories.
  43. # This script also uses the $loglevel environment variable. 1 is the
  44. # default value, and 10 the most verbose. You can set this from the
  45. # Make command line. It's also set by the build farm to give more
  46. # detail for failing builds.
  47. # NOTES FOR TEST CASES:
  48. # Each test case runs in its own shell.
  49. # Exit codes from tests:
  50. # 1 tests failed
  51. # 2 error in starting tests
  52. # 77 this test skipped (random value unlikely to happen by chance, same as
  53. # automake)
  54. # HOWEVER, the overall exit code to the farm is different: we return
  55. # the *number of tests that failed*, so that it will show up nicely in
  56. # the overall summary.
  57. # rsync.fns contains some general setup functions and definitions.
  58. # NOTES ON PORTABILITY:
  59. # Both this script and the Makefile have to be pretty conservative
  60. # about which Unix features they use.
  61. # We cannot count on Make exporting variables to commands, unless
  62. # they're explicitly given on the command line.
  63. # Also, we can't count on 'cp -a' or 'mkdir -p', although they're
  64. # pretty handy (see function makepath for the latter).
  65. # I think some of the GNU documentation suggests that we shouldn't
  66. # rely on shell functions. However, the Bash manual seems to say that
  67. # they're in POSIX 1003.2, and since the build farm relies on them
  68. # they're probably working on most machines we really care about.
  69. # You cannot use "function foo {" syntax, but must instead say "foo()
  70. # {", or it breaks on FreeBSD.
  71. # BSD machines tend not to have "head" or "seq".
  72. # You cannot do "export VAR=VALUE" all on one line; the export must be
  73. # separate from the assignment. (SCO SysV)
  74. # Don't rely on grep -q, as that doesn't work everywhere -- just redirect
  75. # stdout to /dev/null to keep it quiet.
  76. # STILL TO DO:
  77. # We need a good protection against tests that hang indefinitely.
  78. # Perhaps some combination of starting them in the background, wait,
  79. # and kill?
  80. # Perhaps we need a common way to cleanup tests. At the moment just
  81. # clobbering the directory when we're done should be enough.
  82. # If any of the targets fail, then (GNU?) Make returns 2, instead of
  83. # the return code from the failing command. This is fine, but it
  84. # means that the build farm just shows "2" for failed tests, not the
  85. # number of tests that actually failed. For more details we might
  86. # need to grovel through the log files to find a line saying how many
  87. # failed.
  88. set -e
  89. . "./shconfig"
  90. RUNSHFLAGS='-e'
  91. export RUNSHFLAGS
  92. # for Solaris
  93. if [ -d /usr/xpg4/bin ]; then
  94. PATH="/usr/xpg4/bin/:$PATH"
  95. export PATH
  96. fi
  97. if [ "x$loglevel" != x ] && [ "$loglevel" -gt 8 ]; then
  98. if set -x; then
  99. # If it doesn't work the first time, don't keep trying.
  100. RUNSHFLAGS="$RUNSHFLAGS -x"
  101. fi
  102. fi
  103. POSIXLY_CORRECT=1
  104. if test x"$TOOLDIR" = x; then
  105. TOOLDIR=`pwd`
  106. fi
  107. srcdir=`dirname $0`
  108. if test x"$srcdir" = x -o x"$srcdir" = x.; then
  109. srcdir="$TOOLDIR"
  110. fi
  111. if test x"$rsync_bin" = x; then
  112. rsync_bin="$TOOLDIR/rsync"
  113. fi
  114. # This allows the user to specify extra rsync options -- use carefully!
  115. RSYNC="$rsync_bin $*"
  116. #RSYNC="valgrind $rsync_bin $*"
  117. TLS_ARGS=''
  118. if egrep '^#define HAVE_LUTIMES 1' config.h >/dev/null; then
  119. TLS_ARGS="$TLS_ARGS -l"
  120. fi
  121. if egrep '#undef CHOWN_MODIFIES_SYMLINK' config.h >/dev/null; then
  122. TLS_ARGS="$TLS_ARGS -L"
  123. fi
  124. export POSIXLY_CORRECT TOOLDIR srcdir RSYNC TLS_ARGS
  125. echo "============================================================"
  126. echo "$0 running in $TOOLDIR"
  127. echo " rsync_bin=$RSYNC"
  128. echo " srcdir=$srcdir"
  129. echo " TLS_ARGS=$TLS_ARGS"
  130. if [ -f /usr/bin/whoami ]; then
  131. testuser=`/usr/bin/whoami`
  132. elif [ -f /usr/ucb/whoami ]; then
  133. testuser=`/usr/ucb/whoami`
  134. elif [ -f /bin/whoami ]; then
  135. testuser=`/bin/whoami`
  136. else
  137. testuser=`id -un 2>/dev/null || echo ${LOGNAME:-${USERNAME:-${USER:-'UNKNOWN'}}}`
  138. fi
  139. echo " testuser=$testuser"
  140. echo " os=`uname -a`"
  141. # It must be "yes", not just nonnull
  142. if [ "x$preserve_scratch" = xyes ]; then
  143. echo " preserve_scratch=yes"
  144. else
  145. echo " preserve_scratch=no"
  146. fi
  147. # Check if setacl/setfacl is around and if it supports the -k or -s option.
  148. if setacl -k u::7,g::5,o:5 testsuite 2>/dev/null; then
  149. setfacl_nodef='setacl -k'
  150. elif setfacl --help 2>&1 | grep ' -k,\|\[-[a-z]*k' >/dev/null; then
  151. setfacl_nodef='setfacl -k'
  152. elif setfacl -s u::7,g::5,o:5 testsuite 2>/dev/null; then
  153. setfacl_nodef='setfacl -s u::7,g::5,o:5'
  154. else
  155. # The "true" command runs successfully, but does nothing.
  156. setfacl_nodef=true
  157. fi
  158. export setfacl_nodef
  159. if [ ! -f "$rsync_bin" ]; then
  160. echo "rsync_bin $rsync_bin is not a file" >&2
  161. exit 2
  162. fi
  163. if [ ! -d "$srcdir" ]; then
  164. echo "srcdir $srcdir is not a directory" >&2
  165. exit 2
  166. fi
  167. skipped=0
  168. missing=0
  169. passed=0
  170. failed=0
  171. # Directory that holds the other test subdirs. We create separate dirs
  172. # inside for each test case, so that they can be left behind in case of
  173. # failure to aid investigation. We don't remove the testtmp subdir at
  174. # the end so that it can be configured as a symlink to a filesystem that
  175. # has ACLs and xattr support enabled (if desired).
  176. scratchbase="$TOOLDIR"/testtmp
  177. echo " scratchbase=$scratchbase"
  178. [ -d "$scratchbase" ] || mkdir "$scratchbase"
  179. suitedir="$srcdir/testsuite"
  180. export scratchdir suitedir
  181. prep_scratch() {
  182. [ -d "$scratchdir" ] && chmod -R u+rwX "$scratchdir" && rm -rf "$scratchdir"
  183. mkdir "$scratchdir"
  184. # Get rid of default ACLs and dir-setgid to avoid confusing some tests.
  185. $setfacl_nodef "$scratchdir" || true
  186. chmod g-s "$scratchdir"
  187. case "$srcdir" in
  188. /*) ln -s "$srcdir" "$scratchdir/src" ;;
  189. *) ln -s "$TOOLDIR/$srcdir" "$scratchdir/src" ;;
  190. esac
  191. return 0
  192. }
  193. maybe_discard_scratch() {
  194. [ x"$preserve_scratch" != xyes ] && [ -d "$scratchdir" ] && rm -rf "$scratchdir"
  195. return 0
  196. }
  197. if [ "x$whichtests" = x ]; then
  198. whichtests="*.test"
  199. fi
  200. for testscript in $suitedir/$whichtests
  201. do
  202. testbase=`echo $testscript | sed -e 's!.*/!!' -e 's/.test\$//'`
  203. scratchdir="$scratchbase/$testbase"
  204. prep_scratch
  205. set +e
  206. sh $RUNSHFLAGS "$testscript" >"$scratchdir/test.log" 2>&1
  207. result=$?
  208. set -e
  209. if [ "x$always_log" = xyes -o \( $result != 0 -a $result != 77 -a $result != 78 \) ]
  210. then
  211. echo "----- $testbase log follows"
  212. cat "$scratchdir/test.log"
  213. echo "----- $testbase log ends"
  214. if [ -f "$scratchdir/rsyncd.log" ]; then
  215. echo "----- $testbase rsyncd.log follows"
  216. cat "$scratchdir/rsyncd.log"
  217. echo "----- $testbase rsyncd.log ends"
  218. fi
  219. fi
  220. case $result in
  221. 0)
  222. echo "PASS $testbase"
  223. passed=`expr $passed + 1`
  224. maybe_discard_scratch
  225. ;;
  226. 77)
  227. # backticks will fill the whole file onto one line, which is a feature
  228. whyskipped=`cat "$scratchdir/whyskipped"`
  229. echo "SKIP $testbase ($whyskipped)"
  230. skipped=`expr $skipped + 1`
  231. maybe_discard_scratch
  232. ;;
  233. 78)
  234. # It failed, but we expected that. don't dump out error logs,
  235. # because most users won't want to see them. But do leave
  236. # the working directory around.
  237. echo "XFAIL $testbase"
  238. failed=`expr $failed + 1`
  239. ;;
  240. *)
  241. echo "FAIL $testbase"
  242. failed=`expr $failed + 1`
  243. if [ "x$nopersist" = xyes ]; then
  244. exit 1
  245. fi
  246. esac
  247. done
  248. echo '------------------------------------------------------------'
  249. echo "----- overall results:"
  250. echo " $passed passed"
  251. [ "$failed" -gt 0 ] && echo " $failed failed"
  252. [ "$skipped" -gt 0 ] && echo " $skipped skipped"
  253. [ "$missing" -gt 0 ] && echo " $missing missing"
  254. echo '------------------------------------------------------------'
  255. # OK, so expr exits with 0 if the result is neither null nor zero; and
  256. # 1 if the expression is null or zero. This is the opposite of what
  257. # we want, and if we just call expr then this script will always fail,
  258. # because -e is set.
  259. result=`expr $failed + $missing || true`
  260. echo "overall result is $result"
  261. exit $result