Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(994)

Side by Side Diff: build/android/pylib/browsertests/dispatch.py

Issue 18770008: [Android] Redesigns the sharder to allow replicated vs distributed tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixes running multiple gtest suites Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 sys
10
11 from pylib import android_commands
12 from pylib import cmd_helper
13 from pylib import constants
14 from pylib import ports
15 from pylib.base import base_test_result
16 from pylib.base import shard
17 from pylib.gtest import dispatch as gtest_dispatch
18 from pylib.gtest import test_runner
19 from pylib.utils import report_results
20
21 sys.path.insert(0,
22 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib'))
23 from common import unittest_util
24
25
26 def Dispatch(options):
27 """Dispatches all content_browsertests.
28
29 Args:
30 options: optparse.Options object containing command-line options
31 Returns:
32 A tuple of (base_test_result.TestRunResults object, exit code).
33 Raises:
34 Exception: Failed to reset the test server port.
35 """
36
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
48 # to dispatch any tests.
49 if not ports.ResetTestServerPortAllocation():
50 raise Exception('Failed to reset test server port.')
51
52 test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(),
53 options.build_type)
54 options.test_suite = os.path.join(test_suite_dir,
55 'apks',
56 constants.BROWSERTEST_SUITE_NAME + '.apk')
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 # Get tests and split them up based on the number of devices.
75 all_enabled = gtest_dispatch.GetAllEnabledTests(RunnerFactory,
76 attached_devices)
77 if options.test_filter:
78 all_tests = unittest_util.FilterTestNames(all_enabled,
79 options.test_filter)
80 else:
81 all_tests = _FilterTests(all_enabled)
82
83 # Run tests.
84 # TODO(nileshagrawal): remove this abnormally long setup timeout once fewer
85 # files are pushed to the devices for content_browsertests: crbug.com/138275
86 setup_timeout = 20 * 60 # 20 minutes
87 test_results, exit_code = shard.ShardAndRunTests(
88 RunnerFactory, attached_devices, all_tests, options.build_type,
89 setup_timeout=setup_timeout, test_timeout=None,
90 num_retries=options.num_retries)
91 report_results.LogFull(
92 results=test_results,
93 test_type='Unit test',
94 test_package=constants.BROWSERTEST_SUITE_NAME,
95 build_type=options.build_type,
96 flakiness_server=options.flakiness_dashboard_server)
97
98 return (test_results, exit_code)
99
100
101 def _FilterTests(all_enabled_tests):
102 """Filters out tests and fixtures starting with PRE_ and MANUAL_."""
103 return [t for t in all_enabled_tests if _ShouldRunOnBot(t)]
104
105
106 def _ShouldRunOnBot(test):
107 fixture, case = test.split('.', 1)
108 if _StartsWith(fixture, case, 'PRE_'):
109 return False
110 if _StartsWith(fixture, case, 'MANUAL_'):
111 return False
112 return True
113
114
115 def _StartsWith(a, b, prefix):
116 return a.startswith(prefix) or b.startswith(prefix)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698