Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(337)

Side by Side Diff: tools/push-to-trunk/check_clusterfuzz.py

Issue 811073002: Add script to check for clusterfuzz issues. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Rather write the result IDs to a file. Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 #!/usr/bin/env python
2 # Copyright 2014 the V8 project authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file.
5
6 """
7 Script to check for new clusterfuzz issues since the last rolled v8 revision.
8
9 Returns a json list with test case IDs if any.
10
11 Security considerations: The security key and request data must never be
12 written to public logs. Public automated callers of this script should
13 suppress stdout and stderr and only process contents of the results_file.
14 """
15
16
17 import argparse
18 import httplib
19 import json
20 import os
21 import re
22 import sys
23 import urllib
24 import urllib2
25
26
27 # Constants to git repos.
28 BASE_URL = "https://chromium.googlesource.com"
29 DEPS_LOG = BASE_URL + "/chromium/src/+log/master/DEPS?format=JSON"
30
31 # Constants for retrieving v8 rolls.
32 CRREV = "https://cr-rev.appspot.com/_ah/api/crrev/v1/commit/%s"
33 V8_COMMIT_RE = re.compile(
34 r"^Update V8 to version \d+\.\d+\.\d+ \(based on ([a-fA-F0-9]+)\)\..*")
35
36 # Constants for the clusterfuzz backend.
37 HOSTNAME = "backend-dot-cluster-fuzz.appspot.com"
38
39 # Crash patterns.
40 V8_INTERNAL_RE = re.compile(r"^v8::internal.*")
Jakob Kummerow 2014/12/17 14:40:39 Hard to say. If it were possible to identify V8 bu
41 ANY_RE = re.compile(r".*")
42
43 # List of all api requests
tandrii_google 2014/12/17 14:08:38 nit: missing period at the end.
44 BUG_SPECS = [
45 {
46 "args": {
47 "job_type": "linux_asan_chrome_v8",
48 "reproducible": "True",
49 "open": "True",
50 "bug_information": "",
51 },
52 "crash_state": V8_INTERNAL_RE,
53 },
54 {
55 "args": {
56 "job_type": "linux_asan_d8_dbg",
57 "reproducible": "True",
58 "open": "True",
59 "bug_information": "",
60 },
61 "crash_state": ANY_RE,
62 },
63 ]
64
65
66 def GetRequest(url):
67 url_fh = urllib2.urlopen(url, None, 60)
68 try:
69 return url_fh.read()
70 finally:
71 url_fh.close()
72
73
74 def GetLatestV8InChromium():
75 """Returns the commit position number of the latest v8 roll in chromium."""
76
77 # Check currently rolled v8 revision.
78 result = GetRequest(DEPS_LOG)
79 if not result:
80 return None
81
82 # Strip security header and load json.
83 commits = json.loads(result[5:])
tandrii_google 2014/12/17 14:08:38 this constant bothers me, but if you are sure of 5
Michael Achenbach 2014/12/17 15:01:55 See: https://chromium.googlesource.com/chromium/sr
84
85 git_revision = None
86 for commit in commits["log"]:
87 # Get latest commit that matches the v8 roll pattern. Ignore cherry-picks.
88 match = re.match(V8_COMMIT_RE, commit["message"])
89 if match:
90 git_revision = match.group(1)
91 break
92 else:
93 return None
94
95 # Get commit position number for v8 revision.
96 result = GetRequest(CRREV % git_revision)
97 if not result:
98 return None
99
100 commit = json.loads(result)
101 assert commit["repo"] == "v8/v8"
102 return commit["number"]
103
104
105 def APIRequest(key, **params):
106 """Send a request to the clusterfuzz api.
107
108 Returns a json dict of the response.
109 """
110
111 params["api_key"] = key
112 params = urllib.urlencode(params)
113
114 headers = {"Content-type": "application/x-www-form-urlencoded"}
115
116 conn = httplib.HTTPSConnection(HOSTNAME)
117 conn.request("POST", "/_api/", params, headers)
tandrii_google 2014/12/17 14:08:38 can this raise exception and log the URL? If so, i
118
119 response = conn.getresponse()
120
121 # Never leak "data" into public logs.
122 data = response.read()
123 try:
124 return json.loads(data)
125 except:
126 raise Exception("ERROR: Could not read response. Is your key valid?")
127
128 return None
129
130
131 def Main():
132 parser = argparse.ArgumentParser()
133 parser.add_argument("-k", "--key-file", required=True,
134 help="A file with the clusterfuzz api key.")
135 parser.add_argument("-r", "--results-file",
136 help="A file to write the results to.")
137 options = parser.parse_args()
138
139 # Get api key. The key's content must never be logged.
140 assert options.key_file
141 with open(options.key_file) as f:
142 key = f.read().strip()
143 assert key
144
145 revision_number = GetLatestV8InChromium()
146
147 results = []
148 for spec in BUG_SPECS:
149 args = dict(spec["args"])
150 # Use incremented revision as we're interested in all revision greater than
151 # what's currently rolled into chromium.
152 if revision_number:
153 args["revision_greater_or_equal"] = str(int(revision_number) + 1)
154
155 # Never print issue details in public logs.
156 issues = APIRequest(key, **args)
157 assert issues is not None
158 for issue in issues:
159 if re.match(spec["crash_state"], issue["crash_state"]):
160 results.append(issue["id"])
161
162 if options.results_file:
163 with open(options.results_file, "w") as f:
164 f.write(json.dumps(results))
165 else:
166 print results
167
168
169 if __name__ == "__main__":
170 sys.exit(Main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698