You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@subversion.apache.org by hw...@apache.org on 2010/06/21 15:38:00 UTC
svn commit: r956582 - in /subversion/branches/py-tests-as-modules:
build/run_tests.py subversion/tests/cmdline/svntest/main.py
Author: hwright
Date: Mon Jun 21 13:38:00 2010
New Revision: 956582
URL: http://svn.apache.org/viewvc?rev=956582&view=rev
Log:
On the py-tests-as-modules branch:
Revert r956568 from trunk (which itself was a reversion of r956108, r956106,
r956104, r956102, r956101, r956096, r956094, r956085 and r956046).
Modified:
subversion/branches/py-tests-as-modules/build/run_tests.py
subversion/branches/py-tests-as-modules/subversion/tests/cmdline/svntest/main.py
Modified: subversion/branches/py-tests-as-modules/build/run_tests.py
URL: http://svn.apache.org/viewvc/subversion/branches/py-tests-as-modules/build/run_tests.py?rev=956582&r1=956581&r2=956582&view=diff
==============================================================================
--- subversion/branches/py-tests-as-modules/build/run_tests.py (original)
+++ subversion/branches/py-tests-as-modules/build/run_tests.py Mon Jun 21 13:38:00 2010
@@ -42,9 +42,9 @@ separated list of test numbers; the defa
'''
# A few useful constants
-LINE_LENGTH = 40
+LINE_LENGTH = 45
-import os, sys, subprocess
+import os, sys, subprocess, imp
from datetime import datetime
import getopt
@@ -215,43 +215,14 @@ class TestHarness:
self.log.close()
self.log = None
- def _run_test(self, prog, test_nr, total_tests):
- "Run a single test. Return the test's exit code."
-
- if self.log:
- log = self.log
- else:
- log = sys.stdout
-
- test_nums = None
- if '#' in prog:
- prog, test_nums = prog.split('#')
-
+ def _run_c_test(self, prog, test_nums, dot_count):
+ 'Run a c test, escaping parameters as required.'
progdir, progbase = os.path.split(prog)
- if self.log:
- # Using write here because we don't want even a trailing space
- test_info = '%s [%d/%d]' % (progbase, test_nr + 1, total_tests)
- sys.stdout.write('Running tests in %s' % (test_info, ))
- sys.stdout.write('.'*(LINE_LENGTH - len(test_info)))
- sys.stdout.flush()
- log.write('START: %s\n' % progbase)
- log.flush()
+ sys.stdout.write('.' * dot_count)
+ sys.stdout.flush()
- start_time = datetime.now()
- if progbase[-3:] == '.py':
- progname = sys.executable
- cmdline = [progname,
- os.path.join(self.srcdir, prog)]
- if self.base_url is not None:
- cmdline.append('--url=' + self.base_url)
- if self.enable_sasl is not None:
- cmdline.append('--enable-sasl')
- if self.parallel is not None:
- cmdline.append('--parallel')
- if self.config_file is not None:
- cmdline.append('--config-file=' + self.config_file)
- elif os.access(prog, os.X_OK):
+ if os.access(progbase, os.X_OK):
progname = './' + progbase
cmdline = [progname,
'--srcdir=' + os.path.join(self.srcdir, progdir)]
@@ -284,10 +255,127 @@ class TestHarness:
test_nums = test_nums.split(',')
cmdline.extend(test_nums)
+ return self._run_prog(progname, cmdline)
+
+ def _run_py_test(self, prog, test_nums, dot_count):
+ 'Run a python test, passing parameters as needed.'
+ progdir, progbase = os.path.split(prog)
+
+ old_path = sys.path[:]
+ sys.path = [progdir] + sys.path
+
+ try:
+ prog_mod = imp.load_module(progbase[:-3], open(prog, 'r'), prog,
+ ('.py', 'U', imp.PY_SOURCE))
+ except:
+ print('Don\'t know what to do about ' + progbase)
+ raise
+
+ import svntest.main
+
+ # set up our options
+ svntest.main.create_default_options()
+ if self.base_url is not None:
+ svntest.main.options.test_area_url = self.base_url
+ if self.enable_sasl is not None:
+ svntest.main.options.enable_sasl = True
+ if self.parallel is not None:
+ svntest.main.options.parallel = True
+ if self.config_file is not None:
+ svntest.main.options.config_file = self.config_file
+ if self.verbose is not None:
+ svntest.main.options.verbose = True
+ if self.cleanup is not None:
+ svntest.main.options.cleanup = True
+ if self.fs_type is not None:
+ svntest.main.options.fs_type = self.fs_type
+ if self.http_library is not None:
+ svntest.main.options.http_library = self.http_library
+ if self.server_minor_version is not None:
+ svntest.main.options.server_minor_version = self.server_minor_version
+ if self.list_tests is not None:
+ svntest.main.options.list_tests = True
+ if self.svn_bin is not None:
+ svntest.main.options.svn_bin = self.svn_bin
+ if self.fsfs_sharding is not None:
+ svntest.main.options.fsfs_sharding = self.fsfs_sharding
+ if self.fsfs_packing is not None:
+ svntest.main.options.fsfs_packing = self.fsfs_packing
+
+ # setup the output pipes
+ if self.log:
+ sys.stdout.flush()
+ sys.stderr.flush()
+ self.log.flush()
+ old_stdout = os.dup(1)
+ old_stderr = os.dup(2)
+ os.dup2(self.log.fileno(), 1)
+ os.dup2(self.log.fileno(), 2)
+
+ # This has to be class-scoped for use in the progress_func()
+ self.dots_written = 0
+ def progress_func(completed, total):
+ dots = (completed * dot_count) / total
+
+ dots_to_write = dots - self.dots_written
+ if self.log:
+ os.write(old_stdout, '.' * dots_to_write)
+ else:
+ sys.stdout.write(old_stdout, '.' * dots_to_write)
+ sys.stdout.flush()
+
+ self.dots_written = dots
+
+ # run the tests
+ svntest.testcase.TextColors.disable()
+ failed = svntest.main.execute_tests(prog_mod.test_list,
+ test_name=progbase,
+ progress_func=progress_func)
+
+ # restore some values
+ sys.path = old_path
+ if self.log:
+ os.dup2(old_stdout, 1)
+ os.dup2(old_stderr, 2)
+ os.close(old_stdout)
+ os.close(old_stderr)
+
+ return failed
+
+ def _run_test(self, prog, test_nr, total_tests):
+ "Run a single test. Return the test's exit code."
+
+ if self.log:
+ log = self.log
+ else:
+ log = sys.stdout
+
+ test_nums = None
+ if '#' in prog:
+ prog, test_nums = prog.split('#')
+
+ progdir, progbase = os.path.split(prog)
+ if self.log:
+ # Using write here because we don't want even a trailing space
+ test_info = '%s [%d/%d]' % (progbase, test_nr + 1, total_tests)
+ sys.stdout.write('Running tests in %s' % (test_info, ))
+ sys.stdout.flush()
+
+ log.write('START: %s\n' % progbase)
+ log.flush()
+
+ start_time = datetime.now()
+
+ progabs = os.path.abspath(os.path.join(self.srcdir, prog))
old_cwd = os.getcwd()
try:
os.chdir(progdir)
- failed = self._run_prog(progname, cmdline)
+ if progbase[-3:] == '.py':
+ failed = self._run_py_test(progabs, test_nums,
+ (LINE_LENGTH - len(test_info)))
+ else:
+ failed = self._run_c_test(prog, test_nums,
+ (LINE_LENGTH - len(test_info)))
except:
os.chdir(old_cwd)
raise
Modified: subversion/branches/py-tests-as-modules/subversion/tests/cmdline/svntest/main.py
URL: http://svn.apache.org/viewvc/subversion/branches/py-tests-as-modules/subversion/tests/cmdline/svntest/main.py?rev=956582&r1=956581&r2=956582&view=diff
==============================================================================
--- subversion/branches/py-tests-as-modules/subversion/tests/cmdline/svntest/main.py (original)
+++ subversion/branches/py-tests-as-modules/subversion/tests/cmdline/svntest/main.py Mon Jun 21 13:38:00 2010
@@ -424,6 +424,7 @@ def wait_on_pipe(waiter, binary_mode, st
if exit_code and options.verbose:
sys.stderr.write("CMD: %s exited with %d\n"
% (command_string, exit_code))
+ sys.stderr.flush()
return stdout_lines, stderr_lines, exit_code
def spawn_process(command, bufsize=0, binary_mode=0, stdin_lines=None,
@@ -1226,7 +1227,7 @@ def run_one_test(n, test_list, finished_
exit_code = TestRunner(test_list[n], n).run()
return exit_code
-def _internal_run_tests(test_list, testnums, parallel):
+def _internal_run_tests(test_list, testnums, parallel, progress_func):
"""Run the tests from TEST_LIST whose indices are listed in TESTNUMS.
If we're running the tests in parallel spawn as much parallel processes
@@ -1239,9 +1240,12 @@ def _internal_run_tests(test_list, testn
tests_started = 0
if not parallel:
- for testnum in testnums:
+ for i, testnum in enumerate(testnums):
if run_one_test(testnum, test_list) == 1:
exit_code = 1
+ # signal progress
+ if progress_func:
+ progress_func(i+1, len(testnums))
else:
number_queue = queue.Queue()
for num in testnums:
@@ -1260,6 +1264,10 @@ def _internal_run_tests(test_list, testn
results += t.results
results.sort()
+ # signal some kind of progress
+ if progress_func:
+ progress_func(len(testnums), len(testnums))
+
# terminate the line of dots
print("")
@@ -1371,10 +1379,6 @@ def _parse_options(arglist=sys.argv[1:])
return (parser, args)
-# Main func. This is the "entry point" that all the test scripts call
-# to run their list of tests.
-#
-# This routine parses sys.argv to decide what to do.
def run_tests(test_list, serial_only = False):
"""Main routine to run all tests in TEST_LIST.
@@ -1382,6 +1386,19 @@ def run_tests(test_list, serial_only = F
appropriate exit code.
"""
+ sys.exit(execute_tests(test_list, serial_only))
+
+
+# Main func. This is the "entry point" that all the test scripts call
+# to run their list of tests.
+#
+# This routine parses sys.argv to decide what to do.
+def execute_tests(test_list, serial_only = False, test_name = None,
+ progress_func = None):
+ """Similar to run_tests(), but just returns the exit code, rather than
+ exiting the process. This function can be used when a caller doesn't
+ want the process to die."""
+
global pristine_url
global svn_binary
global svnadmin_binary
@@ -1391,6 +1408,9 @@ def run_tests(test_list, serial_only = F
global svnversion_binary
global options
+ if test_name:
+ sys.argv[0] = test_name
+
testnums = []
if not options:
@@ -1503,7 +1523,8 @@ def run_tests(test_list, serial_only = F
svntest.actions.setup_pristine_repository()
# Run the tests.
- exit_code = _internal_run_tests(test_list, testnums, options.parallel)
+ exit_code = _internal_run_tests(test_list, testnums, options.parallel,
+ progress_func)
# Remove all scratchwork: the 'pristine' repository, greek tree, etc.
# This ensures that an 'import' will happen the next time we run.
@@ -1514,4 +1535,4 @@ def run_tests(test_list, serial_only = F
svntest.sandbox.cleanup_deferred_test_paths()
# Return the appropriate exit code from the tests.
- sys.exit(exit_code)
+ return exit_code