commit 13c3975bc3585847dd204d074a66394786bf2007 Author: Damian Johnson atagar@torproject.org Date: Wed Jan 11 10:20:30 2012 -0800
Testing argument to run with a tor binary
Adding a '--tor PATH' argument so the caller can select the tor binary they want to run against. --- run_tests.py | 12 ++++++++++-- stem/process.py | 8 ++++++-- test/runner.py | 12 +++++++----- 3 files changed, 23 insertions(+), 9 deletions(-)
diff --git a/run_tests.py b/run_tests.py index 1b252df..f458a80 100755 --- a/run_tests.py +++ b/run_tests.py @@ -33,7 +33,7 @@ import stem.util.log as log import stem.util.term as term
OPT = "uic:t:l:h" -OPT_EXPANDED = ["unit", "integ", "config=", "targets=", "log=", "help"] +OPT_EXPANDED = ["unit", "integ", "config=", "targets=", "log=", "tor=", "help"] DIVIDER = "=" * 70
# Tests are ordered by the dependencies so the lowest level tests come first. @@ -86,6 +86,7 @@ Runs tests for the stem library. -t, --target TARGET comma separated list of extra targets for integ tests -l, --log RUNLEVEL includes logging output with test results, runlevels: TRACE, DEBUG, INFO, NOTICE, WARN, ERROR + --tor PATH custom tor binary to run testing against -h, --help presents this help
Integration targets: @@ -123,6 +124,7 @@ if __name__ == '__main__': config_path = None test_config = stem.util.conf.get_config("test") logging_runlevel = None + tor_cmd = "tor"
# parses user input, noting any issues try: @@ -158,6 +160,12 @@ if __name__ == '__main__': print "'%s' isn't a logging runlevel, use one of the following instead:" % arg print " TRACE, DEBUG, INFO, NOTICE, WARN, ERROR" sys.exit(1) + elif opt in ("--tor"): + if not os.path.exists(arg): + print "Unable to start tor, '%s' does not exists." % arg + sys.exit(1) + + tor_cmd = arg elif opt in ("-h", "--help"): # Prints usage information and quits. This includes a listing of the # valid integration targets. @@ -260,7 +268,7 @@ if __name__ == '__main__':
for connection_type in connection_types: try: - integ_runner.start(connection_type = connection_type) + integ_runner.start(tor_cmd, connection_type = connection_type)
print term.format("Running tests...", term.Color.BLUE, term.Attr.BOLD) print diff --git a/stem/process.py b/stem/process.py index 0bb9740..2b00117 100644 --- a/stem/process.py +++ b/stem/process.py @@ -13,7 +13,7 @@ import subprocess # number of seconds before we time out our attempt to start a tor instance DEFAULT_INIT_TIMEOUT = 90
-def launch_tor(torrc_path, completion_percent = 100, init_msg_handler = None, timeout = DEFAULT_INIT_TIMEOUT): +def launch_tor(tor_cmd = "tor", torrc_path = None, completion_percent = 100, init_msg_handler = None, timeout = DEFAULT_INIT_TIMEOUT): """ Initializes a tor process. This blocks until initialization completes or we error out. @@ -24,6 +24,7 @@ def launch_tor(torrc_path, completion_percent = 100, init_msg_handler = None, ti to get stuck, taking well over the default timeout.
Arguments: + tor_cmd (str) - command for starting tor torrc_path (str) - location of the torrc for us to use completion_percent (int) - percent of bootstrap completion at which this'll return @@ -45,7 +46,10 @@ def launch_tor(torrc_path, completion_percent = 100, init_msg_handler = None, ti raise OSError("torrc doesn't exist (%s)" % torrc_path)
# starts a tor subprocess, raising an OSError if it fails - tor_process = subprocess.Popen(["tor", "-f", torrc_path], stdout = subprocess.PIPE, stderr = subprocess.PIPE) + runtime_args = [tor_cmd] + if torrc_path: runtime_args += ["-f", torrc_path] + + tor_process = subprocess.Popen(runtime_args, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
if timeout: def timeout_handler(signum, frame): diff --git a/test/runner.py b/test/runner.py index 10c4699..cfe6dbb 100644 --- a/test/runner.py +++ b/test/runner.py @@ -139,12 +139,13 @@ class Runner: self._connection_type = None self._tor_process = None
- def start(self, connection_type = DEFAULT_TOR_CONNECTION, quiet = False): + def start(self, tor_cmd, connection_type = DEFAULT_TOR_CONNECTION, quiet = False): """ Makes temporary testing resources and starts tor, blocking until it completes.
Arguments: + tor_cmd (str) - command to start tor with connection_type (TorConnection) - method for controllers to authenticate to tor quiet (bool) - if False then this prints status information as we start @@ -190,7 +191,7 @@ class Runner: try: self._tor_cwd = os.getcwd() self._run_setup(quiet) - self._start_tor(quiet) + self._start_tor(tor_cmd, quiet)
# revert our cwd back to normal if self._config["test.integ.target.relative_data_dir"]: @@ -478,13 +479,14 @@ class Runner: _print_status("failed (%s)\n\n" % exc, ERROR_ATTR, quiet) raise OSError(exc)
- def _start_tor(self, quiet): + def _start_tor(self, tor_cmd, quiet): """ Initializes a tor process. This blocks until initialization completes or we error out.
Arguments: - quiet (bool) - prints status information to stdout if False + tor_cmd (str) - command to start tor with + quiet (bool) - prints status information to stdout if False
Raises: OSError if we either fail to create the tor process or reached a timeout @@ -503,7 +505,7 @@ class Runner: print_init_line = lambda line: _print_status(" %s\n" % line, SUBSTATUS_ATTR, quiet)
torrc_dst = os.path.join(self._test_dir, "torrc") - self._tor_process = stem.process.launch_tor(torrc_dst, complete_percent, print_init_line) + self._tor_process = stem.process.launch_tor(tor_cmd, torrc_dst, complete_percent, print_init_line)
runtime = time.time() - start_time _print_status(" done (%i seconds)\n\n" % runtime, STATUS_ATTR, quiet)
tor-commits@lists.torproject.org