source: valtobtest/subversion-1.6.2/subversion/tests/cmdline/davautocheck.sh @ 3

Last change on this file since 3 was 3, checked in by valtob, 15 years ago

subversion source 1.6.2 as test

  • Property svn:executable set to *
File size: 11.4 KB
Line 
1#!/bin/bash
2# -*- mode: shell-script; -*-
3# $Id$
4
5# This script simplifies preparation of environment for Subversion client
6# communicating with a server via DAV protocol. The prerequisites of such
7# testing are:
8#   - Subversion built using --enable-shared --enable-dso --with-apxs options,
9#   - Working Apache 2 HTTPD Server with the apxs program reachable through
10#     PATH or specified via the APXS environment variable,
11#   - Modules dav_module and log_config_module compiled as DSO or built into
12#     Apache HTTPD Server executable.
13# The basic intension of this script is to be able to perform "make check"
14# operation over DAV without any configuration efforts whatsoever, provided
15# that conditions above are met.
16#
17# The script will find Apache and all necessary modules including mod_dav_svn,
18# create a temporary directory in subversion/tests/cmdline, create
19# Apache 2 configuration file in this directory, start Apache 2 on a random
20# port number higher than 1024, and execute Subversion command-line client
21# test suites against this instance of HTTPD. Every vital configuration
22# parameter is checked before the tests start. The script will ask questions
23# about browsing Apache error log (default is "no") and about deleting
24# temporary directory (default "yes") and pause for 32 seconds before
25# proceeding with the default. HTTPD access log is also created in the
26# temporary directory.
27#
28# Run this script without parameters to execute the full battery of tests:
29#   subversion/tests/cmdline/davautocheck.sh
30# Run this script with the name of a test suite to run this suite:
31#   subversion/tests/cmdline/davautocheck.sh basic
32# Run this script with the test suite name and test number to execute just this
33# test:
34#   subversion/tests/cmdline/davautocheck.sh basic 4
35#
36# If the temporary directory is not deleted, it can be reused for further
37# manual DAV protocol interoperation testing. HTTPD must be started by
38# specifying configuration file on the command line:
39#   httpd -f subversion/tests/cmdline/<httpd-...>/cfg
40#
41# If you want to run this against an *installed* HTTPD (for example, to test
42# one version's client against another version's server) specify both APXS
43# *and* MODULE_PATH for the other server:
44#
45#   APXS=/opt/svn/1.4.x/bin/apxs MODULE_PATH=/opt/svn/1.4.x/modules \
46#     subversion/tests/cmdline/davautocheck.sh
47
48SCRIPTDIR=$(dirname $0)
49SCRIPT=$(basename $0)
50
51trap stop_httpd_and_die SIGHUP SIGTERM SIGINT
52
53function stop_httpd_and_die() {
54  [ -e "$HTTPD_PID" ] && kill $(cat "$HTTPD_PID")
55  exit 1
56}
57
58function say() {
59  echo "$SCRIPT: $*"
60}
61
62function fail() {
63  say $*
64  stop_httpd_and_die
65}
66
67function query() {
68  echo -n "$SCRIPT: $1 (y/n)? [$2] "
69  read -n 1 -t 32
70  echo
71  [ "${REPLY:-$2}" = 'y' ]
72}
73
74function get_loadmodule_config() {
75  local SO="$($APXS -q LIBEXECDIR)/$1.so"
76
77  # shared object module?
78  if [ -r "$SO" ]; then
79    local NM=$(echo "$1" | sed 's|mod_\(.*\)|\1_module|')
80    echo "LoadModule $NM \"$SO\"" &&
81    return
82  fi
83
84  # maybe it's built-in?
85  "$HTTPD" -l | grep -q "$1\\.c" && return
86
87  return 1
88}
89
90# Check apxs's SBINDIR and BINDIR for given program names
91function get_prog_name() {
92  for prog in $*
93  do
94    for dir in $($APXS -q SBINDIR) $($APXS -q BINDIR)
95    do
96      if [ -e "$dir/$prog" ]; then
97        echo "$dir/$prog" && return
98      fi
99    done
100  done
101
102  return 1
103}
104
105# Don't assume sbin is in the PATH.
106PATH="$PATH:/usr/sbin:/usr/local/sbin"
107
108# Remove any proxy environmental variables that affect wget or curl.
109# We don't need a proxy to connect to localhost and having the proxy
110# environmental variables set breaks the Apache configuration file
111# test below, since wget or curl will ask the proxy to connect to
112# localhost.
113unset PROXY
114unset http_proxy
115unset HTTPS_PROXY
116
117# Pick up value from environment or PATH (also try apxs2 - for Debian)
118[ ${APXS:+set} ] \
119 || APXS=$(which apxs) \
120 || APXS=$(which apxs2) \
121 || fail "neither apxs or apxs2 found - required to run davautocheck"
122
123[ -x $APXS ] || fail "Can't execute apxs executable $APXS"
124
125say "Using '$APXS'..."
126
127if [ -x subversion/svn/svn ]; then
128  ABS_BUILDDIR=$(pwd)
129elif [ -x $SCRIPTDIR/../../svn/svn ]; then
130  pushd $SCRIPTDIR/../../../ >/dev/null
131  ABS_BUILDDIR=$(pwd)
132  popd >/dev/null
133else
134  fail "Run this script from the root of Subversion's build tree!"
135fi
136
137if [ ${MODULE_PATH:+set} ]; then
138    MOD_DAV_SVN="$MODULE_PATH/mod_dav_svn.so"
139    MOD_AUTHZ_SVN="$MODULE_PATH/mod_authz_svn.so"
140else
141    MOD_DAV_SVN="$ABS_BUILDDIR/subversion/mod_dav_svn/.libs/mod_dav_svn.so"
142    MOD_AUTHZ_SVN="$ABS_BUILDDIR/subversion/mod_authz_svn/.libs/mod_authz_svn.so"
143fi
144
145[ -r "$MOD_DAV_SVN" ] \
146  || fail "dav_svn_module not found, please use '--enable-shared --enable-dso --with-apxs' with your 'configure' script"
147[ -r "$MOD_AUTHZ_SVN" ] \
148  || fail "authz_svn_module not found, please use '--enable-shared --enable-dso --with-apxs' with your 'configure' script"
149
150export LD_LIBRARY_PATH="$ABS_BUILDDIR/subversion/libsvn_ra_neon/.libs:$ABS_BUILDDIR/subversion/libsvn_ra_local/.libs:$ABS_BUILDDIR/subversion/libsvn_ra_svn/.libs"
151
152case "`uname`" in
153  Darwin*) LDD='otool -L'
154    ;;
155  *) LDD='ldd'
156    ;;
157esac
158
159CLIENT_CMD="$ABS_BUILDDIR/subversion/svn/svn"
160$LDD "$CLIENT_CMD" | grep -q 'not found' \
161  && fail "Subversion client couldn't be fully linked at run-time"
162"$CLIENT_CMD" --version | egrep -q '^[*] ra_(neon|serf)' \
163  || fail "Subversion client couldn't find and/or load ra_dav library"
164
165httpd="$($APXS -q PROGNAME)"
166HTTPD=$(get_prog_name $httpd) || fail "HTTPD not found"
167[ -x $HTTPD ] || fail "HTTPD '$HTTPD' not executable"
168
169"$HTTPD" -v 1>/dev/null 2>&1 \
170  || fail "HTTPD '$HTTPD' doesn't start properly"
171
172say "Using '$HTTPD'..."
173
174HTPASSWD=$(get_prog_name htpasswd htpasswd2) \
175  || fail "Could not find htpasswd or htpasswd2"
176[ -x $HTPASSWD ] \
177  || fail "HTPASSWD '$HTPASSWD' not executable"
178say "Using '$HTPASSWD'..."
179
180LOAD_MOD_DAV=$(get_loadmodule_config mod_dav) \
181  || fail "DAV module not found"
182
183LOAD_MOD_LOG_CONFIG=$(get_loadmodule_config mod_log_config) \
184  || fail "log_config module not found"
185
186# needed for TypesConfig
187LOAD_MOD_MIME=$(get_loadmodule_config mod_mime) \
188  || fail "MIME module not found"
189
190# needed for Auth*, Require, etc. directives
191LOAD_MOD_AUTH=$(get_loadmodule_config mod_auth) \
192  || {
193say "Monolithic Auth module not found. Assuming we run against Apache 2.1+"
194LOAD_MOD_AUTH="$(get_loadmodule_config mod_auth_basic)" \
195    || fail "Auth_Basic module not found."
196LOAD_MOD_ACCESS_COMPAT="$(get_loadmodule_config mod_access_compat)" \
197    && {
198say "Found Auth modules for Apache 2.3.0+"
199LOAD_MOD_AUTHN_CORE="$(get_loadmodule_config mod_authn_core)" \
200    || fail "Authn_Core module not found."
201LOAD_MOD_AUTHZ_CORE="$(get_loadmodule_config mod_authz_core)" \
202    || fail "Authz_Core module not found."
203LOAD_MOD_AUTHZ_HOST="$(get_loadmodule_config mod_authz_host)" \
204    || fail "Authz_Host module not found."
205}
206LOAD_MOD_AUTHN_FILE="$(get_loadmodule_config mod_authn_file)" \
207    || fail "Authn_File module not found."
208LOAD_MOD_AUTHZ_USER="$(get_loadmodule_config mod_authz_user)" \
209    || fail "Authz_User module not found."
210}
211
212HTTPD_PORT=$(($RANDOM+1024))
213HTTPD_ROOT="$ABS_BUILDDIR/subversion/tests/cmdline/httpd-$(date '+%Y%m%d-%H%M%S')"
214HTTPD_CFG="$HTTPD_ROOT/cfg"
215HTTPD_PID="$HTTPD_ROOT/pid"
216HTTPD_ACCESS_LOG="$HTTPD_ROOT/access_log"
217HTTPD_ERROR_LOG="$HTTPD_ROOT/error_log"
218HTTPD_MIME_TYPES="$HTTPD_ROOT/mime.types"
219BASE_URL="http://localhost:$HTTPD_PORT"
220HTTPD_USERS="$HTTPD_ROOT/users"
221
222mkdir "$HTTPD_ROOT" \
223  || fail "couldn't create temporary directory '$HTTPD_ROOT'"
224
225say "Using directory '$HTTPD_ROOT'..."
226
227say "Adding users for lock authentication"
228$HTPASSWD -bc $HTTPD_USERS jrandom   rayjandom
229$HTPASSWD -b  $HTTPD_USERS jconstant rayjandom
230
231touch $HTTPD_MIME_TYPES
232
233cat > "$HTTPD_CFG" <<__EOF__
234$LOAD_MOD_LOG_CONFIG
235$LOAD_MOD_MIME
236$LOAD_MOD_DAV
237LoadModule          dav_svn_module "$MOD_DAV_SVN"
238$LOAD_MOD_AUTH
239$LOAD_MOD_AUTHN_CORE
240$LOAD_MOD_AUTHN_FILE
241$LOAD_MOD_AUTHZ_CORE
242$LOAD_MOD_AUTHZ_USER
243$LOAD_MOD_AUTHZ_HOST
244LoadModule          authz_svn_module "$MOD_AUTHZ_SVN"
245
246LockFile            lock
247User                $(whoami)
248Group               $(groups | awk '{print $1}')
249Listen              localhost:$HTTPD_PORT
250ServerName          localhost
251PidFile             "$HTTPD_PID"
252LogFormat           "%h %l %u %t \"%r\" %>s %b" common
253CustomLog           "$HTTPD_ACCESS_LOG" common
254ErrorLog            "$HTTPD_ERROR_LOG"
255LogLevel            Debug
256ServerRoot          "$HTTPD_ROOT"
257DocumentRoot        "$HTTPD_ROOT"
258ScoreBoardFile      "$HTTPD_ROOT/run"
259CoreDumpDirectory   "$HTTPD_ROOT"
260TypesConfig         "$HTTPD_MIME_TYPES"
261StartServers        4
262MaxRequestsPerChild 0
263<IfModule worker.c>
264  ThreadsPerChild   8
265</IfModule>
266MaxClients          16
267HostNameLookups     Off
268LogFormat           "%h %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"" format
269CustomLog           "$HTTPD_ROOT/req" format
270CustomLog           "$HTTPD_ROOT/ops" "%t %u %{SVN-REPOS-NAME}e %{SVN-ACTION}e" env=SVN-ACTION
271
272<Directory />
273  AllowOverride     none
274</Directory>
275<Directory "$HTTPD_ROOT">
276  AllowOverride     none
277  #Require           all granted
278</Directory>
279
280<Location /svn-test-work/repositories>
281  DAV               svn
282  SVNParentPath     "$ABS_BUILDDIR/subversion/tests/cmdline/svn-test-work/repositories"
283  AuthzSVNAccessFile "$ABS_BUILDDIR/subversion/tests/cmdline/svn-test-work/authz"
284  AuthType          Basic
285  AuthName          "Subversion Repository"
286  AuthUserFile      $HTTPD_USERS
287  Require           valid-user
288</Location>
289<Location /svn-test-work/local_tmp/repos>
290  DAV               svn
291  SVNPath           "$ABS_BUILDDIR/subversion/tests/cmdline/svn-test-work/local_tmp/repos"
292  AuthzSVNAccessFile "$ABS_BUILDDIR/subversion/tests/cmdline/svn-test-work/authz"
293  AuthType          Basic
294  AuthName          "Subversion Repository"
295  AuthUserFile      $HTTPD_USERS
296  Require           valid-user
297</Location>
298__EOF__
299
300START="$HTTPD -f $HTTPD_CFG"
301
302$START -t \
303  || fail "Configuration file didn't pass the check, most likely modules couldn't be loaded"
304
305# need to pause for some time to let HTTPD start
306$START &
307sleep 2
308
309say "HTTPD started and listening on '$BASE_URL'..."
310
311# Perform a trivial validation of our httpd configuration by
312# downloading a file and comparing it to the original copy.
313### The file at the path "/cfg" can't be retrieved from Apache 2.3+.
314### We get a 500 ISE, with the following error in the log from httpd's
315### server/request.c:ap_process_request_internal():
316###   [Wed Feb 22 13:06:55 2006] [crit] [client 127.0.0.1] configuration error:  couldn't check user: /cfg
317HTTP_FETCH=wget
318HTTP_FETCH_OUTPUT="-q -O"
319type wget > /dev/null 2>&1
320if [ $? -ne 0 ]; then
321  type curl > /dev/null 2>&1
322  if [ $? -ne 0 ]; then
323    fail "Neither curl or wget found."
324  fi
325  HTTP_FETCH=curl
326  HTTP_FETCH_OUTPUT='-s -o'
327fi
328$HTTP_FETCH $HTTP_FETCH_OUTPUT "$HTTPD_CFG-copy" "$BASE_URL/cfg"
329diff -q "$HTTPD_CFG" "$HTTPD_CFG-copy" > /dev/null \
330  || fail "HTTPD doesn't operate according to the generated configuration"
331rm "$HTTPD_CFG-copy"
332
333say "HTTPD is good"
334
335if [ $# -eq 1 ] && [ "x$1" = 'x--no-tests' ]; then
336  exit
337fi
338
339say "starting the tests..."
340
341if [ $# = 0 ]; then
342  time make check "BASE_URL=$BASE_URL"
343  r=$?
344else
345  pushd "$ABS_BUILDDIR/subversion/tests/cmdline/" >/dev/null
346  TEST="$1"
347  shift
348  time "$SCRIPTDIR/${TEST}_tests.py" "--url=$BASE_URL" "$@"
349  r=$?
350  popd >/dev/null
351fi
352
353say "Finished testing..."
354
355kill $(cat "$HTTPD_PID")
356
357query 'Browse server access log' n \
358  && less "$HTTPD_ACCESS_LOG"
359
360query 'Browse server error log' n \
361  && less "$HTTPD_ERROR_LOG"
362
363query 'Delete HTTPD root directory' y \
364  && rm -fr "$HTTPD_ROOT/"
365
366say 'Done'
367
368exit $r
Note: See TracBrowser for help on using the repository browser.