Title: [87967] trunk/Tools
Revision
87967
Author
[email protected]
Date
2011-06-02 17:21:04 -0700 (Thu, 02 Jun 2011)

Log Message

2011-06-02  Dirk Pranke  <[email protected]>

        Reviewed by Tony Chang.

        NRWT needs a way to log to a file without including backspaces without needing --verbose
        https://bugs.webkit.org/show_bug.cgi?id=60328

        This change modifies NRWT so that if it can tell if it is
        writing to a terminal, it will overwrite any messages printed
        in the 'one-line-progress' and 'updates' print options, and if
        not (or if --verbose was specified) the messages will be printed
        without backspaces.

        If the overwriting updates are disabled, one-line-progress will
        only print every 10 seconds instead of on every update. This
        ensures that we still get updates once in a while while the
        tests are running, even if we're not in --verbose mode. Note
        that one-line-progress will now still be printed in --verbose,
        since it's useful as long as you're not flooded with the
        updates.

        * Scripts/webkitpy/layout_tests/layout_package/manager.py:
        * Scripts/webkitpy/layout_tests/layout_package/printing.py:
        * Scripts/webkitpy/layout_tests/layout_package/printing_unittest.py:

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (87966 => 87967)


--- trunk/Tools/ChangeLog	2011-06-03 00:16:38 UTC (rev 87966)
+++ trunk/Tools/ChangeLog	2011-06-03 00:21:04 UTC (rev 87967)
@@ -1,3 +1,28 @@
+2011-06-02  Dirk Pranke  <[email protected]>
+
+        Reviewed by Tony Chang.
+
+        NRWT needs a way to log to a file without including backspaces without needing --verbose
+        https://bugs.webkit.org/show_bug.cgi?id=60328
+
+        This change modifies NRWT so that if it can tell if it is
+        writing to a terminal, it will overwrite any messages printed
+        in the 'one-line-progress' and 'updates' print options, and if
+        not (or if --verbose was specified) the messages will be printed
+        without backspaces.
+
+        If the overwriting updates are disabled, one-line-progress will
+        only print every 10 seconds instead of on every update. This
+        ensures that we still get updates once in a while while the
+        tests are running, even if we're not in --verbose mode. Note
+        that one-line-progress will now still be printed in --verbose,
+        since it's useful as long as you're not flooded with the
+        updates.
+
+        * Scripts/webkitpy/layout_tests/layout_package/manager.py:
+        * Scripts/webkitpy/layout_tests/layout_package/printing.py:
+        * Scripts/webkitpy/layout_tests/layout_package/printing_unittest.py:
+
 2011-06-02  Martin Robinson  <[email protected]>
 
         Reviewed by Gustavo Noronha Silva.

Modified: trunk/Tools/Scripts/webkitpy/common/array_stream.py (87966 => 87967)


--- trunk/Tools/Scripts/webkitpy/common/array_stream.py	2011-06-03 00:16:38 UTC (rev 87966)
+++ trunk/Tools/Scripts/webkitpy/common/array_stream.py	2011-06-03 00:21:04 UTC (rev 87967)
@@ -39,8 +39,9 @@
     concatenates all of the writes together.
     """
 
-    def __init__(self):
+    def __init__(self, tty=False):
         self._contents = []
+        self._tty = tty
 
     def write(self, msg):
         """Implement stream.write() by appending to the stream's contents."""
@@ -64,3 +65,6 @@
 
     def __repr__(self):
         return '<ArrayStream: ' + str(self._contents) + '>'
+
+    def isatty(self):
+        return self._tty

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/manager.py (87966 => 87967)


--- trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/manager.py	2011-06-03 00:16:38 UTC (rev 87966)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/manager.py	2011-06-03 00:21:04 UTC (rev 87967)
@@ -855,6 +855,7 @@
             try:
                 result = test_results.TestResult.loads(self._result_queue.get_nowait())
             except Queue.Empty:
+                self._printer.print_progress(result_summary, self._retrying, self._test_files_list)
                 return
 
             self._update_summary_with_result(result_summary, result)

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/printing.py (87966 => 87967)


--- trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/printing.py	2011-06-03 00:16:38 UTC (rev 87966)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/printing.py	2011-06-03 00:21:04 UTC (rev 87967)
@@ -31,6 +31,7 @@
 
 import logging
 import optparse
