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

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: 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 | no next file » | 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 209 matching lines...) Expand 10 before | Expand all | Expand 10 after
220 # Split the tests into positive and negative patterns (gtest treats 220 # Split the tests into positive and negative patterns (gtest treats
221 # every pattern after the first '-' sign as an exclusion). 221 # every pattern after the first '-' sign as an exclusion).
222 positive_patterns = ':'.join(l for l in filter_lines if l[0] != '-') 222 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] == '-') 223 negative_patterns = ':'.join(l[1:] for l in filter_lines if l[0] == '-')
224 if negative_patterns: 224 if negative_patterns:
225 negative_patterns = '-' + negative_patterns 225 negative_patterns = '-' + negative_patterns
226 226
227 # Join the filter lines into one, big --gtest_filter argument. 227 # Join the filter lines into one, big --gtest_filter argument.
228 return positive_patterns + negative_patterns 228 return positive_patterns + negative_patterns
229 229
230 def TestNameWithoutDisabledPrefix(test_name):
jbudorick 2016/12/06 03:22:05 This should have tests.
shenghuazhang 2016/12/06 23:56:06 Done.
231 """Modify the test name without disabled prefix if prefix 'DISABLED_' or
232 'FLAKY_' presents.
233
234 Args:
235 test_name: The name of a test.
236 Returns:
237 A test name without prefix 'DISABLED_' or 'FLAKY_'.
238 """
239 disabled_prefixes = ['DISABLED_', 'FLAKY_']
jbudorick 2016/12/06 03:22:05 compile DISABLED_ and FLAKY_ into regexes at modul
shenghuazhang 2016/12/06 23:56:06 Done.
240 for dp in disabled_prefixes:
241 if re.match(r'%s' % dp, test_name):
jbudorick 2016/12/06 03:22:05 I think you should be able to do this with one or
shenghuazhang 2016/12/06 23:56:06 Done.
242 test_name = re.sub(r'%s' % dp, '', test_name, 1)
243 if test_name.find(r'\.%s' % dp):
244 test_name = re.sub(r'\.%s' % dp, r'.', test_name)
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 if self._run_disabled:
449 for test in test_list:
jbudorick 2016/12/06 03:22:05 While this appears to work, it looks like it'll be
shenghuazhang 2016/12/06 23:56:06 Refactor the code by escape the outer gtest_filter
450 test_name_no_disabled = [TestNameWithoutDisabledPrefix(test)]
451 if test_name_no_disabled[0] == test:
452 continue
453 if unittest_util.FilterTestNames(test_name_no_disabled,
454 gtest_filter_string) and test not in filtered_test_list:
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 | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698