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 test from a device, excluding disabled tests. | |
nilesh
2013/02/19 23:00:39
list of tests
craigdh
2013/02/19 23:38:31
Done.
| |
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, is_on_emulator): | |
77 """Get all enabled tests and available devices. | |
nilesh
2013/02/19 23:00:39
Why does it say "all enabled tests and available d
craigdh
2013/02/19 23:38:31
Done.
| |
78 | |
79 Obtains a list of enabled tests from the test package on the device, | |
80 then filters it again using the diabled list on the host. | |
nilesh
2013/02/19 23:00:39
disabled.
craigdh
2013/02/19 23:38:31
Done.
| |
81 | |
82 Args: | |
83 runner_factory: callable that takes a devices and returns a TestRunner. | |
84 devices: list of devices. | |
85 is_on_emulator: whether to exclude tests disabled on the emulator. | |
86 | |
87 Returns: | |
88 List of all enabled tests. | |
89 | |
90 Raises Exception if all devices failed. | |
91 """ | |
92 for device in devices: | |
93 print 'trying device: %s' % device | |
94 try: | |
95 logging.info('Obtaining tests from %s', device) | |
96 runner = runner_factory(device) | |
97 return _GetTestsFromDevice(runner) | |
98 except Exception as e: | |
99 logging.warning('Failed obtaining tests from %s with exception: %s', | |
100 device, e) | |
101 raise Exception('No device available to get the list of tests.') | |
102 | |
103 | |
57 def _RunATestSuite(options, suite_name): | 104 def _RunATestSuite(options, suite_name): |
58 """Run a single test suite. | 105 """Run a single test suite. |
59 | 106 |
60 Helper for Dispatch() to allow stop/restart of the emulator across | 107 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 | 108 test bundles. If using the emulator, we start it on entry and stop |
62 it on exit. | 109 it on exit. |
63 | 110 |
64 Args: | 111 Args: |
65 options: options for running the tests. | 112 options: options for running the tests. |
66 suite_name: name of the test suite being run. | 113 suite_name: name of the test suite being run. |
(...skipping 16 matching lines...) Expand all Loading... | |
83 | 130 |
84 if not attached_devices: | 131 if not attached_devices: |
85 logging.critical('A device must be attached and online.') | 132 logging.critical('A device must be attached and online.') |
86 return 1 | 133 return 1 |
87 | 134 |
88 # Reset the test port allocation. It's important to do it before starting | 135 # Reset the test port allocation. It's important to do it before starting |
89 # to dispatch any tests. | 136 # to dispatch any tests. |
90 if not ports.ResetTestServerPortAllocation(): | 137 if not ports.ResetTestServerPortAllocation(): |
91 raise Exception('Failed to reset test server port.') | 138 raise Exception('Failed to reset test server port.') |
92 | 139 |
140 # Constructs a new TestRunner with the current options. | |
141 def RunnerFactory(device): | |
142 return test_runner.TestRunner( | |
143 device, | |
144 options.test_suite, | |
145 options.test_arguments, | |
146 options.timeout, | |
147 options.cleanup_test_files, | |
148 options.tool, | |
149 options.build_type, | |
150 options.webkit) | |
151 | |
152 # Get tests and split them up based on the number of devices. | |
93 if options.gtest_filter: | 153 if options.gtest_filter: |
94 logging.warning('Sharding is not possible with these configurations.') | 154 all_tests = [t for t in options.gtest_filter.split(':') if t] |
nilesh
2013/02/19 23:00:39
This is changing the current behavior right? We di
craigdh
2013/02/19 23:38:31
Yeah, it simplified the code and seemed like a goo
| |
95 attached_devices = [attached_devices[0]] | 155 else: |
156 all_tests = _GetAllEnabledTests(RunnerFactory, attached_devices, | |
157 options.use_emulator) | |
158 num_devices = len(attached_devices) | |
159 tests = [t for t in | |
160 [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)] | |
161 if t] | |
96 | 162 |
97 sharder = test_sharder.TestSharder( | 163 # Run tests. |
98 attached_devices, | 164 test_results = shard.Shard(RunnerFactory, attached_devices, tests, |
99 options.test_suite, | 165 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 | 166 |
108 test_results = sharder.RunShardedTests() | |
109 test_results.LogFull( | 167 test_results.LogFull( |
110 test_type='Unit test', | 168 test_type='Unit test', |
111 test_package=suite_name, | 169 test_package=suite_name, |
112 build_type=options.build_type, | 170 build_type=options.build_type, |
113 flakiness_server=options.flakiness_dashboard_server) | 171 flakiness_server=options.flakiness_dashboard_server) |
114 test_results.PrintAnnotation() | 172 test_results.PrintAnnotation() |
115 | 173 |
116 for buildbot_emulator in buildbot_emulators: | 174 for buildbot_emulator in buildbot_emulators: |
117 buildbot_emulator.Shutdown() | 175 buildbot_emulator.Shutdown() |
118 | 176 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
151 failures = 0 | 209 failures = 0 |
152 for suite_name, suite_path in all_test_suites: | 210 for suite_name, suite_path in all_test_suites: |
153 # Give each test suite its own copy of options. | 211 # Give each test suite its own copy of options. |
154 test_options = copy.deepcopy(options) | 212 test_options = copy.deepcopy(options) |
155 test_options.test_suite = suite_path | 213 test_options.test_suite = suite_path |
156 failures += _RunATestSuite(test_options, suite_name) | 214 failures += _RunATestSuite(test_options, suite_name) |
157 | 215 |
158 if options.use_xvfb: | 216 if options.use_xvfb: |
159 framebuffer.Stop() | 217 framebuffer.Stop() |
160 return failures | 218 return failures |
OLD | NEW |