runtests.sh 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  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. [ -d /usr/xpg4/bin ] && PATH="/usr/xpg4/bin/:$PATH"
  94. if [ "x$loglevel" != x ] && [ "$loglevel" -gt 8 ]; then
  95. if set -x; then
  96. # If it doesn't work the first time, don't keep trying.
  97. RUNSHFLAGS="$RUNSHFLAGS -x"
  98. fi
  99. fi
  100. POSIXLY_CORRECT=1
  101. if test x"$TOOLDIR" = x; then
  102. TOOLDIR=`pwd`
  103. fi
  104. srcdir=`dirname $0`
  105. if test x"$srcdir" = x -o x"$srcdir" = x.; then
  106. srcdir="$TOOLDIR"
  107. fi
  108. if test x"$rsync_bin" = x; then
  109. rsync_bin="$TOOLDIR/rsync"
  110. fi
  111. # This allows the user to specify extra rsync options -- use carefully!
  112. RSYNC="$rsync_bin $*"
  113. #RSYNC="valgrind $rsync_bin $*"
  114. TLS_ARGS=''
  115. if egrep '^#define HAVE_LUTIMES 1' config.h >/dev/null; then
  116. TLS_ARGS="$TLS_ARGS -l"
  117. fi
  118. if egrep '#undef CHOWN_MODIFIES_SYMLINK' config.h >/dev/null; then
  119. TLS_ARGS="$TLS_ARGS -L"
  120. fi
  121. export POSIXLY_CORRECT TOOLDIR srcdir RSYNC TLS_ARGS
  122. echo "============================================================"
  123. echo "$0 running in $TOOLDIR"
  124. echo " rsync_bin=$RSYNC"
  125. echo " srcdir=$srcdir"
  126. echo " TLS_ARGS=$TLS_ARGS"
  127. if [ -f /usr/bin/whoami ]; then
  128. testuser=`/usr/bin/whoami`
  129. elif [ -f /usr/ucb/whoami ]; then
  130. testuser=`/usr/ucb/whoami`
  131. elif [ -f /bin/whoami ]; then
  132. testuser=`/bin/whoami`
  133. else
  134. testuser=`id -un 2>/dev/null || echo ${LOGNAME:-${USERNAME:-${USER:-'UNKNOWN'}}}`
  135. fi
  136. echo " testuser=$testuser"
  137. echo " os=`uname -a`"
  138. # It must be "yes", not just nonnull
  139. if [ "x$preserve_scratch" = xyes ]; then
  140. echo " preserve_scratch=yes"
  141. else
  142. echo " preserve_scratch=no"
  143. fi
  144. # Check if setacl/setfacl is around and if it supports the -k or -s option.
  145. if setacl -k u::7,g::5,o:5 testsuite 2>/dev/null; then
  146. setfacl_nodef='setacl -k'
  147. elif setfacl --help 2>&1 | grep ' -k,\|\[-[a-z]*k' >/dev/null; then
  148. setfacl_nodef='setfacl -k'
  149. elif setfacl -s u::7,g::5,o:5 testsuite 2>/dev/null; then
  150. setfacl_nodef='setfacl -s u::7,g::5,o:5'
  151. else
  152. # The "true" command runs successfully, but does nothing.
  153. setfacl_nodef=true
  154. fi
  155. export setfacl_nodef
  156. if [ ! -f "$rsync_bin" ]; then
  157. echo "rsync_bin $rsync_bin is not a file" >&2
  158. exit 2
  159. fi
  160. if [ ! -d "$srcdir" ]; then
  161. echo "srcdir $srcdir is not a directory" >&2
  162. exit 2
  163. fi
  164. skipped=0
  165. missing=0
  166. passed=0
  167. failed=0
  168. # Directory that holds the other test subdirs. We create separate dirs
  169. # inside for each test case, so that they can be left behind in case of
  170. # failure to aid investigation. We don't remove the testtmp subdir at
  171. # the end so that it can be configured as a symlink to a filesystem that
  172. # has ACLs and xattr support enabled (if desired).
  173. scratchbase="$TOOLDIR"/testtmp
  174. echo " scratchbase=$scratchbase"
  175. [ -d "$scratchbase" ] || mkdir "$scratchbase"
  176. suitedir="$srcdir/testsuite"
  177. export scratchdir suitedir
  178. prep_scratch() {
  179. [ -d "$scratchdir" ] && chmod -R u+rwX "$scratchdir" && rm -rf "$scratchdir"
  180. mkdir "$scratchdir"
  181. # Get rid of default ACLs and dir-setgid to avoid confusing some tests.
  182. $setfacl_nodef "$scratchdir" || true
  183. chmod g-s "$scratchdir"
  184. case "$srcdir" in
  185. /*) ln -s "$srcdir" "$scratchdir/src" ;;
  186. *) ln -s "$TOOLDIR/$srcdir" "$scratchdir/src" ;;
  187. esac
  188. return 0
  189. }
  190. maybe_discard_scratch() {
  191. [ x"$preserve_scratch" != xyes ] && [ -d "$scratchdir" ] && rm -rf "$scratchdir"
  192. return 0
  193. }
  194. if [ "x$whichtests" = x ]; then
  195. whichtests="*.test"
  196. fi
  197. for testscript in $suitedir/$whichtests
  198. do
  199. testbase=`echo $testscript | sed -e 's!.*/!!' -e 's/.test\$//'`
  200. scratchdir="$scratchbase/$testbase"
  201. prep_scratch
  202. set +e
  203. sh $RUNSHFLAGS "$testscript" >"$scratchdir/test.log" 2>&1
  204. result=$?
  205. set -e
  206. if [ "x$always_log" = xyes -o \( $result != 0 -a $result != 77 -a $result != 78 \) ]
  207. then
  208. echo "----- $testbase log follows"
  209. cat "$scratchdir/test.log"
  210. echo "----- $testbase log ends"
  211. if [ -f "$scratchdir/rsyncd.log" ]; then
  212. echo "----- $testbase rsyncd.log follows"
  213. cat "$scratchdir/rsyncd.log"
  214. echo "----- $testbase rsyncd.log ends"
  215. fi
  216. fi
  217. case $result in
  218. 0)
  219. echo "PASS $testbase"
  220. passed=`expr $passed + 1`
  221. maybe_discard_scratch
  222. ;;
  223. 77)
  224. # backticks will fill the whole file onto one line, which is a feature
  225. whyskipped=`cat "$scratchdir/whyskipped"`
  226. echo "SKIP $testbase ($whyskipped)"
  227. skipped=`expr $skipped + 1`
  228. maybe_discard_scratch
  229. ;;
  230. 78)
  231. # It failed, but we expected that. don't dump out error logs,
  232. # because most users won't want to see them. But do leave
  233. # the working directory around.
  234. echo "XFAIL $testbase"
  235. failed=`expr $failed + 1`
  236. ;;
  237. *)
  238. echo "FAIL $testbase"
  239. failed=`expr $failed + 1`
  240. if [ "x$nopersist" = xyes ]; then
  241. exit 1
  242. fi
  243. esac
  244. done
  245. echo '------------------------------------------------------------'
  246. echo "----- overall results:"
  247. echo " $passed passed"
  248. [ "$failed" -gt 0 ] && echo " $failed failed"
  249. [ "$skipped" -gt 0 ] && echo " $skipped skipped"
  250. [ "$missing" -gt 0 ] && echo " $missing missing"
  251. echo '------------------------------------------------------------'
  252. # OK, so expr exits with 0 if the result is neither null nor zero; and
  253. # 1 if the expression is null or zero. This is the opposite of what
  254. # we want, and if we just call expr then this script will always fail,
  255. # because -e is set.
  256. result=`expr $failed + $missing || true`
  257. echo "overall result is $result"
  258. exit $result