Title: [113639] trunk/Tools
Revision
113639
Author
[email protected]
Date
2012-04-09 16:28:25 -0700 (Mon, 09 Apr 2012)

Log Message

add a webkit-patch print-baselines command
https://bugs.webkit.org/show_bug.cgi?id=83348

Reviewed by Adam Barth.

This adds a simple 'print-baselines' command to webkit-patch
that can be used in one of two forms: to print where the
baselines for a given test (or set of tests) on a single port
will be found, or to generate a report for multiple ports.

Example of the former:

$ webkit-patch print-baselines fast/html/keygen.html
// For mac-snowleopard
platform/mac/fast/html/keygen-expected.txt
platform/mac/fast/html/keygen-expected.png
$

The latter is most useful for finding out which fallback dirs are
used by which ports for which tests, for example,
'chromium-mac-leopard' uses 100 results from 'platform/mac/leopard'.
No example output is given because the reports are pretty wordy :).

* Scripts/webkitpy/layout_tests/port/base.py:
(Port.baseline_extensions): Added.
(Port.expected_baseline_dict): Added.
* Scripts/webkitpy/tool/commands/queries.py:
(PrintBaselines):
(PrintBaselines.__init__):
(PrintBaselines.execute):
(PrintBaselines._print_baselines):
(PrintBaselines._platform_for_path):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (113638 => 113639)


--- trunk/Tools/ChangeLog	2012-04-09 23:20:03 UTC (rev 113638)
+++ trunk/Tools/ChangeLog	2012-04-09 23:28:25 UTC (rev 113639)
@@ -1,3 +1,38 @@
+2012-04-09  Dirk Pranke  <[email protected]>
+
+        add a webkit-patch print-baselines command
+        https://bugs.webkit.org/show_bug.cgi?id=83348
+
+        Reviewed by Adam Barth.
+
+        This adds a simple 'print-baselines' command to webkit-patch
+        that can be used in one of two forms: to print where the
+        baselines for a given test (or set of tests) on a single port
+        will be found, or to generate a report for multiple ports.
+
+        Example of the former:
+
+        $ webkit-patch print-baselines fast/html/keygen.html
+        // For mac-snowleopard
+        platform/mac/fast/html/keygen-expected.txt
+        platform/mac/fast/html/keygen-expected.png
+        $
+
+        The latter is most useful for finding out which fallback dirs are
+        used by which ports for which tests, for example,
+        'chromium-mac-leopard' uses 100 results from 'platform/mac/leopard'.
+        No example output is given because the reports are pretty wordy :).
+
+        * Scripts/webkitpy/layout_tests/port/base.py:
+        (Port.baseline_extensions): Added.
+        (Port.expected_baseline_dict): Added.
+        * Scripts/webkitpy/tool/commands/queries.py:
+        (PrintBaselines):
+        (PrintBaselines.__init__):
+        (PrintBaselines.execute):
+        (PrintBaselines._print_baselines):
+        (PrintBaselines._platform_for_path):
+
 2012-04-09  Florin Malita  <[email protected]>
 
         Unreviewed: adding myself to committers.py.

Modified: trunk/Tools/Scripts/webkitpy/layout_tests/port/base.py (113638 => 113639)


--- trunk/Tools/Scripts/webkitpy/layout_tests/port/base.py	2012-04-09 23:20:03 UTC (rev 113638)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/port/base.py	2012-04-09 23:28:25 UTC (rev 113639)
@@ -306,6 +306,27 @@
         # FIXME: Seems we should get this from the Port's Driver class.
         return "DumpRenderTree"
 
