OLD | NEW |
1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
2 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2013 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 """Runs all the buildbot steps for ChromeDriver except for update/compile.""" | 6 """Runs all the buildbot steps for ChromeDriver except for update/compile.""" |
7 | 7 |
8 import bisect | 8 import bisect |
9 import csv | 9 import csv |
10 import datetime | 10 import datetime |
(...skipping 13 matching lines...) Expand all Loading... |
24 _THIS_DIR = os.path.abspath(os.path.dirname(__file__)) | 24 _THIS_DIR = os.path.abspath(os.path.dirname(__file__)) |
25 GS_CHROMEDRIVER_BUCKET = 'gs://chromedriver' | 25 GS_CHROMEDRIVER_BUCKET = 'gs://chromedriver' |
26 GS_CHROMEDRIVER_DATA_BUCKET = 'gs://chromedriver-data' | 26 GS_CHROMEDRIVER_DATA_BUCKET = 'gs://chromedriver-data' |
27 GS_CHROMEDRIVER_RELEASE_URL = 'http://chromedriver.storage.googleapis.com' | 27 GS_CHROMEDRIVER_RELEASE_URL = 'http://chromedriver.storage.googleapis.com' |
28 GS_CONTINUOUS_URL = GS_CHROMEDRIVER_DATA_BUCKET + '/continuous' | 28 GS_CONTINUOUS_URL = GS_CHROMEDRIVER_DATA_BUCKET + '/continuous' |
29 GS_PREBUILTS_URL = GS_CHROMEDRIVER_DATA_BUCKET + '/prebuilts' | 29 GS_PREBUILTS_URL = GS_CHROMEDRIVER_DATA_BUCKET + '/prebuilts' |
30 GS_SERVER_LOGS_URL = GS_CHROMEDRIVER_DATA_BUCKET + '/server_logs' | 30 GS_SERVER_LOGS_URL = GS_CHROMEDRIVER_DATA_BUCKET + '/server_logs' |
31 SERVER_LOGS_LINK = ( | 31 SERVER_LOGS_LINK = ( |
32 'http://chromedriver-data.storage.googleapis.com/server_logs') | 32 'http://chromedriver-data.storage.googleapis.com/server_logs') |
33 TEST_LOG_FORMAT = '%s_log.json' | 33 TEST_LOG_FORMAT = '%s_log.json' |
34 GS_GITHASH_TO_SVN_URL = ( | 34 GS_GIT_LOG_URL = ( |
35 'https://chromium.googlesource.com/chromium/src/+/%s?format=json') | 35 'https://chromium.googlesource.com/chromium/src/+/%s?format=json') |
36 GS_SEARCH_PATTERN = ( | 36 GS_SEARCH_PATTERN = ( |
37 r'.*git-svn-id: svn://svn.chromium.org/chrome/trunk/src@(\d+) ') | 37 r'Cr-Commit-Position: refs/heads/master@{#(\d+)}') |
| 38 CR_REV_URL = 'https://cr-rev.appspot.com/_ah/api/crrev/v1/redirect/%s' |
38 | 39 |
39 SCRIPT_DIR = os.path.join(_THIS_DIR, os.pardir, os.pardir, os.pardir, os.pardir, | 40 SCRIPT_DIR = os.path.join(_THIS_DIR, os.pardir, os.pardir, os.pardir, os.pardir, |
40 os.pardir, os.pardir, os.pardir, 'scripts') | 41 os.pardir, os.pardir, os.pardir, 'scripts') |
41 SITE_CONFIG_DIR = os.path.join(_THIS_DIR, os.pardir, os.pardir, os.pardir, | 42 SITE_CONFIG_DIR = os.path.join(_THIS_DIR, os.pardir, os.pardir, os.pardir, |
42 os.pardir, os.pardir, os.pardir, os.pardir, | 43 os.pardir, os.pardir, os.pardir, os.pardir, |
43 'site_config') | 44 'site_config') |
44 sys.path.append(SCRIPT_DIR) | 45 sys.path.append(SCRIPT_DIR) |
45 sys.path.append(SITE_CONFIG_DIR) | 46 sys.path.append(SITE_CONFIG_DIR) |
46 | 47 |
47 import archive | 48 import archive |
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
377 for file_name in os.listdir(tmp_dir): | 378 for file_name in os.listdir(tmp_dir): |
378 file_path = os.path.join(tmp_dir, file_name) | 379 file_path = os.path.join(tmp_dir, file_name) |
379 if os.path.isdir(file_path): | 380 if os.path.isdir(file_path): |
380 print 'deleting sub-directory', file_path | 381 print 'deleting sub-directory', file_path |
381 shutil.rmtree(file_path, True) | 382 shutil.rmtree(file_path, True) |
382 if file_name.startswith('chromedriver_'): | 383 if file_name.startswith('chromedriver_'): |
383 print 'deleting file', file_path | 384 print 'deleting file', file_path |
384 os.remove(file_path) | 385 os.remove(file_path) |
385 | 386 |
386 | 387 |
387 def _GetSVNRevisionFromGitHash(snapshot_hashcode): | 388 def _GetCommitPositionFromGitHash(snapshot_hashcode): |
388 json_url = GS_GITHASH_TO_SVN_URL % snapshot_hashcode | 389 json_url = GS_GIT_LOG_URL % snapshot_hashcode |
389 try: | 390 try: |
390 response = urllib2.urlopen(json_url) | 391 response = urllib2.urlopen(json_url) |
391 except urllib2.HTTPError as error: | 392 except urllib2.HTTPError as error: |
392 util.PrintAndFlush('HTTP Error %d' % error.getcode()) | 393 util.PrintAndFlush('HTTP Error %d' % error.getcode()) |
| 394 return None |
393 except urllib2.URLError as error: | 395 except urllib2.URLError as error: |
394 util.PrintAndFlush('URL Error %s' % error.message) | 396 util.PrintAndFlush('URL Error %s' % error.message) |
395 return None | 397 return None |
396 data = json.loads(response.read()[4:]) | 398 data = json.loads(response.read()[4:]) |
397 if 'message' in data: | 399 if 'message' in data: |
398 message = data['message'].split('\n') | 400 message = data['message'].split('\n') |
399 message = [line for line in message if line.strip()] | 401 message = [line for line in message if line.strip()] |
400 search_pattern = re.compile(GS_SEARCH_PATTERN) | 402 search_pattern = re.compile(GS_SEARCH_PATTERN) |
401 result = search_pattern.search(message[len(message)-1]) | 403 result = search_pattern.search(message[len(message)-1]) |
402 if result: | 404 if result: |
403 return result.group(1) | 405 return result.group(1) |
404 util.PrintAndFlush('Failed to get svn revision number for %s' % | 406 util.PrintAndFlush('Failed to get svn revision number for %s' % |
405 snapshot_hashcode) | 407 snapshot_hashcode) |
406 return None | 408 return None |
407 | 409 |
408 | 410 |
| 411 def _GetGitHashFromCommitPosition(commit_position): |
| 412 json_url = CR_REV_URL % commit_position |
| 413 try: |
| 414 response = urllib2.urlopen(json_url) |
| 415 except urllib2.HTTPError as error: |
| 416 util.PrintAndFlush('HTTP Error %d' % error.getcode()) |
| 417 return None |
| 418 except urllib2.URLError as error: |
| 419 util.PrintAndFlush('URL Error %s' % error.message) |
| 420 return None |
| 421 data = json.loads(response.read()) |
| 422 if 'git_sha' in data: |
| 423 return data['git_sha'] |
| 424 util.PrintAndFlush('Failed to get git hash for %s' % commit_position) |
| 425 return None |
| 426 |
| 427 |
409 def _WaitForLatestSnapshot(revision): | 428 def _WaitForLatestSnapshot(revision): |
410 util.MarkBuildStepStart('wait_for_snapshot') | 429 util.MarkBuildStepStart('wait_for_snapshot') |
411 def _IsRevisionNumber(revision): | 430 def _IsRevisionNumber(revision): |
412 if isinstance(revision, int): | 431 if isinstance(revision, int): |
413 return True | 432 return True |
414 else: | 433 else: |
415 return revision.isdigit() | 434 return revision.isdigit() |
416 while True: | 435 while True: |
417 snapshot_revision = archive.GetLatestSnapshotVersion() | 436 snapshot_revision = archive.GetLatestSnapshotVersion() |
418 if not _IsRevisionNumber(revision): | |
419 revision = _GetSVNRevisionFromGitHash(revision) | |
420 if not _IsRevisionNumber(snapshot_revision): | 437 if not _IsRevisionNumber(snapshot_revision): |
421 snapshot_revision = _GetSVNRevisionFromGitHash(snapshot_revision) | 438 snapshot_revision = _GetCommitPositionFromGitHash(snapshot_revision) |
422 if revision is not None and snapshot_revision is not None: | 439 if revision is not None and snapshot_revision is not None: |
423 if int(snapshot_revision) >= int(revision): | 440 if int(snapshot_revision) >= int(revision): |
424 break | 441 break |
425 util.PrintAndFlush('Waiting for snapshot >= %s, found %s' % | 442 util.PrintAndFlush('Waiting for snapshot >= %s, found %s' % |
426 (revision, snapshot_revision)) | 443 (revision, snapshot_revision)) |
427 time.sleep(60) | 444 time.sleep(60) |
428 util.PrintAndFlush('Got snapshot revision %s' % snapshot_revision) | 445 util.PrintAndFlush('Got snapshot revision %s' % snapshot_revision) |
429 | 446 |
430 | 447 |
431 def _AddToolsToPath(platform_name): | 448 def _AddToolsToPath(platform_name): |
(...skipping 25 matching lines...) Expand all Loading... |
457 os.environ['PATH'] += os.pathsep + os.pathsep.join(paths) | 474 os.environ['PATH'] += os.pathsep + os.pathsep.join(paths) |
458 | 475 |
459 | 476 |
460 def main(): | 477 def main(): |
461 parser = optparse.OptionParser() | 478 parser = optparse.OptionParser() |
462 parser.add_option( | 479 parser.add_option( |
463 '', '--android-packages', | 480 '', '--android-packages', |
464 help=('Comma separated list of application package names, ' | 481 help=('Comma separated list of application package names, ' |
465 'if running tests on Android.')) | 482 'if running tests on Android.')) |
466 parser.add_option( | 483 parser.add_option( |
467 '-r', '--revision', type='int', help='Chromium revision') | 484 '-r', '--revision', help='Chromium revision') |
468 parser.add_option( | 485 parser.add_option( |
469 '', '--update-log', action='store_true', | 486 '', '--update-log', action='store_true', |
470 help='Update the test results log (only applicable to Android)') | 487 help='Update the test results log (only applicable to Android)') |
471 options, _ = parser.parse_args() | 488 options, _ = parser.parse_args() |
472 | 489 |
473 bitness = '32' | 490 bitness = '32' |
474 if util.IsLinux() and platform_module.architecture()[0] == '64bit': | 491 if util.IsLinux() and platform_module.architecture()[0] == '64bit': |
475 bitness = '64' | 492 bitness = '64' |
476 platform = '%s%s' % (util.GetPlatformName(), bitness) | 493 platform = '%s%s' % (util.GetPlatformName(), bitness) |
477 if options.android_packages: | 494 if options.android_packages: |
478 platform = 'android' | 495 platform = 'android' |
479 | 496 |
480 _CleanTmpDir() | 497 _CleanTmpDir() |
481 | 498 |
| 499 if not options.revision: |
| 500 commit_position = None |
| 501 elif options.revision.isdigit(): |
| 502 commit_position = options.revision |
| 503 else: |
| 504 commit_position = _GetCommitPositionFromGitHash(options.revision) |
| 505 |
482 if platform == 'android': | 506 if platform == 'android': |
483 if not options.revision and options.update_log: | 507 if not options.revision and options.update_log: |
484 parser.error('Must supply a --revision with --update-log') | 508 parser.error('Must supply a --revision with --update-log') |
485 _DownloadPrebuilts() | 509 _DownloadPrebuilts() |
486 else: | 510 else: |
487 if not options.revision: | 511 if not options.revision: |
488 parser.error('Must supply a --revision') | 512 parser.error('Must supply a --revision') |
489 if platform == 'linux64': | 513 if platform == 'linux64': |
490 _ArchivePrebuilts(options.revision) | 514 _ArchivePrebuilts(commit_position) |
491 _WaitForLatestSnapshot(options.revision) | 515 _WaitForLatestSnapshot(commit_position) |
492 | 516 |
493 _AddToolsToPath(platform) | 517 _AddToolsToPath(platform) |
494 | 518 |
495 cmd = [ | 519 cmd = [ |
496 sys.executable, | 520 sys.executable, |
497 os.path.join(_THIS_DIR, 'test', 'run_all_tests.py'), | 521 os.path.join(_THIS_DIR, 'test', 'run_all_tests.py'), |
498 ] | 522 ] |
499 if platform == 'android': | 523 if platform == 'android': |
500 cmd.append('--android-packages=' + options.android_packages) | 524 cmd.append('--android-packages=' + options.android_packages) |
501 | 525 |
502 passed = (util.RunCommand(cmd) == 0) | 526 passed = (util.RunCommand(cmd) == 0) |
503 | 527 |
504 _ArchiveServerLogs() | 528 _ArchiveServerLogs() |
505 | 529 |
506 if platform == 'android': | 530 if platform == 'android': |
507 if options.update_log: | 531 if options.update_log: |
508 util.MarkBuildStepStart('update test result log') | 532 util.MarkBuildStepStart('update test result log') |
509 _UpdateTestResultsLog(platform, options.revision, passed) | 533 _UpdateTestResultsLog(platform, commit_position, passed) |
510 elif passed: | 534 elif passed: |
511 _ArchiveGoodBuild(platform, options.revision) | 535 _ArchiveGoodBuild(platform, commit_position) |
512 _MaybeRelease(platform) | 536 _MaybeRelease(platform) |
513 | 537 |
514 if not passed: | 538 if not passed: |
515 # Make sure the build is red if there is some uncaught exception during | 539 # Make sure the build is red if there is some uncaught exception during |
516 # running run_all_tests.py. | 540 # running run_all_tests.py. |
517 util.MarkBuildStepStart('run_all_tests.py') | 541 util.MarkBuildStepStart('run_all_tests.py') |
518 util.MarkBuildStepError() | 542 util.MarkBuildStepError() |
519 | 543 |
520 # Add a "cleanup" step so that errors from runtest.py or bb_device_steps.py | 544 # Add a "cleanup" step so that errors from runtest.py or bb_device_steps.py |
521 # (which invoke this script) are kept in thier own build step. | 545 # (which invoke this script) are kept in thier own build step. |
522 util.MarkBuildStepStart('cleanup') | 546 util.MarkBuildStepStart('cleanup') |
523 | 547 |
524 | 548 |
525 if __name__ == '__main__': | 549 if __name__ == '__main__': |
526 main() | 550 main() |
OLD | NEW |