OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
5 | 5 |
6 """A tool used to run a Chrome test executable and process the output. | 6 """A tool used to run a Chrome test executable and process the output. |
7 | 7 |
8 This script is used by the buildbot slaves. It must be run from the outer | 8 This script is used by the buildbot slaves. It must be run from the outer |
9 build directory, e.g. chrome-release/build/. | 9 build directory, e.g. chrome-release/build/. |
10 | 10 |
(...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
201 def _GetMaster(): | 201 def _GetMaster(): |
202 """Return the master name for the current host.""" | 202 """Return the master name for the current host.""" |
203 return chromium_utils.GetActiveMaster() | 203 return chromium_utils.GetActiveMaster() |
204 | 204 |
205 | 205 |
206 def _GetMasterString(master): | 206 def _GetMasterString(master): |
207 """Returns a message describing what the master is.""" | 207 """Returns a message describing what the master is.""" |
208 return '[Running for master: "%s"]' % master | 208 return '[Running for master: "%s"]' % master |
209 | 209 |
210 | 210 |
211 def _GetGitCommitPositionFromLog(log): | |
212 """Returns either the commit position or svn rev from a git log.""" | |
213 # Parse from the bottom up, in case the commit message embeds the message | |
214 # from a different commit (e.g., for a revert). | |
215 for r in [GIT_CR_POS_RE, GIT_SVN_ID_RE]: | |
216 for line in reversed(log.splitlines()): | |
217 m = r.match(line.strip()) | |
218 if m: | |
219 return m.group(1) | |
220 return None | |
221 | |
222 | |
223 def _GetGitCommitPosition(dir_path): | |
224 """Extracts the commit position or svn revision number of the HEAD commit.""" | |
225 git_exe = 'git.bat' if sys.platform.startswith('win') else 'git' | |
226 p = subprocess.Popen( | |
227 [git_exe, 'log', '-n', '1', '--pretty=format:%B', 'HEAD'], | |
228 cwd=dir_path, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
229 (log, _) = p.communicate() | |
230 if p.returncode != 0: | |
231 return None | |
232 return _GetGitCommitPositionFromLog(log) | |
233 | |
234 | |
235 def _IsGitDirectory(dir_path): | 211 def _IsGitDirectory(dir_path): |
236 """Checks whether the given directory is in a git repository. | 212 """Checks whether the given directory is in a git repository. |
237 | 213 |
238 Args: | 214 Args: |
239 dir_path: The directory path to be tested. | 215 dir_path: The directory path to be tested. |
240 | 216 |
241 Returns: | 217 Returns: |
242 True if given directory is in a git repository, False otherwise. | 218 True if given directory is in a git repository, False otherwise. |
243 """ | 219 """ |
244 git_exe = 'git.bat' if sys.platform.startswith('win') else 'git' | 220 git_exe = 'git.bat' if sys.platform.startswith('win') else 'git' |
245 with open(os.devnull, 'w') as devnull: | 221 with open(os.devnull, 'w') as devnull: |
246 p = subprocess.Popen([git_exe, 'rev-parse', '--git-dir'], | 222 p = subprocess.Popen([git_exe, 'rev-parse', '--git-dir'], |
247 cwd=dir_path, stdout=devnull, stderr=devnull) | 223 cwd=dir_path, stdout=devnull, stderr=devnull) |
248 return p.wait() == 0 | 224 return p.wait() == 0 |
249 | 225 |
250 | 226 |
251 def _GetRevision(in_directory): | |
252 """Returns the SVN revision, git commit position, or git hash. | |
253 | |
254 Args: | |
255 in_directory: A directory in the repository to be checked. | |
256 | |
257 Returns: | |
258 An SVN revision as a string if the given directory is in a SVN repository, | |
259 or a git commit position number, or if that's not available, a git hash. | |
260 If all of that fails, an empty string is returned. | |
261 """ | |
262 import xml.dom.minidom | |
263 if not os.path.exists(os.path.join(in_directory, '.svn')): | |
264 if _IsGitDirectory(in_directory): | |
265 svn_rev = _GetGitCommitPosition(in_directory) | |
266 if svn_rev: | |
267 return svn_rev | |
268 return _GetGitRevision(in_directory) | |
269 else: | |
270 return '' | |
271 | |
272 # Note: Not thread safe: http://bugs.python.org/issue2320 | 227 # Note: Not thread safe: http://bugs.python.org/issue2320 |
273 output = subprocess.Popen(['svn', 'info', '--xml'], | 228 output = subprocess.Popen(['svn', 'info', '--xml'], |
274 cwd=in_directory, | 229 cwd=in_directory, |
275 shell=(sys.platform == 'win32'), | 230 shell=(sys.platform == 'win32'), |
276 stdout=subprocess.PIPE).communicate()[0] | 231 stdout=subprocess.PIPE).communicate()[0] |
277 try: | 232 try: |
278 dom = xml.dom.minidom.parseString(output) | 233 dom = xml.dom.minidom.parseString(output) |
279 return dom.getElementsByTagName('entry')[0].getAttribute('revision') | 234 return dom.getElementsByTagName('entry')[0].getAttribute('revision') |
280 except xml.parsers.expat.ExpatError: | 235 except xml.parsers.expat.ExpatError: |
281 return '' | 236 return '' |
282 return '' | 237 return '' |
283 | 238 |
284 | 239 |
285 def _GetGitRevision(in_directory): | |
286 """Returns the git hash tag for the given directory. | |
287 | |
288 Args: | |
289 in_directory: The directory where git is to be run. | |
290 | |
291 Returns: | |
292 The git SHA1 hash string. | |
293 """ | |
294 git_exe = 'git.bat' if sys.platform.startswith('win') else 'git' | |
295 p = subprocess.Popen( | |
296 [git_exe, 'rev-parse', 'HEAD'], | |
297 cwd=in_directory, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) | |
298 (stdout, _) = p.communicate() | |
299 return stdout.strip() | |
300 | |
301 | |
302 def _GenerateJSONForTestResults(options, log_processor): | 240 def _GenerateJSONForTestResults(options, log_processor): |
303 """Generates or updates a JSON file from the gtest results XML and upload the | 241 """Generates or updates a JSON file from the gtest results XML and upload the |
304 file to the archive server. | 242 file to the archive server. |
305 | 243 |
306 The archived JSON file will be placed at: | 244 The archived JSON file will be placed at: |
307 www-dir/DEST_DIR/buildname/testname/results.json | 245 www-dir/DEST_DIR/buildname/testname/results.json |
308 on the archive server. NOTE: This will be deprecated. | 246 on the archive server. NOTE: This will be deprecated. |
309 | 247 |
310 Args: | 248 Args: |
311 options: command-line options that are supposed to have build_dir, | 249 options: command-line options that are supposed to have build_dir, |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 | 291 |
354 print _GetMasterString(generate_json_options.master_name) | 292 print _GetMasterString(generate_json_options.master_name) |
355 | 293 |
356 generator = None | 294 generator = None |
357 | 295 |
358 try: | 296 try: |
359 if options.revision: | 297 if options.revision: |
360 generate_json_options.chrome_revision = options.revision | 298 generate_json_options.chrome_revision = options.revision |
361 else: | 299 else: |
362 chrome_dir = chromium_utils.FindUpwardParent(build_dir, 'third_party') | 300 chrome_dir = chromium_utils.FindUpwardParent(build_dir, 'third_party') |
363 generate_json_options.chrome_revision = _GetRevision(chrome_dir) | 301 generate_json_options.chrome_revision = \ |
| 302 slave_utils.GetRevision(chrome_dir) |
364 | 303 |
365 if options.webkit_revision: | 304 if options.webkit_revision: |
366 generate_json_options.webkit_revision = options.webkit_revision | 305 generate_json_options.webkit_revision = options.webkit_revision |
367 else: | 306 else: |
368 webkit_dir = chromium_utils.FindUpward( | 307 webkit_dir = chromium_utils.FindUpward( |
369 build_dir, 'third_party', 'WebKit', 'Source') | 308 build_dir, 'third_party', 'WebKit', 'Source') |
370 generate_json_options.webkit_revision = _GetRevision(webkit_dir) | 309 generate_json_options.webkit_revision = \ |
| 310 slave_utils.GetRevision(webkit_dir) |
371 | 311 |
372 # Generate results JSON file and upload it to the appspot server. | 312 # Generate results JSON file and upload it to the appspot server. |
373 generator = gtest_slave_utils.GenerateJSONResults( | 313 generator = gtest_slave_utils.GenerateJSONResults( |
374 results_map, generate_json_options) | 314 results_map, generate_json_options) |
375 | 315 |
376 except Exception as e: | 316 except Exception as e: |
377 print 'Unexpected error while generating JSON: %s' % e | 317 print 'Unexpected error while generating JSON: %s' % e |
378 sys.excepthook(*sys.exc_info()) | 318 sys.excepthook(*sys.exc_info()) |
379 return False | 319 return False |
380 | 320 |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
470 else: | 410 else: |
471 return LOG_PROCESSOR_CLASSES[options.annotate] | 411 return LOG_PROCESSOR_CLASSES[options.annotate] |
472 else: | 412 else: |
473 raise KeyError('"%s" is not a valid GTest parser!' % options.annotate) | 413 raise KeyError('"%s" is not a valid GTest parser!' % options.annotate) |
474 elif options.generate_json_file: | 414 elif options.generate_json_file: |
475 return LOG_PROCESSOR_CLASSES['gtest'] | 415 return LOG_PROCESSOR_CLASSES['gtest'] |
476 | 416 |
477 return None | 417 return None |
478 | 418 |
479 | 419 |
480 def _GetCommitPos(build_properties): | |
481 """Extracts the commit position from the build properties, if its there.""" | |
482 if 'got_revision_cp' not in build_properties: | |
483 return None | |
484 commit_pos = build_properties['got_revision_cp'] | |
485 return int(re.search(r'{#(\d+)}', commit_pos).group(1)) | |
486 | |
487 | |
488 def _GetMainRevision(options): | 420 def _GetMainRevision(options): |
489 """Return revision to use as the numerical x-value in the perf dashboard. | 421 slave_utils.GetMainRevision( |
490 | 422 options.build_properties, options.build_dir, options.revision) |
491 This will be used as the value of "rev" in the data passed to | |
492 results_dashboard.SendResults. | |
493 | |
494 In order or priority, this function could return: | |
495 1. The value of the --revision flag (IF it can be parsed as an int). | |
496 2. The value of "got_revision_cp" in build properties. | |
497 3. An SVN number, git commit position, or git commit hash. | |
498 """ | |
499 if options.revision and options.revision.isdigit(): | |
500 return options.revision | |
501 commit_pos_num = _GetCommitPos(options.build_properties) | |
502 if commit_pos_num is not None: | |
503 return commit_pos_num | |
504 # TODO(sullivan,qyearsley): Don't fall back to _GetRevision if it returns | |
505 # a git commit, since this should be a numerical revision. Instead, abort | |
506 # and fail. | |
507 return _GetRevision(os.path.dirname(os.path.abspath(options.build_dir))) | |
508 | 423 |
509 | 424 |
510 def _GetBlinkRevision(options): | 425 def _GetBlinkRevision(options): |
511 if options.webkit_revision: | 426 slave_utils.GetBlinkRevision(options.build_dir, options.webkit_revision) |
512 webkit_revision = options.webkit_revision | |
513 else: | |
514 try: | |
515 webkit_dir = chromium_utils.FindUpward( | |
516 os.path.abspath(options.build_dir), 'third_party', 'WebKit', 'Source') | |
517 webkit_revision = _GetRevision(webkit_dir) | |
518 except Exception: | |
519 webkit_revision = None | |
520 return webkit_revision | |
521 | 427 |
522 | 428 |
523 def _GetTelemetryRevisions(options): | 429 def _GetTelemetryRevisions(options): |
524 """Fills in the same revisions fields that process_log_utils does.""" | 430 return slave_utils.GetTelemetryRevisions( |
525 | 431 options.build_properties, |
526 versions = {} | 432 _GetMainRevision(options), |
527 versions['rev'] = _GetMainRevision(options) | 433 _GetBlinkRevision(options), |
528 versions['webkit_rev'] = _GetBlinkRevision(options) | 434 options.point_id) |
529 versions['webrtc_rev'] = options.build_properties.get('got_webrtc_revision') | |
530 versions['v8_rev'] = options.build_properties.get('got_v8_revision') | |
531 versions['ver'] = options.build_properties.get('version') | |
532 versions['git_revision'] = options.build_properties.get('git_revision') | |
533 versions['point_id'] = options.point_id | |
534 # There are a lot of "bad" revisions to check for, so clean them all up here. | |
535 for key in versions.keys(): | |
536 if not versions[key] or versions[key] == 'undefined': | |
537 del versions[key] | |
538 return versions | |
539 | 435 |
540 | 436 |
541 def _CreateLogProcessor(log_processor_class, options, telemetry_info): | 437 def _CreateLogProcessor(log_processor_class, options, telemetry_info): |
542 """Creates a log processor instance. | 438 """Creates a log processor instance. |
543 | 439 |
544 Args: | 440 Args: |
545 log_processor_class: A subclass of PerformanceLogProcessor or similar class. | 441 log_processor_class: A subclass of PerformanceLogProcessor or similar class. |
546 options: Command-line options (from OptionParser). | 442 options: Command-line options (from OptionParser). |
547 telemetry_info: dict of info for run_benchmark runs. | 443 telemetry_info: dict of info for run_benchmark runs. |
548 | 444 |
(...skipping 1358 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1907 finally: | 1803 finally: |
1908 if did_launch_dbus: | 1804 if did_launch_dbus: |
1909 # It looks like the command line argument --exit-with-session | 1805 # It looks like the command line argument --exit-with-session |
1910 # isn't working to clean up the spawned dbus-daemon. Kill it | 1806 # isn't working to clean up the spawned dbus-daemon. Kill it |
1911 # manually. | 1807 # manually. |
1912 _ShutdownDBus() | 1808 _ShutdownDBus() |
1913 | 1809 |
1914 | 1810 |
1915 if '__main__' == __name__: | 1811 if '__main__' == __name__: |
1916 sys.exit(main()) | 1812 sys.exit(main()) |
OLD | NEW |