chromeos: bluetooth: add BluetoothInputClient
[chromium-blink-merge.git] / tools / valgrind / test_suppressions.py
blobd9a6cb47031a3d3eaaadbed040f01c4a1b6a33ff
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 # Use of this source code is governed by a BSD-style license that can be
3 # found in the LICENSE file.
5 from collections import defaultdict
6 import os
7 import re
8 import sys
10 import path_utils
12 import suppressions
15 def ReadReportsFromFile(filename):
16 """ Returns a list of (report_hash, report) and the URL of the report on the
17 waterfall.
18 """
19 input_file = file(filename, 'r')
20 # reports is a list of (error hash, report) pairs.
21 reports = []
22 in_suppression = False
23 cur_supp = []
24 # This stores the last error hash found while reading the file.
25 last_hash = ""
26 for line in input_file:
27 line = line.strip()
28 line = line.replace("</span><span class=\"stdout\">", "")
29 line = line.replace("</span><span class=\"stderr\">", "")
30 line = line.replace("&lt;", "<")
31 line = line.replace("&gt;", ">")
32 if in_suppression:
33 if line == "}":
34 cur_supp += ["}"]
35 reports += [[last_hash, "\n".join(cur_supp)]]
36 in_suppression = False
37 cur_supp = []
38 last_hash = ""
39 else:
40 cur_supp += [" "*3 + line]
41 elif line == "{":
42 in_suppression = True
43 cur_supp = ["{"]
44 elif line.find("Suppression (error hash=#") == 0:
45 last_hash = line[25:41]
46 # The line at the end of the file is assumed to store the URL of the report.
47 return reports,line
50 def main(argv):
51 suppressions_root = path_utils.ScriptDir()
52 JOIN = os.path.join
54 supp_filename = JOIN(suppressions_root, "memcheck", "suppressions.txt")
55 vg_common = suppressions.ReadSuppressionsFromFile(supp_filename)
56 supp_filename = JOIN(suppressions_root, "tsan", "suppressions.txt")
57 tsan_common = suppressions.ReadSuppressionsFromFile(supp_filename)
58 common_suppressions = vg_common + tsan_common
60 supp_filename = JOIN(suppressions_root, "memcheck", "suppressions_mac.txt")
61 vg_mac = suppressions.ReadSuppressionsFromFile(supp_filename)
62 supp_filename = JOIN(suppressions_root, "tsan", "suppressions_mac.txt")
63 tsan_mac = suppressions.ReadSuppressionsFromFile(supp_filename)
64 mac_suppressions = vg_mac + tsan_mac
66 supp_filename = JOIN(suppressions_root, "tsan", "suppressions_win32.txt")
67 tsan_win = suppressions.ReadSuppressionsFromFile(supp_filename)
68 win_suppressions = tsan_win
70 supp_filename = JOIN(suppressions_root, "..", "heapcheck", "suppressions.txt")
71 heapcheck_suppressions = suppressions.ReadSuppressionsFromFile(supp_filename)
73 supp_filename = JOIN(suppressions_root, "drmemory", "suppressions.txt")
74 drmem_suppressions = suppressions.ReadSuppressionsFromFile(supp_filename)
75 supp_filename = JOIN(suppressions_root, "drmemory", "suppressions_full.txt")
76 drmem_full_suppressions = suppressions.ReadSuppressionsFromFile(supp_filename)
78 # all_reports is a map {report: list of urls containing this report}
79 all_reports = defaultdict(list)
80 report_hashes = {}
82 for f in argv:
83 f_reports, url = ReadReportsFromFile(f)
84 for (hash, report) in f_reports:
85 all_reports[report] += [url]
86 report_hashes[report] = hash
88 reports_count = 0
89 for r in all_reports:
90 cur_supp = common_suppressions
91 if all([re.search("%20Mac%20|mac_valgrind", url)
92 for url in all_reports[r]]):
93 # Include mac suppressions if the report is only present on Mac
94 cur_supp += mac_suppressions
95 elif all([re.search("Windows%20", url) for url in all_reports[r]]):
96 # Include win32 suppressions if the report is only present on Windows
97 cur_supp += win_suppressions
98 elif all([re.search("%20Heapcheck", url)
99 for url in all_reports[r]]):
100 cur_supp += heapcheck_suppressions
101 if all(["DrMemory" in url for url in all_reports[r]]):
102 cur_supp += drmem_suppressions
103 if all(["DrMemory%20full" in url for url in all_reports[r]]):
104 cur_supp += drmem_full_suppressions
106 match = False
107 for s in cur_supp:
108 if s.Match(r.split("\n")):
109 match = True
110 break
111 if not match:
112 reports_count += 1
113 print "==================================="
114 print "This report observed at"
115 for url in all_reports[r]:
116 print " %s" % url
117 print "didn't match any suppressions:"
118 print "Suppression (error hash=#%s#):" % (report_hashes[r])
119 print r
120 print "==================================="
122 if reports_count > 0:
123 print ("%d unique reports don't match any of the suppressions" %
124 reports_count)
125 else:
126 print "Congratulations! All reports are suppressed!"
127 # TODO(timurrrr): also make sure none of the old suppressions
128 # were narrowed too much.
131 if __name__ == "__main__":
132 main(sys.argv[1:])