OLD | NEW |
1 # Copyright 2014 The Chromium Authors. All rights reserved. | 1 # Copyright 2014 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 import HTMLParser |
5 import logging | 6 import logging |
6 import os | 7 import os |
7 import re | 8 import re |
8 import tempfile | 9 import tempfile |
| 10 import xml.etree.ElementTree |
9 | 11 |
10 from devil.android import apk_helper | 12 from devil.android import apk_helper |
11 from pylib import constants | 13 from pylib import constants |
12 from pylib.constants import host_paths | 14 from pylib.constants import host_paths |
13 from pylib.base import base_test_result | 15 from pylib.base import base_test_result |
14 from pylib.base import test_instance | 16 from pylib.base import test_instance |
15 from pylib.utils import isolator | 17 from pylib.utils import isolator |
16 | 18 |
17 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): | 19 with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): |
18 import unittest_util # pylint: disable=import-error | 20 import unittest_util # pylint: disable=import-error |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 results.append(base_test_result.BaseTestResult( | 164 results.append(base_test_result.BaseTestResult( |
163 test_name, result_type, duration, | 165 test_name, result_type, duration, |
164 log=('\n'.join(log) if log else ''))) | 166 log=('\n'.join(log) if log else ''))) |
165 test_name = None | 167 test_name = None |
166 | 168 |
167 handle_possibly_unknown_test() | 169 handle_possibly_unknown_test() |
168 | 170 |
169 return results | 171 return results |
170 | 172 |
171 | 173 |
| 174 def ParseGTestXML(xml_content): |
| 175 """Parse gtest XML result.""" |
| 176 results = [] |
| 177 |
| 178 html = HTMLParser.HTMLParser() |
| 179 |
| 180 # TODO(jbudorick): Unclear how this handles crashes. |
| 181 testsuites = xml.etree.ElementTree.fromstring(xml_content) |
| 182 for testsuite in testsuites: |
| 183 suite_name = testsuite.attrib['name'] |
| 184 for testcase in testsuite: |
| 185 case_name = testcase.attrib['name'] |
| 186 result_type = base_test_result.ResultType.PASS |
| 187 log = [] |
| 188 for failure in testcase: |
| 189 result_type = base_test_result.ResultType.FAIL |
| 190 log.append(html.unescape(failure.attrib['message'])) |
| 191 |
| 192 results.append(base_test_result.BaseTestResult( |
| 193 '%s.%s' % (suite_name, case_name), |
| 194 result_type, |
| 195 int(float(testcase.attrib['time']) * 1000), |
| 196 log=('\n'.join(log) if log else ''))) |
| 197 |
| 198 return results |
| 199 |
| 200 |
172 class GtestTestInstance(test_instance.TestInstance): | 201 class GtestTestInstance(test_instance.TestInstance): |
173 | 202 |
174 def __init__(self, args, isolate_delegate, error_func): | 203 def __init__(self, args, isolate_delegate, error_func): |
175 super(GtestTestInstance, self).__init__() | 204 super(GtestTestInstance, self).__init__() |
176 # TODO(jbudorick): Support multiple test suites. | 205 # TODO(jbudorick): Support multiple test suites. |
177 if len(args.suite_name) > 1: | 206 if len(args.suite_name) > 1: |
178 raise ValueError('Platform mode currently supports only 1 gtest suite') | 207 raise ValueError('Platform mode currently supports only 1 gtest suite') |
179 self._extract_test_list_from_filter = args.extract_test_list_from_filter | 208 self._extract_test_list_from_filter = args.extract_test_list_from_filter |
180 self._shard_timeout = args.shard_timeout | 209 self._shard_timeout = args.shard_timeout |
181 self._suite = args.suite_name[0] | 210 self._suite = args.suite_name[0] |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
244 self._app_data_file_dir = args.app_data_file_dir | 273 self._app_data_file_dir = args.app_data_file_dir |
245 else: | 274 else: |
246 self._app_data_file_dir = tempfile.mkdtemp() | 275 self._app_data_file_dir = tempfile.mkdtemp() |
247 logging.critical('Saving app files to %s', self._app_data_file_dir) | 276 logging.critical('Saving app files to %s', self._app_data_file_dir) |
248 else: | 277 else: |
249 self._app_data_files = None | 278 self._app_data_files = None |
250 self._app_data_file_dir = None | 279 self._app_data_file_dir = None |
251 | 280 |
252 self._test_arguments = args.test_arguments | 281 self._test_arguments = args.test_arguments |
253 | 282 |
| 283 # TODO(jbudorick): Remove this once it's deployed. |
| 284 self._enable_xml_result_parsing = args.enable_xml_result_parsing |
| 285 |
254 @property | 286 @property |
255 def activity(self): | 287 def activity(self): |
256 return self._apk_helper and self._apk_helper.GetActivityName() | 288 return self._apk_helper and self._apk_helper.GetActivityName() |
257 | 289 |
258 @property | 290 @property |
259 def apk(self): | 291 def apk(self): |
260 return self._apk_helper and self._apk_helper.path | 292 return self._apk_helper and self._apk_helper.path |
261 | 293 |
262 @property | 294 @property |
263 def apk_helper(self): | 295 def apk_helper(self): |
264 return self._apk_helper | 296 return self._apk_helper |
265 | 297 |
266 @property | 298 @property |
267 def app_file_dir(self): | 299 def app_file_dir(self): |
268 return self._app_data_file_dir | 300 return self._app_data_file_dir |
269 | 301 |
270 @property | 302 @property |
271 def app_files(self): | 303 def app_files(self): |
272 return self._app_data_files | 304 return self._app_data_files |
273 | 305 |
274 @property | 306 @property |
| 307 def enable_xml_result_parsing(self): |
| 308 return self._enable_xml_result_parsing |
| 309 |
| 310 @property |
275 def exe_dist_dir(self): | 311 def exe_dist_dir(self): |
276 return self._exe_dist_dir | 312 return self._exe_dist_dir |
277 | 313 |
278 @property | 314 @property |
279 def extras(self): | 315 def extras(self): |
280 return self._extras | 316 return self._extras |
281 | 317 |
282 @property | 318 @property |
283 def gtest_filter(self): | 319 def gtest_filter(self): |
284 return self._gtest_filter | 320 return self._gtest_filter |
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
381 if l and not l.startswith('#')] | 417 if l and not l.startswith('#')] |
382 | 418 |
383 return '*-%s' % ':'.join(disabled_filter_items) | 419 return '*-%s' % ':'.join(disabled_filter_items) |
384 | 420 |
385 #override | 421 #override |
386 def TearDown(self): | 422 def TearDown(self): |
387 """Clear the mappings created by SetUp.""" | 423 """Clear the mappings created by SetUp.""" |
388 if self._isolate_delegate: | 424 if self._isolate_delegate: |
389 self._isolate_delegate.Clear() | 425 self._isolate_delegate.Clear() |
390 | 426 |
OLD | NEW |