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

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

Issue 1143903002: [Android] Refactor the native test wrappers. (RELAND) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 7 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
« no previous file with comments | « build/android/pylib/gtest/gtest_test_instance.py ('k') | build/android/pylib/gtest/setup.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # Copyright 2014 The Chromium Authors. All rights reserved. 1 # Copyright 2014 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 5
6 import logging 6 import logging
7 import os 7 import os
8 8
9 from pylib import constants 9 from pylib import constants
10 from pylib import ports 10 from pylib import ports
11 from pylib.base import test_run 11 from pylib.base import test_run
12 from pylib.device import device_errors 12 from pylib.device import device_errors
13 from pylib.gtest import gtest_test_instance 13 from pylib.gtest import gtest_test_instance
14 14
15 from pylib.local import local_test_server_spawner 15 from pylib.local import local_test_server_spawner
16 from pylib.local.device import local_device_environment 16 from pylib.local.device import local_device_environment
17 from pylib.local.device import local_device_test_run 17 from pylib.local.device import local_device_test_run
18 from pylib.utils import apk_helper 18 from pylib.utils import apk_helper
19 from pylib.utils import device_temp_file 19 from pylib.utils import device_temp_file
20 20
21 _COMMAND_LINE_FLAGS_SUPPORTED = True 21 _COMMAND_LINE_FLAGS_SUPPORTED = True
22 22
23 _EXTRA_COMMAND_LINE_FILE = ( 23 _EXTRA_COMMAND_LINE_FILE = (
24 'org.chromium.native_test.NativeTestActivity.CommandLineFile') 24 'org.chromium.native_test.NativeTestActivity.CommandLineFile')
25 _EXTRA_COMMAND_LINE_FLAGS = ( 25 _EXTRA_COMMAND_LINE_FLAGS = (
26 'org.chromium.native_test.NativeTestActivity.CommandLineFlags') 26 'org.chromium.native_test.NativeTestActivity.CommandLineFlags')
27 _EXTRA_NATIVE_TEST_ACTIVITY = (
28 'org.chromium.native_test.NativeTestInstrumentationTestRunner'
29 '.NativeTestActivity')
27 30
28 _MAX_SHARD_SIZE = 256 31 _MAX_SHARD_SIZE = 256
29 32
30 # TODO(jbudorick): Move this up to the test instance if the net test server is 33 # TODO(jbudorick): Move this up to the test instance if the net test server is
31 # handled outside of the APK for the remote_device environment. 34 # handled outside of the APK for the remote_device environment.
32 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [ 35 _SUITE_REQUIRES_TEST_SERVER_SPAWNER = [
33 'components_browsertests', 'content_unittests', 'content_browsertests', 36 'components_browsertests', 'content_unittests', 'content_browsertests',
34 'net_unittests', 'unit_tests' 37 'net_unittests', 'unit_tests'
35 ] 38 ]
36 39
37 class _ApkDelegate(object): 40 class _ApkDelegate(object):
38 def __init__(self, apk): 41 def __init__(self, apk):
39 self._apk = apk 42 self._apk = apk
40 self._package = apk_helper.GetPackageName(self._apk) 43
41 self._runner = apk_helper.GetInstrumentationName(self._apk) 44 helper = apk_helper.ApkHelper(self._apk)
45 self._activity = helper.GetActivityName()
46 self._package = helper.GetPackageName()
47 self._runner = helper.GetInstrumentationName()
42 self._component = '%s/%s' % (self._package, self._runner) 48 self._component = '%s/%s' % (self._package, self._runner)
43 self._enable_test_server_spawner = False 49 self._enable_test_server_spawner = False
44 50
45 def Install(self, device): 51 def Install(self, device):
46 device.Install(self._apk) 52 device.Install(self._apk)
47 53
48 def RunWithFlags(self, device, flags, **kwargs): 54 def RunWithFlags(self, device, flags, **kwargs):
49 with device_temp_file.DeviceTempFile(device.adb) as command_line_file: 55 with device_temp_file.DeviceTempFile(device.adb) as command_line_file:
50 device.WriteFile(command_line_file.name, '_ %s' % flags) 56 device.WriteFile(command_line_file.name, '_ %s' % flags)
51 57
52 extras = { 58 extras = {
53 _EXTRA_COMMAND_LINE_FILE: command_line_file.name, 59 _EXTRA_COMMAND_LINE_FILE: command_line_file.name,
60 _EXTRA_NATIVE_TEST_ACTIVITY: self._activity,
54 } 61 }
55 62
56 return device.StartInstrumentation( 63 return device.StartInstrumentation(
57 self._component, extras=extras, raw=False, **kwargs) 64 self._component, extras=extras, raw=False, **kwargs)
58 65
59 def Clear(self, device): 66 def Clear(self, device):
60 device.ClearApplicationState(self._package) 67 device.ClearApplicationState(self._package)
61 68
62 69
63 class _ExeDelegate(object): 70 class _ExeDelegate(object):
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
125 132
126 if self._test_instance.apk: 133 if self._test_instance.apk:
127 self._delegate = _ApkDelegate(self._test_instance.apk) 134 self._delegate = _ApkDelegate(self._test_instance.apk)
128 elif self._test_instance.exe: 135 elif self._test_instance.exe:
129 self._delegate = _ExeDelegate(self, self._test_instance.exe) 136 self._delegate = _ExeDelegate(self, self._test_instance.exe)
130 137
131 self._servers = {} 138 self._servers = {}
132 139
133 #override 140 #override
134 def TestPackage(self): 141 def TestPackage(self):
135 return self._test_instance._suite 142 return self._test_instance.suite
136 143
137 #override 144 #override
138 def SetUp(self): 145 def SetUp(self):
139 146
140 def individual_device_set_up(dev, host_device_tuples): 147 def individual_device_set_up(dev, host_device_tuples):
141 # Install test APK. 148 # Install test APK.
142 self._delegate.Install(dev) 149 self._delegate.Install(dev)
143 150
144 # Push data dependencies. 151 # Push data dependencies.
145 external_storage = dev.GetExternalStoragePath() 152 external_storage = dev.GetExternalStoragePath()
(...skipping 13 matching lines...) Expand all
159 166
160 self._env.parallel_devices.pMap(individual_device_set_up, 167 self._env.parallel_devices.pMap(individual_device_set_up,
161 self._test_instance.GetDataDependencies()) 168 self._test_instance.GetDataDependencies())
162 169
163 #override 170 #override
164 def _ShouldShard(self): 171 def _ShouldShard(self):
165 return True 172 return True
166 173
167 #override 174 #override
168 def _CreateShards(self, tests): 175 def _CreateShards(self, tests):
169 device_count = len(self._env.devices) 176 if self._test_instance.suite in gtest_test_instance.BROWSER_TEST_SUITES:
170 shards = [] 177 return tests
171 for i in xrange(0, device_count): 178 else:
172 unbounded_shard = tests[i::device_count] 179 device_count = len(self._env.devices)
173 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE] 180 shards = []
174 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)] 181 for i in xrange(0, device_count):
175 return [':'.join(s) for s in shards] 182 unbounded_shard = tests[i::device_count]
183 shards += [unbounded_shard[j:j+_MAX_SHARD_SIZE]
184 for j in xrange(0, len(unbounded_shard), _MAX_SHARD_SIZE)]
185 return [':'.join(s) for s in shards]
176 186
177 #override 187 #override
178 def _GetTests(self): 188 def _GetTests(self):
179 tests = self._delegate.RunWithFlags( 189 tests = self._delegate.RunWithFlags(
180 self._env.devices[0], '--gtest_list_tests') 190 self._env.devices[0], '--gtest_list_tests')
181 tests = gtest_test_instance.ParseGTestListTests(tests) 191 tests = gtest_test_instance.ParseGTestListTests(tests)
182 tests = self._test_instance.FilterTests(tests) 192 tests = self._test_instance.FilterTests(tests)
183 return tests 193 return tests
184 194
185 #override 195 #override
186 def _RunTest(self, device, test): 196 def _RunTest(self, device, test):
187 # Run the test. 197 # Run the test.
188 output = self._delegate.RunWithFlags(device, '--gtest_filter=%s' % test, 198 output = self._delegate.RunWithFlags(
189 timeout=900, retries=0) 199 device, '--gtest_filter=%s' % test, timeout=900, retries=0)
190 for s in self._servers[str(device)]: 200 for s in self._servers[str(device)]:
191 s.Reset() 201 s.Reset()
192 self._delegate.Clear(device) 202 self._delegate.Clear(device)
193 203
194 # Parse the output. 204 # Parse the output.
195 # TODO(jbudorick): Transition test scripts away from parsing stdout. 205 # TODO(jbudorick): Transition test scripts away from parsing stdout.
196 results = self._test_instance.ParseGTestOutput(output) 206 results = self._test_instance.ParseGTestOutput(output)
197 return results 207 return results
198 208
199 #override 209 #override
200 def TearDown(self): 210 def TearDown(self):
201 def individual_device_tear_down(dev): 211 def individual_device_tear_down(dev):
202 for s in self._servers[str(dev)]: 212 for s in self._servers[str(dev)]:
203 s.TearDown() 213 s.TearDown()
204 214
205 self._env.parallel_devices.pMap(individual_device_tear_down) 215 self._env.parallel_devices.pMap(individual_device_tear_down)
206 216
OLDNEW
« no previous file with comments | « build/android/pylib/gtest/gtest_test_instance.py ('k') | build/android/pylib/gtest/setup.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698