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 copy | 5 import copy |
| 6 import fnmatch |
6 import logging | 7 import logging |
7 import os | 8 import os |
8 | 9 |
9 from pylib import android_commands | 10 from pylib import android_commands |
10 from pylib import cmd_helper | 11 from pylib import cmd_helper |
11 from pylib import ports | 12 from pylib import ports |
| 13 from pylib.base import shard |
| 14 from pylib.base import test_result |
12 from pylib.utils import emulator | 15 from pylib.utils import emulator |
13 from pylib.utils import xvfb | 16 from pylib.utils import xvfb |
14 | 17 |
15 import gtest_config | 18 import gtest_config |
16 import test_sharder | 19 import test_runner |
17 | 20 |
18 | 21 |
19 def _FullyQualifiedTestSuites(exe, option_test_suite, build_type): | 22 def _FullyQualifiedTestSuites(exe, option_test_suite, build_type): |
20 """Get a list of absolute paths to test suite targets. | 23 """Get a list of absolute paths to test suite targets. |
21 | 24 |
22 Args: | 25 Args: |
23 exe: if True, use the executable-based test runner. | 26 exe: if True, use the executable-based test runner. |
24 option_test_suite: the test_suite specified as an option. | 27 option_test_suite: the test_suite specified as an option. |
25 build_type: 'Release' or 'Debug'. | 28 build_type: 'Release' or 'Debug'. |
26 | 29 |
(...skipping 20 matching lines...) Expand all Loading... |
47 for t in all_test_suites] | 50 for t in all_test_suites] |
48 for t, q in zip(all_test_suites, qualified_test_suites): | 51 for t, q in zip(all_test_suites, qualified_test_suites): |
49 if not os.path.exists(q): | 52 if not os.path.exists(q): |
50 raise Exception('Test suite %s not found in %s.\n' | 53 raise Exception('Test suite %s not found in %s.\n' |
51 'Supported test suites:\n %s\n' | 54 'Supported test suites:\n %s\n' |
52 'Ensure it has been built.\n' % | 55 'Ensure it has been built.\n' % |
53 (t, q, gtest_config.STABLE_TEST_SUITES)) | 56 (t, q, gtest_config.STABLE_TEST_SUITES)) |
54 return zip(all_test_suites, qualified_test_suites) | 57 return zip(all_test_suites, qualified_test_suites) |
55 | 58 |
56 | 59 |
| 60 def _GetTestsFromDevice(runner): |
| 61 """Get a list of tests from a device, excluding disabled tests. |
| 62 |
| 63 Args: |
| 64 runner: a TestRunner. |
| 65 """ |
| 66 # The executable/apk needs to be copied before we can call GetAllTests. |
| 67 runner.test_package.StripAndCopyExecutable() |
| 68 all_tests = runner.test_package.GetAllTests() |
| 69 # Only includes tests that do not have any match in the disabled list. |
| 70 disabled_list = runner.GetDisabledTests() |
| 71 return filter(lambda t: not any([fnmatch.fnmatch(t, disabled_pattern) |
| 72 for disabled_pattern in disabled_list]), |
| 73 all_tests) |
| 74 |
| 75 |
| 76 def _GetAllEnabledTests(runner_factory, devices): |
| 77 """Get all enabled tests. |
| 78 |
| 79 Obtains a list of enabled tests from the test package on the device, |
| 80 then filters it again using the disabled list on the host. |
| 81 |
| 82 Args: |
| 83 runner_factory: callable that takes a devices and returns a TestRunner. |
| 84 devices: list of devices. |
| 85 |
| 86 Returns: |
| 87 List of all enabled tests. |
| 88 |
| 89 Raises Exception if all devices failed. |
| 90 """ |
| 91 for device in devices: |
| 92 try: |
| 93 logging.info('Obtaining tests from %s', device) |
| 94 runner = runner_factory(device) |
| 95 return _GetTestsFromDevice(runner) |
| 96 except Exception as e: |
| 97 logging.warning('Failed obtaining tests from %s with exception: %s', |
| 98 device, e) |
| 99 raise Exception('No device available to get the list of tests.') |
| 100 |
| 101 |
57 def _RunATestSuite(options, suite_name): | 102 def _RunATestSuite(options, suite_name): |
58 """Run a single test suite. | 103 """Run a single test suite. |
59 | 104 |
60 Helper for Dispatch() to allow stop/restart of the emulator across | 105 Helper for Dispatch() to allow stop/restart of the emulator across |
61 test bundles. If using the emulator, we start it on entry and stop | 106 test bundles. If using the emulator, we start it on entry and stop |
62 it on exit. | 107 it on exit. |
63 | 108 |
64 Args: | 109 Args: |
65 options: options for running the tests. | 110 options: options for running the tests. |
66 suite_name: name of the test suite being run. | 111 suite_name: name of the test suite being run. |
(...skipping 16 matching lines...) Expand all Loading... |
83 | 128 |
84 if not attached_devices: | 129 if not attached_devices: |
85 logging.critical('A device must be attached and online.') | 130 logging.critical('A device must be attached and online.') |
86 return 1 | 131 return 1 |
87 | 132 |
88 # Reset the test port allocation. It's important to do it before starting | 133 # Reset the test port allocation. It's important to do it before starting |
89 # to dispatch any tests. | 134 # to dispatch any tests. |
90 if not ports.ResetTestServerPortAllocation(): | 135 if not ports.ResetTestServerPortAllocation(): |
91 raise Exception('Failed to reset test server port.') | 136 raise Exception('Failed to reset test server port.') |
92 | 137 |
| 138 # Constructs a new TestRunner with the current options. |
| 139 def RunnerFactory(device): |
| 140 return test_runner.TestRunner( |
| 141 device, |
| 142 options.test_suite, |
| 143 options.test_arguments, |
| 144 options.timeout, |
| 145 options.cleanup_test_files, |
| 146 options.tool, |
| 147 options.build_type, |
| 148 options.webkit) |
| 149 |
| 150 # Get tests and split them up based on the number of devices. |
93 if options.gtest_filter: | 151 if options.gtest_filter: |
94 logging.warning('Sharding is not possible with these configurations.') | 152 all_tests = [t for t in options.gtest_filter.split(':') if t] |
95 attached_devices = [attached_devices[0]] | 153 else: |
| 154 all_tests = _GetAllEnabledTests(RunnerFactory, attached_devices) |
| 155 num_devices = len(attached_devices) |
| 156 tests = [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)] |
| 157 tests = [t for t in tests if t] |
96 | 158 |
97 sharder = test_sharder.TestSharder( | 159 # Run tests. |
98 attached_devices, | 160 test_results = shard.ShardAndRunTests(RunnerFactory, attached_devices, tests, |
99 options.test_suite, | 161 options.build_type) |
100 options.gtest_filter, | |
101 options.test_arguments, | |
102 options.timeout, | |
103 options.cleanup_test_files, | |
104 options.tool, | |
105 options.build_type, | |
106 options.webkit) | |
107 | 162 |
108 test_results = sharder.RunShardedTests() | |
109 test_results.LogFull( | 163 test_results.LogFull( |
110 test_type='Unit test', | 164 test_type='Unit test', |
111 test_package=suite_name, | 165 test_package=suite_name, |
112 build_type=options.build_type, | 166 build_type=options.build_type, |
113 flakiness_server=options.flakiness_dashboard_server) | 167 flakiness_server=options.flakiness_dashboard_server) |
114 test_results.PrintAnnotation() | 168 test_results.PrintAnnotation() |
115 | 169 |
116 for buildbot_emulator in buildbot_emulators: | 170 for buildbot_emulator in buildbot_emulators: |
117 buildbot_emulator.Shutdown() | 171 buildbot_emulator.Shutdown() |
118 | 172 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 failures = 0 | 205 failures = 0 |
152 for suite_name, suite_path in all_test_suites: | 206 for suite_name, suite_path in all_test_suites: |
153 # Give each test suite its own copy of options. | 207 # Give each test suite its own copy of options. |
154 test_options = copy.deepcopy(options) | 208 test_options = copy.deepcopy(options) |
155 test_options.test_suite = suite_path | 209 test_options.test_suite = suite_path |
156 failures += _RunATestSuite(test_options, suite_name) | 210 failures += _RunATestSuite(test_options, suite_name) |
157 | 211 |
158 if options.use_xvfb: | 212 if options.use_xvfb: |
159 framebuffer.Stop() | 213 framebuffer.Stop() |
160 return failures | 214 return failures |
OLD | NEW |