rebaselineserver_unittest.py 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. # Copyright (C) 2010 Google Inc. All rights reserved.
  2. #
  3. # Redistribution and use in source and binary forms, with or without
  4. # modification, are permitted provided that the following conditions are
  5. # met:
  6. #
  7. # * Redistributions of source code must retain the above copyright
  8. # notice, this list of conditions and the following disclaimer.
  9. # * Redistributions in binary form must reproduce the above
  10. # copyright notice, this list of conditions and the following disclaimer
  11. # in the documentation and/or other materials provided with the
  12. # distribution.
  13. # * Neither the name of Google Inc. nor the names of its
  14. # contributors may be used to endorse or promote products derived from
  15. # this software without specific prior written permission.
  16. #
  17. # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  18. # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  19. # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  20. # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  21. # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  22. # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  24. # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  25. # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  26. # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  27. # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  28. import json
  29. import unittest2 as unittest
  30. from webkitpy.common.net import resultsjsonparser_unittest
  31. from webkitpy.common.host_mock import MockHost
  32. from webkitpy.layout_tests.layout_package.json_results_generator import strip_json_wrapper
  33. from webkitpy.port.base import Port
  34. from webkitpy.tool.commands.rebaselineserver import TestConfig, RebaselineServer
  35. from webkitpy.tool.servers import rebaselineserver
  36. class RebaselineTestTest(unittest.TestCase):
  37. def test_text_rebaseline_update(self):
  38. self._assertRebaseline(
  39. test_files=(
  40. 'fast/text-expected.txt',
  41. 'platform/mac/fast/text-expected.txt',
  42. ),
  43. results_files=(
  44. 'fast/text-actual.txt',
  45. ),
  46. test_name='fast/text.html',
  47. baseline_target='mac',
  48. baseline_move_to='none',
  49. expected_success=True,
  50. expected_log=[
  51. 'Rebaselining fast/text...',
  52. ' Updating baselines for mac',
  53. ' Updated text-expected.txt',
  54. ])
  55. def test_text_rebaseline_new(self):
  56. self._assertRebaseline(
  57. test_files=(
  58. 'fast/text-expected.txt',
  59. ),
  60. results_files=(
  61. 'fast/text-actual.txt',
  62. ),
  63. test_name='fast/text.html',
  64. baseline_target='mac',
  65. baseline_move_to='none',
  66. expected_success=True,
  67. expected_log=[
  68. 'Rebaselining fast/text...',
  69. ' Updating baselines for mac',
  70. ' Updated text-expected.txt',
  71. ])
  72. def test_text_rebaseline_move_no_op_1(self):
  73. self._assertRebaseline(
  74. test_files=(
  75. 'fast/text-expected.txt',
  76. 'platform/win/fast/text-expected.txt',
  77. ),
  78. results_files=(
  79. 'fast/text-actual.txt',
  80. ),
  81. test_name='fast/text.html',
  82. baseline_target='mac',
  83. baseline_move_to='mac-leopard',
  84. expected_success=True,
  85. expected_log=[
  86. 'Rebaselining fast/text...',
  87. ' Updating baselines for mac',
  88. ' Updated text-expected.txt',
  89. ])
  90. def test_text_rebaseline_move_no_op_2(self):
  91. self._assertRebaseline(
  92. test_files=(
  93. 'fast/text-expected.txt',
  94. 'platform/mac/fast/text-expected.checksum',
  95. ),
  96. results_files=(
  97. 'fast/text-actual.txt',
  98. ),
  99. test_name='fast/text.html',
  100. baseline_target='mac',
  101. baseline_move_to='mac-leopard',
  102. expected_success=True,
  103. expected_log=[
  104. 'Rebaselining fast/text...',
  105. ' Moving current mac baselines to mac-leopard',
  106. ' No current baselines to move',
  107. ' Updating baselines for mac',
  108. ' Updated text-expected.txt',
  109. ])
  110. def test_text_rebaseline_move(self):
  111. self._assertRebaseline(
  112. test_files=(
  113. 'fast/text-expected.txt',
  114. 'platform/mac/fast/text-expected.txt',
  115. ),
  116. results_files=(
  117. 'fast/text-actual.txt',
  118. ),
  119. test_name='fast/text.html',
  120. baseline_target='mac',
  121. baseline_move_to='mac-leopard',
  122. expected_success=True,
  123. expected_log=[
  124. 'Rebaselining fast/text...',
  125. ' Moving current mac baselines to mac-leopard',
  126. ' Moved text-expected.txt',
  127. ' Updating baselines for mac',
  128. ' Updated text-expected.txt',
  129. ])
  130. def test_text_rebaseline_move_only_images(self):
  131. self._assertRebaseline(
  132. test_files=(
  133. 'fast/image-expected.txt',
  134. 'platform/mac/fast/image-expected.txt',
  135. 'platform/mac/fast/image-expected.png',
  136. 'platform/mac/fast/image-expected.checksum',
  137. ),
  138. results_files=(
  139. 'fast/image-actual.png',
  140. 'fast/image-actual.checksum',
  141. ),
  142. test_name='fast/image.html',
  143. baseline_target='mac',
  144. baseline_move_to='mac-leopard',
  145. expected_success=True,
  146. expected_log=[
  147. 'Rebaselining fast/image...',
  148. ' Moving current mac baselines to mac-leopard',
  149. ' Moved image-expected.checksum',
  150. ' Moved image-expected.png',
  151. ' Updating baselines for mac',
  152. ' Updated image-expected.checksum',
  153. ' Updated image-expected.png',
  154. ])
  155. def test_text_rebaseline_move_already_exist(self):
  156. self._assertRebaseline(
  157. test_files=(
  158. 'fast/text-expected.txt',
  159. 'platform/mac-leopard/fast/text-expected.txt',
  160. 'platform/mac/fast/text-expected.txt',
  161. ),
  162. results_files=(
  163. 'fast/text-actual.txt',
  164. ),
  165. test_name='fast/text.html',
  166. baseline_target='mac',
  167. baseline_move_to='mac-leopard',
  168. expected_success=False,
  169. expected_log=[
  170. 'Rebaselining fast/text...',
  171. ' Moving current mac baselines to mac-leopard',
  172. ' Already had baselines in mac-leopard, could not move existing mac ones',
  173. ])
  174. def test_image_rebaseline(self):
  175. self._assertRebaseline(
  176. test_files=(
  177. 'fast/image-expected.txt',
  178. 'platform/mac/fast/image-expected.png',
  179. 'platform/mac/fast/image-expected.checksum',
  180. ),
  181. results_files=(
  182. 'fast/image-actual.png',
  183. 'fast/image-actual.checksum',
  184. ),
  185. test_name='fast/image.html',
  186. baseline_target='mac',
  187. baseline_move_to='none',
  188. expected_success=True,
  189. expected_log=[
  190. 'Rebaselining fast/image...',
  191. ' Updating baselines for mac',
  192. ' Updated image-expected.checksum',
  193. ' Updated image-expected.png',
  194. ])
  195. def test_gather_baselines(self):
  196. example_json = resultsjsonparser_unittest.ResultsJSONParserTest._example_full_results_json
  197. results_json = json.loads(strip_json_wrapper(example_json))
  198. server = RebaselineServer()
  199. server._test_config = get_test_config()
  200. server._gather_baselines(results_json)
  201. self.assertEqual(results_json['tests']['svg/dynamic-updates/SVGFEDropShadowElement-dom-stdDeviation-attr.html']['state'], 'needs_rebaseline')
  202. self.assertNotIn('prototype-chocolate.html', results_json['tests'])
  203. def _assertRebaseline(self, test_files, results_files, test_name, baseline_target, baseline_move_to, expected_success, expected_log):
  204. log = []
  205. test_config = get_test_config(test_files, results_files)
  206. success = rebaselineserver._rebaseline_test(
  207. test_name,
  208. baseline_target,
  209. baseline_move_to,
  210. test_config,
  211. log=lambda l: log.append(l))
  212. self.assertEqual(expected_log, log)
  213. self.assertEqual(expected_success, success)
  214. class GetActualResultFilesTest(unittest.TestCase):
  215. def test(self):
  216. test_config = get_test_config(result_files=(
  217. 'fast/text-actual.txt',
  218. 'fast2/text-actual.txt',
  219. 'fast/text2-actual.txt',
  220. 'fast/text-notactual.txt',
  221. ))
  222. self.assertItemsEqual(
  223. ('text-actual.txt',),
  224. rebaselineserver._get_actual_result_files(
  225. 'fast/text.html', test_config))
  226. class GetBaselinesTest(unittest.TestCase):
  227. def test_no_baselines(self):
  228. self._assertBaselines(
  229. test_files=(),
  230. test_name='fast/missing.html',
  231. expected_baselines={})
  232. def test_text_baselines(self):
  233. self._assertBaselines(
  234. test_files=(
  235. 'fast/text-expected.txt',
  236. 'platform/mac/fast/text-expected.txt',
  237. ),
  238. test_name='fast/text.html',
  239. expected_baselines={
  240. 'mac': {'.txt': True},
  241. 'base': {'.txt': False},
  242. })
  243. def test_image_and_text_baselines(self):
  244. self._assertBaselines(
  245. test_files=(
  246. 'fast/image-expected.txt',
  247. 'platform/mac/fast/image-expected.png',
  248. 'platform/mac/fast/image-expected.checksum',
  249. 'platform/win/fast/image-expected.png',
  250. 'platform/win/fast/image-expected.checksum',
  251. ),
  252. test_name='fast/image.html',
  253. expected_baselines={
  254. 'base': {'.txt': True},
  255. 'mac': {'.checksum': True, '.png': True},
  256. 'win': {'.checksum': False, '.png': False},
  257. })
  258. def test_extra_baselines(self):
  259. self._assertBaselines(
  260. test_files=(
  261. 'fast/text-expected.txt',
  262. 'platform/nosuchplatform/fast/text-expected.txt',
  263. ),
  264. test_name='fast/text.html',
  265. expected_baselines={'base': {'.txt': True}})
  266. def _assertBaselines(self, test_files, test_name, expected_baselines):
  267. actual_baselines = rebaselineserver.get_test_baselines(test_name, get_test_config(test_files))
  268. self.assertEqual(expected_baselines, actual_baselines)
  269. def get_test_config(test_files=[], result_files=[]):
  270. # We could grab this from port.layout_tests_dir(), but instantiating a fully mocked port is a pain.
  271. layout_tests_directory = "/mock-checkout/LayoutTests"
  272. results_directory = '/WebKitBuild/Debug/layout-test-results'
  273. host = MockHost()
  274. for file in test_files:
  275. host.filesystem.write_binary_file(host.filesystem.join(layout_tests_directory, file), '')
  276. for file in result_files:
  277. host.filesystem.write_binary_file(host.filesystem.join(results_directory, file), '')
  278. class TestMacPort(Port):
  279. port_name = "mac"
  280. return TestConfig(
  281. TestMacPort(host, 'mac'),
  282. layout_tests_directory,
  283. results_directory,
  284. ('mac', 'mac-leopard', 'win', 'linux'),
  285. host.filesystem,
  286. host.scm())