finch_skia_gold_utils.py 4.6 KB

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