[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [stem/master] Drop test runner's is_ptraceable() method



commit 1b7cb4ff2ba853ee5021d8d5eb137f5922a06431
Author: Damian Johnson <atagar@xxxxxxxxxxxxxx>
Date:   Fri May 12 17:34:02 2017 -0700

    Drop test runner's is_ptraceable() method
    
    This method is effectively only used in one spot, and the caller can do this.
---
 test/integ/util/connection.py |  5 ++---
 test/runner.py                | 18 +-----------------
 test/util.py                  | 22 ++++++++++++++++++++--
 3 files changed, 23 insertions(+), 22 deletions(-)

diff --git a/test/integ/util/connection.py b/test/integ/util/connection.py
index 63f62ff..f641a37 100644
--- a/test/integ/util/connection.py
+++ b/test/integ/util/connection.py
@@ -8,18 +8,17 @@ import unittest
 import test.runner
 
 from stem.util.connection import Resolver, get_connections, system_resolvers
+from test.util import require_ptrace
 
 
 class TestConnection(unittest.TestCase):
+  @require_ptrace
   def check_resolver(self, resolver):
     runner = test.runner.get_runner()
 
     if test.runner.Torrc.PORT not in runner.get_options():
       self.skipTest('(no control port)')
       return
-    elif not runner.is_ptraceable():
-      self.skipTest('(DisableDebuggerAttachment set)')
-      return
     elif resolver not in system_resolvers():
       self.skipTest('(resolver unavailable on this platform)')
       return
diff --git a/test/runner.py b/test/runner.py
index 4b4d29d..0f5a1d0 100644
--- a/test/runner.py
+++ b/test/runner.py
@@ -19,7 +19,6 @@ about the tor test instance they're running against.
     |- stop - stops our tor instance and cleans up any temporary files
     |- is_running - checks if our tor test instance is running
     |- is_accessible - checks if our tor instance can be connected to
-    |- is_ptraceable - checks if DisableDebuggerAttachment is set
     |- get_options - custom torrc options used for our test instance
     |- get_test_dir - testing directory path
     |- get_torrc_path - path to our tor instance's torrc
@@ -48,10 +47,9 @@ import stem.process
 import stem.socket
 import stem.util.conf
 import stem.util.enum
-import stem.version
 
 from test.output import println, STATUS, ERROR, SUBSTATUS, NO_NL
-from test.util import Target, STEM_BASE, tor_version
+from test.util import Target, STEM_BASE
 
 CONFIG = stem.util.conf.config_dict('test', {
   'integ.test_directory': './test/data',
@@ -312,20 +310,6 @@ class Runner(object):
 
     return Torrc.PORT in self._custom_opts or Torrc.SOCKET in self._custom_opts
 
-  def is_ptraceable(self):
-    """
-    Checks if tor's 'DisableDebuggerAttachment' option is set. This feature has
-    a lot of adverse side effects (:trac:`3313`).
-
-    :returns: True if debugger attachment is allowed, False otherwise
-    """
-
-    # If we're running a tor version where ptrace is disabled and we didn't
-    # set 'DisableDebuggerAttachment=1' then we can infer that it's disabled.
-
-    has_option = tor_version() >= stem.version.Requirement.TORRC_DISABLE_DEBUGGER_ATTACHMENT
-    return not has_option or Torrc.PTRACE in self.get_options()
-
   def get_options(self):
     """
     Provides the custom torrc options our tor instance is running with.
diff --git a/test/util.py b/test/util.py
index 7b6f312..99de3a6 100644
--- a/test/util.py
+++ b/test/util.py
@@ -303,6 +303,26 @@ def require_version(req_version):
   return require(lambda: tor_version() >= req_version, 'requires %s' % req_version)
 
 
+def require_ptrace(func):
+  """
+  Skips the test unless 'DisableDebuggerAttachment' is set. This feature has a
+  lot of adverse side effects (:trac:`3313`).
+  """
+
+  def wrapped(self, *args, **kwargs):
+    # If we're running a tor version where ptrace is disabled and we didn't
+    # set 'DisableDebuggerAttachment=1' then we can infer that it's disabled.
+
+    has_option = tor_version() >= stem.version.Requirement.TORRC_DISABLE_DEBUGGER_ATTACHMENT
+
+    if not has_option or test.runner.Torrc.PTRACE in test.runner.get_runner().get_options():
+      return func(self, *args, **kwargs)
+    else:
+      self.skipTest('(DisableDebuggerAttachment is set)')
+
+  return wrapped
+
+
 def require_online(func):
   """
   Skips the test if we weren't started with the ONLINE target, which indicates
@@ -636,5 +656,3 @@ class Task(object):
 
 
 import test.runner  # needs to be imported at the end to avoid a circular dependency
-
-require_ptrace = require(test.runner.get_runner().is_ptraceable, 'DisableDebuggerAttachment is set')



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits