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, | |
257 shard=False) | |
258 | |
259 | |
260 def _GetTests(test_options, test_package, devices): | 222 def _GetTests(test_options, test_package, devices): |
261 """Get a list of tests. | 223 """Get a list of tests. |
262 | 224 |
263 Args: | 225 Args: |
264 test_options: A GTestOptions object. | 226 test_options: A GTestOptions object. |
265 test_package: A TestPackageApk object. | 227 test_package: A TestPackageApk object. |
266 devices: A list of attached devices. | 228 devices: A list of attached devices. |
267 | 229 |
268 Returns: | 230 Returns: |
269 A list of all the tests in the test suite. | 231 A list of all the tests in the test suite. |
270 """ | 232 """ |
271 def TestListerRunnerFactory(device, _shard_index): | 233 def TestListerRunnerFactory(device, _shard_index): |
272 class TestListerRunner(_TestSetupRunner): | 234 class TestListerRunner(test_runner.TestRunner): |
273 def DeviceSteps(self): | 235 def RunTest(self, _test): |
274 return self.test_package.GetAllTests(self.device) | 236 result = base_test_result.BaseTestResult( |
| 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 |
275 return TestListerRunner(test_options, device, test_package) | 243 return TestListerRunner(test_options, device, test_package) |
276 | 244 |
277 results, _no_retry = test_dispatcher.RunTests( | 245 results, _no_retry = test_dispatcher.RunTests( |
278 ['setup'], TestListerRunnerFactory, devices) | 246 ['gtest_list_tests'], TestListerRunnerFactory, devices) |
279 tests = [] | 247 tests = [] |
280 for r in results.GetAll(): | 248 for r in results.GetAll(): |
281 tests.extend(r.setup_result) | 249 tests.extend(r.test_list) |
282 return tests | 250 return tests |
283 | 251 |
284 | 252 |
285 def _FilterTestsUsingPrefixes(all_tests, pre=False, manual=False): | 253 def _FilterTestsUsingPrefixes(all_tests, pre=False, manual=False): |
286 """Removes tests with disabled prefixes. | 254 """Removes tests with disabled prefixes. |
287 | 255 |
288 Args: | 256 Args: |
289 all_tests: List of tests to filter. | 257 all_tests: List of tests to filter. |
290 pre: If True, include tests with PRE_ prefix. | 258 pre: If True, include tests with PRE_ prefix. |
291 manual: If True, include tests with MANUAL_ prefix. | 259 manual: If True, include tests with MANUAL_ prefix. |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
349 test_options.suite_name) | 317 test_options.suite_name) |
350 if not os.path.exists(test_package.suite_path): | 318 if not os.path.exists(test_package.suite_path): |
351 raise Exception( | 319 raise Exception( |
352 'Did not find %s target. Ensure it has been built.' | 320 'Did not find %s target. Ensure it has been built.' |
353 % test_options.suite_name) | 321 % test_options.suite_name) |
354 logging.warning('Found target %s', test_package.suite_path) | 322 logging.warning('Found target %s', test_package.suite_path) |
355 | 323 |
356 _GenerateDepsDirUsingIsolate(test_options.suite_name, | 324 _GenerateDepsDirUsingIsolate(test_options.suite_name, |
357 test_options.isolate_file_path) | 325 test_options.isolate_file_path) |
358 | 326 |
359 _InstallPackage(test_options, test_package, devices) | |
360 tests = _GetTests(test_options, test_package, devices) | 327 tests = _GetTests(test_options, test_package, devices) |
361 | 328 |
362 # Constructs a new TestRunner with the current options. | 329 # Constructs a new TestRunner with the current options. |
363 def TestRunnerFactory(device, _shard_index): | 330 def TestRunnerFactory(device, _shard_index): |
364 return test_runner.TestRunner( | 331 return test_runner.TestRunner( |
365 test_options, | 332 test_options, |
366 device, | 333 device, |
367 test_package) | 334 test_package) |
368 | 335 |
369 if test_options.run_disabled: | 336 if test_options.run_disabled: |
370 test_options = test_options._replace( | 337 test_options = test_options._replace( |
371 test_arguments=('%s --gtest_also_run_disabled_tests' % | 338 test_arguments=('%s --gtest_also_run_disabled_tests' % |
372 test_options.test_arguments)) | 339 test_options.test_arguments)) |
373 else: | 340 else: |
374 tests = _FilterDisabledTests(tests, test_options.suite_name, | 341 tests = _FilterDisabledTests(tests, test_options.suite_name, |
375 bool(test_options.gtest_filter)) | 342 bool(test_options.gtest_filter)) |
376 if test_options.gtest_filter: | 343 if test_options.gtest_filter: |
377 tests = unittest_util.FilterTestNames(tests, test_options.gtest_filter) | 344 tests = unittest_util.FilterTestNames(tests, test_options.gtest_filter) |
378 | 345 |
379 # Coalesce unit tests into a single test per device | 346 # Coalesce unit tests into a single test per device |
380 if test_options.suite_name != 'content_browsertests': | 347 if test_options.suite_name != 'content_browsertests': |
381 num_devices = len(devices) | 348 num_devices = len(devices) |
382 tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)] | 349 tests = [':'.join(tests[i::num_devices]) for i in xrange(num_devices)] |
383 tests = [t for t in tests if t] | 350 tests = [t for t in tests if t] |
384 | 351 |
385 return (TestRunnerFactory, tests) | 352 return (TestRunnerFactory, tests) |
OLD | NEW |