cbda1998065a3c7b7c976890c033da41e856c2b9
[WebKit-https.git] / Tools / Scripts / webkitpy / layout_tests / models / test_run_results_unittest.py
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
29 import unittest
30
31 from webkitpy.common.host_mock import MockHost
32 from webkitpy.layout_tests.models import test_expectations
33 from webkitpy.layout_tests.models import test_failures
34 from webkitpy.layout_tests.models import test_results
35 from webkitpy.layout_tests.models import test_run_results
36
37
38 def get_result(test_name, result_type=test_expectations.PASS, run_time=0):
39     failures = []
40     if result_type == test_expectations.TIMEOUT:
41         failures = [test_failures.FailureTimeout()]
42     elif result_type == test_expectations.AUDIO:
43         failures = [test_failures.FailureAudioMismatch()]
44     elif result_type == test_expectations.CRASH:
45         failures = [test_failures.FailureCrash()]
46     elif result_type == test_expectations.LEAK:
47         failures = [test_failures.FailureDocumentLeak(['http://localhost:8000/failures/expected/leak.html'])]
48     return test_results.TestResult(test_name, failures=failures, test_run_time=run_time)
49
50
51 def run_results(port):
52     tests = ['passes/text.html', 'failures/expected/timeout.html', 'failures/expected/crash.html', 'failures/expected/hang.html',
53              'failures/expected/audio.html', 'failures/expected/leak.html']
54     expectations = test_expectations.TestExpectations(port, tests)
55     expectations.parse_all_expectations()
56     return test_run_results.TestRunResults(expectations, len(tests))
57
58
59 def summarized_results(port, expected, passing, flaky, include_passes=False):
60     test_is_slow = False
61
62     initial_results = run_results(port)
63     if expected:
64         initial_results.add(get_result('passes/text.html', test_expectations.PASS), expected, test_is_slow)
65         initial_results.add(get_result('failures/expected/audio.html', test_expectations.AUDIO), expected, test_is_slow)
66         initial_results.add(get_result('failures/expected/timeout.html', test_expectations.TIMEOUT), expected, test_is_slow)
67         initial_results.add(get_result('failures/expected/crash.html', test_expectations.CRASH), expected, test_is_slow)
68         initial_results.add(get_result('failures/expected/leak.html', test_expectations.LEAK), expected, test_is_slow)
69     elif passing:
70         initial_results.add(get_result('passes/text.html'), expected, test_is_slow)
71         initial_results.add(get_result('failures/expected/audio.html'), expected, test_is_slow)
72         initial_results.add(get_result('failures/expected/timeout.html'), expected, test_is_slow)
73         initial_results.add(get_result('failures/expected/crash.html'), expected, test_is_slow)
74         initial_results.add(get_result('failures/expected/leak.html'), expected, test_is_slow)
75     else:
76         initial_results.add(get_result('passes/text.html', test_expectations.TIMEOUT), expected, test_is_slow)
77         initial_results.add(get_result('failures/expected/audio.html', test_expectations.AUDIO), expected, test_is_slow)
78         initial_results.add(get_result('failures/expected/timeout.html', test_expectations.CRASH), expected, test_is_slow)
79         initial_results.add(get_result('failures/expected/crash.html', test_expectations.TIMEOUT), expected, test_is_slow)
80         initial_results.add(get_result('failures/expected/leak.html', test_expectations.CRASH), expected, test_is_slow)
81
82         # we only list hang.html here, since normally this is WontFix
83         initial_results.add(get_result('failures/expected/hang.html', test_expectations.TIMEOUT), expected, test_is_slow)
84
85     if flaky:
86         retry_results = run_results(port)
87         retry_results.add(get_result('passes/text.html'), True, test_is_slow)
88         retry_results.add(get_result('failures/expected/timeout.html'), True, test_is_slow)
89         retry_results.add(get_result('failures/expected/crash.html'), True, test_is_slow)
90         retry_results.add(get_result('failures/expected/leak.html'), True, test_is_slow)
91     else:
92         retry_results = None
93
94     return test_run_results.summarize_results(port, initial_results.expectations, initial_results, retry_results,
95         enabled_pixel_tests_in_retry=False, include_passes=include_passes)
96
97
98 class InterpretTestFailuresTest(unittest.TestCase):
99     def setUp(self):
100         host = MockHost()
101         self.port = host.port_factory.get(port_name='test')
102
103     def test_interpret_test_failures(self):
104         test_dict = test_run_results._interpret_test_failures([test_failures.FailureImageHashMismatch(diff_percent=0.42)])
105         self.assertEqual(test_dict['image_diff_percent'], 0.42)
106
107         test_dict = test_run_results._interpret_test_failures([test_failures.FailureReftestMismatch(self.port.abspath_for_test('foo/reftest-expected.html'))])
108         self.assertIn('image_diff_percent', test_dict)
109
110         test_dict = test_run_results._interpret_test_failures([test_failures.FailureReftestMismatchDidNotOccur(self.port.abspath_for_test('foo/reftest-expected-mismatch.html'))])
111         self.assertEqual(len(test_dict), 0)
112
113         test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingAudio()])
114         self.assertIn('is_missing_audio', test_dict)
115
116         test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingResult()])
117         self.assertIn('is_missing_text', test_dict)
118
119         test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingImage()])
120         self.assertIn('is_missing_image', test_dict)
121
122         test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingImageHash()])
123         self.assertIn('is_missing_image', test_dict)
124
125
126 class SummarizedResultsTest(unittest.TestCase):
127     def setUp(self):
128         host = MockHost(initialize_scm_by_default=False)
129         self.port = host.port_factory.get(port_name='test')
130
131     def test_no_svn_revision(self):
132         summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
133         self.assertNotIn('revision', summary)
134
135     def test_svn_revision(self):
136         self.port._options.builder_name = 'dummy builder'
137         summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
138         self.assertNotEquals(summary['revision'], '')
139
140     def test_summarized_results_wontfix(self):
141         self.port._options.builder_name = 'dummy builder'
142         summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
143         self.assertTrue(summary['tests']['failures']['expected']['hang.html']['wontfix'])
144
145     def test_summarized_results_include_passes(self):
146         self.port._options.builder_name = 'dummy builder'
147         summary = summarized_results(self.port, expected=False, passing=True, flaky=False, include_passes=True)
148         self.assertEqual(summary['tests']['passes']['text.html']['expected'], 'PASS')