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(os.path.join(os.path.dirname(os.path.realpath( __file__ )), |
15 'WebKit', 'Tools', 'Scripts')) | 15 os.pardir, os.pardir, os.pardir, os.pardir, |
16 'third_party', 'WebKit', 'Tools', 'Scripts')) | |
16 from webkitpy.common.system import executive, filesystem | 17 from webkitpy.common.system import executive, filesystem |
17 from webkitpy.layout_tests.layout_package import json_results_generator | 18 from webkitpy.layout_tests.layout_package import json_results_generator |
18 | 19 |
19 | 20 |
20 # The JSONResultsGenerator gets the filesystem.join operation from the Port | 21 # The JSONResultsGenerator gets the filesystem.join operation from the Port |
21 # object. Creating a Port object requires specifying information that only | 22 # object. Creating a Port object requires specifying information that only |
22 # makes sense for running WebKit layout tests, so we provide a dummy object | 23 # makes sense for running WebKit layout tests, so we provide a dummy object |
23 # that contains the fields required by the generator. | 24 # that contains the fields required by the generator. |
24 class PortDummy(object): | 25 class PortDummy(object): |
25 def __init__(self): | 26 def __init__(self): |
(...skipping 23 matching lines...) Expand all Loading... | |
49 | 50 |
50 #override | 51 #override |
51 def _get_modifier_char(self, test_name): | 52 def _get_modifier_char(self, test_name): |
52 if test_name not in self._test_results_map: | 53 if test_name not in self._test_results_map: |
53 return self.__class__.NO_DATA_RESULT | 54 return self.__class__.NO_DATA_RESULT |
54 | 55 |
55 return self._test_results_map[test_name].modifier | 56 return self._test_results_map[test_name].modifier |
56 | 57 |
57 #override | 58 #override |
58 def _get_svn_revision(self, in_directory): | 59 def _get_svn_revision(self, in_directory): |
59 """Returns the git revision for the given directory. | 60 """Returns the git/svn revision for the given directory. |
60 | 61 |
61 Args: | 62 Args: |
62 in_directory: The directory where git is to be run. | 63 in_directory: The directory relative to src. |
63 """ | 64 """ |
64 git_dir = self._filesystem.join(os.environ.get('CHROME_SRC'), | 65 def _is_git_directory(in_directory): |
65 in_directory, | 66 """Returns true if the given directory is in a git repository. |
66 '.git') | 67 |
67 if self._filesystem.exists(git_dir): | 68 Args: |
68 # Note: Not thread safe: http://bugs.python.org/issue2320 | 69 in_directory: The directory path to be tested. |
69 output = subprocess.Popen( | 70 """ |
70 ['git', '--git-dir=%s' % git_dir, 'show-ref', '--head', | 71 if os.path.exists(os.path.join(in_directory, '.git')): |
71 '--hash=10', 'HEAD'], | 72 return True |
72 stdout=subprocess.PIPE).communicate()[0].strip() | 73 parent = os.path.dirname(in_directory) |
73 return output | 74 if parent == in_directory: |
75 return False | |
76 return _is_git_directory(parent) | |
mkosiba (inactive)
2013/01/14 12:07:55
Won't this cause us to recurse until we hit '/' ?
frankf
2013/01/14 18:54:41
Done.
| |
77 | |
78 def _get_git_revision(in_directory): | |
79 """Returns the git hash tag for the given directory. | |
80 | |
81 Args: | |
82 in_directory: The directory where git is to be run. | |
83 """ | |
84 command_line = ['git', 'log', '-1', '--pretty=oneline'] | |
85 output = subprocess.Popen(command_line, | |
86 cwd=in_directory, | |
87 stdout=subprocess.PIPE).communicate()[0] | |
88 return output[0:40] | |
89 | |
90 in_directory = os.path.join(os.environ.get('CHROME_SRC'), in_directory) | |
91 | |
92 if not os.path.exists(os.path.join(in_directory, '.svn')): | |
93 if _is_git_directory(in_directory): | |
94 return _get_git_revision(in_directory) | |
95 else: | |
96 return '' | |
97 | |
98 # Note: Not thread safe: http://bugs.python.org/issue2320 | |
99 output = subprocess.Popen(['svn', 'info', '--xml'], | |
100 cwd=in_directory, | |
101 stdout=subprocess.PIPE).communicate()[0] | |
102 try: | |
103 dom = xml.dom.minidom.parseString(output) | |
104 return dom.getElementsByTagName('entry')[0].getAttribute('revision') | |
105 except xml.parsers.expat.ExpatError: | |
106 return '' | |
74 return '' | 107 return '' |
75 | 108 |
76 | 109 |
77 class ResultsUploader(object): | 110 class ResultsUploader(object): |
78 """Handles uploading buildbot tests results to the flakiness dashboard.""" | 111 """Handles uploading buildbot tests results to the flakiness dashboard.""" |
79 def __init__(self, tests_type): | 112 def __init__(self, tests_type): |
80 self._build_number = os.environ.get('BUILDBOT_BUILDNUMBER') | 113 self._build_number = os.environ.get('BUILDBOT_BUILDNUMBER') |
81 self._builder_name = os.environ.get('BUILDBOT_BUILDERNAME') | 114 self._builder_name = os.environ.get('BUILDBOT_BUILDERNAME') |
82 self._tests_type = tests_type | 115 self._tests_type = tests_type |
83 self._build_name = 'chromium-android' | |
84 | 116 |
85 if not self._builder_name: | 117 if not self._build_number or not self._builder_name: |
86 raise Exception('You should not be uploading tests results to the server' | 118 raise Exception('You should not be uploading tests results to the server' |
87 'from your local machine.') | 119 'from your local machine.') |
88 | 120 |
89 buildbot_branch = os.environ.get('BUILDBOT_BRANCH') | 121 upstream = tests_type != 'Chromium_Android_Instrumentation' |
craigdh
2013/01/14 17:43:41
nit: parentheses would be nice here.
frankf
2013/01/14 18:54:41
Done.
| |
90 if not buildbot_branch: | 122 if upstream: |
91 buildbot_branch = 'master' | 123 from slave import slave_utils |
92 self._master_name = '%s-%s' % (self._build_name, buildbot_branch) | 124 chrome_src_dir = os.environ.get('CHROME_SRC') |
125 assert chrome_src_dir | |
126 self._build_name = slave_utils.SlaveBuildName(chrome_src_dir) | |
127 self._master_name = slave_utils.GetActiveMaster() | |
128 else: | |
129 self._build_name = 'chromium-android' | |
130 buildbot_branch = os.environ.get('BUILDBOT_BRANCH') | |
131 if not buildbot_branch: | |
132 buildbot_branch = 'master' | |
133 self._master_name = '%s-%s' % (self._build_name, buildbot_branch) | |
134 | |
93 self._test_results_map = {} | 135 self._test_results_map = {} |
94 | 136 |
95 def AddResults(self, test_results): | 137 def AddResults(self, test_results): |
96 conversion_map = [ | 138 conversion_map = [ |
97 (test_results.ok, False, | 139 (test_results.ok, False, |
98 json_results_generator.JSONResultsGeneratorBase.PASS_RESULT), | 140 json_results_generator.JSONResultsGeneratorBase.PASS_RESULT), |
99 (test_results.failed, True, | 141 (test_results.failed, True, |
100 json_results_generator.JSONResultsGeneratorBase.FAIL_RESULT), | 142 json_results_generator.JSONResultsGeneratorBase.FAIL_RESULT), |
101 (test_results.crashed, True, | 143 (test_results.crashed, True, |
102 "C"), | 144 "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. | 191 """Reports test results to the flakiness dashboard for Chrome for Android. |
150 | 192 |
151 Args: | 193 Args: |
152 flakiness_dashboard_server: the server to upload the results to. | 194 flakiness_dashboard_server: the server to upload the results to. |
153 test_type: the type of the tests (as displayed by the flakiness dashboard). | 195 test_type: the type of the tests (as displayed by the flakiness dashboard). |
154 results: test results. | 196 results: test results. |
155 """ | 197 """ |
156 uploader = ResultsUploader(test_type) | 198 uploader = ResultsUploader(test_type) |
157 uploader.AddResults(results) | 199 uploader.AddResults(results) |
158 uploader.Upload(flakiness_dashboard_server) | 200 uploader.Upload(flakiness_dashboard_server) |
OLD | NEW |