Log Message
webkitpy: Add an explicit ImageDiffResult.passed rather than relying on diff_image being non-None https://bugs.webkit.org/show_bug.cgi?id=232266
Reviewed by Jonathan Bedard. A ref test was considered failing if it ImageDiffResult.diff_image was not None, allowing for confusing unit tests that used a value of True for diff_image. Fix by giving ImageDiffResult an explicit 'passes' field, and testing it rather than diff_image. Also used named arguments when creating ImageDiffResults for readability. * Scripts/webkitpy/layout_tests/controllers/single_test_runner.py: (SingleTestRunner._compare_image): Use `diff_result.passed` as truth for whether the test passed, and only store the error_string in failure cases (which allows ImageDiff to spew diagnostic errors without triggering failures). (SingleTestRunner._compare_output_with_reference): * Scripts/webkitpy/layout_tests/controllers/test_result_writer_unittest.py: (TestResultWriterTest.test_reftest_diff_image.ImageDiffTestPort.diff_image): (TestResultWriterTest): * Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py: (RunTest.test_tolerance.ImageDiffTestPort.diff_image): * Scripts/webkitpy/port/base.py: (Port.diff_image): * Scripts/webkitpy/port/image_diff.py: (ImageDiffResult.__init__): (ImageDiffResult.__eq__): (ImageDiffResult.__repr__): (ImageDiffer._read): * Scripts/webkitpy/port/port_testcase.py: (PortTestCase.integration_test_image_diff): (PortTestCase.test_diff_image__missing_both): (PortTestCase.test_diff_image__missing_actual): (PortTestCase.test_diff_image__missing_expected): (PortTestCase.test_diff_image): (PortTestCase.test_diff_image_passed): (PortTestCase.test_diff_image_failed): (PortTestCase.test_diff_image_crashed): * Scripts/webkitpy/port/test.py:
Modified Paths
- trunk/Tools/ChangeLog
- trunk/Tools/Scripts/webkitpy/layout_tests/controllers/single_test_runner.py
- trunk/Tools/Scripts/webkitpy/layout_tests/controllers/test_result_writer_unittest.py
- trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py
- trunk/Tools/Scripts/webkitpy/port/base.py
- trunk/Tools/Scripts/webkitpy/port/image_diff.py
- trunk/Tools/Scripts/webkitpy/port/port_testcase.py
- trunk/Tools/Scripts/webkitpy/port/test.py
Diff
Modified: trunk/Tools/ChangeLog (284844 => 284845)
--- trunk/Tools/ChangeLog 2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/ChangeLog 2021-10-25 23:25:03 UTC (rev 284845)
@@ -1,3 +1,46 @@
+2021-10-25 Simon Fraser <[email protected]>
+
+ webkitpy: Add an explicit ImageDiffResult.passed rather than relying on diff_image being non-None
+ https://bugs.webkit.org/show_bug.cgi?id=232266
+
+ Reviewed by Jonathan Bedard.
+
+ A ref test was considered failing if it ImageDiffResult.diff_image was not None, allowing
+ for confusing unit tests that used a value of True for diff_image.
+
+ Fix by giving ImageDiffResult an explicit 'passes' field, and testing it rather than
+ diff_image.
+
+ Also used named arguments when creating ImageDiffResults for readability.
+
+ * Scripts/webkitpy/layout_tests/controllers/single_test_runner.py:
+ (SingleTestRunner._compare_image): Use `diff_result.passed` as truth for whether the test passed,
+ and only store the error_string in failure cases (which allows ImageDiff to spew diagnostic errors
+ without triggering failures).
+ (SingleTestRunner._compare_output_with_reference):
+ * Scripts/webkitpy/layout_tests/controllers/test_result_writer_unittest.py:
+ (TestResultWriterTest.test_reftest_diff_image.ImageDiffTestPort.diff_image):
+ (TestResultWriterTest):
+ * Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py:
+ (RunTest.test_tolerance.ImageDiffTestPort.diff_image):
+ * Scripts/webkitpy/port/base.py:
+ (Port.diff_image):
+ * Scripts/webkitpy/port/image_diff.py:
+ (ImageDiffResult.__init__):
+ (ImageDiffResult.__eq__):
+ (ImageDiffResult.__repr__):
+ (ImageDiffer._read):
+ * Scripts/webkitpy/port/port_testcase.py:
+ (PortTestCase.integration_test_image_diff):
+ (PortTestCase.test_diff_image__missing_both):
+ (PortTestCase.test_diff_image__missing_actual):
+ (PortTestCase.test_diff_image__missing_expected):
+ (PortTestCase.test_diff_image):
+ (PortTestCase.test_diff_image_passed):
+ (PortTestCase.test_diff_image_failed):
+ (PortTestCase.test_diff_image_crashed):
+ * Scripts/webkitpy/port/test.py:
+
2021-10-25 Alex Christensen <[email protected]>
WebKit ought to be able to play videos without Content-Length HTTP header fields and without range support
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/controllers/single_test_runner.py (284844 => 284845)
--- trunk/Tools/Scripts/webkitpy/layout_tests/controllers/single_test_runner.py 2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/controllers/single_test_runner.py 2021-10-25 23:25:03 UTC (rev 284845)
@@ -294,17 +294,15 @@
failures.append(test_failures.FailureMissingImageHash())
elif driver_output.image_hash != expected_driver_output.image_hash:
diff_result = self._port.diff_image(expected_driver_output.image, driver_output.image)
- if diff_result.error_string:
- _log.warning(' %s : %s' % (self._test_name, diff_result.error_string))
- failures.append(test_failures.FailureImageHashMismatch())
- driver_output.error = (driver_output.error or '') + diff_result.error_string
+ if not diff_result.passed:
+ failures.append(test_failures.FailureImageHashMismatch(diff_result.diff_percent))
+ if diff_result.error_string:
+ _log.warning(' %s : %s' % (self._test_name, diff_result.error_string))
+ driver_output.error = (driver_output.error or '') + diff_result.error_string
+ driver_output.image_diff = diff_result.diff_image
else:
- driver_output.image_diff = diff_result.diff_image
- if driver_output.image_diff:
- failures.append(test_failures.FailureImageHashMismatch(diff_result.diff_percent))
- else:
- # See https://bugs.webkit.org/show_bug.cgi?id=69444 for why this isn't a full failure.
- _log.warning(' %s -> pixel hash failed (but diff passed)' % self._test_name)
+ # See https://bugs.webkit.org/show_bug.cgi?id=69444 for why this isn't a full failure.
+ _log.warning(' %s -> pixel hash failed (but diff passed)' % self._test_name)
return failures
def _run_reftest(self):
@@ -357,11 +355,10 @@
elif reference_driver_output.image_hash != actual_driver_output.image_hash:
# ImageDiff has a hard coded color distance threshold even though tolerance=0 is specified.
diff_result = self._port.diff_image(reference_driver_output.image, actual_driver_output.image, tolerance=0)
- if diff_result.error_string:
- _log.warning(' %s : %s' % (self._test_name, diff_result.error_string))
+ if not diff_result.passed:
failures.append(test_failures.FailureReftestMismatch(reference_filename))
- actual_driver_output.error = (actual_driver_output.error or '') + diff_result.error_string
- elif diff_result.diff_image:
- failures.append(test_failures.FailureReftestMismatch(reference_filename))
+ if diff_result.error_string:
+ _log.warning(' %s : %s' % (self._test_name, diff_result.error_string))
+ actual_driver_output.error = (actual_driver_output.error or '') + diff_result.error_string
return TestResult(self._test_input, failures, total_test_time, has_stderr, pid=actual_driver_output.pid)
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/controllers/test_result_writer_unittest.py (284844 => 284845)
--- trunk/Tools/Scripts/webkitpy/layout_tests/controllers/test_result_writer_unittest.py 2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/controllers/test_result_writer_unittest.py 2021-10-25 23:25:03 UTC (rev 284845)
@@ -42,7 +42,7 @@
class ImageDiffTestPort(TestPort):
def diff_image(self, expected_contents, actual_contents, tolerance=None):
used_tolerance_values.append(tolerance)
- return ImageDiffResult(True, 1, None)
+ return ImageDiffResult(passed=False, diff_image=b'', difference=1)
host = MockHost()
port = ImageDiffTestPort(host)
Modified: trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py (284844 => 284845)
--- trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py 2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/layout_tests/run_webkit_tests_integrationtest.py 2021-10-25 23:25:03 UTC (rev 284845)
@@ -752,7 +752,7 @@
class ImageDiffTestPort(test.TestPort):
def diff_image(self, expected_contents, actual_contents, tolerance=None):
self.tolerance_used_for_diff_image = self._options.tolerance
- return ImageDiffResult(True, 1, None)
+ return ImageDiffResult(passed=False, diff_image=b'', difference=1)
def get_port_for_run(args):
options, parsed_args = run_webkit_tests.parse_args(args)
Modified: trunk/Tools/Scripts/webkitpy/port/base.py (284844 => 284845)
--- trunk/Tools/Scripts/webkitpy/port/base.py 2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/port/base.py 2021-10-25 23:25:03 UTC (rev 284845)
@@ -307,10 +307,10 @@
If an error occurs (like ImageDiff isn't found, or crashes, we log an error and return True (for a diff).
"""
if not actual_contents and not expected_contents:
- return ImageDiffResult(None, 0, None)
+ return ImageDiffResult(passed=True, diff_image=None, difference=0)
if not actual_contents or not expected_contents:
- return ImageDiffResult(True, 0, None)
+ return ImageDiffResult(passed=False, diff_image=b'', difference=1)
if not self._image_differ:
self._image_differ = image_diff.ImageDiffer(self)
Modified: trunk/Tools/Scripts/webkitpy/port/image_diff.py (284844 => 284845)
--- trunk/Tools/Scripts/webkitpy/port/image_diff.py 2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/port/image_diff.py 2021-10-25 23:25:03 UTC (rev 284845)
@@ -40,7 +40,8 @@
class ImageDiffResult(object):
- def __init__(self, diff_image, difference, error_string):
+ def __init__(self, passed, diff_image, difference, error_string=None):
+ self.passed = passed
self.diff_image = diff_image
self.diff_percent = difference
self.error_string = error_string
@@ -47,7 +48,8 @@
def __eq__(self, other):
if isinstance(other, self.__class__):
- return (self.diff_image == other.diff_image and
+ return (self.passed == other.passed and
+ self.diff_image == other.diff_image and
self.diff_percent == other.diff_percent and
self.error_string == other.error_string)
@@ -57,7 +59,7 @@
return not self.__eq__(other)
def __repr__(self):
- return 'ImageDiffResult({} {} {})'.format(self.diff_image, self.diff_percent, self.error_string)
+ return 'ImageDiffResult(Passed {} {} {} {})'.format(self.passed, self.diff_image, self.diff_percent, self.error_string)
class ImageDiffer(object):
def __init__(self, port):
@@ -128,10 +130,10 @@
if output and output.startswith(b'diff'):
m = re.match(b'diff: (.+)% (passed|failed)', output)
if m.group(2) == b'passed':
- return ImageDiffResult(None, 0, None)
+ return ImageDiffResult(passed=True, diff_image=None, difference=0)
diff_percent = float(string_utils.decode(m.group(1), target_type=str))
- return ImageDiffResult(output_image, diff_percent, err_str or None)
+ return ImageDiffResult(passed=False, diff_image=output_image, difference=diff_percent, error_string=err_str or None)
def stop(self):
if self._process:
Modified: trunk/Tools/Scripts/webkitpy/port/port_testcase.py (284844 => 284845)
--- trunk/Tools/Scripts/webkitpy/port/port_testcase.py 2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/port/port_testcase.py 2021-10-25 23:25:03 UTC (rev 284845)
@@ -249,36 +249,35 @@
dir = port.layout_tests_dir()
file1 = port._filesystem.join(dir, 'fast', 'css', 'button_center.png')
contents1 = port._filesystem.read_binary_file(file1)
- file2 = port._filesystem.join(dir, 'fast', 'css',
- 'remove-shorthand-expected.png')
+ file2 = port._filesystem.join(dir, 'fast', 'css', 'remove-shorthand-expected.png')
contents2 = port._filesystem.read_binary_file(file2)
tmpfd, tmpfile = port._filesystem.open_binary_tempfile('')
tmpfd.close()
- self.assertFalse(port.diff_image(contents1, contents1).diff_image)
- self.assertTrue(port.diff_image(contents1, contents2).diff_image)
+ self.assertTrue(port.diff_image(contents1, contents1).passed)
+ self.assertFalse(port.diff_image(contents1, contents2).passed)
- self.assertTrue(port.diff_image(contents1, contents2, tmpfile).diff_image)
+ self.assertFalse(port.diff_image(contents1, contents2, tmpfile).passed)
port._filesystem.remove(tmpfile)
def test_diff_image__missing_both(self):
port = self.make_port()
- self.assertFalse(port.diff_image(None, None).diff_image)
- self.assertFalse(port.diff_image(None, b'').diff_image)
- self.assertFalse(port.diff_image(b'', None).diff_image)
+ self.assertTrue(port.diff_image(None, None).passed)
+ self.assertTrue(port.diff_image(None, b'').passed)
+ self.assertTrue(port.diff_image(b'', None).passed)
- self.assertFalse(port.diff_image(b'', b'').diff_image)
+ self.assertTrue(port.diff_image(b'', b'').passed)
def test_diff_image__missing_actual(self):
port = self.make_port()
- self.assertTrue(port.diff_image(None, b'foo').diff_image)
- self.assertTrue(port.diff_image(b'', b'foo').diff_image)
+ self.assertFalse(port.diff_image(None, b'foo').passed)
+ self.assertFalse(port.diff_image(b'', b'foo').passed)
def test_diff_image__missing_expected(self):
port = self.make_port()
- self.assertTrue(port.diff_image(b'foo', None).diff_image)
- self.assertTrue(port.diff_image(b'foo', b'').diff_image)
+ self.assertFalse(port.diff_image(b'foo', None).passed)
+ self.assertFalse(port.diff_image(b'foo', b'').passed)
def test_diff_image(self):
port = self.make_port()
@@ -298,11 +297,11 @@
# First test the case of not using the JHBuild wrapper.
self.assertFalse(port._should_use_jhbuild())
- self.assertEqual(port.diff_image(b'foo', b'bar'), ImageDiffResult(b'', 100.0, None))
+ self.assertEqual(port.diff_image(b'foo', b'bar'), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
self.assertEqual(self.proc.cmd, [port._path_to_image_diff(), "--tolerance", "0.1"])
- self.assertEqual(port.diff_image(b'foo', b'bar', None), ImageDiffResult(b'', 100.0, None))
+ self.assertEqual(port.diff_image(b'foo', b'bar', None), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
self.assertEqual(self.proc.cmd, [port._path_to_image_diff(), "--tolerance", "0.1"])
- self.assertEqual(port.diff_image(b'foo', b'bar', 0), ImageDiffResult(b'', 100.0, None))
+ self.assertEqual(port.diff_image(b'foo', b'bar', 0), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
self.assertEqual(self.proc.cmd, [port._path_to_image_diff(), "--tolerance", "0"])
# Now test the case of using JHBuild wrapper.
@@ -309,11 +308,11 @@
port._filesystem.maybe_make_directory(port.path_from_webkit_base('WebKitBuild', 'Dependencies%s' % port.port_name.upper()))
self.assertTrue(port._should_use_jhbuild())
- self.assertEqual(port.diff_image(b'foo', b'bar'), ImageDiffResult(b'', 100.0, None))
+ self.assertEqual(port.diff_image(b'foo', b'bar'), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
self.assertEqual(self.proc.cmd, port._jhbuild_wrapper + [port._path_to_image_diff(), "--tolerance", "0.1"])
- self.assertEqual(port.diff_image(b'foo', b'bar', None), ImageDiffResult(b'', 100.0, None))
+ self.assertEqual(port.diff_image(b'foo', b'bar', None), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
self.assertEqual(self.proc.cmd, port._jhbuild_wrapper + [port._path_to_image_diff(), "--tolerance", "0.1"])
- self.assertEqual(port.diff_image(b'foo', b'bar', 0), ImageDiffResult(b'', 100.0, None))
+ self.assertEqual(port.diff_image(b'foo', b'bar', 0), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
self.assertEqual(self.proc.cmd, port._jhbuild_wrapper + [port._path_to_image_diff(), "--tolerance", "0"])
port.clean_up_test_run()
@@ -324,13 +323,13 @@
port = self.make_port()
port._server_process_constructor = lambda port, nm, cmd, env, crash_message=None: MockServerProcess(lines=['diff: 0% passed\n'])
image_differ = ImageDiffer(port)
- self.assertEqual(image_differ.diff_image(b'foo', b'bar', 0.1), ImageDiffResult(None, 0, None))
+ self.assertEqual(image_differ.diff_image(b'foo', b'bar', 0.1), ImageDiffResult(passed=True, diff_image=None, difference=0))
def test_diff_image_failed(self):
port = self.make_port()
port._server_process_constructor = lambda port, nm, cmd, env, crash_message=None: MockServerProcess(lines=['diff: 100% failed\n'])
image_differ = ImageDiffer(port)
- self.assertEqual(image_differ.diff_image(b'foo', b'bar', 0.1), ImageDiffResult(b'', 100.0, None))
+ self.assertEqual(image_differ.diff_image(b'foo', b'bar', 0.1), ImageDiffResult(passed=False, diff_image=b'', difference=100.0))
def test_diff_image_crashed(self):
port = self.make_port()
@@ -346,7 +345,7 @@
port._server_process_constructor = make_proc
port.setup_test_run()
- self.assertEqual(port.diff_image(b'foo', b'bar'), ImageDiffResult(b'', 0, 'ImageDiff crashed\n'))
+ self.assertEqual(port.diff_image(b'foo', b'bar'), ImageDiffResult(passed=False, diff_image=b'', difference=0, error_string='ImageDiff crashed\n'))
port.clean_up_test_run()
@slow
Modified: trunk/Tools/Scripts/webkitpy/port/test.py (284844 => 284845)
--- trunk/Tools/Scripts/webkitpy/port/test.py 2021-10-25 23:20:28 UTC (rev 284844)
+++ trunk/Tools/Scripts/webkitpy/port/test.py 2021-10-25 23:25:03 UTC (rev 284845)
@@ -408,20 +408,23 @@
actual_contents = string_utils.encode(actual_contents)
diffed = actual_contents != expected_contents
if not actual_contents and not expected_contents:
- return ImageDiffResult(None, 0, None)
+ return ImageDiffResult(passed=True, diff_image=None, difference=0)
if not actual_contents or not expected_contents:
- return ImageDiffResult(True, 0, None)
+ return ImageDiffResult(passed=False, diff_image=b'', difference=0)
if b'ref' in expected_contents:
assert tolerance == 0
if diffed:
- return ImageDiffResult("< {}\n---\n> {}\n".format(
- string_utils.decode(expected_contents, target_type=str),
- string_utils.decode(actual_contents, target_type=str),
- ), 1, None)
+ return ImageDiffResult(
+ passed=False,
+ diff_image="< {}\n---\n> {}\n".format(
+ string_utils.decode(expected_contents, target_type=str),
+ string_utils.decode(actual_contents, target_type=str),
+ ),
+ difference=1)
- return ImageDiffResult(None, 0, None)
+ return ImageDiffResult(passed=True, diff_image=None, difference=0)
def layout_tests_dir(self):
return LAYOUT_TEST_DIR
_______________________________________________ webkit-changes mailing list [email protected] https://lists.webkit.org/mailman/listinfo/webkit-changes
