OLD | NEW |
---|---|
1 # Copyright 2013 The Chromium Authors. All rights reserved. | 1 # Copyright 2013 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 """Generates test runner factory and tests for GTests.""" | 5 """Generates test runner factory and tests for GTests.""" |
6 # pylint: disable=W0212 | 6 # pylint: disable=W0212 |
7 | 7 |
8 import fnmatch | 8 import fnmatch |
9 import glob | 9 import glob |
10 import logging | 10 import logging |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
211 return '*' | 211 return '*' |
212 | 212 |
213 filters = [x for x in [x.strip() for x in file(filter_file_path).readlines()] | 213 filters = [x for x in [x.strip() for x in file(filter_file_path).readlines()] |
214 if x and x[0] != '#'] | 214 if x and x[0] != '#'] |
215 disabled_filter = '*-%s' % ':'.join(filters) | 215 disabled_filter = '*-%s' % ':'.join(filters) |
216 logging.info('Applying filter "%s" obtained from %s', | 216 logging.info('Applying filter "%s" obtained from %s', |
217 disabled_filter, filter_file_path) | 217 disabled_filter, filter_file_path) |
218 return disabled_filter | 218 return disabled_filter |
219 | 219 |
220 | 220 |
221 # A helper class for scheduling setup-related tasks on devices. | |
222 class _TestSetupRunner(test_runner.TestRunner): | |
223 def SetUp(self): | |
224 pass | |
225 | |
226 def TearDown(self): | |
227 pass | |
228 | |
229 def DeviceSteps(self): | |
230 """ Steps to be run for device. Should be implemented in subclasses. | |
231 | |
232 Returns: | |
233 A value that will be put into 'setup_result' field of corresponding | |
234 test result. | |
235 """ | |
bulach
2014/06/11 16:59:11
nit: raise NotImplementedError()
Victor Starodub
2014/07/02 14:48:17
Done.
| |
236 | |
237 def RunTest(self, _test): | |
238 result = base_test_result.BaseTestResult( | |
239 "dummy", base_test_result.ResultType.PASS) | |
bulach
2014/06/11 16:59:11
nit: s/"/'/
Victor Starodub
2014/07/02 14:48:17
Done.
| |
240 | |
241 result.setup_result = self.DeviceSteps() | |
242 results = base_test_result.TestRunResults() | |
243 results.AddResult(result) | |
244 return results, None | |
245 | |
246 | |
247 def _InstallPackage(test_options, test_package, devices): | |
248 def TestInstallerRunnerFactory(device, _shard_index): | |
249 class TestInstallerRunner(_TestSetupRunner): | |
250 def DeviceSteps(self): | |
251 self.test_package.Install(self.device) | |
252 return TestInstallerRunner(test_options, device, test_package) | |
253 | |
254 test_dispatcher.RunTests(['setup'], TestInstallerRunnerFactory, devices, | |
255 shard=False) | |
256 | |
257 | |
221 def _GetTests(test_options, test_package, devices): | 258 def _GetTests(test_options, test_package, devices): |
222 """Get a list of tests. | 259 """Get a list of tests. |
223 | 260 |
224 Args: | 261 Args: |
225 test_options: A GTestOptions object. | 262 test_options: A GTestOptions object. |
226 test_package: A TestPackageApk object. | 263 test_package: A TestPackageApk object. |
227 devices: A list of attached devices. | 264 devices: A list of attached devices. |
228 | 265 |
229 Returns: | 266 Returns: |
230 A list of all the tests in the test suite. | 267 A list of all the tests in the test suite. |
231 """ | 268 """ |
232 def TestListerRunnerFactory(device, _shard_index): | 269 def TestListerRunnerFactory(device, _shard_index): |
233 class TestListerRunner(test_runner.TestRunner): | 270 class TestListerRunner(_TestSetupRunner): |
jbudorick
2014/06/16 18:16:51
One other thought, since we were talking about thi
Victor Starodub
2014/07/02 14:48:17
Second install attempt would be ~2.5s if the packa
| |
234 def RunTest(self, _test): | 271 def DeviceSteps(self): |
235 result = base_test_result.BaseTestResult( | 272 return self.test_package.GetAllTests(self.device) |
236 'gtest_list_tests', base_test_result.ResultType.PASS) | |
237 self.test_package.Install(self.device) | |
238 result.test_list = self.test_package.GetAllTests(self.device) | |
239 results = base_test_result.TestRunResults() | |
240 results.AddResult(result) | |
241 return results, None | |
242 return TestListerRunner(test_options, device, test_package) | 273 return TestListerRunner(test_options, device, test_package) |
243 | 274 |
244 results, _no_retry = test_dispatcher.RunTests( | 275 results, _no_retry = test_dispatcher.RunTests( |
245 ['gtest_list_tests'], TestListerRunnerFactory, devices) | 276 ['setup'], TestListerRunnerFactory, devices) |
246 tests = [] | 277 tests = [] |
247 for r in results.GetAll(): | 278 for r in results.GetAll(): |
248 tests.extend(r.test_list) | 279 tests.extend(r.setup_result) |
249 return tests | 280 return tests |
250 | 281 |
251 | 282 |
252 def _FilterTestsUsingPrefixes(all_tests, pre=False, manual=False): | 283 def _FilterTestsUsingPrefixes(all_tests, pre=False, manual=False): |
253 """Removes tests with disabled prefixes. | 284 """Removes tests with disabled prefixes. |
254 | 285 |
255 Args: | 286 Args: |
256 all_tests: List of tests to filter. | 287 all_tests: List of tests to filter. |
257 pre: If True, include tests with PRE_ prefix. | 288 pre: If True, include tests with PRE_ prefix. |
258 manual: If True, include tests with MANUAL_ prefix. | 289 manual: If True, include tests with MANUAL_ prefix. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
316 test_options.suite_name) | 347 test_options.suite_name) |
317 if not os.path.exists(test_package.suite_path): | 348 if not os.path.exists(test_package.suite_path): |
318 raise Exception( | 349 raise Exception( |
319 'Did not find %s target. Ensure it has been built.' | 350 'Did not find %s target. Ensure it has been built.' |
320 % test_options.suite_name) | 351 % test_options.suite_name) |
321 logging.warning('Found target %s', test_package.suite_path) | 352 logging.warning('Found target %s', test_package.suite_path) |
322 | 353 |
323 _GenerateDepsDirUsingIsolate(test_options.suite_name, | 354 _GenerateDepsDirUsingIsolate(test_options.suite_name, |
324 test_options.isolate_file_path) | 355 test_options.isolate_file_path) |
325 | 356 |
357 _InstallPackage(test_options, test_package, devices) | |
jbudorick
2014/06/11 18:22:58
I believe this is the "complex setup" you're refer
Victor Starodub
2014/06/11 19:13:29
We're just installing the package, we don't try pu
| |
326 tests = _GetTests(test_options, test_package, devices) | 358 tests = _GetTests(test_options, test_package, devices) |
327 | 359 |
328 # Constructs a new TestRunner with the current options. | 360 # Constructs a new TestRunner with the current options. |
329 def TestRunnerFactory(device, _shard_index): | 361 def TestRunnerFactory(device, _shard_index): |
330 return test_runner.TestRunner( | 362 return test_runner.TestRunner( |
331 test_options, | 363 test_options, |
332 device, | 364 device, |
333 test_package) | 365 test_package) |
334 | 366 |
335 if test_options.run_disabled: | 367 if test_options.run_disabled: |
336 test_options = test_options._replace( | 368 test_options = test_options._replace( |
337 test_arguments=('%s --gtest_also_run_disabled_tests' % | 369 test_arguments=('%s --gtest_also_run_disabled_tests' % |
338 test_options.test_arguments)) | 370 test_options.test_arguments)) |
339 else: | 371 else: |
340 tests = _FilterDisabledTests(tests, test_options.suite_name, | 372 tests = _FilterDisabledTests(tests, test_options.suite_name, |
341 bool(test_options.gtest_filter)) | 373 bool(test_options.gtest_filter)) |
342 if test_options.gtest_filter: | 374 if test_options.gtest_filter: |
343 tests = unittest_util.FilterTestNames(tests, test_options.gtest_filter) | 375 tests = unittest_util.FilterTestNames(tests, test_options.gtest_filter) |
344 | 376 |
345 # Coalesce unit tests into a single test per device | 377 # Coalesce unit tests into a single test per device |
346 if test_options.suite_name != 'content_browsertests': | 378 if test_options.suite_name != 'content_browsertests': |
347 num_devices = len(devices) | 379 num_devices = len(devices) |
348 tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)] | 380 tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)] |
349 tests = [t for t in tests if t] | 381 tests = [t for t in tests if t] |
350 | 382 |
351 return (TestRunnerFactory, tests) | 383 return (TestRunnerFactory, tests) |
OLD | NEW |