+import time
 
 from webkitpy.common.net import resultsjsonparser
 from webkitpy.layout_tests.layout_package import metered_stream
@@ -42,6 +43,8 @@
 TestExpectations = test_expectations.TestExpectations
 
 NUM_SLOW_TESTS_TO_LOG = 10
+FAST_UPDATES_SECONDS = 0.03
+SLOW_UPDATES_SECONDS = 10.0
 
 PRINT_DEFAULT = ("misc,one-line-progress,one-line-summary,unexpected,"
                  "unexpected-results,updates")
@@ -68,7 +71,7 @@
                         (# passes, # failures, etc.)
 
 During the run:
-    one-line-progress   print a one-line progress bar
+    one-line-progress   print a one-line progress message or bar
     unexpected          print any unexpected results as they occur
     updates             print updates on which stage is executing
     trace-everything    print detailed info on every test's results
@@ -116,7 +119,7 @@
             help="show detailed help on controlling print output"),
         optparse.make_option("-v", "--verbose", action=""
             default=False, help="include debug-level logging"),
-    ]
+   ]
 
 
 def parse_print_options(print_options, verbose):
@@ -130,7 +133,6 @@
         switches = set(print_options.split(','))
     elif verbose:
         switches = set(PRINT_EVERYTHING.split(','))
-        switches.discard('one-line-progress')
     else:
         switches = set(PRINT_DEFAULT.split(','))
 
@@ -206,18 +208,23 @@
         self._buildbot_stream = buildbot_output
         self._options = options
         self._port = port
+        self._meter = None
         self._stream = regular_output
 
-        self._meter = None
-        if options.verbose:
-            self._logging_handler = _configure_logging(regular_output, options.verbose)
+        # These are used for --print one-line-progress
+        self._last_remaining = None
+        self._last_update_time = None
+
+        self.switches = parse_print_options(options.print_options, options.verbose)
+
+        if self._stream.isatty() and not options.verbose:
+            self._update_interval_seconds = FAST_UPDATES_SECONDS
+            self._meter = metered_stream.MeteredStream(self._stream)
+            self._logging_handler = _configure_logging(self._meter, options.verbose)
         else:
-            self._meter = metered_stream.MeteredStream(regular_output)
-            self._logging_handler = _configure_logging(self._meter, options.verbose)
+            self._logging_handler = _configure_logging(self._stream, options.verbose)
+            self._update_interval_seconds = SLOW_UPDATES_SECONDS
 
-        self.switches = parse_print_options(options.print_options,
-            options.verbose)
-
     def cleanup(self):
         """Restore logging configuration to its initial settings."""
         if self._logging_handler:
@@ -341,14 +348,24 @@
         if self.disabled('one-line-progress'):
             return
 
+        now = time.time()
+        if self._last_update_time is None:
+            self._last_update_time = now
+
+        time_since_last_update = now - self._last_update_time
+        if time_since_last_update <= self._update_interval_seconds:
+            return
+
+        self._last_update_time = now
+
         percent_complete = 100 * (result_summary.expected +
             result_summary.unexpected) / result_summary.total
         action = ""
         if retrying:
             action = ""
-        self._update("%s (%d%%): %d ran as expected, %d didn't,"
-            " %d left" % (action, percent_complete, result_summary.expected,
-             result_summary.unexpected, result_summary.remaining))
+        self._update("%s (%d%%): %d ran as expected, %d didn't, %d left" %
+                     (action, percent_complete, result_summary.expected,
+                      result_summary.unexpected, result_summary.remaining))
 
         if result_summary.remaining == 0:
             self._update('')

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/printing_unittest.py (87966 => 87967)


--- trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/printing_unittest.py	2011-06-03 00:16:38 UTC (rev 87966)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/layout_package/printing_unittest.py	2011-06-03 00:21:04 UTC (rev 87967)
@@ -29,9 +29,10 @@
 
 """Unit tests for printing.py."""
 
+import logging
 import optparse
+import time
 import unittest
-import logging
 
 from webkitpy.common import array_stream
 from webkitpy.common.system import logtesting
@@ -91,7 +92,7 @@
         test_switches([], printing.PRINT_DEFAULT)
 
         # test that verbose defaults to everything
