Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(366)

Side by Side Diff: build/android/pylib/flakiness_dashboard_results_uploader.py

Issue 11885010: [Android] Enable uploading instrumentation tests to flakiness dashboard. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Addressed ilevy's comments Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 # found in the LICENSE file.
4
5 """Uploads the results to the flakiness dashboard server."""
6
7 import logging
8 import os
9 import shutil
10 import subprocess
11 import sys
12 import tempfile
13
14 sys.path.append(os.path.join(sys.path[0], '..', '..', 'third_party',
15 'WebKit', 'Tools', 'Scripts'))
16 from webkitpy.common.system import executive, filesystem
17 from webkitpy.layout_tests.layout_package import json_results_generator
18
19
20 # The JSONResultsGenerator gets the filesystem.join operation from the Port
21 # 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 # that contains the fields required by the generator.
24 class PortDummy(object):
25 def __init__(self):
26 self._executive = executive.Executive()
27 self._filesystem = filesystem.FileSystem()
28
29
30 class JSONResultsGenerator(json_results_generator.JSONResultsGeneratorBase):
31 """Writes test results to a JSON file and handles uploading that file to
32 the test results server.
33 """
34 def __init__(self, port, builder_name, build_name, build_number, tmp_folder,
35 test_results_map, test_results_server, test_type, master_name):
36 super(JSONResultsGenerator, self).__init__(
37 port=port,
38 builder_name=builder_name,
39 build_name=build_name,
40 build_number=build_number,
41 results_file_base_path=tmp_folder,
42 builder_base_url=None,
43 test_results_map=test_results_map,
44 svn_repositories=(('webkit', 'third_party/WebKit'),
45 ('chrome', '.')),
46 test_results_server=test_results_server,
47 test_type=test_type,
48 master_name=master_name)
49
50 #override
51 def _get_modifier_char(self, test_name):
52 if test_name not in self._test_results_map:
53 return self.__class__.NO_DATA_RESULT
54
55 return self._test_results_map[test_name].modifier
56
57 #override
58 def _get_svn_revision(self, in_directory):
59 """Returns the git revision for the given directory.
60
61 Args:
62 in_directory: The directory where git is to be run.
63 """
64 git_dir = self._filesystem.join(os.environ.get('CHROME_SRC'),
65 in_directory,
66 '.git')
67 if self._filesystem.exists(git_dir):
68 # Note: Not thread safe: http://bugs.python.org/issue2320
69 output = subprocess.Popen(
70 ['git', '--git-dir=%s' % git_dir, 'show-ref', '--head',
71 '--hash=10', 'HEAD'],
72 stdout=subprocess.PIPE).communicate()[0].strip()
73 return output
74 return ''
75
76
77 class ResultsUploader(object):
78 """Handles uploading buildbot tests results to the flakiness dashboard."""
79 def __init__(self, tests_type):
80 self._build_number = os.environ.get('BUILDBOT_BUILDNUMBER')
81 self._builder_name = os.environ.get('BUILDBOT_BUILDERNAME')
82 self._tests_type = tests_type
83 self._build_name = 'chromium-android'
84
85 if not self._builder_name:
86 raise Exception('You should not be uploading tests results to the server'
87 'from your local machine.')
88
89 buildbot_branch = os.environ.get('BUILDBOT_BRANCH')
90 if not buildbot_branch:
91 buildbot_branch = 'master'
92 self._master_name = '%s-%s' % (self._build_name, buildbot_branch)
93 self._test_results_map = {}
94
95 def AddResults(self, test_results):
96 conversion_map = [
97 (test_results.ok, False,
98 json_results_generator.JSONResultsGeneratorBase.PASS_RESULT),
99 (test_results.failed, True,
100 json_results_generator.JSONResultsGeneratorBase.FAIL_RESULT),
101 (test_results.crashed, True,
102 "C"),
103 (test_results.unknown, True,
104 json_results_generator.JSONResultsGeneratorBase.NO_DATA_RESULT),
105 ]
106
107 for results_list, failed, modifier in conversion_map:
108 for single_test_result in results_list:
109 test_result = json_results_generator.TestResult(
110 test=single_test_result.name,
111 failed=failed,
112 elapsed_time=single_test_result.dur / 1000)
113 # The WebKit TestResult object sets the modifier it based on test name.
114 # Since we don't use the same test naming convention as WebKit the
115 # modifier will be wrong, so we need to overwrite it.
116 test_result.modifier = modifier
117
118 self._test_results_map[single_test_result.name] = test_result
119
120 def Upload(self, test_results_server):
121 if not self._test_results_map:
122 return
123
124 tmp_folder = tempfile.mkdtemp()
125
126 try:
127 results_generator = JSONResultsGenerator(
128 port=PortDummy(),
129 builder_name=self._builder_name,
130 build_name=self._build_name,
131 build_number=self._build_number,
132 tmp_folder=tmp_folder,
133 test_results_map=self._test_results_map,
134 test_results_server=test_results_server,
135 test_type=self._tests_type,
136 master_name=self._master_name)
137
138 json_files = ["incremental_results.json", "times_ms.json"]
139 results_generator.generate_json_output()
140 results_generator.generate_times_ms_file()
141 results_generator.upload_json_files(json_files)
142 except Exception as e:
143 logging.error("Uploading results to test server failed: %s." % e);
144 finally:
145 shutil.rmtree(tmp_folder)
146
147
148 def Upload(flakiness_dashboard_server, test_type, results):
149 """Reports test results to the flakiness dashboard for Chrome for Android.
150
151 Args:
152 flakiness_dashboard_server: the server to upload the results to.
153 test_type: the type of the tests (as displayed by the flakiness dashboard).
154 results: test results.
155 """
156 uploader = ResultsUploader(test_type)
157 uploader.AddResults(results)
158 uploader.Upload(flakiness_dashboard_server)
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/test_result.py » ('j') | build/android/pylib/utils/flakiness_dashboard_results_uploader.py » ('J')

Powered by Google App Engine
This is Rietveld 408576698