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

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: Adds support for cleanup_test_files 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 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 sys.path.insert(0,
23 os.path.join(constants.DIR_SOURCE_ROOT, 'build', 'util', 'lib'))
24 from common import unittest_util
25
26
27 def Dispatch(options):
28 """Dispatches all content_browsertests.
29
30 Args:
31 options: optparse.Options object containing command-line options
32 Returns:
33 A tuple of (base_test_result.TestRunResults object, exit code).
34 Raises:
35 Exception: Failed to reset the test server port.
36 """
37
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():
51 raise Exception('Failed to reset test server port.')
52
53 test_suite_dir = os.path.join(cmd_helper.OutDirectory.get(),
54 options.build_type)
55 options.test_suite = os.path.join(test_suite_dir,
56 'apks',
57 constants.BROWSERTEST_SUITE_NAME + '.apk')
58
59 gtest_dispatch._GenerateDepsDirUsingIsolate(
60 constants.BROWSERTEST_SUITE_NAME, options.build_type)
61
62 # Constructs a new TestRunner with the current options.
63 def RunnerFactory(device, shard_index):
64 return test_runner.TestRunner(
65 device,
66 options.test_suite,
67 options.test_arguments,
68 options.timeout,
69 options.cleanup_test_files,
70 options.tool,
71 options.build_type,
72 options.webkit,
73 options.push_deps,
74 constants.BROWSERTEST_TEST_PACKAGE_NAME,
75 constants.BROWSERTEST_TEST_ACTIVITY_NAME,
76 constants.BROWSERTEST_COMMAND_LINE_FILE)
77
78 # Get tests and split them up based on the number of devices.
79 all_enabled = gtest_dispatch.GetAllEnabledTests(RunnerFactory,
80 attached_devices)
81 if options.test_filter:
82 all_tests = unittest_util.FilterTestNames(all_enabled,
83 options.test_filter)
84 else:
85 all_tests = _FilterTests(all_enabled)
86
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):
103 shutil.rmtree(constants.ISOLATE_DEPS_DIR)
104
105 return (test_results, exit_code)
106
107
108 def _FilterTests(all_enabled_tests):
109 """Filters out tests and fixtures starting with PRE_ and MANUAL_."""
110 return [t for t in all_enabled_tests if _ShouldRunOnBot(t)]
111
112
113 def _ShouldRunOnBot(test):
114 fixture, case = test.split('.', 1)
115 if _StartsWith(fixture, case, 'PRE_'):
116 return False
117 if _StartsWith(fixture, case, 'MANUAL_'):
118 return False
119 return True
120
121
122 def _StartsWith(a, b, prefix):
123 return a.startswith(prefix) or b.startswith(prefix)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698