• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Copyright 2022 The Chromium Authors
2# Use of this source code is governed by a BSD-style license that can be
3# found in the LICENSE file.
4
5import logging
6import sys
7from .finch_skia_gold_properties import FinchSkiaGoldProperties
8from .finch_skia_gold_session_manager import FinchSkiaGoldSessionManager
9
10# This is the corpus used by skia gold to identify the data set.
11# We are not using the same corpus as the rest of the skia gold chromium tests.
12# This corpus is a dedicated one for finch smoke tests.
13CORPUS = 'finch-smoke-tests'
14
15
16class FinchSkiaGoldUtil:
17  def __init__(self, temp_dir, args):
18    self._skia_gold_properties = FinchSkiaGoldProperties(args)
19    self._skia_gold_session_manager = FinchSkiaGoldSessionManager(
20        temp_dir, self._skia_gold_properties)
21    self._skia_gold_session = self._GetSkiaGoldSession()
22    self._retry_without_patch = False
23    if args.isolated_script_test_filter:
24      self._retry_without_patch = True
25
26  @property
27  def SkiaGoldProperties(self):
28    return self._skia_gold_properties
29
30  @property
31  def SkiaGoldSessionManager(self):
32    return self._skia_gold_session_manager
33
34  @property
35  def SkiaGoldSession(self):
36    return self._skia_gold_session
37
38  @property
39  def IsTryjobRun(self):
40    return self._skia_gold_properties.IsTryjobRun()
41
42  @property
43  def IsRetryWithoutPatch(self):
44    return self._retry_without_patch
45
46  def _GetSkiaGoldSession(self):
47    """Returns a SkiaGoldSession from the given session_manager.
48
49    Returns:
50      a SkiaGoldSession object.
51    """
52    key_input = {}
53    key_input['platform'] = _get_platform()
54    return self._skia_gold_session_manager.GetSkiaGoldSession(
55        key_input, CORPUS)
56
57
58def _get_platform():
59  """Returns the host platform.
60
61  Returns:
62    One of 'linux', 'win' and 'mac'.
63  """
64  if sys.platform == 'win32' or sys.platform == 'cygwin':
65    return 'win'
66  if sys.platform.startswith('linux'):
67    return 'linux'
68  if sys.platform == 'darwin':
69    return 'mac'
70
71  raise RuntimeError(
72    'Unsupported platform: %s. Only Linux (linux*) and Mac (darwin) and '
73    'Windows (win32 or cygwin) are supported' % sys.platform)
74
75
76def _output_local_diff_files(skia_gold_session, image_name):
77  """Logs the local diff image files from the given SkiaGoldSession
78
79  Args:
80    skia_gold_session: A SkiaGoldSession instance to pull files
81        from.
82    image_name: A string containing the name of the image/test that was
83        compared.
84
85  Returns:
86    None
87  """
88  given_file = skia_gold_session.GetGivenImageLink(image_name)
89  closest_file = skia_gold_session.GetClosestImageLink(image_name)
90  diff_file = skia_gold_session.GetDiffImageLink(image_name)
91  failure_message = 'Unable to retrieve link'
92  logging.error('Generated image: %s', given_file or failure_message)
93  logging.error('Closest image: %s', closest_file or failure_message)
94  logging.error('Diff image: %s', diff_file or failure_message)
95
96
97def log_skia_gold_status_code(skia_gold_session, image_name, status, error):
98  """Checks the skia gold status code and logs more detailed message
99
100  Args:
101    skia_gold_session: A SkiaGoldSession object.
102    image_name: The name of the image file.
103    status: A StatusCodes returned from RunComparison.
104    error: An error message describing the status if not successful
105
106  Returns:
107    A link to a triage page if there are images to triage, otherwise None
108  """
109  triage_link = None
110  status_codes = skia_gold_session.StatusCodes
111  if status in (status_codes.AUTH_FAILURE, status_codes.INIT_FAILURE):
112    logging.error('Gold failed with code %d output %s', status, error)
113  elif status == status_codes.COMPARISON_FAILURE_REMOTE:
114    _, triage_link = skia_gold_session.GetTriageLinks(image_name)
115    if not triage_link:
116      logging.error('Failed to get triage link for %s, raw output: %s',
117                    image_name, error)
118      logging.error('Reason for no triage link: %s',
119                    skia_gold_session.GetTriageLinkOmissionReason(image_name))
120    else:
121      logging.warning('triage link: %s', triage_link)
122  elif status == status_codes.COMPARISON_FAILURE_LOCAL:
123    logging.error('Local comparison failed. Local diff files:')
124    _output_local_diff_files(skia_gold_session, image_name)
125  elif status == status_codes.LOCAL_DIFF_FAILURE:
126    logging.error(
127        'Local comparison failed and an error occurred during diff '
128        'generation: %s', error)
129    # There might be some files, so try outputting them.
130    logging.error('Local diff files:')
131    _output_local_diff_files(skia_gold_session, image_name)
132  else:
133    logging.error(
134        'Given unhandled SkiaGoldSession StatusCode %s with error %s', status,
135        error)
136  return triage_link
137