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 """Dispatches content_browsertests.""" | 5 """Runs content_browsertests.""" |
6 | 6 |
7 import logging | 7 import logging |
8 import os | 8 import os |
9 import sys | 9 import sys |
10 | 10 |
11 from pylib import android_commands | 11 from pylib import android_commands |
12 from pylib import cmd_helper | 12 from pylib import cmd_helper |
13 from pylib import constants | 13 from pylib import constants |
| 14 from pylib import dispatch |
14 from pylib import ports | 15 from pylib import ports |
15 from pylib.base import base_test_result | 16 from pylib.base import base_test_result |
16 from pylib.base import shard | 17 from pylib.base import shard |
17 from pylib.gtest import dispatch as gtest_dispatch | 18 from pylib.gtest import dispatch as gtest_dispatch |
18 from pylib.gtest import test_runner | 19 from pylib.gtest import test_runner |
19 from pylib.utils import report_results | 20 from pylib.utils import report_results |
20 | 21 |
21 sys.path.insert(0, | 22 sys.path.insert(0, |
22 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib')) | 23 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib')) |
23 from common import unittest_util | 24 from common import unittest_util |
24 | 25 |
25 | 26 |
26 def Dispatch(options): | 27 def RunContentBrowserTests(options): |
27 """Dispatches all content_browsertests. | 28 """Runs all content_browsertests. |
28 | 29 |
29 Args: | 30 Args: |
30 options: optparse.Options object containing command-line options | 31 options: optparse.Options object containing command-line options |
31 Returns: | 32 Returns: |
32 A tuple of (base_test_result.TestRunResults object, exit code). | 33 A tuple of (base_test_result.TestRunResults object, exit code). |
33 Raises: | 34 Raises: |
34 Exception: Failed to reset the test server port. | 35 Exception: Failed to reset the test server port. |
35 """ | 36 """ |
36 | 37 |
37 attached_devices = [] | |
38 if options.test_device: | |
39 attached_devices = [options.test_device] | |
40 else: | |
41 attached_devices = android_commands.GetAttachedDevices() | |
42 | |
43 if not attached_devices: | |
44 logging.critical('A device must be attached and online.') | |
45 return (base_test_result.TestRunResults(), constants.ERROR_EXIT_CODE) | |
46 | |
47 # Reset the test port allocation. It's important to do it before starting | 38 # Reset the test port allocation. It's important to do it before starting |
48 # to dispatch any tests. | 39 # to dispatch any tests. |
49 if not ports.ResetTestServerPortAllocation(): | 40 if not ports.ResetTestServerPortAllocation(): |
50 raise Exception('Failed to reset test server port.') | 41 raise Exception('Failed to reset test server port.') |
51 | 42 |
52 test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(), | 43 test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(), |
53 options.build_type) | 44 options.build_type) |
54 options.test_suite = os.path.join(test_suite_dir, | 45 options.test_suite = os.path.join(test_suite_dir, |
55 'apks', | 46 'apks', |
56 constants.BROWSERTEST_SUITE_NAME + '.apk') | 47 constants.BROWSERTEST_SUITE_NAME + '.apk') |
57 | 48 |
58 # Constructs a new TestRunner with the current options. | 49 # Constructs a new TestRunner with the current options. |
59 def RunnerFactory(device, shard_index): | 50 def TestRunnerFactory(device, shard_index): |
60 return test_runner.TestRunner( | 51 return test_runner.TestRunner( |
61 device, | 52 device, |
62 options.test_suite, | 53 options.test_suite, |
63 options.test_arguments, | 54 options.test_arguments, |
64 options.timeout, | 55 options.timeout, |
65 options.cleanup_test_files, | 56 options.cleanup_test_files, |
66 options.tool, | 57 options.tool, |
67 options.build_type, | 58 options.build_type, |
68 options.webkit, | 59 options.webkit, |
69 options.push_deps, | 60 options.push_deps, |
70 constants.BROWSERTEST_TEST_PACKAGE_NAME, | 61 constants.BROWSERTEST_TEST_PACKAGE_NAME, |
71 constants.BROWSERTEST_TEST_ACTIVITY_NAME, | 62 constants.BROWSERTEST_TEST_ACTIVITY_NAME, |
72 constants.BROWSERTEST_COMMAND_LINE_FILE) | 63 constants.BROWSERTEST_COMMAND_LINE_FILE) |
73 | 64 |
| 65 # TODO(gkanwar): This breaks the abstraction of having dispatch.Dispatch deal |
| 66 # entirely with the devices. Can we do this another way? |
| 67 attached_devices = android_commands.GetAttachedDevices() |
74 # Get tests and split them up based on the number of devices. | 68 # Get tests and split them up based on the number of devices. |
75 all_enabled = gtest_dispatch.GetAllEnabledTests(RunnerFactory, | 69 all_enabled = gtest_dispatch.GetAllEnabledTests(TestRunnerFactory, |
76 attached_devices) | 70 attached_devices) |
77 if options.test_filter: | 71 if options.test_filter: |
78 all_tests = unittest_util.FilterTestNames(all_enabled, | 72 all_tests = unittest_util.FilterTestNames(all_enabled, |
79 options.test_filter) | 73 options.test_filter) |
80 else: | 74 else: |
81 all_tests = _FilterTests(all_enabled) | 75 all_tests = _FilterTests(all_enabled) |
82 | 76 |
83 # Run tests. | 77 # Run tests. |
84 # TODO(nileshagrawal): remove this abnormally long setup timeout once fewer | 78 # TODO(nileshagrawal): remove this abnormally long setup timeout once fewer |
85 # files are pushed to the devices for content_browsertests: crbug.com/138275 | 79 # files are pushed to the devices for content_browsertests: crbug.com/138275 |
86 setup_timeout = 20 * 60 # 20 minutes | 80 setup_timeout = 20 * 60 # 20 minutes |
87 test_results, exit_code = shard.ShardAndRunTests( | 81 results, exit_code = dispatch.Dispatch(options, all_tests, TestRunnerFactory, |
88 RunnerFactory, attached_devices, all_tests, options.build_type, | 82 sharding='distribute', |
89 setup_timeout=setup_timeout, test_timeout=None, | 83 setup_timeout=setup_timeout) |
90 num_retries=options.num_retries) | |
91 report_results.LogFull( | 84 report_results.LogFull( |
92 results=test_results, | 85 results=results, |
93 test_type='Unit test', | 86 test_type='Unit test', |
94 test_package=constants.BROWSERTEST_SUITE_NAME, | 87 test_package=constants.BROWSERTEST_SUITE_NAME, |
95 build_type=options.build_type, | 88 build_type=options.build_type, |
96 flakiness_server=options.flakiness_dashboard_server) | 89 flakiness_server=options.flakiness_dashboard_server) |
97 | 90 |
98 return (test_results, exit_code) | 91 return (results, exit_code) |
99 | 92 |
100 | 93 |
101 def _FilterTests(all_enabled_tests): | 94 def _FilterTests(all_enabled_tests): |
102 """Filters out tests and fixtures starting with PRE_ and MANUAL_.""" | 95 """Filters out tests and fixtures starting with PRE_ and MANUAL_.""" |
103 return [t for t in all_enabled_tests if _ShouldRunOnBot(t)] | 96 return [t for t in all_enabled_tests if _ShouldRunOnBot(t)] |
104 | 97 |
105 | 98 |
106 def _ShouldRunOnBot(test): | 99 def _ShouldRunOnBot(test): |
107 fixture, case = test.split('.', 1) | 100 fixture, case = test.split('.', 1) |
108 if _StartsWith(fixture, case, 'PRE_'): | 101 if _StartsWith(fixture, case, 'PRE_'): |
109 return False | 102 return False |
110 if _StartsWith(fixture, case, 'MANUAL_'): | 103 if _StartsWith(fixture, case, 'MANUAL_'): |
111 return False | 104 return False |
112 return True | 105 return True |
113 | 106 |
114 | 107 |
115 def _StartsWith(a, b, prefix): | 108 def _StartsWith(a, b, prefix): |
116 return a.startswith(prefix) or b.startswith(prefix) | 109 return a.startswith(prefix) or b.startswith(prefix) |
OLD | NEW |