Title: [120794] trunk/Tools
Revision
120794
Author
[email protected]
Date
2012-06-19 21:01:29 -0700 (Tue, 19 Jun 2012)

Log Message

test-webkitpy: add a -p flag to pass through captured output to enable debugging
https://bugs.webkit.org/show_bug.cgi?id=89158

Reviewed by Eric Seidel.

Normally when outputcapture runs it intercepts stdout/stderr,
which makes running under the debugger difficult and mostly
pointless (since you can't see any output). This change adds a
flag to test-webkitpy (-p) that will cause outputcapture to pass
through the output as well as capture it.

* Scripts/webkitpy/common/system/outputcapture.py:
(OutputCapture.stream_wrapper):
(OutputCapture._capture_output_with_name):
* Scripts/webkitpy/common/system/outputcapture_unittest.py:
(OutputCaptureTest.setUp):
* Scripts/webkitpy/test/main.py:
(Tester._parse_args):
(Tester._run_tests):
(Tester._log_exception):
(_CaptureAndPassThroughStream):
(_CaptureAndPassThroughStream.__init__):
(_CaptureAndPassThroughStream.write):
(_CaptureAndPassThroughStream._message_is_from_pdb):
(_CaptureAndPassThroughStream.flush):
(_CaptureAndPassThroughStream.getvalue):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (120793 => 120794)


--- trunk/Tools/ChangeLog	2012-06-20 03:43:21 UTC (rev 120793)
+++ trunk/Tools/ChangeLog	2012-06-20 04:01:29 UTC (rev 120794)
@@ -1,3 +1,32 @@
+2012-06-19  Dirk Pranke  <[email protected]>
+
+        test-webkitpy: add a -p flag to pass through captured output to enable debugging
+        https://bugs.webkit.org/show_bug.cgi?id=89158
+
+        Reviewed by Eric Seidel.
+
+        Normally when outputcapture runs it intercepts stdout/stderr,
+        which makes running under the debugger difficult and mostly
+        pointless (since you can't see any output). This change adds a
+        flag to test-webkitpy (-p) that will cause outputcapture to pass
+        through the output as well as capture it.
+
+        * Scripts/webkitpy/common/system/outputcapture.py:
+        (OutputCapture.stream_wrapper):
+        (OutputCapture._capture_output_with_name):
+        * Scripts/webkitpy/common/system/outputcapture_unittest.py:
+        (OutputCaptureTest.setUp):
+        * Scripts/webkitpy/test/main.py:
+        (Tester._parse_args):
+        (Tester._run_tests):
+        (Tester._log_exception):
+        (_CaptureAndPassThroughStream):
+        (_CaptureAndPassThroughStream.__init__):
+        (_CaptureAndPassThroughStream.write):
+        (_CaptureAndPassThroughStream._message_is_from_pdb):
+        (_CaptureAndPassThroughStream.flush):
+        (_CaptureAndPassThroughStream.getvalue):
+
 2012-06-19  Adam Barth  <[email protected]>
 
         garden-o-matic fails to rebaseline tests with MISSING results

Modified: trunk/Tools/Scripts/webkitpy/common/system/outputcapture.py (120793 => 120794)


--- trunk/Tools/Scripts/webkitpy/common/system/outputcapture.py	2012-06-20 03:43:21 UTC (rev 120793)
+++ trunk/Tools/Scripts/webkitpy/common/system/outputcapture.py	2012-06-20 04:01:29 UTC (rev 120794)
@@ -3,7 +3,7 @@
 # Redistribution and use in source and binary forms, with or without
 # modification, are permitted provided that the following conditions are
 # met:
-# 
+#
 #     * Redistributions of source code must retain the above copyright
 # notice, this list of conditions and the following disclaimer.
 #     * Redistributions in binary form must reproduce the above
@@ -13,7 +13,7 @@
 #     * Neither the name of Google Inc. nor the names of its
 # contributors may be used to endorse or promote products derived from
 # this software without specific prior written permission.
-# 
+#
 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
@@ -35,6 +35,13 @@
 
 
 class OutputCapture(object):
+    # By default we capture the output to a stream. Other modules may override
+    # this function in order to do things like pass through the output. See
+    # webkitpy.test.main for an example.
+    @staticmethod
+    def stream_wrapper(stream):
+        return StringIO()
+
     def __init__(self):
         self.saved_outputs = dict()
         self._log_level = logging.INFO
@@ -45,8 +52,9 @@
             self._logs_handler.setLevel(self._log_level)
 
     def _capture_output_with_name(self, output_name):
-        self.saved_outputs[output_name] = getattr(sys, output_name)
-        captured_output = StringIO()
+        stream = getattr(sys, output_name)
+        captured_output = self.stream_wrapper(stream)
+        self.saved_outputs[output_name] = stream
         setattr(sys, output_name, captured_output)
         return captured_output
 

Modified: trunk/Tools/Scripts/webkitpy/test/main.py (120793 => 120794)


--- trunk/Tools/Scripts/webkitpy/test/main.py	2012-06-20 03:43:21 UTC (rev 120793)
+++ trunk/Tools/Scripts/webkitpy/test/main.py	2012-06-20 04:01:29 UTC (rev 120794)
@@ -25,12 +25,14 @@
 
 import logging
 import optparse
+import os
 import StringIO
 import sys
 import traceback
 import unittest
 
 from webkitpy.common.system.filesystem import FileSystem
+from webkitpy.common.system import outputcapture
 from webkitpy.test.test_finder import TestFinder
 from webkitpy.test.runner import TestRunner
 
@@ -59,6 +61,8 @@
                           help='verbose output (specify once for individual test results, twice for debug messages)')
         parser.add_option('--skip-integrationtests', action='', default=False,
                           help='do not run the integration tests')
+        parser.add_option('-p', '--pass-through', action='', default=False,
+                          help='be debugger friendly by passing captured output through to the system')
 
         parser.epilog = ('[args...] is an optional list of modules, test_classes, or individual tests. '
                          'If no args are given, all the tests will be run.')
@@ -176,6 +180,8 @@
         test_runner = TestRunner(self.stream, self._options, loader)
 
         _log.debug("Running the tests.")
+        if self._options.pass_through:
+            outputcapture.OutputCapture.stream_wrapper = _CaptureAndPassThroughStream
         result = test_runner.run(test_suite)
         if self._options.coverage:
             cov.stop()
@@ -188,3 +194,32 @@
         traceback.print_exc(file=s)
         for l in s.buflist:
             _log.error('  ' + l.rstrip())
+
+
+class _CaptureAndPassThroughStream(object):
+    def __init__(self, stream):
+        self._buffer = StringIO.StringIO()
+        self._stream = stream
+
+    def write(self, msg):
+        self._stream.write(msg)
+
+        # Note that we don't want to capture any output generated by the debugger
+        # because that could cause the results of capture_output() to be invalid.
+        if not self._message_is_from_pdb():
+            self._buffer.write(msg)
+
+    def _message_is_from_pdb(self):
+        # We will assume that if the pdb module is in the stack then the output
+        # is being generated by the python debugger (or the user calling something
+        # from inside the debugger).
+        import inspect
+        import pdb
+        stack = inspect.stack()
+        return any(frame[1] == pdb.__file__.replace('.pyc', '.py') for frame in stack)
+
+    def flush(self):
+        self._stream.flush()
+
+    def getvalue(self):
+        return self._buffer.getvalue()
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to