test_run_results_unittest.py 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  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 unittest2 as unittest
  29. from webkitpy.common.host_mock import MockHost
  30. from webkitpy.layout_tests.models import test_expectations
  31. from webkitpy.layout_tests.models import test_failures
  32. from webkitpy.layout_tests.models import test_results
  33. from webkitpy.layout_tests.models import test_run_results
  34. def get_result(test_name, result_type=test_expectations.PASS, run_time=0):
  35. failures = []
  36. if result_type == test_expectations.TIMEOUT:
  37. failures = [test_failures.FailureTimeout()]
  38. elif result_type == test_expectations.AUDIO:
  39. failures = [test_failures.FailureAudioMismatch()]
  40. elif result_type == test_expectations.CRASH:
  41. failures = [test_failures.FailureCrash()]
  42. return test_results.TestResult(test_name, failures=failures, test_run_time=run_time)
  43. def run_results(port):
  44. tests = ['passes/text.html', 'failures/expected/timeout.html', 'failures/expected/crash.html', 'failures/expected/hang.html',
  45. 'failures/expected/audio.html']
  46. expectations = test_expectations.TestExpectations(port, tests)
  47. return test_run_results.TestRunResults(expectations, len(tests))
  48. def summarized_results(port, expected, passing, flaky):
  49. test_is_slow = False
  50. initial_results = run_results(port)
  51. if expected:
  52. initial_results.add(get_result('passes/text.html', test_expectations.PASS), expected, test_is_slow)
  53. initial_results.add(get_result('failures/expected/audio.html', test_expectations.AUDIO), expected, test_is_slow)
  54. initial_results.add(get_result('failures/expected/timeout.html', test_expectations.TIMEOUT), expected, test_is_slow)
  55. initial_results.add(get_result('failures/expected/crash.html', test_expectations.CRASH), expected, test_is_slow)
  56. elif passing:
  57. initial_results.add(get_result('passes/text.html'), expected, test_is_slow)
  58. initial_results.add(get_result('failures/expected/audio.html'), expected, test_is_slow)
  59. initial_results.add(get_result('failures/expected/timeout.html'), expected, test_is_slow)
  60. initial_results.add(get_result('failures/expected/crash.html'), expected, test_is_slow)
  61. else:
  62. initial_results.add(get_result('passes/text.html', test_expectations.TIMEOUT), expected, test_is_slow)
  63. initial_results.add(get_result('failures/expected/audio.html', test_expectations.AUDIO), expected, test_is_slow)
  64. initial_results.add(get_result('failures/expected/timeout.html', test_expectations.CRASH), expected, test_is_slow)
  65. initial_results.add(get_result('failures/expected/crash.html', test_expectations.TIMEOUT), expected, test_is_slow)
  66. # we only list hang.html here, since normally this is WontFix
  67. initial_results.add(get_result('failures/expected/hang.html', test_expectations.TIMEOUT), expected, test_is_slow)
  68. if flaky:
  69. retry_results = run_results(port)
  70. retry_results.add(get_result('passes/text.html'), True, test_is_slow)
  71. retry_results.add(get_result('failures/expected/timeout.html'), True, test_is_slow)
  72. retry_results.add(get_result('failures/expected/crash.html'), True, test_is_slow)
  73. else:
  74. retry_results = None
  75. return test_run_results.summarize_results(port, initial_results.expectations, initial_results, retry_results, enabled_pixel_tests_in_retry=False)
  76. class InterpretTestFailuresTest(unittest.TestCase):
  77. def setUp(self):
  78. host = MockHost()
  79. self.port = host.port_factory.get(port_name='test')
  80. def test_interpret_test_failures(self):
  81. test_dict = test_run_results._interpret_test_failures([test_failures.FailureImageHashMismatch(diff_percent=0.42)])
  82. self.assertEqual(test_dict['image_diff_percent'], 0.42)
  83. test_dict = test_run_results._interpret_test_failures([test_failures.FailureReftestMismatch(self.port.abspath_for_test('foo/reftest-expected.html'))])
  84. self.assertIn('image_diff_percent', test_dict)
  85. test_dict = test_run_results._interpret_test_failures([test_failures.FailureReftestMismatchDidNotOccur(self.port.abspath_for_test('foo/reftest-expected-mismatch.html'))])
  86. self.assertEqual(len(test_dict), 0)
  87. test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingAudio()])
  88. self.assertIn('is_missing_audio', test_dict)
  89. test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingResult()])
  90. self.assertIn('is_missing_text', test_dict)
  91. test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingImage()])
  92. self.assertIn('is_missing_image', test_dict)
  93. test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingImageHash()])
  94. self.assertIn('is_missing_image', test_dict)
  95. class SummarizedResultsTest(unittest.TestCase):
  96. def setUp(self):
  97. host = MockHost(initialize_scm_by_default=False)
  98. self.port = host.port_factory.get(port_name='test')
  99. def test_no_svn_revision(self):
  100. summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
  101. self.assertNotIn('revision', summary)
  102. def test_svn_revision(self):
  103. self.port._options.builder_name = 'dummy builder'
  104. summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
  105. self.assertNotEquals(summary['revision'], '')
  106. def test_summarized_results_wontfix(self):
  107. self.port._options.builder_name = 'dummy builder'
  108. summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
  109. self.assertTrue(summary['tests']['failures']['expected']['hang.html']['wontfix'])