OLD | NEW |
| (Empty) |
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 | |
3 # found in the LICENSE file. | |
4 | |
5 """Dispatches content_browsertests.""" | |
6 | |
7 import logging | |
8 import os | |
9 import shutil | |
10 import sys | |
11 | |
12 from pylib import android_commands | |
13 from pylib import cmd_helper | |
14 from pylib import constants | |
15 from pylib import ports | |
16 from pylib.base import base_test_result | |
17 from pylib.base import shard | |
18 from pylib.gtest import dispatch as gtest_dispatch | |
19 from pylib.gtest import test_runner | |
20 from pylib.utils import report_results | |
21 | |
22 | |
23 def Dispatch(options): | |
24 """Dispatches all content_browsertests. | |
25 | |
26 Args: | |
27 options: optparse.Options object containing command-line options | |
28 Returns: | |
29 A tuple of (base_test_result.TestRunResults object, exit code). | |
30 Raises: | |
31 Exception: Failed to reset the test server port. | |
32 """ | |
33 | |
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(): | |
47 raise Exception('Failed to reset test server port.') | |
48 | |
49 test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(), | |
50 options.build_type) | |
51 options.test_suite = os.path.join(test_suite_dir, | |
52 'apks', | |
53 constants.BROWSERTEST_SUITE_NAME + '.apk') | |
54 | |
55 gtest_dispatch._GenerateDepsDirUsingIsolate( | |
56 constants.BROWSERTEST_SUITE_NAME, options.build_type) | |
57 | |
58 # Constructs a new TestRunner with the current options. | |
59 def RunnerFactory(device, shard_index): | |
60 return test_runner.TestRunner( | |
61 device, | |
62 options.test_suite, | |
63 options.test_arguments, | |
64 options.timeout, | |
65 options.cleanup_test_files, | |
66 options.tool, | |
67 options.build_type, | |
68 options.webkit, | |
69 options.push_deps, | |
70 constants.BROWSERTEST_TEST_PACKAGE_NAME, | |
71 constants.BROWSERTEST_TEST_ACTIVITY_NAME, | |
72 constants.BROWSERTEST_COMMAND_LINE_FILE) | |
73 | |
74 tests = gtest_dispatch.GetTestsFiltered( | |
75 constants.BROWSERTEST_SUITE_NAME, options.test_filter, RunnerFactory, | |
76 attached_devices) | |
77 | |
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): | |
94 shutil.rmtree(constants.ISOLATE_DEPS_DIR) | |
95 | |
96 return (test_results, exit_code) | |
OLD | NEW |