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

Side by Side Diff: build/android/pylib/base/base_test_runner.py

Issue 12378048: [Android] Switch instrumentation tests to the new shard/runner paradigm. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: add retries to the end of the queue instead of the beginning Created 7 years, 9 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
« no previous file with comments | « no previous file | build/android/pylib/base/base_test_sharder.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 (c) 2012 The Chromium Authors. All rights reserved. 1 # Copyright (c) 2012 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 contextlib 5 import contextlib
6 import httplib 6 import httplib
7 import logging 7 import logging
8 import os 8 import os
9 import tempfile 9 import tempfile
10 import time 10 import time
(...skipping 14 matching lines...) Expand all
25 NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports' 25 NET_TEST_SERVER_PORT_INFO_FILE = 'net-test-server-ports'
26 26
27 27
28 class BaseTestRunner(object): 28 class BaseTestRunner(object):
29 """Base class for running tests on a single device. 29 """Base class for running tests on a single device.
30 30
31 A subclass should implement RunTests() with no parameter, so that calling 31 A subclass should implement RunTests() with no parameter, so that calling
32 the Run() method will set up tests, run them and tear them down. 32 the Run() method will set up tests, run them and tear them down.
33 """ 33 """
34 34
35 def __init__(self, device, tool, shard_index, build_type): 35 def __init__(self, device, tool, build_type):
36 """ 36 """
37 Args: 37 Args:
38 device: Tests will run on the device of this ID. 38 device: Tests will run on the device of this ID.
39 shard_index: Index number of the shard on which the test suite will run. 39 shard_index: Index number of the shard on which the test suite will run.
40 build_type: 'Release' or 'Debug'. 40 build_type: 'Release' or 'Debug'.
41 """ 41 """
42 self.device = device 42 self.device = device
43 self.adb = android_commands.AndroidCommands(device=device) 43 self.adb = android_commands.AndroidCommands(device=device)
44 self.tool = CreateTool(tool, self.adb) 44 self.tool = CreateTool(tool, self.adb)
45 self._http_server = None 45 self._http_server = None
46 self._forwarder = None 46 self._forwarder = None
47 self._forwarder_device_port = 8000 47 self._forwarder_device_port = 8000
48 self.forwarder_base_url = ('http://localhost:%d' % 48 self.forwarder_base_url = ('http://localhost:%d' %
49 self._forwarder_device_port) 49 self._forwarder_device_port)
50 self.flags = FlagChanger(self.adb) 50 self.flags = FlagChanger(self.adb)
51 self.shard_index = shard_index
52 self.flags.AddFlags(['--disable-fre']) 51 self.flags.AddFlags(['--disable-fre'])
53 self._spawning_server = None 52 self._spawning_server = None
54 self._spawner_forwarder = None 53 self._spawner_forwarder = None
55 # We will allocate port for test server spawner when calling method 54 # We will allocate port for test server spawner when calling method
56 # LaunchChromeTestServerSpawner and allocate port for test server when 55 # LaunchChromeTestServerSpawner and allocate port for test server when
57 # starting it in TestServerThread. 56 # starting it in TestServerThread.
58 self.test_server_spawner_port = 0 57 self.test_server_spawner_port = 0
59 self.test_server_port = 0 58 self.test_server_port = 0
60 self.build_type = build_type 59 self.build_type = build_type
61 60
62 def _PushTestServerPortInfoToDevice(self): 61 def _PushTestServerPortInfoToDevice(self):
63 """Pushes the latest port information to device.""" 62 """Pushes the latest port information to device."""
64 self.adb.SetFileContents(self.adb.GetExternalStorage() + '/' + 63 self.adb.SetFileContents(self.adb.GetExternalStorage() + '/' +
65 NET_TEST_SERVER_PORT_INFO_FILE, 64 NET_TEST_SERVER_PORT_INFO_FILE,
66 '%d:%d' % (self.test_server_spawner_port, 65 '%d:%d' % (self.test_server_spawner_port,
67 self.test_server_port)) 66 self.test_server_port))
68 67
69 def Run(self): 68 def RunTest(self, test):
70 """Calls subclass functions to set up tests, run them and tear them down. 69 """Runs a test. Needs to be overridden.
70
71 Args:
72 test: A test to run.
71 73
72 Returns: 74 Returns:
73 Test results returned from RunTests(). 75 Tuple containing: (test_result.TestResults, tests to rerun or None)
74 """ 76 """
75 if not self.HasTests(): 77 raise NotImplementedError
76 return True
77 self.SetUp()
78 try:
79 return self.RunTests()
80 finally:
81 self.TearDown()
82 78
83 def SetUp(self): 79 def SetUp(self):
84 """Called before tests run.""" 80 """Run once before all tests are run."""
85 Forwarder.KillDevice(self.adb, self.tool) 81 Forwarder.KillDevice(self.adb, self.tool)
86 82
87 def HasTests(self):
88 """Whether the test suite has tests to run."""
89 return True
90
91 def RunTests(self):
92 """Runs the tests. Need to be overridden."""
93 raise NotImplementedError
94
95 def TearDown(self): 83 def TearDown(self):
96 """Called when tests finish running.""" 84 """Run once after all tests are run."""
97 self.ShutdownHelperToolsForTestSuite() 85 self.ShutdownHelperToolsForTestSuite()
98 86
99 def CopyTestData(self, test_data_paths, dest_dir): 87 def CopyTestData(self, test_data_paths, dest_dir):
100 """Copies |test_data_paths| list of files/directories to |dest_dir|. 88 """Copies |test_data_paths| list of files/directories to |dest_dir|.
101 89
102 Args: 90 Args:
103 test_data_paths: A list of files or directories relative to |dest_dir| 91 test_data_paths: A list of files or directories relative to |dest_dir|
104 which should be copied to the device. The paths must exist in 92 which should be copied to the device. The paths must exist in
105 |CHROME_DIR|. 93 |CHROME_DIR|.
106 dest_dir: Absolute path to copy to on the device. 94 dest_dir: Absolute path to copy to on the device.
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
163 if not ports.IsDevicePortUsed(self.adb, 151 if not ports.IsDevicePortUsed(self.adb,
164 self._forwarder_device_port): 152 self._forwarder_device_port):
165 self.StartForwarderForHttpServer() 153 self.StartForwarderForHttpServer()
166 154
167 def ShutdownHelperToolsForTestSuite(self): 155 def ShutdownHelperToolsForTestSuite(self):
168 """Shuts down the server and the forwarder.""" 156 """Shuts down the server and the forwarder."""
169 # Forwarders should be killed before the actual servers they're forwarding 157 # Forwarders should be killed before the actual servers they're forwarding
170 # to as they are clients potentially with open connections and to allow for 158 # to as they are clients potentially with open connections and to allow for
171 # proper hand-shake/shutdown. 159 # proper hand-shake/shutdown.
172 Forwarder.KillDevice(self.adb, self.tool) 160 Forwarder.KillDevice(self.adb, self.tool)
161 if self._forwarder:
162 self._forwarder.Close()
173 if self._http_server: 163 if self._http_server:
174 self._http_server.ShutdownHttpServer() 164 self._http_server.ShutdownHttpServer()
175 if self._spawning_server: 165 if self._spawning_server:
176 self._spawning_server.Stop() 166 self._spawning_server.Stop()
177 self.flags.Restore() 167 self.flags.Restore()
178 168
179 def LaunchChromeTestServerSpawner(self): 169 def LaunchChromeTestServerSpawner(self):
180 """Launches test server spawner.""" 170 """Launches test server spawner."""
181 server_ready = False 171 server_ready = False
182 error_msgs = [] 172 error_msgs = []
(...skipping 18 matching lines...) Expand all
201 # Wait for 2 seconds then restart. 191 # Wait for 2 seconds then restart.
202 time.sleep(2) 192 time.sleep(2)
203 if not server_ready: 193 if not server_ready:
204 logging.error(';'.join(error_msgs)) 194 logging.error(';'.join(error_msgs))
205 raise Exception('Can not start the test spawner server.') 195 raise Exception('Can not start the test spawner server.')
206 self._PushTestServerPortInfoToDevice() 196 self._PushTestServerPortInfoToDevice()
207 self._spawner_forwarder = self._CreateAndRunForwarder( 197 self._spawner_forwarder = self._CreateAndRunForwarder(
208 self.adb, 198 self.adb,
209 [(self.test_server_spawner_port, self.test_server_spawner_port)], 199 [(self.test_server_spawner_port, self.test_server_spawner_port)],
210 self.tool, '127.0.0.1', self.build_type) 200 self.tool, '127.0.0.1', self.build_type)
OLDNEW
« no previous file with comments | « no previous file | build/android/pylib/base/base_test_sharder.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698