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 logging | 5 import logging |
6 import os | 6 import os |
7 import re | 7 import re |
8 import tempfile | 8 import tempfile |
9 | 9 |
10 from devil.android import apk_helper | 10 from devil.android import apk_helper |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 r'\[ +((?:RUN)|(?:FAILED)|(?:OK)|(?:CRASHED)) +\]' | 91 r'\[ +((?:RUN)|(?:FAILED)|(?:OK)|(?:CRASHED)) +\]' |
92 r' ?([^ ]+)?(?: \((\d+) ms\))?$') | 92 r' ?([^ ]+)?(?: \((\d+) ms\))?$') |
93 _RE_TEST_RUN_STATUS = re.compile( | 93 _RE_TEST_RUN_STATUS = re.compile( |
94 r'\[ +(PASSED|RUNNER_FAILED|CRASHED) \] ?[^ ]+') | 94 r'\[ +(PASSED|RUNNER_FAILED|CRASHED) \] ?[^ ]+') |
95 # Crash detection constants. | 95 # Crash detection constants. |
96 _RE_TEST_ERROR = re.compile(r'FAILURES!!! Tests run: \d+,' | 96 _RE_TEST_ERROR = re.compile(r'FAILURES!!! Tests run: \d+,' |
97 r' Failures: \d+, Errors: 1') | 97 r' Failures: \d+, Errors: 1') |
98 _RE_TEST_CURRENTLY_RUNNING = re.compile(r'\[ERROR:.*?\]' | 98 _RE_TEST_CURRENTLY_RUNNING = re.compile(r'\[ERROR:.*?\]' |
99 r' Currently running: (.*)') | 99 r' Currently running: (.*)') |
100 | 100 |
101 # TODO(jbudorick): Make this a class method of GtestTestInstance once | |
102 # test_package_apk and test_package_exe are gone. | |
103 def ParseGTestListTests(raw_list): | 101 def ParseGTestListTests(raw_list): |
104 """Parses a raw test list as provided by --gtest_list_tests. | 102 """Parses a raw test list as provided by --gtest_list_tests. |
105 | 103 |
106 Args: | 104 Args: |
107 raw_list: The raw test listing with the following format: | 105 raw_list: The raw test listing with the following format: |
108 | 106 |
109 IPCChannelTest. | 107 IPCChannelTest. |
110 SendMessageInChannelConnected | 108 SendMessageInChannelConnected |
111 IPCSyncChannelTest. | 109 IPCSyncChannelTest. |
112 Simple | 110 Simple |
(...skipping 13 matching lines...) Expand all Loading... |
126 if test[0] != ' ': | 124 if test[0] != ' ': |
127 test_case = test.split()[0] | 125 test_case = test.split()[0] |
128 if test_case.endswith('.'): | 126 if test_case.endswith('.'): |
129 current = test_case | 127 current = test_case |
130 elif not 'YOU HAVE' in test: | 128 elif not 'YOU HAVE' in test: |
131 test_name = test.split()[0] | 129 test_name = test.split()[0] |
132 ret += [current + test_name] | 130 ret += [current + test_name] |
133 return ret | 131 return ret |
134 | 132 |
135 | 133 |
| 134 def ParseGTestOutput(output): |
| 135 """Parses raw gtest output and returns a list of results. |
| 136 |
| 137 Args: |
| 138 output: A list of output lines. |
| 139 Returns: |
| 140 A list of base_test_result.BaseTestResults. |
| 141 """ |
| 142 log = [] |
| 143 result_type = None |
| 144 results = [] |
| 145 test_name = None |
| 146 |
| 147 def handle_possibly_unknown_test(): |
| 148 if test_name is not None: |
| 149 results.append(base_test_result.BaseTestResult( |
| 150 test_name, base_test_result.ResultType.UNKNOWN, 0, |
| 151 log=('\n'.join(log) if log else ''))) |
| 152 |
| 153 for l in output: |
| 154 logging.info(l) |
| 155 matcher = _RE_TEST_STATUS.match(l) |
| 156 if matcher: |
| 157 if matcher.group(1) == 'RUN': |
| 158 handle_possibly_unknown_test() |
| 159 log = [] |
| 160 elif matcher.group(1) == 'OK': |
| 161 result_type = base_test_result.ResultType.PASS |
| 162 elif matcher.group(1) == 'FAILED': |
| 163 result_type = base_test_result.ResultType.FAIL |
| 164 elif matcher.group(1) == 'CRASHED': |
| 165 result_type = base_test_result.ResultType.CRASH |
| 166 # Be aware that test name and status might not appear on same line. |
| 167 test_name = matcher.group(2) if matcher.group(2) else test_name |
| 168 duration = int(matcher.group(3)) if matcher.group(3) else 0 |
| 169 |
| 170 else: |
| 171 # Needs another matcher here to match crashes, like those of DCHECK. |
| 172 matcher = _RE_TEST_CURRENTLY_RUNNING.match(l) |
| 173 if matcher: |
| 174 test_name = matcher.group(1) |
| 175 result_type = base_test_result.ResultType.CRASH |
| 176 duration = 0 # Don't know. |
| 177 |
| 178 if log is not None: |
| 179 log.append(l) |
| 180 |
| 181 if result_type: |
| 182 results.append(base_test_result.BaseTestResult( |
| 183 test_name, result_type, duration, |
| 184 log=('\n'.join(log) if log else ''))) |
| 185 log = None |
| 186 result_type = None |
| 187 test_name = None |
| 188 |
| 189 handle_possibly_unknown_test() |
| 190 |
| 191 return results |
| 192 |
| 193 |
136 class GtestTestInstance(test_instance.TestInstance): | 194 class GtestTestInstance(test_instance.TestInstance): |
137 | 195 |
138 def __init__(self, args, isolate_delegate, error_func): | 196 def __init__(self, args, isolate_delegate, error_func): |
139 super(GtestTestInstance, self).__init__() | 197 super(GtestTestInstance, self).__init__() |
140 # TODO(jbudorick): Support multiple test suites. | 198 # TODO(jbudorick): Support multiple test suites. |
141 if len(args.suite_name) > 1: | 199 if len(args.suite_name) > 1: |
142 raise ValueError('Platform mode currently supports only 1 gtest suite') | 200 raise ValueError('Platform mode currently supports only 1 gtest suite') |
143 self._extract_test_list_from_filter = args.extract_test_list_from_filter | 201 self._extract_test_list_from_filter = args.extract_test_list_from_filter |
144 self._shard_timeout = args.shard_timeout | 202 self._shard_timeout = args.shard_timeout |
145 self._suite = args.suite_name[0] | 203 self._suite = args.suite_name[0] |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
344 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'pylib', 'gtest', | 402 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'pylib', 'gtest', |
345 'filter', '%s_disabled' % self._suite) | 403 'filter', '%s_disabled' % self._suite) |
346 if disabled_tests_file_path and os.path.exists(disabled_tests_file_path): | 404 if disabled_tests_file_path and os.path.exists(disabled_tests_file_path): |
347 with open(disabled_tests_file_path) as disabled_tests_file: | 405 with open(disabled_tests_file_path) as disabled_tests_file: |
348 disabled_filter_items += [ | 406 disabled_filter_items += [ |
349 '%s' % l for l in (line.strip() for line in disabled_tests_file) | 407 '%s' % l for l in (line.strip() for line in disabled_tests_file) |
350 if l and not l.startswith('#')] | 408 if l and not l.startswith('#')] |
351 | 409 |
352 return '*-%s' % ':'.join(disabled_filter_items) | 410 return '*-%s' % ':'.join(disabled_filter_items) |
353 | 411 |
354 # pylint: disable=no-self-use | |
355 def ParseGTestOutput(self, output): | |
356 """Parses raw gtest output and returns a list of results. | |
357 | |
358 Args: | |
359 output: A list of output lines. | |
360 Returns: | |
361 A list of base_test_result.BaseTestResults. | |
362 """ | |
363 log = [] | |
364 result_type = None | |
365 results = [] | |
366 test_name = None | |
367 for l in output: | |
368 logging.info(l) | |
369 matcher = _RE_TEST_STATUS.match(l) | |
370 if matcher: | |
371 # Be aware that test name and status might not appear on same line. | |
372 test_name = matcher.group(2) if matcher.group(2) else test_name | |
373 duration = int(matcher.group(3)) if matcher.group(3) else 0 | |
374 if matcher.group(1) == 'RUN': | |
375 log = [] | |
376 elif matcher.group(1) == 'OK': | |
377 result_type = base_test_result.ResultType.PASS | |
378 elif matcher.group(1) == 'FAILED': | |
379 result_type = base_test_result.ResultType.FAIL | |
380 elif matcher.group(1) == 'CRASHED': | |
381 result_type = base_test_result.ResultType.CRASH | |
382 | |
383 # Needs another matcher here to match crashes, like those of DCHECK. | |
384 matcher = _RE_TEST_CURRENTLY_RUNNING.match(l) | |
385 if matcher: | |
386 test_name = matcher.group(1) | |
387 result_type = base_test_result.ResultType.CRASH | |
388 duration = 0 # Don't know. | |
389 | |
390 if log is not None: | |
391 log.append(l) | |
392 | |
393 if result_type: | |
394 results.append(base_test_result.BaseTestResult( | |
395 test_name, result_type, duration, | |
396 log=('\n'.join(log) if log else ''))) | |
397 log = None | |
398 result_type = None | |
399 | |
400 return results | |
401 | |
402 #override | 412 #override |
403 def TearDown(self): | 413 def TearDown(self): |
404 """Clear the mappings created by SetUp.""" | 414 """Clear the mappings created by SetUp.""" |
405 if self._isolate_delegate: | 415 if self._isolate_delegate: |
406 self._isolate_delegate.Clear() | 416 self._isolate_delegate.Clear() |
407 | 417 |
OLD | NEW |