c0d9265f07db11ead09b3aebab91afd85aa93bad
[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 unittest2 as 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     return test_results.TestResult(test_name, failures=failures, test_run_time=run_time)
47
48
49 def run_results(port):
50     tests = ['passes/text.html', 'failures/expected/timeout.html', 'failures/expected/crash.html', 'failures/expected/hang.html',
51              'failures/expected/audio.html']
52     expectations = test_expectations.TestExpectations(port, tests)
53     return test_run_results.TestRunResults(expectations, len(tests))
54
55
56 def summarized_results(port, expected, passing, flaky):
57     test_is_slow = False
58
59     initial_results = run_results(port)
60     if expected:
61         initial_results.add(get_result('passes/text.html', test_expectations.PASS), expected, test_is_slow)
62         initial_results.add(get_result('failures/expected/audio.html', test_expectations.AUDIO), expected, test_is_slow)
63         initial_results.add(get_result('failures/expected/timeout.html', test_expectations.TIMEOUT), expected, test_is_slow)
64         initial_results.add(get_result('failures/expected/crash.html', test_expectations.CRASH), expected, test_is_slow)
65     elif passing:
66         initial_results.add(get_result('passes/text.html'), expected, test_is_slow)
67         initial_results.add(get_result('failures/expected/audio.html'), expected, test_is_slow)
68         initial_results.add(get_result('failures/expected/timeout.html'), expected, test_is_slow)
69         initial_results.add(get_result('failures/expected/crash.html'), expected, test_is_slow)
70     else:
71         initial_results.add(get_result('passes/text.html', test_expectations.TIMEOUT), expected, test_is_slow)
72         initial_results.add(get_result('failures/expected/audio.html', test_expectations.AUDIO), expected, test_is_slow)
73         initial_results.add(get_result('failures/expected/timeout.html', test_expectations.CRASH), expected, test_is_slow)
74         initial_results.add(get_result('failures/expected/crash.html', test_expectations.TIMEOUT), expected, test_is_slow)
75
76         # we only list hang.html here, since normally this is WontFix
77         initial_results.add(get_result('failures/expected/hang.html', test_expectations.TIMEOUT), expected, test_is_slow)
78
79     if flaky:
80         retry_results = run_results(port)
81         retry_results.add(get_result('passes/text.html'), True, test_is_slow)
82         retry_results.add(get_result('failures/expected/timeout.html'), True, test_is_slow)
83         retry_results.add(get_result('failures/expected/crash.html'), True, test_is_slow)
84     else:
85         retry_results = None
86
87     return test_run_results.summarize_results(port, initial_results.expectations, initial_results, retry_results, enabled_pixel_tests_in_retry=False)
88
89
90 class InterpretTestFailuresTest(unittest.TestCase):
91     def setUp(self):
92         host = MockHost()
93         self.port = host.port_factory.get(port_name='test')
94
95     def test_interpret_test_failures(self):
96         test_dict = test_run_results._interpret_test_failures([test_failures.FailureImageHashMismatch(diff_percent=0.42)])
97         self.assertEqual(test_dict['image_diff_percent'], 0.42)
98
99         test_dict = test_run_results._interpret_test_failures([test_failures.FailureReftestMismatch(self.port.abspath_for_test('foo/reftest-expected.html'))])
100         self.assertIn('image_diff_percent', test_dict)
101
102         test_dict = test_run_results._interpret_test_failures([test_failures.FailureReftestMismatchDidNotOccur(self.port.abspath_for_test('foo/reftest-expected-mismatch.html'))])
103         self.assertEqual(len(test_dict), 0)
104
105         test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingAudio()])
106         self.assertIn('is_missing_audio', test_dict)
107
108         test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingResult()])
109         self.assertIn('is_missing_text', test_dict)
110
111         test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingImage()])
112         self.assertIn('is_missing_image', test_dict)
113
114         test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingImageHash()])
115         self.assertIn('is_missing_image', test_dict)
116
117
118 class SummarizedResultsTest(unittest.TestCase):
119     def setUp(self):
120         host = MockHost(initialize_scm_by_default=False)
121         self.port = host.port_factory.get(port_name='test')
122
123     def test_no_svn_revision(self):
124         summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
125         self.assertNotIn('revision', summary)
126
127     def test_svn_revision(self):
128         self.port._options.builder_name = 'dummy builder'
129         summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
130         self.assertNotEquals(summary['revision'], '')
131
132     def test_summarized_results_wontfix(self):
133         self.port._options.builder_name = 'dummy builder'
134         summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
135         self.assertTrue(summary['tests']['failures']['expected']['hang.html']['wontfix'])