test-webkitpy: add --timing
authordpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Mar 2012 19:29:53 +0000 (19:29 +0000)
committerdpranke@chromium.org <dpranke@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 29 Mar 2012 19:29:53 +0000 (19:29 +0000)
https://bugs.webkit.org/show_bug.cgi?id=82550

Reviewed by Eric Seidel.

This patch adds a --timing option that will display the time
each test takes. It also removes the --silent option, since
probably no one ever used it, and cleans up the logging
option parsing code to be easier to follow.

* Scripts/webkitpy/test/main.py:
(Tester._parse_args):
(Tester._configure):
* Scripts/webkitpy/test/runner.py:
(TestRunner.write_result):
* Scripts/webkitpy/test/runner_unittest.py:
(RunnerTest.test_regular):
(RunnerTest.test_verbose):
(RunnerTest):
(RunnerTest.test_timing):

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@112561 268f45cc-cd09-0410-ab3c-d52691b4dbfc

Tools/ChangeLog
Tools/Scripts/webkitpy/test/main.py
Tools/Scripts/webkitpy/test/runner.py
Tools/Scripts/webkitpy/test/runner_unittest.py

index 0dbe7c7..b0e69d5 100644 (file)
@@ -1,3 +1,26 @@
+2012-03-29  Dirk Pranke  <dpranke@chromium.org>
+
+        test-webkitpy: add --timing
+        https://bugs.webkit.org/show_bug.cgi?id=82550
+
+        Reviewed by Eric Seidel.
+
+        This patch adds a --timing option that will display the time
+        each test takes. It also removes the --silent option, since
+        probably no one ever used it, and cleans up the logging
+        option parsing code to be easier to follow.
+
+        * Scripts/webkitpy/test/main.py:
+        (Tester._parse_args):
+        (Tester._configure):
+        * Scripts/webkitpy/test/runner.py:
+        (TestRunner.write_result):
+        * Scripts/webkitpy/test/runner_unittest.py:
+        (RunnerTest.test_regular):
+        (RunnerTest.test_verbose):
+        (RunnerTest):
+        (RunnerTest.test_timing):
+
 2012-03-29  Caio Marcelo de Oliveira Filho  <caio.oliveira@openbossa.org>
 
         HashMap<>::add should return a more descriptive object
index 546269c..1035201 100644 (file)
@@ -1,3 +1,4 @@
+# Copyright (C) 2012 Google, Inc.
 # Copyright (C) 2010 Chris Jerdonek (cjerdonek@webkit.org)
 #
 # Redistribution and use in source and binary forms, with or without
@@ -38,7 +39,6 @@ _log = logging.getLogger(__name__)
 
 class Tester(object):
     def __init__(self, filesystem=None):
-        self._verbosity = 1
         self.finder = TestFinder(filesystem or FileSystem())
         self.stream = sys.stderr
 
@@ -53,8 +53,8 @@ class Tester(object):
                           help='generate code coverage info (requires http://pypi.python.org/pypi/coverage)'),
         parser.add_option('-q', '--quiet', action='store_true', default=False,
                           help='run quietly (errors, warnings, and progress only)'),
-        parser.add_option('-s', '--silent', action='store_true', default=False,
-                          help='run silently (errors and warnings only)'),
+        parser.add_option('-t', '--timing', action='store_true', default=False,
+                          help='display per-test execution time (implies --verbose)'),
         parser.add_option('-x', '--xml', action='store_true', default=False,
                           help='output xUnit-style XML output')
         parser.add_option('-v', '--verbose', action='count', default=0,
@@ -70,21 +70,16 @@ class Tester(object):
     def _configure(self, options):
         self._options = options
 
-        if options.silent:
-            self._verbosity = 0
-            self._configure_logging(logging.WARNING)
-        elif options.quiet:
-            self._verbosity = 1
-            self._configure_logging(logging.WARNING)
-        elif options.verbose == 0:
-            self._verbosity = 1
-            self._configure_logging(logging.INFO)
-        elif options.verbose == 1:
-            self._verbosity = 2
-            self._configure_logging(logging.INFO)
+        if options.timing:
+            # --timing implies --verbose
+            options.verbose = max(options.verbose, 1)
+
+        log_level = logging.INFO
+        if options.quiet:
+            log_level = logging.WARNING
         elif options.verbose == 2:
-            self._verbosity = 2
-            self._configure_logging(logging.DEBUG)
+            log_level = logging.DEBUG
+        self._configure_logging(log_level)
 
     def _configure_logging(self, log_level):
         """Configure the root logger.
index b2b0dfc..e190f2c 100644 (file)
@@ -82,6 +82,9 @@ class TestRunner(object):
         return result
 
     def write_result(self, result, test_name, test_time, failure=None, err=None):
+        timing = ''
+        if self.options.timing:
+            timing = ' %.4fs' % test_time
         if self.options.verbose:
             if failure:
                 msg = ' failed'
@@ -89,7 +92,7 @@ class TestRunner(object):
                 msg = ' erred'
             else:
                 msg = ' passed'
-            self.stream.write(msg + '\n')
+            self.stream.write(msg + timing + '\n')
         else:
             if failure:
                 msg = 'F'
index 70c0b37..e2ea31a 100644 (file)
@@ -69,7 +69,7 @@ class FakeLoader(object):
 
 class RunnerTest(unittest.TestCase):
     def test_regular(self):
-        options = MockOptions(verbose=False)
+        options = MockOptions(verbose=0, timing=False)
         stream = StringIO.StringIO()
         loader = FakeLoader(('test1 (Foo)', '.', ''),
                             ('test2 (Foo)', 'F', 'test2\nfailed'),
@@ -82,7 +82,20 @@ class RunnerTest(unittest.TestCase):
         # FIXME: check the output from the test
 
     def test_verbose(self):
-        options = MockOptions(verbose=True)
+        options = MockOptions(verbose=1, timing=False)
+        stream = StringIO.StringIO()
+        loader = FakeLoader(('test1 (Foo)', '.', ''),
+                            ('test2 (Foo)', 'F', 'test2\nfailed'),
+                            ('test3 (Foo)', 'E', 'test3\nerred'))
+        result = TestRunner(stream, options, loader).run(loader.top_suite())
+        self.assertFalse(result.wasSuccessful())
+        self.assertEquals(result.testsRun, 3)
+        self.assertEquals(len(result.failures), 1)
+        self.assertEquals(len(result.errors), 1)
+        # FIXME: check the output from the test
+
+    def test_timing(self):
+        options = MockOptions(verbose=0, timing=True)
         stream = StringIO.StringIO()
         loader = FakeLoader(('test1 (Foo)', '.', ''),
                             ('test2 (Foo)', 'F', 'test2\nfailed'),