2010-10-04 Tony Chang <tony@chromium.org>
authortkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Oct 2010 04:21:10 +0000 (04:21 +0000)
committertkent@chromium.org <tkent@chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Tue, 5 Oct 2010 04:21:10 +0000 (04:21 +0000)
        Reviewed by Kent Tamura.

        [chromium] fix image diffing in NRWT
        https://bugs.webkit.org/show_bug.cgi?id=47128

        * Scripts/webkitpy/layout_tests/port/chromium.py: Flush data to the
              temp file and check the image_diff error code more carefully
        * Scripts/webkitpy/layout_tests/port/chromium_unittest.py:

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

WebKitTools/ChangeLog
WebKitTools/Scripts/webkitpy/layout_tests/port/chromium.py
WebKitTools/Scripts/webkitpy/layout_tests/port/chromium_unittest.py

index 632a6e2..5b662ae 100644 (file)
@@ -1,3 +1,14 @@
+2010-10-04  Tony Chang  <tony@chromium.org>
+
+        Reviewed by Kent Tamura.
+
+        [chromium] fix image diffing in NRWT
+        https://bugs.webkit.org/show_bug.cgi?id=47128
+
+        * Scripts/webkitpy/layout_tests/port/chromium.py: Flush data to the
+              temp file and check the image_diff error code more carefully
+        * Scripts/webkitpy/layout_tests/port/chromium_unittest.py:
+
 2010-10-04  Dirk Pranke  <dpranke@chromium.org>
 
         Reviewed by Adam Barth.
 2010-10-04  Dirk Pranke  <dpranke@chromium.org>
 
         Reviewed by Adam Barth.
index a72627a..d9a3e4c 100644 (file)
@@ -136,8 +136,10 @@ class ChromiumPort(base.Port):
         executable = self._path_to_image_diff()
         expected_tmpfile = tempfile.NamedTemporaryFile()
         expected_tmpfile.write(expected_contents)
         executable = self._path_to_image_diff()
         expected_tmpfile = tempfile.NamedTemporaryFile()
         expected_tmpfile.write(expected_contents)
+        expected_tmpfile.flush()
         actual_tmpfile = tempfile.NamedTemporaryFile()
         actual_tmpfile.write(actual_contents)
         actual_tmpfile = tempfile.NamedTemporaryFile()
         actual_tmpfile.write(actual_contents)
+        actual_tmpfile.flush()
         if diff_filename:
             cmd = [executable, '--diff', expected_tmpfile.name,
                    actual_tmpfile.name, diff_filename]
         if diff_filename:
             cmd = [executable, '--diff', expected_tmpfile.name,
                    actual_tmpfile.name, diff_filename]
@@ -146,8 +148,14 @@ class ChromiumPort(base.Port):
 
         result = True
         try:
 
         result = True
         try:
-            if self._executive.run_command(cmd, return_exit_code=True) == 0:
-                return False
+            exit_code = self._executive.run_command(cmd, return_exit_code=True)
+            if exit_code == 0:
+                # The images are the same.
+                result = False
+            elif exit_code != 1:
+                # Some other error occurred.
+                raise ValueError("image diff returned an exit code of " +
+                                 str(exit_code))
         except OSError, e:
             if e.errno == errno.ENOENT or e.errno == errno.EACCES:
                 _compare_available = False
         except OSError, e:
             if e.errno == errno.ENOENT or e.errno == errno.EACCES:
                 _compare_available = False
index a4a9ea6..48e9585 100644 (file)
@@ -156,5 +156,47 @@ DEFER LINUX WIN : fast/js/very-good.js = TIMEOUT PASS"""
         self.assertEquals(options.configuration, 'default')
         self.assertTrue(port.default_configuration_called)
 
         self.assertEquals(options.configuration, 'default')
         self.assertTrue(port.default_configuration_called)
 
+    def test_diff_image(self):
+        class TestPort(ChromiumPortTest.TestLinuxPort):
+            def _path_to_image_diff(self):
+                return "/path/to/image_diff"
+
+        class EmptyOptions:
+            use_drt = False
+
+        class MockExecute:
+            def __init__(self, result):
+                self._result = result
+
+            def run_command(self,
+                            args,
+                            cwd=None,
+                            input=None,
+                            error_handler=None,
+                            return_exit_code=False,
+                            return_stderr=True,
+                            decode_output=False):
+                return self._result
+
+        options = EmptyOptions()
+        port = ChromiumPortTest.TestLinuxPort(options)
+
+        # Images are different.
+        port._executive = MockExecute(0)
+        self.assertEquals(False, port.diff_image("EXPECTED", "ACTUAL"))
+
+        # Images are the same.
+        port._executive = MockExecute(1)
+        self.assertEquals(True, port.diff_image("EXPECTED", "ACTUAL"))
+
+        # There was some error running image_diff.
+        port._executive = MockExecute(2)
+        exception_raised = False
+        try:
+            port.diff_image("EXPECTED", "ACTUAL")
+        except ValueError, e:
+            exception_raised = True
+        self.assertTrue(exception_raised)
+
 if __name__ == '__main__':
     unittest.main()
 if __name__ == '__main__':
     unittest.main()