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 | |
10 import sys | 9 import sys |
11 | 10 |
12 from pylib import android_commands | 11 from pylib import android_commands |
13 from pylib import cmd_helper | 12 from pylib import cmd_helper |
14 from pylib import constants | 13 from pylib import constants |
15 from pylib import ports | 14 from pylib import ports |
16 from pylib.base import base_test_result | 15 from pylib.base import base_test_result |
17 from pylib.base import shard | 16 from pylib.gtest import setup as gtest_setup |
18 from pylib.gtest import dispatch as gtest_dispatch | |
19 from pylib.gtest import test_runner | 17 from pylib.gtest import test_runner |
20 from pylib.utils import report_results | 18 from pylib.utils import report_results |
21 | 19 |
22 | 20 |
23 def Dispatch(options): | 21 def Setup(test_arguments, timeout, cleanup_test_files, tool, build_type, |
24 """Dispatches all content_browsertests. | 22 webkit, push_deps, gtest_filter): |
| 23 """Create the test runner factory and tests. |
25 | 24 |
26 Args: | 25 Args: |
27 options: optparse.Options object containing command-line options | 26 test_arguments: Additional arguments to pass to the test binary. |
| 27 timeout: Timeout for each test. |
| 28 cleanup_test_files: Whether or not to cleanup test files on device. |
| 29 tool: Name of the Valgrind tool. |
| 30 build_type: 'Release' or 'Debug'. |
| 31 webkit: Whether the suite is being run from a WebKit checkout. |
| 32 push_deps: If True, push all dependencies to the device. |
| 33 gtest_filter: filter for tests. |
| 34 |
28 Returns: | 35 Returns: |
29 A tuple of (base_test_result.TestRunResults object, exit code). | 36 A tuple of (TestRunnerFactory, tests). |
30 Raises: | |
31 Exception: Failed to reset the test server port. | |
32 """ | 37 """ |
33 | 38 |
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(): | 39 if not ports.ResetTestServerPortAllocation(): |
47 raise Exception('Failed to reset test server port.') | 40 raise Exception('Failed to reset test server port.') |
48 | 41 |
49 test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(), | 42 suite_path = os.path.join(cmd_helper.OutDirectory.get(), build_type, 'apks', |
50 options.build_type) | 43 constants.BROWSERTEST_SUITE_NAME + '.apk') |
51 options.test_suite = os.path.join(test_suite_dir, | |
52 'apks', | |
53 constants.BROWSERTEST_SUITE_NAME + '.apk') | |
54 | 44 |
55 gtest_dispatch._GenerateDepsDirUsingIsolate( | 45 gtest_setup._GenerateDepsDirUsingIsolate( |
56 constants.BROWSERTEST_SUITE_NAME, options.build_type) | 46 constants.BROWSERTEST_SUITE_NAME, build_type) |
57 | 47 |
58 # Constructs a new TestRunner with the current options. | 48 # Constructs a new TestRunner with the current options. |
59 def RunnerFactory(device, shard_index): | 49 def TestRunnerFactory(device, shard_index): |
60 return test_runner.TestRunner( | 50 return test_runner.TestRunner( |
61 device, | 51 device, |
62 options.test_suite, | 52 suite_path, |
63 options.test_arguments, | 53 test_arguments, |
64 options.timeout, | 54 timeout, |
65 options.cleanup_test_files, | 55 cleanup_test_files, |
66 options.tool, | 56 tool, |
67 options.build_type, | 57 build_type, |
68 options.webkit, | 58 webkit, |
69 options.push_deps, | 59 push_deps, |
70 constants.BROWSERTEST_TEST_PACKAGE_NAME, | 60 constants.BROWSERTEST_TEST_PACKAGE_NAME, |
71 constants.BROWSERTEST_TEST_ACTIVITY_NAME, | 61 constants.BROWSERTEST_TEST_ACTIVITY_NAME, |
72 constants.BROWSERTEST_COMMAND_LINE_FILE) | 62 constants.BROWSERTEST_COMMAND_LINE_FILE) |
73 | 63 |
74 tests = gtest_dispatch.GetTestsFiltered( | 64 # TODO(gkanwar): This breaks the abstraction of having test_dispatcher.py deal |
75 constants.BROWSERTEST_SUITE_NAME, options.test_filter, RunnerFactory, | 65 # entirely with the devices. Can we do this another way? |
| 66 attached_devices = android_commands.GetAttachedDevices() |
| 67 |
| 68 all_tests = gtest_setup.GetTestsFiltered( |
| 69 constants.BROWSERTEST_SUITE_NAME, gtest_filter, TestRunnerFactory, |
76 attached_devices) | 70 attached_devices) |
77 | 71 |
78 # Run tests. | 72 return (TestRunnerFactory, all_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 | 73 |
93 if os.path.isdir(constants.ISOLATE_DEPS_DIR): | |
94 shutil.rmtree(constants.ISOLATE_DEPS_DIR) | |
95 | 74 |
96 return (test_results, exit_code) | 75 def _FilterTests(all_enabled_tests): |
| 76 """Filters out tests and fixtures starting with PRE_ and MANUAL_.""" |
| 77 return [t for t in all_enabled_tests if _ShouldRunOnBot(t)] |
| 78 |
| 79 |
| 80 def _ShouldRunOnBot(test): |
| 81 fixture, case = test.split('.', 1) |
| 82 if _StartsWith(fixture, case, 'PRE_'): |
| 83 return False |
| 84 if _StartsWith(fixture, case, 'MANUAL_'): |
| 85 return False |
| 86 return True |
| 87 |
| 88 |
| 89 def _StartsWith(a, b, prefix): |
| 90 return a.startswith(prefix) or b.startswith(prefix) |
OLD | NEW |