+    def expected_baselines_by_extension(self, test_name):
+        """Returns a dict mapping baseline suffix to relative path for each baseline in
+        a test. For reftests, it returns ".==" or ".!=" instead of the suffix."""
+        # FIXME: The name similarity between this and expected_baselines() below, is unfortunate.
+        # We should probably rename them both.
+        baseline_dict = {}
+        reference_files = self.reference_files(test_name)
+        if reference_files:
+            # FIXME: How should this handle more than one type of reftest?
+            baseline_dict['.' + reference_files[0][0]] = self.relative_test_filename(reference_files[0][1])
+
+        for extension in self.baseline_extensions():
+            path = self.expected_filename(test_name, extension, return_default=False)
+            baseline_dict[extension] = self.relative_test_filename(path) if path else path
+
+        return baseline_dict
+
+    def baseline_extensions(self):
+        """Returns a tuple of all of the non-reftest baseline extensions we use. The extensions include the leading '.'."""
+        return ('.wav', '.webarchive', '.txt', '.png')
+
     def expected_baselines(self, test_name, suffix, all_baselines=False):
         """Given a test name, finds where the baseline results are located.
 
@@ -355,7 +376,7 @@
 
         return [(None, baseline_filename)]
 
-    def expected_filename(self, test_name, suffix):
+    def expected_filename(self, test_name, suffix, return_default=True):
         """Given a test name, returns an absolute path to its expected results.
 
         If no expected results are found in any of the searched directories,
@@ -370,6 +391,8 @@
         platform: the most-specific directory name to use to build the
             search list of directories, e.g., 'chromium-win', or
             'chromium-cg-mac-leopard' (we follow the WebKit format)
+        return_default: if True, returns the path to the generic expectation if nothing
+            else is found; if False, returns None.
 
         This routine is generic but is implemented here to live alongside
         the other baseline and filename manipulation routines.
@@ -383,7 +406,9 @@
         if actual_test_name:
             return self.expected_filename(actual_test_name, suffix)
 
-        return self._filesystem.join(self.layout_tests_dir(), baseline_filename)
+        if return_default:
+            return self._filesystem.join(self.layout_tests_dir(), baseline_filename)
+        return None
 
     def expected_checksum(self, test_name):
         """Returns the checksum of the image we expect the test to produce, or None if it is a text-only test."""

Modified: trunk/Tools/Scripts/webkitpy/tool/commands/queries.py (113638 => 113639)


--- trunk/Tools/Scripts/webkitpy/tool/commands/queries.py	2012-04-09 23:20:03 UTC (rev 113638)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/queries.py	2012-04-09 23:28:25 UTC (rev 113639)
@@ -4,7 +4,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
@@ -14,7 +14,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
@@ -27,6 +27,8 @@
 # (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 fnmatch
+import re
 
 from optparse import make_option
 
@@ -397,3 +399,68 @@
                 print "Ports skipping test %r: %s" % (test_name, ', '.join(ports))
             else:
                 print "Test %r is not skipped by any port." % test_name
+
+
+class PrintBaselines(AbstractDeclarativeCommand):
+    name = 'print-baselines'
+    help_text = 'Prints the baseline locations for given test(s) on the given port(s)'
+
+    def __init__(self):
+        options = [
+            make_option('-p', '--platform', action='',
+                        help='platform/port(s) to display expectations for. Use glob-style wildcards for multiple ports (note that that will imply --csv)'),
+            make_option('--all', action='', default=False,
+                        help='display the baselines for *all* tests'),
+            make_option('--csv', action='', default=False,
+                        help='Print a CSV-style report that includes the port name, test_name, test platform, baseline type, baseline location, and baseline platform'),
+            make_option('--include-virtual-tests', action='',
+                        help='Include virtual tests'),
+        ]
+        AbstractDeclarativeCommand.__init__(self, options=options)
+        self._platform_regexp = re.compile('platform/([^\/]+)/(.+)')
+
+    def execute(self, options, args, tool):
+        if not args and not options.all:
+            print "You must either specify one or more test paths or --all."
+            return
+
+        default_port = tool.port_factory.get()
+        if options.platform:
+            port_names = fnmatch.filter(tool.port_factory.all_port_names(), options.platform)
+            if not port_names:
+                print "No port names match '%s'" % options.platform
+        else:
+            port_names = [default_port.name()]
+
+        if len(port_names) > 1:
+            options.csv = True
+
+        if options.include_virtual_tests:
+            tests = sorted(default_port.tests(args))
+        else:
+            # FIXME: make real_tests() a public method.
+            tests = sorted(default_port._real_tests(args))
+
+        if not options.csv:
+            print "// For %s" % port_names[0]
+
+        for port_name in port_names:
+            port = tool.port_factory.get(port_name)
+            for test_name in tests:
+                self._print_baselines(options, port_name, test_name, port.expected_baselines_by_extension(test_name))
+
+    def _print_baselines(self, options, port_name, test_name, baselines):
+        for extension in sorted(baselines.keys()):
+            baseline_location = baselines[extension]
+            if baseline_location:
+                if options.csv:
+                    print "%s,%s,%s,%s,%s,%s" % (port_name, test_name, self._platform_for_path(test_name),
+                                                 extension[1:], baseline_location, self._platform_for_path(baseline_location))
+                else:
+                    print baseline_location
+
+    def _platform_for_path(self, relpath):
+        platform_matchobj = self._platform_regexp.match(relpath)
+        if platform_matchobj:
+            return platform_matchobj.group(1)
+        return None

