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