OLD | NEW |
---|---|
1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 # Use of this source code is governed by a BSD-style license that can be |
3 # found in the LICENSE file. | 3 # found in the LICENSE file. |
4 | 4 |
5 """Uploads the results to the flakiness dashboard server.""" | 5 """Uploads the results to the flakiness dashboard server.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import shutil | 9 import shutil |
10 import subprocess | 10 import subprocess |
11 import sys | 11 import sys |
12 import tempfile | 12 import tempfile |
13 | 13 |
14 sys.path.append(os.path.join(sys.path[0], '..', '..', 'third_party', | 14 sys.path.append( |
15 'WebKit', 'Tools', 'Scripts')) | 15 os.path.abspath(os.path.join(os.path.dirname(__file__ ), |
16 os.pardir, os.pardir, os.pardir, os.pardir, | |
17 'third_party', 'WebKit', 'Tools', 'Scripts'))) | |
16 from webkitpy.common.system import executive, filesystem | 18 from webkitpy.common.system import executive, filesystem |
17 from webkitpy.layout_tests.layout_package import json_results_generator | 19 from webkitpy.layout_tests.layout_package import json_results_generator |
18 | 20 |
21 #TODO(craigdh): pylib/utils/ should not depend on pylib/. | |
22 from pylib import constants | |
23 | |
19 | 24 |
20 # The JSONResultsGenerator gets the filesystem.join operation from the Port | 25 # The JSONResultsGenerator gets the filesystem.join operation from the Port |
21 # object. Creating a Port object requires specifying information that only | 26 # object. Creating a Port object requires specifying information that only |
22 # makes sense for running WebKit layout tests, so we provide a dummy object | 27 # makes sense for running WebKit layout tests, so we provide a dummy object |
23 # that contains the fields required by the generator. | 28 # that contains the fields required by the generator. |
24 class PortDummy(object): | 29 class PortDummy(object): |
25 def __init__(self): | 30 def __init__(self): |
26 self._executive = executive.Executive() | 31 self._executive = executive.Executive() |
27 self._filesystem = filesystem.FileSystem() | 32 self._filesystem = filesystem.FileSystem() |
28 | 33 |
(...skipping 20 matching lines...) Expand all Loading... | |
49 | 54 |
50 #override | 55 #override |
51 def _get_modifier_char(self, test_name): | 56 def _get_modifier_char(self, test_name): |
52 if test_name not in self._test_results_map: | 57 if test_name not in self._test_results_map: |
53 return self.__class__.NO_DATA_RESULT | 58 return self.__class__.NO_DATA_RESULT |
54 | 59 |
55 return self._test_results_map[test_name].modifier | 60 return self._test_results_map[test_name].modifier |
56 | 61 |
57 #override | 62 #override |
58 def _get_svn_revision(self, in_directory): | 63 def _get_svn_revision(self, in_directory): |
59 """Returns the git revision for the given directory. | 64 """Returns the git/svn revision for the given directory. |
60 | 65 |
61 Args: | 66 Args: |
62 in_directory: The directory where git is to be run. | 67 in_directory: The directory relative to src. |
63 """ | 68 """ |
64 git_dir = self._filesystem.join(os.environ.get('CHROME_SRC'), | 69 def _is_git_directory(in_directory): |
65 in_directory, | 70 """Returns true if the given directory is in a git repository. |
66 '.git') | 71 |
67 if self._filesystem.exists(git_dir): | 72 Args: |
68 # Note: Not thread safe: http://bugs.python.org/issue2320 | 73 in_directory: The directory path to be tested. |
69 output = subprocess.Popen( | 74 """ |
70 ['git', '--git-dir=%s' % git_dir, 'show-ref', '--head', | 75 if os.path.exists(os.path.join(in_directory, '.git')): |
71 '--hash=10', 'HEAD'], | 76 return True |
72 stdout=subprocess.PIPE).communicate()[0].strip() | 77 parent = os.path.dirname(in_directory) |
73 return output | 78 if parent == constants.CHROME_DIR or parent == in_directory: |
79 return False | |
80 return _is_git_directory(parent) | |
81 | |
82 def _get_git_revision(in_directory): | |
83 """Returns the git hash tag for the given directory. | |
84 | |
85 Args: | |
86 in_directory: The directory where git is to be run. | |
87 """ | |
88 command_line = ['git', 'log', '-1', '--pretty=format:%H'] | |
89 output = subprocess.Popen(command_line, | |
90 cwd=in_directory, | |
91 stdout=subprocess.PIPE).communicate()[0] | |
92 return output[0:40] | |
Isaac (use chromium)
2013/01/15 00:03:07
nit: output.strip()?
| |
93 | |
94 in_directory = os.path.join(constants.CHROME_DIR, in_directory) | |
95 | |
96 if not os.path.exists(os.path.join(in_directory, '.svn')): | |
97 if _is_git_directory(in_directory): | |
98 return _get_git_revision(in_directory) | |
99 else: | |
100 return '' | |
101 | |
102 # Note: Not thread safe: http://bugs.python.org/issue2320 | |
103 output = subprocess.Popen(['svn', 'info', '--xml'], | |
104 cwd=in_directory, | |
105 stdout=subprocess.PIPE).communicate()[0] | |
106 try: | |
107 dom = xml.dom.minidom.parseString(output) | |
108 return dom.getElementsByTagName('entry')[0].getAttribute('revision') | |
109 except xml.parsers.expat.ExpatError: | |
110 return '' | |
74 return '' | 111 return '' |
75 | 112 |
76 | 113 |
77 class ResultsUploader(object): | 114 class ResultsUploader(object): |
78 """Handles uploading buildbot tests results to the flakiness dashboard.""" | 115 """Handles uploading buildbot tests results to the flakiness dashboard.""" |
79 def __init__(self, tests_type): | 116 def __init__(self, tests_type): |
80 self._build_number = os.environ.get('BUILDBOT_BUILDNUMBER') | 117 self._build_number = os.environ.get('BUILDBOT_BUILDNUMBER') |
81 self._builder_name = os.environ.get('BUILDBOT_BUILDERNAME') | 118 self._builder_name = os.environ.get('BUILDBOT_BUILDERNAME') |
82 self._tests_type = tests_type | 119 self._tests_type = tests_type |
83 self._build_name = 'chromium-android' | |
84 | 120 |
85 if not self._builder_name: | 121 if not self._build_number or not self._builder_name: |
86 raise Exception('You should not be uploading tests results to the server' | 122 raise Exception('You should not be uploading tests results to the server' |
87 'from your local machine.') | 123 'from your local machine.') |
88 | 124 |
89 buildbot_branch = os.environ.get('BUILDBOT_BRANCH') | 125 upstream = (tests_type != 'Chromium_Android_Instrumentation') |
90 if not buildbot_branch: | 126 if upstream: |
91 buildbot_branch = 'master' | 127 # TODO(frankf): Use factory properties (see buildbot/bb_device_steps.py) |
92 self._master_name = '%s-%s' % (self._build_name, buildbot_branch) | 128 # This requires passing the actual master name (e.g. 'ChromiumFYI' not |
129 # 'chromium.fyi'). | |
130 from slave import slave_utils | |
131 self._build_name = slave_utils.SlaveBuildName(constants.CHROME_DIR) | |
132 self._master_name = slave_utils.GetActiveMaster() | |
133 else: | |
134 self._build_name = 'chromium-android' | |
135 buildbot_branch = os.environ.get('BUILDBOT_BRANCH') | |
136 if not buildbot_branch: | |
137 buildbot_branch = 'master' | |
138 self._master_name = '%s-%s' % (self._build_name, buildbot_branch) | |
139 | |
93 self._test_results_map = {} | 140 self._test_results_map = {} |
94 | 141 |
95 def AddResults(self, test_results): | 142 def AddResults(self, test_results): |
96 conversion_map = [ | 143 conversion_map = [ |
97 (test_results.ok, False, | 144 (test_results.ok, False, |
98 json_results_generator.JSONResultsGeneratorBase.PASS_RESULT), | 145 json_results_generator.JSONResultsGeneratorBase.PASS_RESULT), |
99 (test_results.failed, True, | 146 (test_results.failed, True, |
100 json_results_generator.JSONResultsGeneratorBase.FAIL_RESULT), | 147 json_results_generator.JSONResultsGeneratorBase.FAIL_RESULT), |
101 (test_results.crashed, True, | 148 (test_results.crashed, True, |
102 "C"), | 149 "C"), |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 """Reports test results to the flakiness dashboard for Chrome for Android. | 196 """Reports test results to the flakiness dashboard for Chrome for Android. |
150 | 197 |
151 Args: | 198 Args: |
152 flakiness_dashboard_server: the server to upload the results to. | 199 flakiness_dashboard_server: the server to upload the results to. |
153 test_type: the type of the tests (as displayed by the flakiness dashboard). | 200 test_type: the type of the tests (as displayed by the flakiness dashboard). |
154 results: test results. | 201 results: test results. |
155 """ | 202 """ |
156 uploader = ResultsUploader(test_type) | 203 uploader = ResultsUploader(test_type) |
157 uploader.AddResults(results) | 204 uploader.AddResults(results) |
158 uploader.Upload(flakiness_dashboard_server) | 205 uploader.Upload(flakiness_dashboard_server) |
OLD | NEW |