jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 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 |
| 3 | # found in the LICENSE file. |
| 4 | |
jbudorick | 5cea02e | 2016-09-23 17:06:16 | [diff] [blame] | 5 | import HTMLParser |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 6 | import logging |
| 7 | import os |
jbudorick | 8f49528 | 2014-12-15 22:23:29 | [diff] [blame] | 8 | import re |
jbudorick | 5ee4589 | 2015-06-10 18:46:22 | [diff] [blame] | 9 | import tempfile |
mikecase | c37f55c | 2016-11-18 20:59:22 | [diff] [blame] | 10 | import threading |
jbudorick | 5cea02e | 2016-09-23 17:06:16 | [diff] [blame] | 11 | import xml.etree.ElementTree |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 12 | |
jbudorick | 06162944 | 2015-09-03 18:00:57 | [diff] [blame] | 13 | from devil.android import apk_helper |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 14 | from pylib import constants |
jbudorick | d28554a | 2016-01-11 16:22:59 | [diff] [blame] | 15 | from pylib.constants import host_paths |
jbudorick | 8f49528 | 2014-12-15 22:23:29 | [diff] [blame] | 16 | from pylib.base import base_test_result |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 17 | from pylib.base import test_instance |
Zhiling Huang | 4e9529db | 2017-09-01 21:55:24 | [diff] [blame] | 18 | from pylib.symbols import stack_symbolizer |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 19 | |
jbudorick | d28554a | 2016-01-11 16:22:59 | [diff] [blame] | 20 | with host_paths.SysPath(host_paths.BUILD_COMMON_PATH): |
| 21 | import unittest_util # pylint: disable=import-error |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 22 | |
| 23 | |
jbudorick | 08b097a93 | 2015-05-22 02:54:57 | [diff] [blame] | 24 | BROWSER_TEST_SUITES = [ |
| 25 | 'components_browsertests', |
| 26 | 'content_browsertests', |
| 27 | ] |
| 28 | |
jcivelli | f4462a35 | 2017-01-10 04:45:59 | [diff] [blame] | 29 | RUN_IN_SUB_THREAD_TEST_SUITES = [ |
| 30 | # Multiprocess tests should be run outside of the main thread. |
| 31 | 'base_unittests', # file_locking_unittest.cc uses a child process. |
| 32 | 'ipc_perftests', |
| 33 | 'ipc_tests', |
Oksana Zhuravlova | 32f0a13 | 2018-02-27 00:12:55 | [diff] [blame^] | 34 | 'mojo_perftests', |
Oksana Zhuravlova | 1792d19f | 2018-02-22 19:13:31 | [diff] [blame] | 35 | 'mojo_unittests', |
jcivelli | f4462a35 | 2017-01-10 04:45:59 | [diff] [blame] | 36 | 'net_unittests' |
| 37 | ] |
jbudorick | 566592ab | 2015-09-21 15:32:47 | [diff] [blame] | 38 | |
jbudorick | 08b097a93 | 2015-05-22 02:54:57 | [diff] [blame] | 39 | |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 40 | # Used for filtering large data deps at a finer grain than what's allowed in |
| 41 | # isolate files since pushing deps to devices is expensive. |
| 42 | # Wildcards are allowed. |
| 43 | _DEPS_EXCLUSION_LIST = [ |
| 44 | 'chrome/test/data/extensions/api_test', |
| 45 | 'chrome/test/data/extensions/secure_shell', |
| 46 | 'chrome/test/data/firefox*', |
| 47 | 'chrome/test/data/gpu', |
| 48 | 'chrome/test/data/image_decoding', |
| 49 | 'chrome/test/data/import', |
| 50 | 'chrome/test/data/page_cycler', |
| 51 | 'chrome/test/data/perf', |
| 52 | 'chrome/test/data/pyauto_private', |
| 53 | 'chrome/test/data/safari_import', |
| 54 | 'chrome/test/data/scroll', |
| 55 | 'chrome/test/data/third_party', |
| 56 | 'third_party/hunspell_dictionaries/*.dic', |
| 57 | # crbug.com/258690 |
| 58 | 'webkit/data/bmp_decoder', |
| 59 | 'webkit/data/ico_decoder', |
| 60 | ] |
| 61 | |
| 62 | |
jbudorick | 590a3d7 | 2015-06-12 23:53:31 | [diff] [blame] | 63 | _EXTRA_NATIVE_TEST_ACTIVITY = ( |
| 64 | 'org.chromium.native_test.NativeTestInstrumentationTestRunner.' |
| 65 | 'NativeTestActivity') |
jbudorick | 566592ab | 2015-09-21 15:32:47 | [diff] [blame] | 66 | _EXTRA_RUN_IN_SUB_THREAD = ( |
ynovikov | 389d9e44 | 2016-05-27 02:34:56 | [diff] [blame] | 67 | 'org.chromium.native_test.NativeTest.RunInSubThread') |
jbudorick | 6ef3cbd | 2015-09-30 09:04:19 | [diff] [blame] | 68 | EXTRA_SHARD_NANO_TIMEOUT = ( |
| 69 | 'org.chromium.native_test.NativeTestInstrumentationTestRunner.' |
| 70 | 'ShardNanoTimeout') |
jbudorick | 58b4d36 | 2015-09-08 16:44:59 | [diff] [blame] | 71 | _EXTRA_SHARD_SIZE_LIMIT = ( |
jbudorick | 590a3d7 | 2015-06-12 23:53:31 | [diff] [blame] | 72 | 'org.chromium.native_test.NativeTestInstrumentationTestRunner.' |
| 73 | 'ShardSizeLimit') |
| 74 | |
jbudorick | 8f49528 | 2014-12-15 22:23:29 | [diff] [blame] | 75 | # TODO(jbudorick): Remove these once we're no longer parsing stdout to generate |
| 76 | # results. |
| 77 | _RE_TEST_STATUS = re.compile( |
hzl | 09361b7 | 2016-03-09 00:00:15 | [diff] [blame] | 78 | r'\[ +((?:RUN)|(?:FAILED)|(?:OK)|(?:CRASHED)) +\]' |
| 79 | r' ?([^ ]+)?(?: \((\d+) ms\))?$') |
hzl | 09361b7 | 2016-03-09 00:00:15 | [diff] [blame] | 80 | # Crash detection constants. |
| 81 | _RE_TEST_ERROR = re.compile(r'FAILURES!!! Tests run: \d+,' |
| 82 | r' Failures: \d+, Errors: 1') |
| 83 | _RE_TEST_CURRENTLY_RUNNING = re.compile(r'\[ERROR:.*?\]' |
| 84 | r' Currently running: (.*)') |
shenghuazhang | 61757ce | 2016-12-08 22:53:01 | [diff] [blame] | 85 | _RE_DISABLED = re.compile(r'DISABLED_') |
| 86 | _RE_FLAKY = re.compile(r'FLAKY_') |
jbudorick | 8f49528 | 2014-12-15 22:23:29 | [diff] [blame] | 87 | |
Zhiling Huang | 4e9529db | 2017-09-01 21:55:24 | [diff] [blame] | 88 | # Detect stack line in stdout. |
| 89 | _STACK_LINE_RE = re.compile(r'\s*#\d+') |
| 90 | |
jbudorick | 8f49528 | 2014-12-15 22:23:29 | [diff] [blame] | 91 | def ParseGTestListTests(raw_list): |
| 92 | """Parses a raw test list as provided by --gtest_list_tests. |
| 93 | |
| 94 | Args: |
| 95 | raw_list: The raw test listing with the following format: |
| 96 | |
| 97 | IPCChannelTest. |
| 98 | SendMessageInChannelConnected |
| 99 | IPCSyncChannelTest. |
| 100 | Simple |
| 101 | DISABLED_SendWithTimeoutMixedOKAndTimeout |
| 102 | |
| 103 | Returns: |
| 104 | A list of all tests. For the above raw listing: |
| 105 | |
| 106 | [IPCChannelTest.SendMessageInChannelConnected, IPCSyncChannelTest.Simple, |
| 107 | IPCSyncChannelTest.DISABLED_SendWithTimeoutMixedOKAndTimeout] |
| 108 | """ |
| 109 | ret = [] |
| 110 | current = '' |
| 111 | for test in raw_list: |
| 112 | if not test: |
| 113 | continue |
jbudorick | ef60bcc9 | 2016-12-19 18:33:07 | [diff] [blame] | 114 | if not test.startswith(' '): |
jbudorick | 8f49528 | 2014-12-15 22:23:29 | [diff] [blame] | 115 | test_case = test.split()[0] |
| 116 | if test_case.endswith('.'): |
| 117 | current = test_case |
jbudorick | ef60bcc9 | 2016-12-19 18:33:07 | [diff] [blame] | 118 | else: |
| 119 | test = test.strip() |
| 120 | if test and not 'YOU HAVE' in test: |
| 121 | test_name = test.split()[0] |
| 122 | ret += [current + test_name] |
jbudorick | 8f49528 | 2014-12-15 22:23:29 | [diff] [blame] | 123 | return ret |
| 124 | |
| 125 | |
Zhiling Huang | 4e9529db | 2017-09-01 21:55:24 | [diff] [blame] | 126 | def ParseGTestOutput(output, symbolizer, device_abi): |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 127 | """Parses raw gtest output and returns a list of results. |
| 128 | |
| 129 | Args: |
| 130 | output: A list of output lines. |
Zhiling Huang | 4e9529db | 2017-09-01 21:55:24 | [diff] [blame] | 131 | symbolizer: The symbolizer used to symbolize stack. |
| 132 | device_abi: Device abi that is needed for symbolization. |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 133 | Returns: |
| 134 | A list of base_test_result.BaseTestResults. |
| 135 | """ |
John Budorick | c4f4073 | 2016-07-12 18:13:59 | [diff] [blame] | 136 | duration = 0 |
| 137 | fallback_result_type = None |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 138 | log = [] |
Zhiling Huang | 4e9529db | 2017-09-01 21:55:24 | [diff] [blame] | 139 | stack = [] |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 140 | result_type = None |
| 141 | results = [] |
| 142 | test_name = None |
| 143 | |
Zhiling Huang | 4e9529db | 2017-09-01 21:55:24 | [diff] [blame] | 144 | def symbolize_stack_and_merge_with_log(): |
| 145 | log_string = '\n'.join(log or []) |
| 146 | if not stack: |
| 147 | stack_string = '' |
| 148 | else: |
| 149 | stack_string = '\n'.join( |
| 150 | symbolizer.ExtractAndResolveNativeStackTraces( |
| 151 | stack, device_abi)) |
| 152 | return '%s\n%s' % (log_string, stack_string) |
| 153 | |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 154 | def handle_possibly_unknown_test(): |
| 155 | if test_name is not None: |
| 156 | results.append(base_test_result.BaseTestResult( |
shenghuazhang | d0287a2 | 2017-03-15 18:57:31 | [diff] [blame] | 157 | TestNameWithoutDisabledPrefix(test_name), |
John Budorick | c4f4073 | 2016-07-12 18:13:59 | [diff] [blame] | 158 | fallback_result_type or base_test_result.ResultType.UNKNOWN, |
Zhiling Huang | 4e9529db | 2017-09-01 21:55:24 | [diff] [blame] | 159 | duration, log=symbolize_stack_and_merge_with_log())) |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 160 | |
| 161 | for l in output: |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 162 | matcher = _RE_TEST_STATUS.match(l) |
| 163 | if matcher: |
| 164 | if matcher.group(1) == 'RUN': |
| 165 | handle_possibly_unknown_test() |
John Budorick | c4f4073 | 2016-07-12 18:13:59 | [diff] [blame] | 166 | duration = 0 |
| 167 | fallback_result_type = None |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 168 | log = [] |
Zhiling Huang | 4e9529db | 2017-09-01 21:55:24 | [diff] [blame] | 169 | stack = [] |
John Budorick | c4f4073 | 2016-07-12 18:13:59 | [diff] [blame] | 170 | result_type = None |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 171 | elif matcher.group(1) == 'OK': |
| 172 | result_type = base_test_result.ResultType.PASS |
| 173 | elif matcher.group(1) == 'FAILED': |
| 174 | result_type = base_test_result.ResultType.FAIL |
| 175 | elif matcher.group(1) == 'CRASHED': |
John Budorick | c4f4073 | 2016-07-12 18:13:59 | [diff] [blame] | 176 | fallback_result_type = base_test_result.ResultType.CRASH |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 177 | # Be aware that test name and status might not appear on same line. |
| 178 | test_name = matcher.group(2) if matcher.group(2) else test_name |
| 179 | duration = int(matcher.group(3)) if matcher.group(3) else 0 |
| 180 | |
| 181 | else: |
| 182 | # Needs another matcher here to match crashes, like those of DCHECK. |
| 183 | matcher = _RE_TEST_CURRENTLY_RUNNING.match(l) |
| 184 | if matcher: |
| 185 | test_name = matcher.group(1) |
| 186 | result_type = base_test_result.ResultType.CRASH |
| 187 | duration = 0 # Don't know. |
| 188 | |
| 189 | if log is not None: |
Zhiling Huang | b73321e5 | 2017-09-06 21:51:38 | [diff] [blame] | 190 | if not matcher and _STACK_LINE_RE.match(l): |
Zhiling Huang | 4e9529db | 2017-09-01 21:55:24 | [diff] [blame] | 191 | stack.append(l) |
| 192 | else: |
| 193 | log.append(l) |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 194 | |
jbudorick | 244896c | 2016-05-31 23:35:06 | [diff] [blame] | 195 | if result_type and test_name: |
Benjamin Pastene | d3fca32 | 2018-01-05 21:05:44 | [diff] [blame] | 196 | # Don't bother symbolizing output if the test passed. |
| 197 | if result_type == base_test_result.ResultType.PASS: |
| 198 | stack = [] |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 199 | results.append(base_test_result.BaseTestResult( |
shenghuazhang | d0287a2 | 2017-03-15 18:57:31 | [diff] [blame] | 200 | TestNameWithoutDisabledPrefix(test_name), result_type, duration, |
Zhiling Huang | 4e9529db | 2017-09-01 21:55:24 | [diff] [blame] | 201 | log=symbolize_stack_and_merge_with_log())) |
jbudorick | f746111 | 2016-05-27 04:30:49 | [diff] [blame] | 202 | test_name = None |
| 203 | |
| 204 | handle_possibly_unknown_test() |
| 205 | |
| 206 | return results |
| 207 | |
| 208 | |
jbudorick | 5cea02e | 2016-09-23 17:06:16 | [diff] [blame] | 209 | def ParseGTestXML(xml_content): |
| 210 | """Parse gtest XML result.""" |
| 211 | results = [] |
John Budorick | 79cd156c | 2017-09-15 21:23:28 | [diff] [blame] | 212 | if not xml_content: |
| 213 | return results |
jbudorick | 5cea02e | 2016-09-23 17:06:16 | [diff] [blame] | 214 | |
| 215 | html = HTMLParser.HTMLParser() |
| 216 | |
jbudorick | 5cea02e | 2016-09-23 17:06:16 | [diff] [blame] | 217 | testsuites = xml.etree.ElementTree.fromstring(xml_content) |
| 218 | for testsuite in testsuites: |
| 219 | suite_name = testsuite.attrib['name'] |
| 220 | for testcase in testsuite: |
| 221 | case_name = testcase.attrib['name'] |
| 222 | result_type = base_test_result.ResultType.PASS |
| 223 | log = [] |
| 224 | for failure in testcase: |
| 225 | result_type = base_test_result.ResultType.FAIL |
| 226 | log.append(html.unescape(failure.attrib['message'])) |
| 227 | |
| 228 | results.append(base_test_result.BaseTestResult( |
shenghuazhang | d0287a2 | 2017-03-15 18:57:31 | [diff] [blame] | 229 | '%s.%s' % (suite_name, TestNameWithoutDisabledPrefix(case_name)), |
jbudorick | 5cea02e | 2016-09-23 17:06:16 | [diff] [blame] | 230 | result_type, |
| 231 | int(float(testcase.attrib['time']) * 1000), |
| 232 | log=('\n'.join(log) if log else ''))) |
| 233 | |
| 234 | return results |
| 235 | |
| 236 | |
lukasza | 1f3f8c66 | 2016-11-08 16:53:56 | [diff] [blame] | 237 | def ConvertTestFilterFileIntoGTestFilterArgument(input_lines): |
| 238 | """Converts test filter file contents into --gtest_filter argument. |
| 239 | |
| 240 | See //testing/buildbot/filters/README.md for description of the |
| 241 | syntax that |input_lines| are expected to follow. |
| 242 | |
| 243 | See |
| 244 | https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide.md#running-a-subset-of-the-tests |
| 245 | for description of the syntax that --gtest_filter argument should follow. |
| 246 | |
| 247 | Args: |
| 248 | input_lines: An iterable (e.g. a list or a file) containing input lines. |
| 249 | Returns: |
| 250 | a string suitable for feeding as an argument of --gtest_filter parameter. |
| 251 | """ |
Sergey Ulanov | 3d567ae | 2017-08-26 02:11:54 | [diff] [blame] | 252 | # Strip comments and whitespace from each line and filter non-empty lines. |
| 253 | stripped_lines = (l.split('#', 1)[0].strip() for l in input_lines) |
| 254 | filter_lines = list(l for l in stripped_lines if l) |
lukasza | 1f3f8c66 | 2016-11-08 16:53:56 | [diff] [blame] | 255 | |
| 256 | # Split the tests into positive and negative patterns (gtest treats |
| 257 | # every pattern after the first '-' sign as an exclusion). |
| 258 | positive_patterns = ':'.join(l for l in filter_lines if l[0] != '-') |
| 259 | negative_patterns = ':'.join(l[1:] for l in filter_lines if l[0] == '-') |
| 260 | if negative_patterns: |
| 261 | negative_patterns = '-' + negative_patterns |
| 262 | |
| 263 | # Join the filter lines into one, big --gtest_filter argument. |
| 264 | return positive_patterns + negative_patterns |
| 265 | |
shenghuazhang | 61757ce | 2016-12-08 22:53:01 | [diff] [blame] | 266 | def TestNameWithoutDisabledPrefix(test_name): |
| 267 | """Modify the test name without disabled prefix if prefix 'DISABLED_' or |
| 268 | 'FLAKY_' presents. |
| 269 | |
| 270 | Args: |
| 271 | test_name: The name of a test. |
| 272 | Returns: |
| 273 | A test name without prefix 'DISABLED_' or 'FLAKY_'. |
| 274 | """ |
| 275 | disabled_prefixes = [_RE_DISABLED, _RE_FLAKY] |
| 276 | for dp in disabled_prefixes: |
| 277 | test_name = dp.sub('', test_name) |
| 278 | return test_name |
lukasza | 1f3f8c66 | 2016-11-08 16:53:56 | [diff] [blame] | 279 | |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 280 | class GtestTestInstance(test_instance.TestInstance): |
| 281 | |
jbudorick | d29ecfa7 | 2016-11-18 22:45:42 | [diff] [blame] | 282 | def __init__(self, args, data_deps_delegate, error_func): |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 283 | super(GtestTestInstance, self).__init__() |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 284 | # TODO(jbudorick): Support multiple test suites. |
jbudorick | 8f49528 | 2014-12-15 22:23:29 | [diff] [blame] | 285 | if len(args.suite_name) > 1: |
rnephew | 5c49978 | 2014-12-12 19:08:55 | [diff] [blame] | 286 | raise ValueError('Platform mode currently supports only 1 gtest suite') |
Edward Lemur | e627ef8 | 2017-12-13 13:00:33 | [diff] [blame] | 287 | self._chartjson_result_file = args.chartjson_result_file |
hzl | 19e0bee7 | 2016-11-15 01:14:22 | [diff] [blame] | 288 | self._exe_dist_dir = None |
jbudorick | 84188b5 | 2017-03-15 05:29:24 | [diff] [blame] | 289 | self._external_shard_index = args.test_launcher_shard_index |
agrieve | 0f5e53e | 2016-02-04 03:47:37 | [diff] [blame] | 290 | self._extract_test_list_from_filter = args.extract_test_list_from_filter |
jbudorick | 84188b5 | 2017-03-15 05:29:24 | [diff] [blame] | 291 | self._filter_tests_lock = threading.Lock() |
Edward Lemur | e627ef8 | 2017-12-13 13:00:33 | [diff] [blame] | 292 | self._gs_test_artifacts_bucket = args.gs_test_artifacts_bucket |
jbudorick | 24616eb | 2015-10-06 02:40:57 | [diff] [blame] | 293 | self._shard_timeout = args.shard_timeout |
hzl | 19e0bee7 | 2016-11-15 01:14:22 | [diff] [blame] | 294 | self._store_tombstones = args.store_tombstones |
agrieve | 0f5e53e | 2016-02-04 03:47:37 | [diff] [blame] | 295 | self._suite = args.suite_name[0] |
Zhiling Huang | 4e9529db | 2017-09-01 21:55:24 | [diff] [blame] | 296 | self._symbolizer = stack_symbolizer.Symbolizer(None, False) |
Edward Lemur | e627ef8 | 2017-12-13 13:00:33 | [diff] [blame] | 297 | self._total_external_shards = args.test_launcher_total_shards |
Andrew Grieve | 0904ce15 | 2017-10-03 21:09:12 | [diff] [blame] | 298 | self._wait_for_java_debugger = args.wait_for_java_debugger |
jbudorick | 24616eb | 2015-10-06 02:40:57 | [diff] [blame] | 299 | |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 300 | # GYP: |
| 301 | if args.executable_dist_dir: |
| 302 | self._exe_dist_dir = os.path.abspath(args.executable_dist_dir) |
| 303 | else: |
| 304 | # TODO(agrieve): Remove auto-detection once recipes pass flag explicitly. |
| 305 | exe_dist_dir = os.path.join(constants.GetOutDirectory(), |
| 306 | '%s__dist' % self._suite) |
| 307 | |
| 308 | if os.path.exists(exe_dist_dir): |
| 309 | self._exe_dist_dir = exe_dist_dir |
agrieve | 4931af8c | 2016-02-10 19:25:26 | [diff] [blame] | 310 | |
| 311 | incremental_part = '' |
Andrew Grieve | 2ec70f3 | 2017-08-11 20:47:43 | [diff] [blame] | 312 | if args.test_apk_incremental_install_json: |
agrieve | 4931af8c | 2016-02-10 19:25:26 | [diff] [blame] | 313 | incremental_part = '_incremental' |
| 314 | |
agrieve | 7c7f080 | 2015-10-09 19:08:50 | [diff] [blame] | 315 | apk_path = os.path.join( |
jbudorick | 08b097a93 | 2015-05-22 02:54:57 | [diff] [blame] | 316 | constants.GetOutDirectory(), '%s_apk' % self._suite, |
agrieve | 1a02e58 | 2015-10-15 21:35:39 | [diff] [blame] | 317 | '%s-debug%s.apk' % (self._suite, incremental_part)) |
Andrew Grieve | 2ec70f3 | 2017-08-11 20:47:43 | [diff] [blame] | 318 | self._test_apk_incremental_install_json = ( |
| 319 | args.test_apk_incremental_install_json) |
agrieve | 7c7f080 | 2015-10-09 19:08:50 | [diff] [blame] | 320 | if not os.path.exists(apk_path): |
| 321 | self._apk_helper = None |
jbudorick | 590a3d7 | 2015-06-12 23:53:31 | [diff] [blame] | 322 | else: |
agrieve | 7c7f080 | 2015-10-09 19:08:50 | [diff] [blame] | 323 | self._apk_helper = apk_helper.ApkHelper(apk_path) |
jbudorick | 590a3d7 | 2015-06-12 23:53:31 | [diff] [blame] | 324 | self._extras = { |
agrieve | 7c7f080 | 2015-10-09 19:08:50 | [diff] [blame] | 325 | _EXTRA_NATIVE_TEST_ACTIVITY: self._apk_helper.GetActivityName(), |
jbudorick | 590a3d7 | 2015-06-12 23:53:31 | [diff] [blame] | 326 | } |
jbudorick | 566592ab | 2015-09-21 15:32:47 | [diff] [blame] | 327 | if self._suite in RUN_IN_SUB_THREAD_TEST_SUITES: |
| 328 | self._extras[_EXTRA_RUN_IN_SUB_THREAD] = 1 |
jbudorick | 590a3d7 | 2015-06-12 23:53:31 | [diff] [blame] | 329 | if self._suite in BROWSER_TEST_SUITES: |
| 330 | self._extras[_EXTRA_SHARD_SIZE_LIMIT] = 1 |
jbudorick | 24616eb | 2015-10-06 02:40:57 | [diff] [blame] | 331 | self._extras[EXTRA_SHARD_NANO_TIMEOUT] = int(1e9 * self._shard_timeout) |
jbudorick | 8932b41 | 2016-05-19 17:52:23 | [diff] [blame] | 332 | self._shard_timeout = 10 * self._shard_timeout |
Andrew Grieve | 0904ce15 | 2017-10-03 21:09:12 | [diff] [blame] | 333 | if args.wait_for_java_debugger: |
| 334 | self._extras[EXTRA_SHARD_NANO_TIMEOUT] = int(1e15) # Forever |
jbudorick | 590a3d7 | 2015-06-12 23:53:31 | [diff] [blame] | 335 | |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 336 | if not self._apk_helper and not self._exe_dist_dir: |
jbudorick | 8f49528 | 2014-12-15 22:23:29 | [diff] [blame] | 337 | error_func('Could not find apk or executable for %s' % self._suite) |
| 338 | |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 339 | self._data_deps = [] |
jbudorick | 442a693 | 2015-02-03 03:01:15 | [diff] [blame] | 340 | if args.test_filter: |
| 341 | self._gtest_filter = args.test_filter |
| 342 | elif args.test_filter_file: |
| 343 | with open(args.test_filter_file, 'r') as f: |
lukasza | 1f3f8c66 | 2016-11-08 16:53:56 | [diff] [blame] | 344 | self._gtest_filter = ConvertTestFilterFileIntoGTestFilterArgument(f) |
jbudorick | 442a693 | 2015-02-03 03:01:15 | [diff] [blame] | 345 | else: |
| 346 | self._gtest_filter = None |
jbudorick | 590a3d7 | 2015-06-12 23:53:31 | [diff] [blame] | 347 | |
shenghuazhang | b58f48f4 | 2016-12-01 01:50:34 | [diff] [blame] | 348 | self._run_disabled = args.run_disabled |
| 349 | |
jbudorick | d29ecfa7 | 2016-11-18 22:45:42 | [diff] [blame] | 350 | self._data_deps_delegate = data_deps_delegate |
| 351 | self._runtime_deps_path = args.runtime_deps_path |
| 352 | if not self._runtime_deps_path: |
| 353 | logging.warning('No data dependencies will be pushed.') |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 354 | |
jbudorick | 5ee4589 | 2015-06-10 18:46:22 | [diff] [blame] | 355 | if args.app_data_files: |
| 356 | self._app_data_files = args.app_data_files |
| 357 | if args.app_data_file_dir: |
| 358 | self._app_data_file_dir = args.app_data_file_dir |
| 359 | else: |
| 360 | self._app_data_file_dir = tempfile.mkdtemp() |
| 361 | logging.critical('Saving app files to %s', self._app_data_file_dir) |
| 362 | else: |
| 363 | self._app_data_files = None |
| 364 | self._app_data_file_dir = None |
| 365 | |
jbudorick | 7d30806c | 2017-03-16 19:18:52 | [diff] [blame] | 366 | self._flags = None |
| 367 | self._initializeCommandLineFlags(args) |
jbudorick | a58ea51 | 2015-10-20 14:36:58 | [diff] [blame] | 368 | |
jbudorick | 5cea02e | 2016-09-23 17:06:16 | [diff] [blame] | 369 | # TODO(jbudorick): Remove this once it's deployed. |
| 370 | self._enable_xml_result_parsing = args.enable_xml_result_parsing |
| 371 | |
jbudorick | 7d30806c | 2017-03-16 19:18:52 | [diff] [blame] | 372 | def _initializeCommandLineFlags(self, args): |
| 373 | self._flags = [] |
| 374 | if args.command_line_flags: |
| 375 | self._flags.extend(args.command_line_flags) |
| 376 | if args.device_flags_file: |
| 377 | with open(args.device_flags_file) as f: |
| 378 | stripped_lines = (l.strip() for l in f) |
| 379 | self._flags.extend(flag for flag in stripped_lines if flag) |
| 380 | if args.run_disabled: |
| 381 | self._flags.append('--gtest_also_run_disabled_tests') |
jbudorick | 7d30806c | 2017-03-16 19:18:52 | [diff] [blame] | 382 | |
jbudorick | a58ea51 | 2015-10-20 14:36:58 | [diff] [blame] | 383 | @property |
| 384 | def activity(self): |
| 385 | return self._apk_helper and self._apk_helper.GetActivityName() |
| 386 | |
| 387 | @property |
| 388 | def apk(self): |
| 389 | return self._apk_helper and self._apk_helper.path |
| 390 | |
| 391 | @property |
| 392 | def apk_helper(self): |
| 393 | return self._apk_helper |
| 394 | |
| 395 | @property |
| 396 | def app_file_dir(self): |
| 397 | return self._app_data_file_dir |
| 398 | |
| 399 | @property |
| 400 | def app_files(self): |
| 401 | return self._app_data_files |
| 402 | |
| 403 | @property |
jbudorick | 5cea02e | 2016-09-23 17:06:16 | [diff] [blame] | 404 | def enable_xml_result_parsing(self): |
| 405 | return self._enable_xml_result_parsing |
| 406 | |
| 407 | @property |
agrieve | 62ab0028 | 2016-04-05 02:03:45 | [diff] [blame] | 408 | def exe_dist_dir(self): |
| 409 | return self._exe_dist_dir |
jbudorick | a58ea51 | 2015-10-20 14:36:58 | [diff] [blame] | 410 | |
| 411 | @property |
jbudorick | 84188b5 | 2017-03-15 05:29:24 | [diff] [blame] | 412 | def external_shard_index(self): |
| 413 | return self._external_shard_index |
| 414 | |
| 415 | @property |
| 416 | def extract_test_list_from_filter(self): |
| 417 | return self._extract_test_list_from_filter |
| 418 | |
| 419 | @property |
jbudorick | a58ea51 | 2015-10-20 14:36:58 | [diff] [blame] | 420 | def extras(self): |
| 421 | return self._extras |
| 422 | |
agrieve | 065d746 | 2015-10-13 23:23:36 | [diff] [blame] | 423 | @property |
jbudorick | 7d30806c | 2017-03-16 19:18:52 | [diff] [blame] | 424 | def flags(self): |
| 425 | return self._flags |
shenghuazhang | b58f48f4 | 2016-12-01 01:50:34 | [diff] [blame] | 426 | |
| 427 | @property |
Edward Lemur | 29acd73 | 2017-09-26 15:20:04 | [diff] [blame] | 428 | def gs_test_artifacts_bucket(self): |
| 429 | return self._gs_test_artifacts_bucket |
| 430 | |
| 431 | @property |
agrieve | 065d746 | 2015-10-13 23:23:36 | [diff] [blame] | 432 | def gtest_filter(self): |
| 433 | return self._gtest_filter |
| 434 | |
jbudorick | a58ea51 | 2015-10-20 14:36:58 | [diff] [blame] | 435 | @property |
Edward Lemur | e627ef8 | 2017-12-13 13:00:33 | [diff] [blame] | 436 | def chartjson_result_file(self): |
| 437 | return self._chartjson_result_file |
| 438 | |
| 439 | @property |
jbudorick | a58ea51 | 2015-10-20 14:36:58 | [diff] [blame] | 440 | def package(self): |
| 441 | return self._apk_helper and self._apk_helper.GetPackageName() |
| 442 | |
| 443 | @property |
| 444 | def permissions(self): |
| 445 | return self._apk_helper and self._apk_helper.GetPermissions() |
| 446 | |
| 447 | @property |
| 448 | def runner(self): |
| 449 | return self._apk_helper and self._apk_helper.GetInstrumentationName() |
| 450 | |
| 451 | @property |
| 452 | def shard_timeout(self): |
| 453 | return self._shard_timeout |
| 454 | |
| 455 | @property |
hzl | 19e0bee7 | 2016-11-15 01:14:22 | [diff] [blame] | 456 | def store_tombstones(self): |
| 457 | return self._store_tombstones |
| 458 | |
| 459 | @property |
jbudorick | a58ea51 | 2015-10-20 14:36:58 | [diff] [blame] | 460 | def suite(self): |
| 461 | return self._suite |
| 462 | |
| 463 | @property |
Zhiling Huang | 4e9529db | 2017-09-01 21:55:24 | [diff] [blame] | 464 | def symbolizer(self): |
| 465 | return self._symbolizer |
| 466 | |
| 467 | @property |
Andrew Grieve | 2ec70f3 | 2017-08-11 20:47:43 | [diff] [blame] | 468 | def test_apk_incremental_install_json(self): |
| 469 | return self._test_apk_incremental_install_json |
agrieve | 4931af8c | 2016-02-10 19:25:26 | [diff] [blame] | 470 | |
| 471 | @property |
jbudorick | 84188b5 | 2017-03-15 05:29:24 | [diff] [blame] | 472 | def total_external_shards(self): |
| 473 | return self._total_external_shards |
agrieve | 0f5e53e | 2016-02-04 03:47:37 | [diff] [blame] | 474 | |
Andrew Grieve | 0904ce15 | 2017-10-03 21:09:12 | [diff] [blame] | 475 | @property |
| 476 | def wait_for_java_debugger(self): |
| 477 | return self._wait_for_java_debugger |
| 478 | |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 479 | #override |
| 480 | def TestType(self): |
| 481 | return 'gtest' |
| 482 | |
| 483 | #override |
| 484 | def SetUp(self): |
| 485 | """Map data dependencies via isolate.""" |
jbudorick | d29ecfa7 | 2016-11-18 22:45:42 | [diff] [blame] | 486 | self._data_deps.extend( |
| 487 | self._data_deps_delegate(self._runtime_deps_path)) |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 488 | |
| 489 | def GetDataDependencies(self): |
| 490 | """Returns the test suite's data dependencies. |
| 491 | |
| 492 | Returns: |
| 493 | A list of (host_path, device_path) tuples to push. If device_path is |
| 494 | None, the client is responsible for determining where to push the file. |
| 495 | """ |
| 496 | return self._data_deps |
| 497 | |
| 498 | def FilterTests(self, test_list, disabled_prefixes=None): |
| 499 | """Filters |test_list| based on prefixes and, if present, a filter string. |
| 500 | |
| 501 | Args: |
| 502 | test_list: The list of tests to filter. |
| 503 | disabled_prefixes: A list of test prefixes to filter. Defaults to |
| 504 | DISABLED_, FLAKY_, FAILS_, PRE_, and MANUAL_ |
| 505 | Returns: |
| 506 | A filtered list of tests to run. |
| 507 | """ |
| 508 | gtest_filter_strings = [ |
| 509 | self._GenerateDisabledFilterString(disabled_prefixes)] |
| 510 | if self._gtest_filter: |
| 511 | gtest_filter_strings.append(self._gtest_filter) |
| 512 | |
| 513 | filtered_test_list = test_list |
mikecase | c37f55c | 2016-11-18 20:59:22 | [diff] [blame] | 514 | # This lock is required because on older versions of Python |
| 515 | # |unittest_util.FilterTestNames| use of |fnmatch| is not threadsafe. |
| 516 | with self._filter_tests_lock: |
| 517 | for gtest_filter_string in gtest_filter_strings: |
| 518 | logging.debug('Filtering tests using: %s', gtest_filter_string) |
| 519 | filtered_test_list = unittest_util.FilterTestNames( |
| 520 | filtered_test_list, gtest_filter_string) |
shenghuazhang | 61757ce | 2016-12-08 22:53:01 | [diff] [blame] | 521 | |
| 522 | if self._run_disabled and self._gtest_filter: |
| 523 | out_filtered_test_list = list(set(test_list)-set(filtered_test_list)) |
| 524 | for test in out_filtered_test_list: |
| 525 | test_name_no_disabled = TestNameWithoutDisabledPrefix(test) |
| 526 | if test_name_no_disabled != test and unittest_util.FilterTestNames( |
| 527 | [test_name_no_disabled], self._gtest_filter): |
| 528 | filtered_test_list.append(test) |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 529 | return filtered_test_list |
| 530 | |
| 531 | def _GenerateDisabledFilterString(self, disabled_prefixes): |
| 532 | disabled_filter_items = [] |
| 533 | |
| 534 | if disabled_prefixes is None: |
shenghuazhang | b58f48f4 | 2016-12-01 01:50:34 | [diff] [blame] | 535 | disabled_prefixes = ['FAILS_', 'PRE_', 'MANUAL_'] |
| 536 | if not self._run_disabled: |
| 537 | disabled_prefixes += ['DISABLED_', 'FLAKY_'] |
| 538 | |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 539 | disabled_filter_items += ['%s*' % dp for dp in disabled_prefixes] |
jbudorick | 8f49528 | 2014-12-15 22:23:29 | [diff] [blame] | 540 | disabled_filter_items += ['*.%s*' % dp for dp in disabled_prefixes] |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 541 | |
| 542 | disabled_tests_file_path = os.path.join( |
jbudorick | d28554a | 2016-01-11 16:22:59 | [diff] [blame] | 543 | host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'pylib', 'gtest', |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 544 | 'filter', '%s_disabled' % self._suite) |
| 545 | if disabled_tests_file_path and os.path.exists(disabled_tests_file_path): |
| 546 | with open(disabled_tests_file_path) as disabled_tests_file: |
| 547 | disabled_filter_items += [ |
| 548 | '%s' % l for l in (line.strip() for line in disabled_tests_file) |
| 549 | if l and not l.startswith('#')] |
| 550 | |
| 551 | return '*-%s' % ':'.join(disabled_filter_items) |
| 552 | |
| 553 | #override |
| 554 | def TearDown(self): |
jbudorick | d29ecfa7 | 2016-11-18 22:45:42 | [diff] [blame] | 555 | """Do nothing.""" |
| 556 | pass |
jbudorick | 27e6905f | 2014-12-03 23:27:48 | [diff] [blame] | 557 | |