Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 import fnmatch | |
| 5 import logging | 6 import logging |
| 6 import os | 7 import os |
| 7 | 8 |
| 8 from pylib import android_commands | 9 from pylib import android_commands |
| 9 from pylib import cmd_helper | 10 from pylib import cmd_helper |
| 10 from pylib import constants | 11 from pylib import constants |
| 11 from pylib import ports | 12 from pylib import ports |
| 12 from pylib.base import shard | 13 from pylib.base import shard |
| 13 from pylib.gtest import dispatch as gtest_dispatch | 14 from pylib.gtest import dispatch as gtest_dispatch |
| 14 from pylib.gtest import test_runner | 15 from pylib.gtest import test_runner |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 46 options.test_arguments, | 47 options.test_arguments, |
| 47 options.timeout, | 48 options.timeout, |
| 48 options.cleanup_test_files, | 49 options.cleanup_test_files, |
| 49 options.tool, | 50 options.tool, |
| 50 options.build_type, | 51 options.build_type, |
| 51 options.webkit, | 52 options.webkit, |
| 52 constants.BROWSERTEST_TEST_PACKAGE_NAME, | 53 constants.BROWSERTEST_TEST_PACKAGE_NAME, |
| 53 constants.BROWSERTEST_TEST_ACTIVITY_NAME, | 54 constants.BROWSERTEST_TEST_ACTIVITY_NAME, |
| 54 constants.BROWSERTEST_COMMAND_LINE_FILE) | 55 constants.BROWSERTEST_COMMAND_LINE_FILE) |
| 55 | 56 |
| 56 # Get tests and split them up based on the number of devices. | 57 # Get tests and split them up based on the number of devices. |
| 58 all_enabled = gtest_dispatch.GetAllEnabledTests(RunnerFactory, | |
| 59 attached_devices) | |
| 57 if options.gtest_filter: | 60 if options.gtest_filter: |
| 58 all_tests = [t for t in options.gtest_filter.split(':') if t] | 61 all_tests = _ApplyGtestFilter(all_enabled, options.gtest_filter) |
| 59 else: | 62 else: |
| 60 all_enabled = gtest_dispatch.GetAllEnabledTests(RunnerFactory, | |
| 61 attached_devices) | |
| 62 all_tests = _FilterTests(all_enabled) | 63 all_tests = _FilterTests(all_enabled) |
| 63 | 64 |
| 64 # Run tests. | 65 # Run tests. |
| 65 # TODO(nileshagrawal): remove this abnormally long setup timeout once fewer | 66 # TODO(nileshagrawal): remove this abnormally long setup timeout once fewer |
| 66 # files are pushed to the devices for content_browsertests: crbug.com/138275 | 67 # files are pushed to the devices for content_browsertests: crbug.com/138275 |
| 67 setup_timeout = 20 * 60 # 20 minutes | 68 setup_timeout = 20 * 60 # 20 minutes |
| 68 test_results = shard.ShardAndRunTests(RunnerFactory, attached_devices, | 69 test_results = shard.ShardAndRunTests(RunnerFactory, attached_devices, |
| 69 all_tests, options.build_type, | 70 all_tests, options.build_type, |
| 70 setup_timeout=setup_timeout, | 71 setup_timeout=setup_timeout, |
| 71 test_timeout=None, | 72 test_timeout=None, |
| 72 num_retries=options.num_retries) | 73 num_retries=options.num_retries) |
| 73 report_results.LogFull( | 74 report_results.LogFull( |
| 74 results=test_results, | 75 results=test_results, |
| 75 test_type='Unit test', | 76 test_type='Unit test', |
| 76 test_package=constants.BROWSERTEST_SUITE_NAME, | 77 test_package=constants.BROWSERTEST_SUITE_NAME, |
| 77 build_type=options.build_type, | 78 build_type=options.build_type, |
| 78 flakiness_server=options.flakiness_dashboard_server) | 79 flakiness_server=options.flakiness_dashboard_server) |
| 79 report_results.PrintAnnotation(test_results) | 80 report_results.PrintAnnotation(test_results) |
| 80 | 81 |
| 81 def _FilterTests(all_enabled_tests): | 82 def _FilterTests(all_enabled_tests): |
| 82 """Filters out tests and fixtures starting with PRE_ and MANUAL_.""" | 83 """Filters out tests and fixtures starting with PRE_ and MANUAL_.""" |
| 83 return [t for t in all_enabled_tests if _ShouldRunOnBot(t)] | 84 return [t for t in all_enabled_tests if _ShouldRunOnBot(t)] |
| 84 | 85 |
| 86 def _ApplyGtestFilter(all_enabled_tests, gtest_filter): | |
|
frankf
2013/05/16 01:15:52
Take a look at //chrome/test/pylib/common/unittest
Sami
2013/05/16 10:41:34
Thanks for the tip -- code reuse ftw!
| |
| 87 """Computes the list of tests that match a gtest filter. | |
| 88 | |
| 89 Args: | |
| 90 all_enabled_tests: List of available and enabled tests. | |
| 91 gtest_filter: Gtest filter string. See testing/gtest/src/gtest.cc. | |
| 92 | |
| 93 Returns: | |
| 94 A list of tests that match the given gtest filter. | |
| 95 """ | |
| 96 filter_patterns = [t for t in gtest_filter.split(':') if t] | |
| 97 # Any test that matches a positive patterns but does not match any negative | |
| 98 # pattern should be returned. | |
| 99 result = set() | |
| 100 for pattern in filter_patterns: | |
| 101 if not pattern.startswith('-'): | |
| 102 result.update([t for t in all_enabled_tests | |
| 103 if fnmatch.fnmatch(t, pattern)]) | |
| 104 for pattern in filter_patterns: | |
| 105 if pattern.startswith('-'): | |
| 106 result.difference_update([t for t in all_tests | |
|
frankf
2013/05/16 01:15:52
all_tests -> all_enabeld_tests
Sami
2013/05/16 10:41:34
Oops, well spotted.
| |
| 107 if fnmatch.fnmatch(t, pattern[1:])]) | |
| 108 return list(result) | |
| 109 | |
| 85 def _ShouldRunOnBot(test): | 110 def _ShouldRunOnBot(test): |
| 86 fixture, case = test.split('.', 1) | 111 fixture, case = test.split('.', 1) |
| 87 if _StartsWith(fixture, case, "PRE_"): | 112 if _StartsWith(fixture, case, "PRE_"): |
| 88 return False | 113 return False |
| 89 if _StartsWith(fixture, case, "MANUAL_"): | 114 if _StartsWith(fixture, case, "MANUAL_"): |
| 90 return False | 115 return False |
| 91 return True | 116 return True |
| 92 | 117 |
| 93 def _StartsWith(a, b, prefix): | 118 def _StartsWith(a, b, prefix): |
| 94 return a.startswith(prefix) or b.startswith(prefix) | 119 return a.startswith(prefix) or b.startswith(prefix) |
| OLD | NEW |