NRWT: Add the ability to upload test results to new test results server
[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, include_passes=False):
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,
88         enabled_pixel_tests_in_retry=False, include_passes=include_passes)
89
90
91 class InterpretTestFailuresTest(unittest.TestCase):
92     def setUp(self):
93         host = MockHost()
94         self.port = host.port_factory.get(port_name='test')
95
96     def test_interpret_test_failures(self):
97         test_dict = test_run_results._interpret_test_failures([test_failures.FailureImageHashMismatch(diff_percent=0.42)])
98         self.assertEqual(test_dict['image_diff_percent'], 0.42)
99
100         test_dict = test_run_results._interpret_test_failures([test_failures.FailureReftestMismatch(self.port.abspath_for_test('foo/reftest-expected.html'))])
101         self.assertIn('image_diff_percent', test_dict)
102
103         test_dict = test_run_results._interpret_test_failures([test_failures.FailureReftestMismatchDidNotOccur(self.port.abspath_for_test('foo/reftest-expected-mismatch.html'))])
104         self.assertEqual(len(test_dict), 0)
105
106         test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingAudio()])
107         self.assertIn('is_missing_audio', test_dict)
108
109         test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingResult()])
110         self.assertIn('is_missing_text', test_dict)
111
112         test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingImage()])
113         self.assertIn('is_missing_image', test_dict)
114
115         test_dict = test_run_results._interpret_test_failures([test_failures.FailureMissingImageHash()])
116         self.assertIn('is_missing_image', test_dict)
117
118
119 class SummarizedResultsTest(unittest.TestCase):
120     def setUp(self):
121         host = MockHost(initialize_scm_by_default=False)
122         self.port = host.port_factory.get(port_name='test')
123
124     def test_no_svn_revision(self):
125         summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
126         self.assertNotIn('revision', summary)
127
128     def test_svn_revision(self):
129         self.port._options.builder_name = 'dummy builder'
130         summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
131         self.assertNotEquals(summary['revision'], '')
132
133     def test_summarized_results_wontfix(self):
134         self.port._options.builder_name = 'dummy builder'
135         summary = summarized_results(self.port, expected=False, passing=False, flaky=False)
136         self.assertTrue(summary['tests']['failures']['expected']['hang.html']['wontfix'])
137
138     def test_summarized_results_include_passes(self):
139         self.port._options.builder_name = 'dummy builder'
140         summary = summarized_results(self.port, expected=False, passing=True, flaky=False, include_passes=True)
141         self.assertEqual(summary['tests']['passes']['text.html']['expected'], 'PASS')