initial import
[vuplus_webkit] / Tools / Scripts / webkitpy / common / net / failuremap.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
30 # FIXME: This probably belongs in the buildbot module.
31 class FailureMap(object):
32     def __init__(self):
33         self._failures = []
34
35     def add_regression_window(self, builder, regression_window):
36         self._failures.append({
37             'builder': builder,
38             'regression_window': regression_window,
39         })
40
41     def is_empty(self):
42         return not self._failures
43
44     def failing_revisions(self):
45         failing_revisions = [failure_info['regression_window'].revisions()
46                              for failure_info in self._failures]
47         return sorted(set(sum(failing_revisions, [])))
48
49     def builders_failing_for(self, revision):
50         return self._builders_failing_because_of([revision])
51
52     def tests_failing_for(self, revision):
53         tests = [failure_info['regression_window'].failing_tests()
54                  for failure_info in self._failures
55                  if revision in failure_info['regression_window'].revisions()
56                     and failure_info['regression_window'].failing_tests()]
57         result = set()
58         for test in tests:
59             result = result.union(test)
60         return sorted(result)
61
62     def failing_tests(self):
63         return set(sum([self.tests_failing_for(revision) for revision in self.failing_revisions()], []))
64
65     def _old_failures(self, is_old_failure):
66         return filter(lambda revision: is_old_failure(revision),
67                       self.failing_revisions())
68
69     def _builders_failing_because_of(self, revisions):
70         revision_set = set(revisions)
71         return [failure_info['builder'] for failure_info in self._failures
72                 if revision_set.intersection(
73                     failure_info['regression_window'].revisions())]
74
75     # FIXME: We should re-process old failures after some time delay.
76     # https://bugs.webkit.org/show_bug.cgi?id=36581
77     def filter_out_old_failures(self, is_old_failure):
78         old_failures = self._old_failures(is_old_failure)
79         old_failing_builder_names = set([builder.name()
80             for builder in self._builders_failing_because_of(old_failures)])
81
82         # We filter out all the failing builders that could have been caused
83         # by old_failures.  We could miss some new failures this way, but
84         # emperically, this reduces the amount of spam we generate.
85         failures = self._failures
86         self._failures = [failure_info for failure_info in failures
87             if failure_info['builder'].name() not in old_failing_builder_names]
88         self._cache = {}