WebDriver: add an option to dump test results to a json file
authorcarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2017 07:25:53 +0000 (07:25 +0000)
committercarlosgc@webkit.org <carlosgc@webkit.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Wed, 29 Nov 2017 07:25:53 +0000 (07:25 +0000)
https://bugs.webkit.org/show_bug.cgi?id=180082

Reviewed by Brian Burg.

Add --json-output command line option to run-webdriver-tests to dump test results to a json file in a format
compatible with the W3C report. WebDriverTestResult now represents a test file and contains a list of
subtests, instead of having one WebDriverTestResult per subtest. This way we can store also the harness result
and dump the results to different formats.

* Scripts/run-webdriver-tests:
* Scripts/webkitpy/webdriver_tests/webdriver_test_result.py:
(WebDriverTestResult.__init__):
(WebDriverTestResult):
(WebDriverTestResult.add_subtest_results):
* Scripts/webkitpy/webdriver_tests/webdriver_test_runner.py:
(WebDriverTestRunner.print_results):
(WebDriverTestRunner):
(WebDriverTestRunner.dump_results_to_json_file):
* Scripts/webkitpy/webdriver_tests/webdriver_test_runner_w3c.py:
(WebDriverTestRunnerW3C.run):

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

Tools/ChangeLog
Tools/Scripts/run-webdriver-tests
Tools/Scripts/webkitpy/webdriver_tests/webdriver_test_result.py
Tools/Scripts/webkitpy/webdriver_tests/webdriver_test_runner.py
Tools/Scripts/webkitpy/webdriver_tests/webdriver_test_runner_w3c.py

index 42d6f01..158c1bb 100644 (file)
@@ -1,3 +1,27 @@
+2017-11-28  Carlos Garcia Campos  <cgarcia@igalia.com>
+
+        WebDriver: add an option to dump test results to a json file
+        https://bugs.webkit.org/show_bug.cgi?id=180082
+
+        Reviewed by Brian Burg.
+
+        Add --json-output command line option to run-webdriver-tests to dump test results to a json file in a format
+        compatible with the W3C report. WebDriverTestResult now represents a test file and contains a list of
+        subtests, instead of having one WebDriverTestResult per subtest. This way we can store also the harness result
+        and dump the results to different formats.
+
+        * Scripts/run-webdriver-tests:
+        * Scripts/webkitpy/webdriver_tests/webdriver_test_result.py:
+        (WebDriverTestResult.__init__):
+        (WebDriverTestResult):
+        (WebDriverTestResult.add_subtest_results):
+        * Scripts/webkitpy/webdriver_tests/webdriver_test_runner.py:
+        (WebDriverTestRunner.print_results):
+        (WebDriverTestRunner):
+        (WebDriverTestRunner.dump_results_to_json_file):
+        * Scripts/webkitpy/webdriver_tests/webdriver_test_runner_w3c.py:
+        (WebDriverTestRunnerW3C.run):
+
 2017-11-28  Alexey Proskuryakov  <ap@apple.com>
 
         Stop silencing leaks in TextCodecICU::registerCodecs, as the problem was fixed a while ago.
index 2e601cf..ef9af0f 100755 (executable)
@@ -47,6 +47,8 @@ option_parser.add_option('--debug', action='store_const', const='Debug', dest="c
                          help='Set the configuration to Debug')
 option_parser.add_option('--timeout', action='store', type='int', dest='timeout', default=10,
                          help='Time in seconds until a test times out (use 0 to disable)')
+option_parser.add_option('--json-output', action='store', metavar="FILE",
+                         help='Write results to JSON file at the given path')
 option_parser.add_option('--display-server', choices=['xvfb', 'xorg', 'weston', 'wayland'], default='xvfb',
                          help='"xvfb": Use a virtualized X11 server. "xorg": Use the current X11 session. '
                               '"weston": Use a virtualized Weston server. "wayland": Use the current wayland session.')
@@ -66,5 +68,8 @@ runner = WebDriverTestRunner(port)
 retval = runner.run(args)
 runner.print_results()
 
+if options.json_output is not None:
+    runner.dump_results_to_json_file(options.json_output)
+
 sys.exit(retval)
 
index 5e507cf..66a17ec 100644 (file)
@@ -25,11 +25,14 @@ import os
 
 class WebDriverTestResult(object):
 
-    def __init__(self, test_prefix, test, status, message, backtrace=None):
-        self.test = os.path.join(test_prefix, test)
+    def __init__(self, test, status, message=None):
+        self.test = test
         self.status = status
         self.message = message
-        self.backtrace = backtrace
+        self.subtest_results = []
+
+    def add_subtest_results(self, subtest, status, message, backtrace):
+        self.subtest_results.append((subtest, status, message, backtrace))
 
     def __repr__(self):
         return "<%s.%s %s %s>" % (self.__module__, self.__class__.__name__, self.test, self.status)
index 64661ea..5aa3a21 100644 (file)
@@ -20,7 +20,9 @@
 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
 # SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
+import json
 import logging
+import os
 
 from webkitpy.webdriver_tests.webdriver_test_runner_w3c import WebDriverTestRunnerW3C
 
@@ -54,11 +56,16 @@ class WebDriverTestRunner(object):
         passed_count = 0
         failures_count = 0
         for result in self._runner.results():
-            if result.status == 'PASS':
-                passed_count += 1
-            elif result.status == 'FAIL':
-                results.setdefault(result.status, []).append(result.test)
-                failures_count += 1
+            if result.status == 'OK':
+                for subtest, status, _, _ in result.subtest_results:
+                    if status == 'PASS':
+                        passed_count += 1
+                    elif status == 'FAIL':
+                        results.setdefault(status, []).append(os.path.join(os.path.dirname(result.test), subtest))
+                        failures_count += 1
+            else:
+                # FIXME: handle other results.
+                pass
 
         _log.info('')
 
@@ -73,3 +80,27 @@ class WebDriverTestRunner(object):
             _log.info('Unexpected failures (%d)' % len(failed))
             for test in failed:
                 _log.info('  %s' % test)
+
+    def dump_results_to_json_file(self, output_path):
+        json_results = {}
+        json_results['results'] = []
+        for result in self._runner.results():
+            results = {}
+            results['test'] = result.test
+            results['status'] = result.status
+            results['message'] = result.message
+            results['subtests'] = []
+            for name, status, message, _ in result.subtest_results:
+                subtest = {}
+                subtest['name'] = name
+                subtest['status'] = status
+                subtest['message'] = message
+                results['subtests'].append(subtest)
+            json_results['results'].append(results)
+
+        directory = os.path.dirname(output_path)
+        if not os.path.exists(directory):
+            os.makedirs(directory)
+
+        with open(output_path, 'wb') as fp:
+            json.dump(json_results, fp)
index 0bdd93f..ec5d2e4 100644 (file)
@@ -96,10 +96,14 @@ class WebDriverTestRunnerW3C(object):
             for test in tests:
                 test_name = os.path.relpath(test, self._tests_dir())
                 harness_result, test_results = executor.run(test)
-                if harness_result[0] != 'OK':
-                    _log.error("Failed to run test %s: %s" % (test_name, harness_result[1]))
+                result = WebDriverTestResult(test_name, *harness_result)
+                if harness_result[0] == 'OK':
+                    for test_result in test_results:
+                        result.add_subtest_results(*test_result)
                 else:
-                    self._add_results(os.path.dirname(test_name), test_results)
+                    # FIXME: handle other results.
+                    pass
+                self._results.append(result)
         finally:
             executor.teardown()
             self._server.stop()