Modified: trunk/Tools/Scripts/webkitpy/tool/commands/queries_unittest.py (113638 => 113639)


--- trunk/Tools/Scripts/webkitpy/tool/commands/queries_unittest.py	2012-04-09 23:20:03 UTC (rev 113638)
+++ trunk/Tools/Scripts/webkitpy/tool/commands/queries_unittest.py	2012-04-09 23:28:25 UTC (rev 113639)
@@ -29,10 +29,11 @@
 import unittest
 
 from webkitpy.common.net.bugzilla import Bugzilla
+from webkitpy.common.system.outputcapture import OutputCapture
 from webkitpy.thirdparty.mock import Mock
 from webkitpy.tool.commands.commandtest import CommandsTest
 from webkitpy.tool.commands.queries import *
-from webkitpy.tool.mocktool import MockTool
+from webkitpy.tool.mocktool import MockTool, MockOptions
 
 
 class MockTestPort1(object):
@@ -115,3 +116,46 @@
             raise Exception("MESSAGE")
         tool.checkout().commit_info_for_revision = raising_mock
         self.assertEquals(command._blame_line_for_revision(None), "FAILED to fetch CommitInfo for rNone, exception: MESSAGE")
+
+
+class PrintBaselinesTest(unittest.TestCase):
+    def setUp(self):
+        self.oc = None
+        self.tool = MockTool()
+        self.test_port = self.tool.port_factory.get('test-win-xp')
+        self.tool.port_factory.get = lambda port_name=None: self.test_port
+        self.tool.port_factory.all_port_names = lambda: ['test-win-xp']
+
+    def tearDown(self):
+        if self.oc:
+            self.restore_output()
+
+    def capture_output(self):
+        self.oc = OutputCapture()
+        self.oc.capture_output()
+
+    def restore_output(self):
+        stdout, stderr, logs = self.oc.restore_output()
+        self.oc = None
+        return (stdout, stderr, logs)
+
+    def test_basic(self):
+        command = PrintBaselines()
+        command.bind_to_tool(self.tool)
+        self.capture_output()
+        command.execute(MockOptions(all=False, include_virtual_tests=False, csv=False, platform=None), ['passes/text.html'], self.tool)
+        stdout, _, _ = self.restore_output()
+        self.assertEquals(stdout,
+                          ('// For test-win-xp\n'
+                           'passes/text-expected.png\n'
+                           'passes/text-expected.txt\n'))
+
+    def test_csv(self):
+        command = PrintBaselines()
+        command.bind_to_tool(self.tool)
+        self.capture_output()
+        command.execute(MockOptions(all=False, platform='*xp', csv=True, include_virtual_tests=False), ['passes/text.html'], self.tool)
+        stdout, _, _ = self.restore_output()
+        self.assertEquals(stdout,
+                          ('test-win-xp,passes/text.html,None,png,passes/text-expected.png,None\n'
+                           'test-win-xp,passes/text.html,None,txt,passes/text-expected.txt,None\n'))
_______________________________________________
webkit-changes mailing list
[email protected]
http://lists.webkit.org/mailman/listinfo.cgi/webkit-changes

Reply via email to