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

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

Issue 2477813002: Fixing how --gtest-filter-file handles negative patterns. (Closed)
Patch Set: Converted a comment into a doc string. Created 4 years, 1 month 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 xml.etree.ElementTree 10 import xml.etree.ElementTree
(...skipping 180 matching lines...) Expand 10 before | Expand all | Expand 10 after
191 191
192 results.append(base_test_result.BaseTestResult( 192 results.append(base_test_result.BaseTestResult(
193 '%s.%s' % (suite_name, case_name), 193 '%s.%s' % (suite_name, case_name),
194 result_type, 194 result_type,
195 int(float(testcase.attrib['time']) * 1000), 195 int(float(testcase.attrib['time']) * 1000),
196 log=('\n'.join(log) if log else ''))) 196 log=('\n'.join(log) if log else '')))
197 197
198 return results 198 return results
199 199
200 200
201 def ConvertTestFilterFileIntoGTestFilterArgument(input_lines):
202 """Converts test filter file contents into --gtest_filter argument.
203
204 See //testing/buildbot/filters/README.md for description of the
205 syntax that |input_lines| are expected to follow.
206
207 See
208 https://github.com/google/googletest/blob/master/googletest/docs/AdvancedGuide .md#running-a-subset-of-the-tests
209 for description of the syntax that --gtest_filter argument should follow.
210
211 Args:
212 input_lines: An iterable (e.g. a list or a file) containing input lines.
213 Returns:
214 a string suitable for feeding as an argument of --gtest_filter parameter.
215 """
216 # Strip whitespace + skip empty lines and lines beginning with '#'.
217 stripped_lines = (l.strip() for l in input_lines)
218 filter_lines = list(l for l in stripped_lines if l and l[0] != '#')
219
220 # Split the tests into positive and negative patterns (gtest treats
221 # every pattern after the first '-' sign as an exclusion).
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] == '-')
224 if negative_patterns:
225 negative_patterns = '-' + negative_patterns
226
227 # Join the filter lines into one, big --gtest_filter argument.
228 return positive_patterns + negative_patterns
229
230
201 class GtestTestInstance(test_instance.TestInstance): 231 class GtestTestInstance(test_instance.TestInstance):
202 232
203 def __init__(self, args, isolate_delegate, error_func): 233 def __init__(self, args, isolate_delegate, error_func):
204 super(GtestTestInstance, self).__init__() 234 super(GtestTestInstance, self).__init__()
205 # TODO(jbudorick): Support multiple test suites. 235 # TODO(jbudorick): Support multiple test suites.
206 if len(args.suite_name) > 1: 236 if len(args.suite_name) > 1:
207 raise ValueError('Platform mode currently supports only 1 gtest suite') 237 raise ValueError('Platform mode currently supports only 1 gtest suite')
208 self._extract_test_list_from_filter = args.extract_test_list_from_filter 238 self._extract_test_list_from_filter = args.extract_test_list_from_filter
209 self._shard_timeout = args.shard_timeout 239 self._shard_timeout = args.shard_timeout
210 self._suite = args.suite_name[0] 240 self._suite = args.suite_name[0]
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
245 self._shard_timeout = 10 * self._shard_timeout 275 self._shard_timeout = 10 * self._shard_timeout
246 276
247 if not self._apk_helper and not self._exe_dist_dir: 277 if not self._apk_helper and not self._exe_dist_dir:
248 error_func('Could not find apk or executable for %s' % self._suite) 278 error_func('Could not find apk or executable for %s' % self._suite)
249 279
250 self._data_deps = [] 280 self._data_deps = []
251 if args.test_filter: 281 if args.test_filter:
252 self._gtest_filter = args.test_filter 282 self._gtest_filter = args.test_filter
253 elif args.test_filter_file: 283 elif args.test_filter_file:
254 with open(args.test_filter_file, 'r') as f: 284 with open(args.test_filter_file, 'r') as f:
255 # Strip whitespace + skip empty lines and lines beginning with '#'. 285 self._gtest_filter = ConvertTestFilterFileIntoGTestFilterArgument(f)
256 # This should be consistent with processing of
257 # --test-launcher-filter-file in base/test/launcher/test_launcher.cc.
258 stripped_lines = (l.strip() for l in f)
259 filter_lines = (l for l in stripped_lines if l and l[0] != '#')
260 # Join the filter lines into one, big --gtest_filter argument.
261 self._gtest_filter = ':'.join(filter_lines)
262 else: 286 else:
263 self._gtest_filter = None 287 self._gtest_filter = None
264 288
265 if (args.isolate_file_path and 289 if (args.isolate_file_path and
266 not isolator.IsIsolateEmpty(args.isolate_file_path)): 290 not isolator.IsIsolateEmpty(args.isolate_file_path)):
267 self._isolate_abs_path = os.path.abspath(args.isolate_file_path) 291 self._isolate_abs_path = os.path.abspath(args.isolate_file_path)
268 self._isolate_delegate = isolate_delegate 292 self._isolate_delegate = isolate_delegate
269 self._isolated_abs_path = os.path.join( 293 self._isolated_abs_path = os.path.join(
270 constants.GetOutDirectory(), '%s.isolated' % self._suite) 294 constants.GetOutDirectory(), '%s.isolated' % self._suite)
271 else: 295 else:
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 if l and not l.startswith('#')] 447 if l and not l.startswith('#')]
424 448
425 return '*-%s' % ':'.join(disabled_filter_items) 449 return '*-%s' % ':'.join(disabled_filter_items)
426 450
427 #override 451 #override
428 def TearDown(self): 452 def TearDown(self):
429 """Clear the mappings created by SetUp.""" 453 """Clear the mappings created by SetUp."""
430 if self._isolate_delegate: 454 if self._isolate_delegate:
431 self._isolate_delegate.Clear() 455 self._isolate_delegate.Clear()
432 456
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