-        test_switches([], printing.PRINT_EVERYTHING.replace(',one-line-progress',''), verbose=True)
+        test_switches([], printing.PRINT_EVERYTHING, verbose=True)
 
         # test that --print default does what it's supposed to
         test_switches(['--print', 'default'], printing.PRINT_DEFAULT)
@@ -108,7 +109,7 @@
 
 
 class  Testprinter(unittest.TestCase):
-    def get_printer(self, args=None):
+    def get_printer(self, args=None, tty=False):
         args = args or []
         printing_options = printing.print_options()
         option_parser = optparse.OptionParser(option_list=printing_options)
@@ -116,7 +117,7 @@
         self._port = port.get('test', options)
         nproc = 2
 
-        regular_output = array_stream.ArrayStream()
+        regular_output = array_stream.ArrayStream(tty=tty)
         buildbot_output = array_stream.ArrayStream()
         printer = printing.Printer(self._port, options, regular_output,
                                    buildbot_output, configure_logging=True)
@@ -157,7 +158,7 @@
     def do_switch_tests(self, method_name, switch, to_buildbot,
                         message='hello', exp_err=None, exp_bot=None):
         def do_helper(method_name, switch, message, exp_err, exp_bot):
-            printer, err, bot = self.get_printer(['--print', switch])
+            printer, err, bot = self.get_printer(['--print', switch], tty=True)
             getattr(printer, method_name)(message)
             self.assertEqual(err.get(), exp_err)
             self.assertEqual(bot.get(), exp_bot)
@@ -325,12 +326,12 @@
     def test_print_progress(self):
         expectations = ''
 
-        # test that we print nothing
         printer, err, out = self.get_printer(['--print', 'nothing'])
         tests = ['passes/text.html', 'failures/expected/timeout.html',
                  'failures/expected/crash.html']
         paths, rs, exp = self.get_result_summary(tests, expectations)
 
+        # First, test that we print nothing.
         printer.print_progress(rs, False, paths)
         self.assertTrue(out.empty())
         self.assertTrue(err.empty())
@@ -339,19 +340,56 @@
         self.assertTrue(out.empty())
         self.assertTrue(err.empty())
 
-        # test regular functionality
-        printer, err, out = self.get_printer(['--print',
-                                              'one-line-progress'])
-        printer.print_progress(rs, False, paths)
-        self.assertTrue(out.empty())
-        self.assertFalse(err.empty())
+        self.times = [1, 2, 12, 13, 14, 23, 33]
 
-        err.reset()
-        out.reset()
-        printer.print_progress(rs, True, paths)
-        self.assertFalse(err.empty())
-        self.assertTrue(out.empty())
+        def mock_time():
+            return self.times.pop(0)
 
+        orig_time = time.time
+        try:
+            time.time = mock_time
+
+            # Test printing progress updates to a file.
+            printer, err, out = self.get_printer(['--print', 'one-line-progress'])
+            printer.print_progress(rs, False, paths)
+            printer.print_progress(rs, False, paths)
+            self.assertTrue(out.empty())
+            self.assertTrue(err.empty())
+
+            printer.print_progress(rs, False, paths)
+            self.assertTrue(out.empty())
+            self.assertFalse(err.empty())
+
+            err.reset()
+            out.reset()
+            printer.print_progress(rs, True, paths)
+            self.assertTrue(out.empty())
+            self.assertTrue(err.empty())
+
+            printer.print_progress(rs, True, paths)
+            self.assertTrue(out.empty())
+            self.assertFalse(err.empty())
+
+            # Now reconfigure the printer to test printing to a TTY instead of a file.
+            self.times = [1, 1.01, 2, 3]
+            printer, err, out = self.get_printer(['--print', 'one-line-progress'], tty=True)
+            printer.print_progress(rs, False, paths)
+            printer.print_progress(rs, False, paths)
+            self.assertTrue(out.empty())
+            self.assertTrue(err.empty())
+
+            printer.print_progress(rs, False, paths)
+            self.assertTrue(out.empty())
+            self.assertFalse(err.empty())
+
+            err.reset()
+            out.reset()
+            printer.print_progress(rs, True, paths)
+            self.assertTrue(out.empty())
+            self.assertFalse(err.empty())
+        finally:
+            time.time = orig_time
+
     def test_write_nothing(self):
         printer, err, out = self.get_printer(['--print', 'nothing'])
         printer.write("foo")
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to