OLD | NEW |
---|---|
1 # Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 # Copyright (c) 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 """Utility script to launch browser-tests on the Chromoting bot.""" | 6 """Utility script to launch browser-tests on the Chromoting bot.""" |
7 import argparse | 7 import argparse |
8 import glob | 8 import glob |
9 import hashlib | 9 import hashlib |
10 import os | 10 import os |
11 from os.path import expanduser | 11 from os.path import expanduser |
12 import shutil | 12 import shutil |
13 import socket | 13 import socket |
14 import subprocess | 14 import subprocess |
15 | 15 |
16 import psutil | 16 import psutil |
17 | 17 |
18 BROWSER_TEST_ID = 'browser_tests' | 18 BROWSER_TEST_ID = 'browser_tests' |
19 PROD_DIR_ID = '#PROD_DIR#' | 19 PROD_DIR_ID = '#PROD_DIR#' |
20 HOST_HASH_VALUE = hashlib.md5(socket.gethostname()).hexdigest() | 20 HOST_HASH_VALUE = hashlib.md5(socket.gethostname()).hexdigest() |
21 SUCCESS_INDICATOR = 'SUCCESS: all tests passed.' | 21 SUCCESS_INDICATOR = 'SUCCESS: all tests passed.' |
22 NATIVE_MESSAGING_DIR = 'NativeMessagingHosts' | 22 NATIVE_MESSAGING_DIR = 'NativeMessagingHosts' |
23 CRD_ID = 'chrome-remote-desktop' # Used in a few file/folder names | 23 CRD_ID = 'chrome-remote-desktop' # Used in a few file/folder names |
24 CHROMOTING_HOST_PATH = '/opt/google/chrome-remote-desktop/chrome-remote-desktop' | 24 CHROMOTING_HOST_PATH = './remoting/host/linux/linux_me2me_host.py' |
25 TEST_FAILURE = False | 25 TEST_FAILURE = False |
26 FAILING_TESTS = '' | 26 FAILING_TESTS = '' |
27 HOST_READY_INDICATOR = 'Host ready to receive connections.' | 27 HOST_READY_INDICATOR = 'Host ready to receive connections.' |
28 BROWSER_NOT_STARTED_ERROR = ( | 28 BROWSER_NOT_STARTED_ERROR = ( |
29 'Still waiting for the following processes to finish') | 29 'Still waiting for the following processes to finish') |
30 TIME_OUT_INDICATOR = '(TIMED OUT)' | 30 TIME_OUT_INDICATOR = '(TIMED OUT)' |
31 MAX_RETRIES = 1 | 31 MAX_RETRIES = 1 |
32 ISOLATE_TEMP_FOLDER = '' | |
joedow
2015/08/07 22:16:19
Can you init this variable up here instead of usin
anandc
2015/08/07 22:26:41
Done.
| |
32 | 33 |
33 | 34 |
34 def LaunchBTCommand(args, command): | 35 def LaunchBTCommand(args, command): |
35 """Launches the specified browser-test command. | 36 """Launches the specified browser-test command. |
36 | 37 |
37 If the execution failed because a browser-instance was not launched, retry | 38 If the execution failed because a browser-instance was not launched, retry |
38 once. | 39 once. |
39 Args: | 40 Args: |
40 args: Command line args, used for test-case startup tasks. | 41 args: Command line args, used for test-case startup tasks. |
41 command: Browser-test command line. | 42 command: Browser-test command line. |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
149 def RestartMe2MeHost(): | 150 def RestartMe2MeHost(): |
150 """Stops and starts the Me2Me host on the test machine. | 151 """Stops and starts the Me2Me host on the test machine. |
151 | 152 |
152 Waits to confirm that host is ready to receive connections before returning. | 153 Waits to confirm that host is ready to receive connections before returning. |
153 | 154 |
154 Returns: | 155 Returns: |
155 True: if HOST_READY_INDICATOR is found in stdout, indicating host is ready. | 156 True: if HOST_READY_INDICATOR is found in stdout, indicating host is ready. |
156 False: if HOST_READY_INDICATOR not found in stdout. | 157 False: if HOST_READY_INDICATOR not found in stdout. |
157 """ | 158 """ |
158 | 159 |
160 # To start the host, we want to be in the temp-folder for this test execution. | |
161 # Store the current folder to return back to it later. | |
162 cwd = os.getcwd() | |
joedow
2015/08/07 22:16:19
can you use previous_directory here? It is no lon
anandc
2015/08/07 22:26:41
Done.
| |
163 os.chdir(ISOLATE_TEMP_FOLDER) | |
164 | |
159 # Stop chromoting host. | 165 # Stop chromoting host. |
160 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop') | 166 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop') |
161 # Start chromoting host. | 167 # Start chromoting host. |
162 results = RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start') | 168 results = RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start') |
169 | |
170 # Go back to starting folder. | |
joedow
2015/08/07 22:16:19
nit: remove comment, I think it will be obvious if
anandc
2015/08/07 22:26:41
Done.
| |
171 os.chdir(cwd) | |
172 print 'Now in %s: ' % os.getcwd() | |
163 # Confirm that the start process completed, and we got: | 173 # Confirm that the start process completed, and we got: |
164 # "Host ready to receive connections." in the log. | 174 # "Host ready to receive connections." in the log. |
165 if HOST_READY_INDICATOR not in results: | 175 if HOST_READY_INDICATOR not in results: |
166 return False | 176 return False |
167 return True | 177 return True |
168 | 178 |
169 | 179 |
170 def SetupUserProfileDir(me2me_manifest_file, it2me_manifest_file, | 180 def SetupUserProfileDir(me2me_manifest_file, it2me_manifest_file, |
171 user_profile_dir): | 181 user_profile_dir): |
172 """Sets up the Google Chrome user profile directory. | 182 """Sets up the Google Chrome user profile directory. |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
213 # Host restart failed. Don't run any more tests. | 223 # Host restart failed. Don't run any more tests. |
214 raise Exception('Host restart failed.') | 224 raise Exception('Host restart failed.') |
215 | 225 |
216 # Reset the user profile directory to start each test with a clean slate. | 226 # Reset the user profile directory to start each test with a clean slate. |
217 SetupUserProfileDir(args.me2me_manifest_file, args.it2me_manifest_file, | 227 SetupUserProfileDir(args.me2me_manifest_file, args.it2me_manifest_file, |
218 args.user_profile_dir) | 228 args.user_profile_dir) |
219 | 229 |
220 | 230 |
221 def main(args): | 231 def main(args): |
222 | 232 |
233 global ISOLATE_TEMP_FOLDER | |
234 # On a Swarming bot where these tests are executed, a temp folder is created | |
235 # under which the files specified in an .isolate are copied. This temp folder | |
236 # has a random name, which we'll store here for use late. | |
237 # Note that the test-execution always start from the testing/chromoting folder | |
238 # under the temp folder. | |
239 ISOLATE_TEMP_FOLDER = os.path.abspath(os.path.join(os.getcwd(), '../..')) | |
240 | |
223 InitialiseTestMachineForLinux(args.cfg_file) | 241 InitialiseTestMachineForLinux(args.cfg_file) |
224 | 242 |
225 with open(args.commands_file) as f: | 243 with open(args.commands_file) as f: |
226 for line in f: | 244 for line in f: |
227 # Replace the PROD_DIR value in the command-line with | 245 # Replace the PROD_DIR value in the command-line with |
228 # the passed in value. | 246 # the passed in value. |
229 line = line.replace(PROD_DIR_ID, args.prod_dir) | 247 line = line.replace(PROD_DIR_ID, args.prod_dir) |
230 # Launch specified command line for test. | 248 # Launch specified command line for test. |
231 LaunchBTCommand(args, line) | 249 LaunchBTCommand(args, line) |
232 | 250 |
233 # All tests completed. Include host-logs in the test results. | 251 # All tests completed. Include host-logs in the test results. |
234 host_log_contents = '' | 252 host_log_contents = '' |
235 # There should be only 1 log file, as we delete logs on test completion. | |
236 # Loop through matching files, just in case there are more. | |
237 for log_file in glob.glob('/tmp/chrome_remote_desktop_*'): | 253 for log_file in glob.glob('/tmp/chrome_remote_desktop_*'): |
238 with open(log_file, 'r') as log: | 254 with open(log_file, 'r') as log: |
239 host_log_contents += '\nHOST LOG %s\n CONTENTS:\n%s' % ( | 255 host_log_contents += '\nHOST LOG %s\n CONTENTS:\n%s' % ( |
240 log_file, log.read()) | 256 log_file, log.read()) |
241 print host_log_contents | 257 print host_log_contents |
242 | 258 |
243 # Was there any test failure? | |
244 if TEST_FAILURE: | 259 if TEST_FAILURE: |
245 print '++++++++++AT LEAST 1 TEST FAILED++++++++++' | 260 print '++++++++++AT LEAST 1 TEST FAILED++++++++++' |
246 print FAILING_TESTS.rstrip('\n') | 261 print FAILING_TESTS.rstrip('\n') |
247 print '++++++++++++++++++++++++++++++++++++++++++' | 262 print '++++++++++++++++++++++++++++++++++++++++++' |
248 raise Exception('At least one test failed.') | 263 raise Exception('At least one test failed.') |
249 | 264 |
250 if __name__ == '__main__': | 265 if __name__ == '__main__': |
251 | 266 |
252 parser = argparse.ArgumentParser() | 267 parser = argparse.ArgumentParser() |
253 parser.add_argument('-f', '--commands_file', | 268 parser.add_argument('-f', '--commands_file', |
254 help='path to file listing commands to be launched.') | 269 help='path to file listing commands to be launched.') |
255 parser.add_argument('-p', '--prod_dir', | 270 parser.add_argument('-p', '--prod_dir', |
256 help='path to folder having product and test binaries.') | 271 help='path to folder having product and test binaries.') |
257 parser.add_argument('-c', '--cfg_file', | 272 parser.add_argument('-c', '--cfg_file', |
258 help='path to test host config file.') | 273 help='path to test host config file.') |
259 parser.add_argument('--me2me_manifest_file', | 274 parser.add_argument('--me2me_manifest_file', |
260 help='path to me2me host manifest file.') | 275 help='path to me2me host manifest file.') |
261 parser.add_argument('--it2me_manifest_file', | 276 parser.add_argument('--it2me_manifest_file', |
262 help='path to it2me host manifest file.') | 277 help='path to it2me host manifest file.') |
263 parser.add_argument( | 278 parser.add_argument( |
264 '-u', '--user_profile_dir', | 279 '-u', '--user_profile_dir', |
265 help='path to user-profile-dir, used by connect-to-host tests.') | 280 help='path to user-profile-dir, used by connect-to-host tests.') |
266 command_line_args = parser.parse_args() | 281 command_line_args = parser.parse_args() |
267 try: | 282 try: |
268 main(command_line_args) | 283 main(command_line_args) |
269 finally: | 284 finally: |
270 # Stop host and cleanup user-profile-dir. | 285 # Stop host and cleanup user-profile-dir. |
271 TestMachineCleanup(command_line_args.user_profile_dir) | 286 TestMachineCleanup(command_line_args.user_profile_dir) |
OLD | NEW |