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

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

Issue 12278020: [Android] Re-write the gtest TestRunner and introduce a new generic sharder. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: raise an exception if there are no devices visible Created 7 years, 10 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 | Annotate | Revision Log
OLDNEW
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 import copy 5 import copy
6 import fnmatch
6 import logging 7 import logging
7 import os 8 import os
8 9
9 from pylib import android_commands 10 from pylib import android_commands
10 from pylib import cmd_helper 11 from pylib import cmd_helper
11 from pylib import ports 12 from pylib import ports
13 from pylib.base import shard
14 from pylib.base import test_result
12 from pylib.utils import emulator 15 from pylib.utils import emulator
13 from pylib.utils import xvfb 16 from pylib.utils import xvfb
14 17
15 import gtest_config 18 import gtest_config
16 import test_sharder 19 import test_runner
17 20
18 21
19 def _FullyQualifiedTestSuites(exe, option_test_suite, build_type): 22 def _FullyQualifiedTestSuites(exe, option_test_suite, build_type):
20 """Get a list of absolute paths to test suite targets. 23 """Get a list of absolute paths to test suite targets.
21 24
22 Args: 25 Args:
23 exe: if True, use the executable-based test runner. 26 exe: if True, use the executable-based test runner.
24 option_test_suite: the test_suite specified as an option. 27 option_test_suite: the test_suite specified as an option.
25 build_type: 'Release' or 'Debug'. 28 build_type: 'Release' or 'Debug'.
26 29
(...skipping 20 matching lines...) Expand all
47 for t in all_test_suites] 50 for t in all_test_suites]
48 for t, q in zip(all_test_suites, qualified_test_suites): 51 for t, q in zip(all_test_suites, qualified_test_suites):
49 if not os.path.exists(q): 52 if not os.path.exists(q):
50 raise Exception('Test suite %s not found in %s.\n' 53 raise Exception('Test suite %s not found in %s.\n'
51 'Supported test suites:\n %s\n' 54 'Supported test suites:\n %s\n'
52 'Ensure it has been built.\n' % 55 'Ensure it has been built.\n' %
53 (t, q, gtest_config.STABLE_TEST_SUITES)) 56 (t, q, gtest_config.STABLE_TEST_SUITES))
54 return zip(all_test_suites, qualified_test_suites) 57 return zip(all_test_suites, qualified_test_suites)
55 58
56 59
60 def _GetTestsFromDevice(runner):
61 """Get a list of tests from a device, excluding disabled tests.
62
63 Args:
64 runner: a TestRunner.
65 """
66 # The executable/apk needs to be copied before we can call GetAllTests.
67 runner.test_package.StripAndCopyExecutable()
68 all_tests = runner.test_package.GetAllTests()
69 # Only includes tests that do not have any match in the disabled list.
70 disabled_list = runner.GetDisabledTests()
71 return filter(lambda t: not any([fnmatch.fnmatch(t, disabled_pattern)
72 for disabled_pattern in disabled_list]),
73 all_tests)
74
75
76 def _GetAllEnabledTests(runner_factory, devices, is_on_emulator):
77 """Get all enabled tests.
78
79 Obtains a list of enabled tests from the test package on the device,
80 then filters it again using the disabled list on the host.
81
82 Args:
83 runner_factory: callable that takes a devices and returns a TestRunner.
84 devices: list of devices.
85 is_on_emulator: whether to exclude tests disabled on the emulator.
frankf 2013/02/20 18:55:31 This isn't used anywhere, can be removed.
craigdh 2013/02/20 19:38:09 Done.
86
87 Returns:
88 List of all enabled tests.
89
90 Raises Exception if all devices failed.
91 """
92 for device in devices:
93 print 'trying device: %s' % device
frankf 2013/02/20 18:55:31 we only use logging
craigdh 2013/02/20 19:38:09 Done.
94 try:
95 logging.info('Obtaining tests from %s', device)
96 runner = runner_factory(device)
97 return _GetTestsFromDevice(runner)
98 except Exception as e:
99 logging.warning('Failed obtaining tests from %s with exception: %s',
100 device, e)
101 raise Exception('No device available to get the list of tests.')
102
103
57 def _RunATestSuite(options, suite_name): 104 def _RunATestSuite(options, suite_name):
58 """Run a single test suite. 105 """Run a single test suite.
59 106
60 Helper for Dispatch() to allow stop/restart of the emulator across 107 Helper for Dispatch() to allow stop/restart of the emulator across
61 test bundles. If using the emulator, we start it on entry and stop 108 test bundles. If using the emulator, we start it on entry and stop
62 it on exit. 109 it on exit.
63 110
64 Args: 111 Args:
65 options: options for running the tests. 112 options: options for running the tests.
66 suite_name: name of the test suite being run. 113 suite_name: name of the test suite being run.
(...skipping 16 matching lines...) Expand all
83 130
84 if not attached_devices: 131 if not attached_devices:
85 logging.critical('A device must be attached and online.') 132 logging.critical('A device must be attached and online.')
86 return 1 133 return 1
87 134
88 # Reset the test port allocation. It's important to do it before starting 135 # Reset the test port allocation. It's important to do it before starting
89 # to dispatch any tests. 136 # to dispatch any tests.
90 if not ports.ResetTestServerPortAllocation(): 137 if not ports.ResetTestServerPortAllocation():
91 raise Exception('Failed to reset test server port.') 138 raise Exception('Failed to reset test server port.')
92 139
140 # Constructs a new TestRunner with the current options.
141 def RunnerFactory(device):
142 return test_runner.TestRunner(
143 device,
144 options.test_suite,
145 options.test_arguments,
146 options.timeout,
147 options.cleanup_test_files,
148 options.tool,
149 options.build_type,
150 options.webkit)
151
152 # Get tests and split them up based on the number of devices.
93 if options.gtest_filter: 153 if options.gtest_filter:
94 logging.warning('Sharding is not possible with these configurations.') 154 all_tests = [t for t in options.gtest_filter.split(':') if t]
95 attached_devices = [attached_devices[0]] 155 else:
156 all_tests = _GetAllEnabledTests(RunnerFactory, attached_devices,
157 options.use_emulator)
158 num_devices = len(attached_devices)
159 tests = [':'.join(all_tests[i::num_devices]) for i in xrange(num_devices)]
160 tests = [t for t in tests if t]
96 161
97 sharder = test_sharder.TestSharder( 162 # Run tests.
98 attached_devices, 163 test_results = shard.ShardAndRunTests(RunnerFactory, attached_devices, tests,
99 options.test_suite, 164 options.build_type)
100 options.gtest_filter,
101 options.test_arguments,
102 options.timeout,
103 options.cleanup_test_files,
104 options.tool,
105 options.build_type,
106 options.webkit)
107 165
108 test_results = sharder.RunShardedTests()
109 test_results.LogFull( 166 test_results.LogFull(
110 test_type='Unit test', 167 test_type='Unit test',
111 test_package=suite_name, 168 test_package=suite_name,
112 build_type=options.build_type, 169 build_type=options.build_type,
113 flakiness_server=options.flakiness_dashboard_server) 170 flakiness_server=options.flakiness_dashboard_server)
114 test_results.PrintAnnotation() 171 test_results.PrintAnnotation()
115 172
116 for buildbot_emulator in buildbot_emulators: 173 for buildbot_emulator in buildbot_emulators:
117 buildbot_emulator.Shutdown() 174 buildbot_emulator.Shutdown()
118 175
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 failures = 0 208 failures = 0
152 for suite_name, suite_path in all_test_suites: 209 for suite_name, suite_path in all_test_suites:
153 # Give each test suite its own copy of options. 210 # Give each test suite its own copy of options.
154 test_options = copy.deepcopy(options) 211 test_options = copy.deepcopy(options)
155 test_options.test_suite = suite_path 212 test_options.test_suite = suite_path
156 failures += _RunATestSuite(test_options, suite_name) 213 failures += _RunATestSuite(test_options, suite_name)
157 214
158 if options.use_xvfb: 215 if options.use_xvfb:
159 framebuffer.Stop() 216 framebuffer.Stop()
160 return failures 217 return failures
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698