Title: [174743] trunk/Tools
Revision
174743
Author
[email protected]
Date
2014-10-15 13:56:11 -0700 (Wed, 15 Oct 2014)

Log Message

Add --json flag to test-webkitpy to emit JSON formatted test results
to stdout
https://bugs.webkit.org/show_bug.cgi?id=137353

Patch by Jake Nielsen <[email protected]> on 2014-10-15
Reviewed by Daniel Bates.

* Scripts/webkitpy/port/server_process_unittest.py:
Adds the read method to MockFile to allow the stdout of test_webkitpy
to be redirected without causing erroneous test failures.
In particular,
webkitpy.port.server_process_unittest.TestServerProcess.test_broken_pipe
and
webkitpy.port.server_process_unittest.TestServerProcess.test_cleanup
because when redirecting to a file, the
_wait_for_data_and_update_buffers_using_select method in
server_process.py will find that there is a read file descriptor in
its call to select.select, which eventually leads to it calling read()
on the MockFile object.
(MockFile.read):
* Scripts/webkitpy/test/main.py:
Adds the _print_results_as_json method and the --json flag which
determines whether _print_results_as_json will get called.
(Tester._parse_args):
(Tester._print_results_as_json):
(Tester._print_results_as_json.result_dict_from_tuple):
(Tester._run_tests):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (174742 => 174743)


--- trunk/Tools/ChangeLog	2014-10-15 19:39:05 UTC (rev 174742)
+++ trunk/Tools/ChangeLog	2014-10-15 20:56:11 UTC (rev 174743)
@@ -1,3 +1,32 @@
+2014-10-15  Jake Nielsen  <[email protected]>
+
+        Add --json flag to test-webkitpy to emit JSON formatted test results
+        to stdout
+        https://bugs.webkit.org/show_bug.cgi?id=137353
+
+        Reviewed by Daniel Bates.
+
+        * Scripts/webkitpy/port/server_process_unittest.py:
+        Adds the read method to MockFile to allow the stdout of test_webkitpy
+        to be redirected without causing erroneous test failures.
+        In particular,
+        webkitpy.port.server_process_unittest.TestServerProcess.test_broken_pipe
+        and
+        webkitpy.port.server_process_unittest.TestServerProcess.test_cleanup
+        because when redirecting to a file, the
+        _wait_for_data_and_update_buffers_using_select method in 
+        server_process.py will find that there is a read file descriptor in
+        its call to select.select, which eventually leads to it calling read()
+        on the MockFile object.
+        (MockFile.read):
+        * Scripts/webkitpy/test/main.py:
+        Adds the _print_results_as_json method and the --json flag which
+        determines whether _print_results_as_json will get called.
+        (Tester._parse_args):
+        (Tester._print_results_as_json):
+        (Tester._print_results_as_json.result_dict_from_tuple):
+        (Tester._run_tests):
+
 2014-10-13  David Farler  <[email protected]>
 
         [iOS] LayoutTestRelay: Detect broken pipe when reading simulator app's stdout and stderr.

Modified: trunk/Tools/Scripts/webkitpy/port/server_process_unittest.py (174742 => 174743)


--- trunk/Tools/Scripts/webkitpy/port/server_process_unittest.py	2014-10-15 19:39:05 UTC (rev 174742)
+++ trunk/Tools/Scripts/webkitpy/port/server_process_unittest.py	2014-10-15 20:56:11 UTC (rev 174743)
@@ -66,6 +66,10 @@
         self._server_process.broken_pipes.append(self)
         raise IOError
 
+    def read(self, size=0):
+        # This means end of file
+        return ''
+
     def close(self):
         self.closed = True
 

Modified: trunk/Tools/Scripts/webkitpy/test/main.py (174742 => 174743)


--- trunk/Tools/Scripts/webkitpy/test/main.py	2014-10-15 19:39:05 UTC (rev 174742)
+++ trunk/Tools/Scripts/webkitpy/test/main.py	2014-10-15 20:56:11 UTC (rev 174743)
@@ -24,8 +24,11 @@
 """unit testing code for webkitpy."""
 
 import StringIO
+import itertools
+import json
 import logging
 import multiprocessing
+import operator
 import optparse
 import os
 import sys
@@ -72,6 +75,17 @@
     return not tester.run()
 
 
+def _print_results_as_json(stream, all_test_names, failures, errors):
+    def result_dict_from_tuple(result_tuple):
+        return {'name': result_tuple[0], 'result': result_tuple[1]}
+
+    results = {}
+    results['failures'] = map(result_dict_from_tuple, sorted(failures, key=operator.itemgetter(0)))
+    results['errors'] = map(result_dict_from_tuple, sorted(errors, key=operator.itemgetter(0)))
+    results['passes'] = sorted(set(all_test_names) - set(map(operator.itemgetter(0), failures)) - set(map(operator.itemgetter(0), errors)))
+
+    json.dump(results, stream, separators=(',', ':'))
+
 class Tester(object):
     def __init__(self, filesystem=None):
         self.finder = Finder(filesystem or FileSystem())
@@ -102,6 +116,8 @@
                           help='display per-test execution time (implies --verbose)')
         parser.add_option('-v', '--verbose', action='', default=0,
                           help='verbose output (specify once for individual test results, twice for debug messages)')
+        parser.add_option('--json', action='', default=False,
+                          help='write JSON formatted test results to stdout')
 
         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.')
@@ -156,6 +172,9 @@
 
         self.printer.print_result(time.time() - start)
 
+        if self._options.json:
+            _print_results_as_json(sys.stdout, itertools.chain(parallel_tests, serial_tests), test_runner.failures, test_runner.errors)
+
         if self._options.coverage:
             cov.stop()
             cov.save()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to