Index: win-tests.py =================================================================== --- win-tests.py (revision 19109) +++ win-tests.py (working copy) @@ -11,6 +11,9 @@ --svnserve-args=list comma-separated list of arguments for svnserve; default is '-d,-r,' --asp.net-hack use '_svn' instead of '.svn' for the admin dir name + --httpd-dir location of Apache HTTPD + --httpd-port port for Apache HTTPD; random port number will be + used, if not specified """ import os, sys @@ -19,6 +22,7 @@ import traceback import ConfigParser import string +import random import getopt try: @@ -42,7 +46,8 @@ opts, args = my_getopt(sys.argv[1:], 'rdvcu:f:', ['release', 'debug', 'verbose', 'cleanup', 'url=', - 'svnserve-args=', 'fs-type=', 'asp.net-hack']) + 'svnserve-args=', 'fs-type=', 'asp.net-hack', + 'httpd-dir=', 'httpd-port=']) if len(args) > 1: print 'Warning: non-option arguments after the first one will be ignored' @@ -53,21 +58,12 @@ log = 'tests.log' run_svnserve = None svnserve_args = None +run_httpd = None +httpd_port = None for opt, val in opts: if opt in ('-u', '--url'): - all_tests = client_tests - repo_loc = 'remote repository ' + val + '.' base_url = val - if val[:4] == 'http': - log = 'dav-tests.log' - elif val[:3] == 'svn': - log = 'svn-tests.log' - run_svnserve = 1 - else: - # Don't know this scheme, but who're we to judge whether it's - # correct or not? - log = 'url-tests.log' elif opt in ('-f', '--fs-type'): fs_type = val elif opt in ('-v', '--verbose'): @@ -83,8 +79,12 @@ run_svnserve = 1 elif opt == '--asp.net-hack': os.environ['SVN_ASP_DOT_NET_HACK'] = opt + elif opt == '--httpd-dir': + abs_httpd_dir = os.path.abspath(val) + run_httpd = 1 + elif opt == '--httpd-port': + httpd_port = int(val) - # Calculate the source and test directory names abs_srcdir = os.path.abspath("") abs_objdir = os.path.join(abs_srcdir, objdir) @@ -95,6 +95,25 @@ abs_builddir = os.path.abspath(args[0]) create_dirs = 1 +if run_httpd: + if not httpd_port: + httpd_port = random.randrange(1024, 30000) + if not base_url: + base_url = 'http://localhost:' + str(httpd_port) + +if base_url: + all_tests = client_tests + repo_loc = 'remote repository ' + base_url + '.' + if base_url[:4] == 'http': + log = 'dav-tests.log' + elif base_url[:3] == 'svn': + log = 'svn-tests.log' + run_svnserve = 1 + else: + # Don't know this scheme, but who're we to judge whether it's + # correct or not? + log = 'url-tests.log' + # Have to move the executables where the tests expect them to be copied_execs = [] # Store copied exec files to avoid the final dir scan @@ -228,6 +247,119 @@ pass print 'Svnserve.stop not implemented' +class Httpd: + "Run httpd for ra_dav tests" + def __init__(self, abs_httpd_dir, abs_builddir, httpd_port): + self.name = 'apache.exe' + self.service_name = 'svn-test-httpd' + self.httpd_dir = abs_httpd_dir + self.path = os.path.join(self.httpd_dir, 'bin', self.name) + self.root = os.path.join(abs_builddir, CMDLINE_TEST_SCRIPT_NATIVE_PATH, + 'httpd') + self.httpd_config = os.path.join(self.root, 'httpd.conf') + self.httpd_users = os.path.join(self.root, 'users') + self.httpd_mime_types = os.path.join(self.root, 'mime.types') + self.httpd_port = httpd_port + self.abs_builddir = abs_builddir + self.httpd_args = [self.name, '-n', self.service_name, + '-f', self._quote(self.httpd_config)] + + create_target_dir(self.root) + + self._create_users_file() + self._create_mime_types_file() + + # Create httpd config file + fp = open(self.httpd_config, 'w') + + # Global Environment + fp.write('ServerRoot ' + self._quote(self.root) + '\n') + fp.write('DocumentRoot ' + self._quote(self.root) + '\n') + fp.write('ServerName localhost\n') + fp.write('PidFile pid\n') + fp.write('ErrorLog log\n') + fp.write('Listen ' + str(self.httpd_port) + '\n') + + # Write LoadModule for minimal system module + fp.write(self._sys_module('dav_module', 'mod_dav.so')) + fp.write(self._sys_module('auth_module', 'mod_auth.so')) + fp.write(self._sys_module('mime_module', 'mod_mime.so')) + fp.write(self._sys_module('log_config_module', 'mod_log_config.so')) + + # Write LoadModule for Subversion modules + fp.write(self._svn_module('dav_svn_module', os.path.join('mod_dav_svn', + 'mod_dav_svn.so'))) + fp.write(self._svn_module('authz_svn_module', os.path.join( + 'mod_authz_svn', 'mod_authz_svn.so'))) + + # Define two locations for repositories + fp.write(self._svn_repo('repositories')) + fp.write(self._svn_repo('local_tmp')) + + fp.write('TypesConfig ' + self._quote(self.httpd_mime_types) + '\n') + fp.write('LogLevel Debug\n') + fp.write('HostNameLookups Off\n') + + fp.close() + + def __del__(self): + "Stop httpd when the object is deleted" + self.stop() + + def _quote(self, arg): + if ' ' in arg: + return '"' + arg + '"' + else: + return arg + + def _create_users_file(self): + "Create users file" + htpasswd = os.path.join(self.httpd_dir, 'bin', 'htpasswd.exe') + os.spawnv(os.P_WAIT, htpasswd, ['htpasswd.exe', '-mbc', self.httpd_users, + 'jrandom', 'rayjandom']) + os.spawnv(os.P_WAIT, htpasswd, ['htpasswd.exe', '-mb', self.httpd_users, + 'jconstant', 'rayjandom']) + + def _create_mime_types_file(self): + "Create empty mime.types file" + fp = open(self.httpd_mime_types, 'w') + fp.close() + + def _sys_module(self, name, path): + full_path = os.path.join(self.httpd_dir, 'modules', path) + return 'LoadModule ' + name + " " + self._quote(full_path) + '\n' + + def _svn_module(self, name, path): + full_path = os.path.join(self.abs_builddir, 'subversion', path) + return 'LoadModule ' + name + ' ' + self._quote(full_path) + '\n' + + def _svn_repo(self, name): + path = os.path.join(self.abs_builddir, + CMDLINE_TEST_SCRIPT_NATIVE_PATH, + 'svn-test-work', name) + location = '/svn-test-work/' + name + return \ + '\n' \ + ' DAV svn\n' \ + ' SVNParentPath ' + self._quote(path) + '\n' \ + ' AuthType Basic\n' \ + ' AuthName "Subversion Repository"\n' \ + ' AuthUserFile ' + self._quote(self.httpd_users) + '\n' \ + ' Require valid-user\n' \ + '\n' + + def start(self): + "Install and start HTTPD service" + print 'Installing service', self.service_name + os.spawnv(os.P_WAIT, self.path, self.httpd_args + ['-k', 'install']) + print 'Starting service', self.service_name + os.spawnv(os.P_WAIT, self.path, self.httpd_args + ['-k', 'start']) + + def stop(self): + "Stop and unintall HTTPD service" + os.spawnv(os.P_WAIT, self.path, self.httpd_args + ['-k', 'stop']) + os.spawnv(os.P_WAIT, self.path, self.httpd_args + ['-k', 'uninstall']) + # Move the binaries to the test directory locate_libs() if create_dirs: @@ -250,6 +382,11 @@ if run_svnserve: svnserve = Svnserve(svnserve_args, objdir, abs_objdir, abs_builddir) svnserve.start() + +if run_httpd: + httpd = Httpd(abs_httpd_dir, abs_builddir, httpd_port) + httpd.start() + print 'Testing', objdir, 'configuration on', repo_loc sys.path.insert(0, os.path.join(abs_srcdir, 'build')) import run_tests