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

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

Issue 867073002: [Android] Add a java version of the test server spawner. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: findbugs Created 5 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
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.ChromeNativeTestActivity.CommandLineFile') 24 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFile')
25 _EXTRA_COMMAND_LINE_FLAGS = ( 25 _EXTRA_COMMAND_LINE_FLAGS = (
26 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFlags') 26 'org.chromium.native_test.ChromeNativeTestActivity.CommandLineFlags')
27 _EXTRA_ENABLE_TEST_SERVER_SPAWNER = (
28 'org.chromium.native_test.ChromeNativeTestInstrumentationTestRunner'
29 '.EnableTestServerSpawner')
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 'content_unittests', 'content_browsertests', 'net_unittests', 'unit_tests' 36 'content_unittests', 'content_browsertests', 'net_unittests', 'unit_tests'
34 ] 37 ]
35 38
36 class _ApkDelegate(object): 39 class _ApkDelegate(object):
37 def __init__(self, apk): 40 def __init__(self, apk):
38 self._apk = apk 41 self._apk = apk
39 self._package = apk_helper.GetPackageName(self._apk) 42 self._package = apk_helper.GetPackageName(self._apk)
40 self._runner = apk_helper.GetInstrumentationName(self._apk) 43 self._runner = apk_helper.GetInstrumentationName(self._apk)
41 self._component = '%s/%s' % (self._package, self._runner) 44 self._component = '%s/%s' % (self._package, self._runner)
45 self._enable_test_server_spawner = False
46
47 def EnableTestServerSpawner(self):
48 self._enable_test_server_spawner = True
42 49
43 def Install(self, device): 50 def Install(self, device):
44 device.Install(self._apk) 51 device.Install(self._apk)
45 52
46 def RunWithFlags(self, device, flags, **kwargs): 53 def RunWithFlags(self, device, flags, **kwargs):
47 with device_temp_file.DeviceTempFile(device.adb) as command_line_file: 54 with device_temp_file.DeviceTempFile(device.adb) as command_line_file:
48 device.WriteFile(command_line_file.name, '_ %s' % flags) 55 device.WriteFile(command_line_file.name, '_ %s' % flags)
49 56
57 extras = {
58 _EXTRA_COMMAND_LINE_FILE: command_line_file.name,
59 }
60 if self._enable_test_server_spawner:
61 extras[_EXTRA_ENABLE_TEST_SERVER_SPAWNER] = '1'
62
50 return device.StartInstrumentation( 63 return device.StartInstrumentation(
51 self._component, 64 self._component, extras=extras, raw=False, **kwargs)
52 extras={_EXTRA_COMMAND_LINE_FILE: command_line_file.name},
53 raw=False,
54 **kwargs)
55 65
56 def Clear(self, device): 66 def Clear(self, device):
57 device.ClearApplicationState(self._package) 67 device.ClearApplicationState(self._package)
58 68
59 69
60 class _ExeDelegate(object): 70 class _ExeDelegate(object):
61 def __init__(self, exe, tr): 71 def __init__(self, exe, tr):
62 self._exe_host_path = exe 72 self._exe_host_path = exe
63 self._exe_file_name = os.path.split(exe)[-1] 73 self._exe_file_name = os.path.split(exe)[-1]
64 self._exe_device_path = '%s/%s' % ( 74 self._exe_device_path = '%s/%s' % (
65 constants.TEST_EXECUTABLE_DIR, self._exe_file_name) 75 constants.TEST_EXECUTABLE_DIR, self._exe_file_name)
66 deps_host_path = self._exe_host_path + '_deps' 76 deps_host_path = self._exe_host_path + '_deps'
67 if os.path.exists(deps_host_path): 77 if os.path.exists(deps_host_path):
68 self._deps_host_path = deps_host_path 78 self._deps_host_path = deps_host_path
69 self._deps_device_path = self._exe_device_path + '_deps' 79 self._deps_device_path = self._exe_device_path + '_deps'
70 else: 80 else:
71 self._deps_host_path = None 81 self._deps_host_path = None
72 self._test_run = tr 82 self._test_run = tr
73 83
84 def EnableTestServerSpawner(self):
85 pass
86
74 def Install(self, device): 87 def Install(self, device):
75 # TODO(jbudorick): Look into merging this with normal data deps pushing if 88 # TODO(jbudorick): Look into merging this with normal data deps pushing if
76 # executables become supported on nonlocal environments. 89 # executables become supported on nonlocal environments.
77 host_device_tuples = [(self._exe_host_path, self._exe_device_path)] 90 host_device_tuples = [(self._exe_host_path, self._exe_device_path)]
78 if self._deps_host_path: 91 if self._deps_host_path:
79 host_device_tuples.append((self._deps_host_path, self._deps_device_path)) 92 host_device_tuples.append((self._deps_host_path, self._deps_device_path))
80 device.PushChangedFiles(host_device_tuples) 93 device.PushChangedFiles(host_device_tuples)
81 94
82 def RunWithFlags(self, device, flags, **kwargs): 95 def RunWithFlags(self, device, flags, **kwargs):
83 cmd = [ 96 cmd = [
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
123 def __init__(self, env, test_instance): 136 def __init__(self, env, test_instance):
124 assert isinstance(env, local_device_environment.LocalDeviceEnvironment) 137 assert isinstance(env, local_device_environment.LocalDeviceEnvironment)
125 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance) 138 assert isinstance(test_instance, gtest_test_instance.GtestTestInstance)
126 super(LocalDeviceGtestRun, self).__init__(env, test_instance) 139 super(LocalDeviceGtestRun, self).__init__(env, test_instance)
127 140
128 if self._test_instance.apk: 141 if self._test_instance.apk:
129 self._delegate = _ApkDelegate(self._test_instance.apk) 142 self._delegate = _ApkDelegate(self._test_instance.apk)
130 elif self._test_instance.exe: 143 elif self._test_instance.exe:
131 self._delegate = _ExeDelegate(self, self._test_instance.exe) 144 self._delegate = _ExeDelegate(self, self._test_instance.exe)
132 145
133 self._servers = {}
134
135 #override 146 #override
136 def TestPackage(self): 147 def TestPackage(self):
137 return self._test_instance._suite 148 return self._test_instance._suite
138 149
139 #override 150 #override
140 def SetUp(self): 151 def SetUp(self):
141 152
142 def individual_device_set_up(dev, host_device_tuples): 153 def individual_device_set_up(dev, host_device_tuples):
143 # Install test APK. 154 # Install test APK.
144 self._delegate.Install(dev) 155 self._delegate.Install(dev)
145 156
146 # Push data dependencies. 157 # Push data dependencies.
147 external_storage = dev.GetExternalStoragePath() 158 external_storage = dev.GetExternalStoragePath()
148 host_device_tuples = [ 159 host_device_tuples = [
149 (h, d if d is not None else external_storage) 160 (h, d if d is not None else external_storage)
150 for h, d in host_device_tuples] 161 for h, d in host_device_tuples]
151 dev.PushChangedFiles(host_device_tuples) 162 dev.PushChangedFiles(host_device_tuples)
152 163
153 self._servers[str(dev)] = []
154 if self.TestPackage() in _SUITE_REQUIRES_TEST_SERVER_SPAWNER: 164 if self.TestPackage() in _SUITE_REQUIRES_TEST_SERVER_SPAWNER:
155 self._servers[str(dev)].append( 165 self._delegate.EnableTestServerSpawner()
156 local_test_server_spawner.LocalTestServerSpawner(
157 ports.AllocateTestServerPort(), dev, self.GetTool(dev)))
158
159 for s in self._servers[str(dev)]:
160 s.SetUp()
161 166
162 self._env.parallel_devices.pMap(individual_device_set_up, 167 self._env.parallel_devices.pMap(individual_device_set_up,
163 self._test_instance.GetDataDependencies()) 168 self._test_instance.GetDataDependencies())
164 169
165 #override 170 #override
166 def _ShouldShard(self): 171 def _ShouldShard(self):
167 return True 172 return True
168 173
169 #override 174 #override
170 def _CreateShards(self, tests): 175 def _CreateShards(self, tests):
(...skipping 11 matching lines...) Expand all
182 self._env.devices[0], '--gtest_list_tests') 187 self._env.devices[0], '--gtest_list_tests')
183 tests = gtest_test_instance.ParseGTestListTests(tests) 188 tests = gtest_test_instance.ParseGTestListTests(tests)
184 tests = self._test_instance.FilterTests(tests) 189 tests = self._test_instance.FilterTests(tests)
185 return tests 190 return tests
186 191
187 #override 192 #override
188 def _RunTest(self, device, test): 193 def _RunTest(self, device, test):
189 # Run the test. 194 # Run the test.
190 output = self._delegate.RunWithFlags(device, '--gtest_filter=%s' % test, 195 output = self._delegate.RunWithFlags(device, '--gtest_filter=%s' % test,
191 timeout=900, retries=0) 196 timeout=900, retries=0)
192 for s in self._servers[str(device)]:
193 s.Reset()
194 self._delegate.Clear(device) 197 self._delegate.Clear(device)
195 198
196 # Parse the output. 199 # Parse the output.
197 # TODO(jbudorick): Transition test scripts away from parsing stdout. 200 # TODO(jbudorick): Transition test scripts away from parsing stdout.
198 results = self._test_instance.ParseGTestOutput(output) 201 results = self._test_instance.ParseGTestOutput(output)
199 return results 202 return results
200 203
201 #override 204 #override
202 def TearDown(self): 205 def TearDown(self):
203 def individual_device_tear_down(dev): 206 pass
204 for s in self._servers[str(dev)]:
205 s.TearDown()
206 207
207 self._env.parallel_devices.pMap(individual_device_tear_down)
208
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698