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__ )), |
Isaac (away)
2013/01/14 19:59:44
Nit: put abspath outside of os.path.join so it res
frankf
2013/01/14 22:54:42
Done.
| |
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 |
20 #TODO(craigdh): pylib/utils/ should not depend on pylib/. | |
21 from pylib import constants | |
19 | 22 |
20 # The JSONResultsGenerator gets the filesystem.join operation from the Port | 23 # The JSONResultsGenerator gets the filesystem.join operation from the Port |
21 # object. Creating a Port object requires specifying information that only | 24 # object. Creating a Port object requires specifying information that only |
22 # makes sense for running WebKit layout tests, so we provide a dummy object | 25 # makes sense for running WebKit layout tests, so we provide a dummy object |
23 # that contains the fields required by the generator. | 26 # that contains the fields required by the generator. |
24 class PortDummy(object): | 27 class PortDummy(object): |
25 def __init__(self): | 28 def __init__(self): |
26 self._executive = executive.Executive() | 29 self._executive = executive.Executive() |
27 self._filesystem = filesystem.FileSystem() | 30 self._filesystem = filesystem.FileSystem() |
28 | 31 |
(...skipping 20 matching lines...) Expand all Loading... | |
49 | 52 |
50 #override | 53 #override |
51 def _get_modifier_char(self, test_name): | 54 def _get_modifier_char(self, test_name): |
52 if test_name not in self._test_results_map: | 55 if test_name not in self._test_results_map: |
53 return self.__class__.NO_DATA_RESULT | 56 return self.__class__.NO_DATA_RESULT |
54 | 57 |
55 return self._test_results_map[test_name].modifier | 58 return self._test_results_map[test_name].modifier |
56 | 59 |
57 #override | 60 #override |
58 def _get_svn_revision(self, in_directory): | 61 def _get_svn_revision(self, in_directory): |
59 """Returns the git revision for the given directory. | 62 """Returns the git/svn revision for the given directory. |
60 | 63 |
61 Args: | 64 Args: |
62 in_directory: The directory where git is to be run. | 65 in_directory: The directory relative to src. |
63 """ | 66 """ |
64 git_dir = self._filesystem.join(os.environ.get('CHROME_SRC'), | 67 def _is_git_directory(in_directory): |
65 in_directory, | 68 """Returns true if the given directory is in a git repository. |
66 '.git') | 69 |
67 if self._filesystem.exists(git_dir): | 70 Args: |
68 # Note: Not thread safe: http://bugs.python.org/issue2320 | 71 in_directory: The directory path to be tested. |
69 output = subprocess.Popen( | 72 """ |
70 ['git', '--git-dir=%s' % git_dir, 'show-ref', '--head', | 73 if os.path.exists(os.path.join(in_directory, '.git')): |
71 '--hash=10', 'HEAD'], | 74 return True |
72 stdout=subprocess.PIPE).communicate()[0].strip() | 75 parent = os.path.dirname(in_directory) |
73 return output | 76 if parent == constants.CHROME_DIR or parent == in_directory: |
77 return False | |
78 return _is_git_directory(parent) | |
Isaac (away)
2013/01/14 19:59:44
We could alternatively look for the absence of a .
frankf
2013/01/14 22:54:42
This gives us a strong guarantee of this being a g
Isaac (use chromium)
2013/01/14 23:37:27
What about the situation where you have an svn che
frankf
2013/01/14 23:58:47
In that case, we'll encounter .svn first, and don'
Isaac (use chromium)
2013/01/15 00:03:07
SGTM
| |
79 | |
80 def _get_git_revision(in_directory): | |
81 """Returns the git hash tag for the given directory. | |
82 | |
83 Args: | |
84 in_directory: The directory where git is to be run. | |
85 """ | |
86 command_line = ['git', 'log', '-1', '--pretty=oneline'] | |
Isaac (away)
2013/01/14 19:59:44
nit you can have git output just the sha with the
frankf
2013/01/14 22:54:42
Done.
| |
87 output = subprocess.Popen(command_line, | |
88 cwd=in_directory, | |
89 stdout=subprocess.PIPE).communicate()[0] | |
90 return output[0:40] | |
91 | |
92 in_directory = os.path.join(constants.CHROME_DIR, in_directory) | |
93 | |
94 if not os.path.exists(os.path.join(in_directory, '.svn')): | |
95 if _is_git_directory(in_directory): | |
96 return _get_git_revision(in_directory) | |
97 else: | |
98 return '' | |
99 | |
100 # Note: Not thread safe: http://bugs.python.org/issue2320 | |
101 output = subprocess.Popen(['svn', 'info', '--xml'], | |
102 cwd=in_directory, | |
103 stdout=subprocess.PIPE).communicate()[0] | |
104 try: | |
105 dom = xml.dom.minidom.parseString(output) | |
106 return dom.getElementsByTagName('entry')[0].getAttribute('revision') | |
107 except xml.parsers.expat.ExpatError: | |
108 return '' | |
74 return '' | 109 return '' |
75 | 110 |
76 | 111 |
77 class ResultsUploader(object): | 112 class ResultsUploader(object): |
78 """Handles uploading buildbot tests results to the flakiness dashboard.""" | 113 """Handles uploading buildbot tests results to the flakiness dashboard.""" |
79 def __init__(self, tests_type): | 114 def __init__(self, tests_type): |
80 self._build_number = os.environ.get('BUILDBOT_BUILDNUMBER') | 115 self._build_number = os.environ.get('BUILDBOT_BUILDNUMBER') |
81 self._builder_name = os.environ.get('BUILDBOT_BUILDERNAME') | 116 self._builder_name = os.environ.get('BUILDBOT_BUILDERNAME') |
82 self._tests_type = tests_type | 117 self._tests_type = tests_type |
83 self._build_name = 'chromium-android' | |
84 | 118 |
85 if not self._builder_name: | 119 if not self._build_number or not self._builder_name: |
86 raise Exception('You should not be uploading tests results to the server' | 120 raise Exception('You should not be uploading tests results to the server' |
87 'from your local machine.') | 121 'from your local machine.') |
88 | 122 |
89 buildbot_branch = os.environ.get('BUILDBOT_BRANCH') | 123 upstream = (tests_type != 'Chromium_Android_Instrumentation') |
90 if not buildbot_branch: | 124 if upstream: |
Isaac (away)
2013/01/14 19:59:44
Would be a safer to pull this from the factory_pro
frankf
2013/01/14 22:54:42
Currently, the mastername is specified as:
"master
Isaac (use chromium)
2013/01/14 23:37:27
Sounds good to me, but as this increases the risk
| |
91 buildbot_branch = 'master' | 125 from slave import slave_utils |
92 self._master_name = '%s-%s' % (self._build_name, buildbot_branch) | 126 self._build_name = slave_utils.SlaveBuildName(constants.CHROME_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 |