Commit 2a4a0f03 authored by Xianzhu Wang's avatar Xianzhu Wang Committed by Commit Bot

[run_web_tests] Fix --reset-results when platform baseline exists but fallback doesn't

Previously, --reset-results removed the existing platform baseline
without recreating one if the fallback baseline doesn't exist.

Fix the issue by checking non-exist and non-missing condition
before removing the current baseline.

Bug: 845781
Change-Id: I7dbe46665d9574b310020c4ffc4041b6235d5570
Reviewed-on: https://chromium-review.googlesource.com/1173483
Commit-Queue: Xianzhu Wang <wangxianzhu@chromium.org>
Reviewed-by: default avatarQuinten Yearsley <qyearsley@chromium.org>
Cr-Commit-Position: refs/heads/master@{#583005}
parent 31f1f7d3
......@@ -189,9 +189,16 @@ class SingleTestRunner(object):
def _save_baseline_data(self, data, extension, is_missing):
if data is None:
return
port = self._port
fs = self._filesystem
# It's OK that a testharness test or image-first test doesn't have the
# particular baseline, as long as |is_missing| is False.
current_expected_path = port.expected_filename(self._test_name, extension)
if not fs.exists(current_expected_path) and not is_missing:
return
flag_specific_dir = port.baseline_flag_specific_dir()
if flag_specific_dir:
output_dir = fs.join(flag_specific_dir, fs.dirname(self._test_name))
......@@ -212,11 +219,9 @@ class SingleTestRunner(object):
_log.info('Removing the current baseline "%s"', port.relative_test_filename(output_path))
fs.remove(output_path)
# Note that current_expected_path may change because of the above file removal.
current_expected_path = port.expected_filename(self._test_name, extension)
if not fs.exists(current_expected_path):
if not is_missing or not self._options.reset_results:
return
elif fs.sha1(current_expected_path) == hashlib.sha1(data).hexdigest():
if fs.exists(current_expected_path) and fs.sha1(current_expected_path) == hashlib.sha1(data).hexdigest():
if self._options.reset_results:
_log.info('Not writing new expected result "%s" because it is the same as the current expected result',
port.relative_test_filename(output_path))
......
......@@ -1510,6 +1510,58 @@ class RebaselineTest(unittest.TestCase, StreamTestingMixin):
'virtual/virtual_failures/failures/unexpected/text-image-checksum',
expected_extensions=['.png'])
def test_new_platform_baseline_with_fallback(self):
# Test that we update the existing baseline in the platform-specific
# directory if the new baseline is different, with existing fallback
# baseline (which should not matter).
host = MockHost()
host.filesystem.write_text_file(
test.LAYOUT_TEST_DIR +
'/platform/test-mac-mac10.10/failures/unexpected/text-image-checksum-expected.png',
'wrong-png-baseline')
details, log_stream, _ = logging_run(
[
'--reset-results',
'failures/unexpected/text-image-checksum.html'
],
tests_included=True, host=host)
file_list = host.filesystem.written_files.keys()
self.assertEqual(details.exit_code, 0)
self.assertEqual(len(file_list), 7)
# We should reset the platform image baseline.
self.assert_baselines(
file_list, log_stream,
'platform/test-mac-mac10.10/failures/unexpected/text-image-checksum',
expected_extensions=['.png'])
def test_new_platform_baseline_without_fallback(self):
# Test that we update the existing baseline in the platform-specific
# directory if the new baseline is different, without existing fallback
# baseline (which should not matter).
host = MockHost()
host.filesystem.write_text_file(
test.LAYOUT_TEST_DIR +
'/platform/test-mac-mac10.10/failures/unexpected/text-image-checksum-expected.png',
'wrong-png-baseline')
host.filesystem.remove(
test.LAYOUT_TEST_DIR + '/failures/unexpected/text-image-checksum-expected.png')
details, log_stream, _ = logging_run(
[
'--reset-results',
'failures/unexpected/text-image-checksum.html'
],
tests_included=True, host=host)
file_list = host.filesystem.written_files.keys()
self.assertEqual(details.exit_code, 0)
self.assertEqual(len(file_list), 8)
# We should reset the platform image baseline.
self.assert_baselines(
file_list, log_stream,
'platform/test-mac-mac10.10/failures/unexpected/text-image-checksum',
expected_extensions=['.png'])
def test_new_virtual_baseline_optimize(self):
# Test removing existing baselines under flag-specific directory if the
# actual results are the same as the fallback baselines.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment