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 | 21 |
23 def Dispatch(options): | 22 def Setup(test_arguments, timeout, cleanup_test_files, tool, build_type, |
24 """Dispatches all content_browsertests. | 23 webkit, push_deps, gtest_filter): |
| 24 """Create the test runner factory and tests. |
25 | 25 |
26 Args: | 26 Args: |
27 options: optparse.Options object containing command-line options | 27 test_arguments: Additional arguments to pass to the test binary. |
| 28 timeout: Timeout for each test. |
| 29 cleanup_test_files: Whether or not to cleanup test files on device. |
| 30 tool: Name of the Valgrind tool. |
| 31 build_type: 'Release' or 'Debug'. |
| 32 webkit: Whether the suite is being run from a WebKit checkout. |
| 33 push_deps: If True, push all dependencies to the device. |
| 34 gtest_filter: filter for tests. |
| 35 |
28 Returns: | 36 Returns: |
29 A tuple of (base_test_result.TestRunResults object, exit code). | 37 A tuple of (TestRunnerFactory, tests). |
30 Raises: | |
31 Exception: Failed to reset the test server port. | |
32 """ | 38 """ |
33 | 39 |
34 attached_devices = [] | |
35 if options.test_device: | |
36 attached_devices = [options.test_device] | |
37 else: | |
38 attached_devices = android_commands.GetAttachedDevices() | |
39 | |
40 if not attached_devices: | |
41 logging.critical('A device must be attached and online.') | |
42 return (base_test_result.TestRunResults(), constants.ERROR_EXIT_CODE) | |
43 | |
44 # Reset the test port allocation. It's important to do it before starting | |
45 # to dispatch any tests. | |
46 if not ports.ResetTestServerPortAllocation(): | 40 if not ports.ResetTestServerPortAllocation(): |
47 raise Exception('Failed to reset test server port.') | 41 raise Exception('Failed to reset test server port.') |
48 | 42 |
49 test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(), | 43 suite_path = os.path.join(cmd_helper.OutDirectory.get(), build_type, 'apks', |
50 options.build_type) | 44 constants.BROWSERTEST_SUITE_NAME + '.apk') |
51 options.test_suite = os.path.join(test_suite_dir, | |
52 'apks', | |
53 constants.BROWSERTEST_SUITE_NAME + '.apk') | |
54 | 45 |
55 gtest_dispatch._GenerateDepsDirUsingIsolate( | 46 gtest_setup._GenerateDepsDirUsingIsolate( |
56 constants.BROWSERTEST_SUITE_NAME, options.build_type) | 47 constants.BROWSERTEST_SUITE_NAME, build_type) |
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 suite_path, |
63 options.test_arguments, | 54 test_arguments, |
64 options.timeout, | 55 timeout, |
65 options.cleanup_test_files, | 56 cleanup_test_files, |
66 options.tool, | 57 tool, |
67 options.build_type, | 58 build_type, |
68 options.webkit, | 59 webkit, |
69 options.push_deps, | 60 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 |
74 tests = gtest_dispatch.GetTestsFiltered( | 65 # TODO(gkanwar): This breaks the abstraction of having test_dispatcher.py deal |
75 constants.BROWSERTEST_SUITE_NAME, options.test_filter, RunnerFactory, | 66 # entirely with the devices. Can we do this another way? |
| 67 attached_devices = android_commands.GetAttachedDevices() |
| 68 |
| 69 all_tests = gtest_setup.GetTestsFiltered( |
| 70 constants.BROWSERTEST_SUITE_NAME, gtest_filter, TestRunnerFactory, |
76 attached_devices) | 71 attached_devices) |
77 | 72 |
78 # Run tests. | |
79 # TODO(nileshagrawal): remove this abnormally long setup timeout once fewer | |
80 # files are pushed to the devices for content_browsertests: crbug.com/138275 | |
81 setup_timeout = 20 * 60 # 20 minutes | |
82 test_results, exit_code = shard.ShardAndRunTests( | |
83 RunnerFactory, attached_devices, tests, options.build_type, | |
84 setup_timeout=setup_timeout, test_timeout=None, | |
85 num_retries=options.num_retries) | |
86 report_results.LogFull( | |
87 results=test_results, | |
88 test_type='Unit test', | |
89 test_package=constants.BROWSERTEST_SUITE_NAME, | |
90 build_type=options.build_type, | |
91 flakiness_server=options.flakiness_dashboard_server) | |
92 | |
93 if os.path.isdir(constants.ISOLATE_DEPS_DIR): | 73 if os.path.isdir(constants.ISOLATE_DEPS_DIR): |
94 shutil.rmtree(constants.ISOLATE_DEPS_DIR) | 74 shutil.rmtree(constants.ISOLATE_DEPS_DIR) |
95 | 75 |
96 return (test_results, exit_code) | 76 return (TestRunnerFactory, all_tests) |
| 77 |
| 78 |
| 79 def _FilterTests(all_enabled_tests): |
| 80 """Filters out tests and fixtures starting with PRE_ and MANUAL_.""" |
| 81 return [t for t in all_enabled_tests if _ShouldRunOnBot(t)] |
| 82 |
| 83 |
| 84 def _ShouldRunOnBot(test): |
| 85 fixture, case = test.split('.', 1) |
| 86 if _StartsWith(fixture, case, 'PRE_'): |
| 87 return False |
| 88 if _StartsWith(fixture, case, 'MANUAL_'): |
| 89 return False |
| 90 return True |
| 91 |
| 92 |
| 93 def _StartsWith(a, b, prefix): |
| 94 return a.startswith(prefix) or b.startswith(prefix) |
OLD | NEW |