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

Side by Side Diff: build/android/pylib/gtest/gtest_test_instance.py

Issue 2555633002: [Android] Support gtest_filter + gtest_also_run_disabled_tests (Closed)
Patch Set: John comment Created 4 years 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
« no previous file with comments | « no previous file | build/android/pylib/gtest/gtest_test_instance_test.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 HTMLParser
6 import logging 6 import logging
7 import os 7 import os
8 import re 8 import re
9 import tempfile 9 import tempfile
10 import threading 10 import threading
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 # TODO(jbudorick): Remove these once we're no longer parsing stdout to generate 66 # TODO(jbudorick): Remove these once we're no longer parsing stdout to generate
67 # results. 67 # results.
68 _RE_TEST_STATUS = re.compile( 68 _RE_TEST_STATUS = re.compile(
69 r'\[ +((?:RUN)|(?:FAILED)|(?:OK)|(?:CRASHED)) +\]' 69 r'\[ +((?:RUN)|(?:FAILED)|(?:OK)|(?:CRASHED)) +\]'
70 r' ?([^ ]+)?(?: \((\d+) ms\))?$') 70 r' ?([^ ]+)?(?: \((\d+) ms\))?$')
71 # Crash detection constants. 71 # Crash detection constants.
72 _RE_TEST_ERROR = re.compile(r'FAILURES!!! Tests run: \d+,' 72 _RE_TEST_ERROR = re.compile(r'FAILURES!!! Tests run: \d+,'
73 r' Failures: \d+, Errors: 1') 73 r' Failures: \d+, Errors: 1')
74 _RE_TEST_CURRENTLY_RUNNING = re.compile(r'\[ERROR:.*?\]' 74 _RE_TEST_CURRENTLY_RUNNING = re.compile(r'\[ERROR:.*?\]'
75 r' Currently running: (.*)') 75 r' Currently running: (.*)')
76 _RE_DISABLED = re.compile(r'DISABLED_')
77 _RE_FLAKY = re.compile(r'FLAKY_')
76 78
77 def ParseGTestListTests(raw_list): 79 def ParseGTestListTests(raw_list):
78 """Parses a raw test list as provided by --gtest_list_tests. 80 """Parses a raw test list as provided by --gtest_list_tests.
79 81
80 Args: 82 Args:
81 raw_list: The raw test listing with the following format: 83 raw_list: The raw test listing with the following format:
82 84
83 IPCChannelTest. 85 IPCChannelTest.
84 SendMessageInChannelConnected 86 SendMessageInChannelConnected
85 IPCSyncChannelTest. 87 IPCSyncChannelTest.
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 # Split the tests into positive and negative patterns (gtest treats 222 # Split the tests into positive and negative patterns (gtest treats
221 # every pattern after the first '-' sign as an exclusion). 223 # every pattern after the first '-' sign as an exclusion).
222 positive_patterns = ':'.join(l for l in filter_lines if l[0] != '-') 224 positive_patterns = ':'.join(l for l in filter_lines if l[0] != '-')
223 negative_patterns = ':'.join(l[1:] for l in filter_lines if l[0] == '-') 225 negative_patterns = ':'.join(l[1:] for l in filter_lines if l[0] == '-')
224 if negative_patterns: 226 if negative_patterns:
225 negative_patterns = '-' + negative_patterns 227 negative_patterns = '-' + negative_patterns
226 228
227 # Join the filter lines into one, big --gtest_filter argument. 229 # Join the filter lines into one, big --gtest_filter argument.
228 return positive_patterns + negative_patterns 230 return positive_patterns + negative_patterns
229 231
232 def TestNameWithoutDisabledPrefix(test_name):
233 """Modify the test name without disabled prefix if prefix 'DISABLED_' or
234 'FLAKY_' presents.
235
236 Args:
237 test_name: The name of a test.
238 Returns:
239 A test name without prefix 'DISABLED_' or 'FLAKY_'.
240 """
241 disabled_prefixes = [_RE_DISABLED, _RE_FLAKY]
242 for dp in disabled_prefixes:
243 test_name = re.sub(dp, '', test_name, 1)
244 test_name = re.sub(r'\.%s' % dp.pattern, '.', test_name)
jbudorick 2016/12/08 01:32:57 nit: you should be able to replace these two lines
jbudorick 2016/12/08 01:38:01 lgtm w/ this nit
shenghuazhang 2016/12/08 19:37:29 Refactor this by 2 pattern groups. - _RE_DISABLED
245 return test_name
230 246
231 class GtestTestInstance(test_instance.TestInstance): 247 class GtestTestInstance(test_instance.TestInstance):
232 248
233 def __init__(self, args, data_deps_delegate, error_func): 249 def __init__(self, args, data_deps_delegate, error_func):
234 super(GtestTestInstance, self).__init__() 250 super(GtestTestInstance, self).__init__()
235 # TODO(jbudorick): Support multiple test suites. 251 # TODO(jbudorick): Support multiple test suites.
236 if len(args.suite_name) > 1: 252 if len(args.suite_name) > 1:
237 raise ValueError('Platform mode currently supports only 1 gtest suite') 253 raise ValueError('Platform mode currently supports only 1 gtest suite')
238 self._exe_dist_dir = None 254 self._exe_dist_dir = None
239 self._extract_test_list_from_filter = args.extract_test_list_from_filter 255 self._extract_test_list_from_filter = args.extract_test_list_from_filter
(...skipping 182 matching lines...) Expand 10 before | Expand all | Expand 10 after
422 gtest_filter_strings.append(self._gtest_filter) 438 gtest_filter_strings.append(self._gtest_filter)
423 439
424 filtered_test_list = test_list 440 filtered_test_list = test_list
425 # This lock is required because on older versions of Python 441 # This lock is required because on older versions of Python
426 # |unittest_util.FilterTestNames| use of |fnmatch| is not threadsafe. 442 # |unittest_util.FilterTestNames| use of |fnmatch| is not threadsafe.
427 with self._filter_tests_lock: 443 with self._filter_tests_lock:
428 for gtest_filter_string in gtest_filter_strings: 444 for gtest_filter_string in gtest_filter_strings:
429 logging.debug('Filtering tests using: %s', gtest_filter_string) 445 logging.debug('Filtering tests using: %s', gtest_filter_string)
430 filtered_test_list = unittest_util.FilterTestNames( 446 filtered_test_list = unittest_util.FilterTestNames(
431 filtered_test_list, gtest_filter_string) 447 filtered_test_list, gtest_filter_string)
448
449 if self._run_disabled and self._gtest_filter:
450 out_filtered_test_list = list(set(test_list)-set(filtered_test_list))
451 for test in out_filtered_test_list:
jbudorick 2016/12/08 01:32:57 1) this is much better :) 2) to be consistent w/ t
jbudorick 2016/12/08 01:38:01 spoke offline, this is fine.
452 test_name_no_disabled = TestNameWithoutDisabledPrefix(test)
453 if test_name_no_disabled != test and unittest_util.FilterTestNames(
454 [test_name_no_disabled], self._gtest_filter):
455 filtered_test_list.append(test)
432 return filtered_test_list 456 return filtered_test_list
433 457
434 def _GenerateDisabledFilterString(self, disabled_prefixes): 458 def _GenerateDisabledFilterString(self, disabled_prefixes):
435 disabled_filter_items = [] 459 disabled_filter_items = []
436 460
437 if disabled_prefixes is None: 461 if disabled_prefixes is None:
438 disabled_prefixes = ['FAILS_', 'PRE_', 'MANUAL_'] 462 disabled_prefixes = ['FAILS_', 'PRE_', 'MANUAL_']
439 if not self._run_disabled: 463 if not self._run_disabled:
440 disabled_prefixes += ['DISABLED_', 'FLAKY_'] 464 disabled_prefixes += ['DISABLED_', 'FLAKY_']
441 465
442 disabled_filter_items += ['%s*' % dp for dp in disabled_prefixes] 466 disabled_filter_items += ['%s*' % dp for dp in disabled_prefixes]
443 disabled_filter_items += ['*.%s*' % dp for dp in disabled_prefixes] 467 disabled_filter_items += ['*.%s*' % dp for dp in disabled_prefixes]
444 468
445 disabled_tests_file_path = os.path.join( 469 disabled_tests_file_path = os.path.join(
446 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'pylib', 'gtest', 470 host_paths.DIR_SOURCE_ROOT, 'build', 'android', 'pylib', 'gtest',
447 'filter', '%s_disabled' % self._suite) 471 'filter', '%s_disabled' % self._suite)
448 if disabled_tests_file_path and os.path.exists(disabled_tests_file_path): 472 if disabled_tests_file_path and os.path.exists(disabled_tests_file_path):
449 with open(disabled_tests_file_path) as disabled_tests_file: 473 with open(disabled_tests_file_path) as disabled_tests_file:
450 disabled_filter_items += [ 474 disabled_filter_items += [
451 '%s' % l for l in (line.strip() for line in disabled_tests_file) 475 '%s' % l for l in (line.strip() for line in disabled_tests_file)
452 if l and not l.startswith('#')] 476 if l and not l.startswith('#')]
453 477
454 return '*-%s' % ':'.join(disabled_filter_items) 478 return '*-%s' % ':'.join(disabled_filter_items)
455 479
456 #override 480 #override
457 def TearDown(self): 481 def TearDown(self):
458 """Do nothing.""" 482 """Do nothing."""
459 pass 483 pass
460 484
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/gtest/gtest_test_instance_test.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698