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