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 = '/opt/google/chrome-remote-desktop/chrome-remote-desktop' |
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 = ( |
| 29 'Still waiting for the following processes to finish') |
| 30 TIME_OUT_INDICATOR = '(TIMED OUT)' |
| 31 MAX_RETRIES = 1 |
28 | 32 |
29 | 33 |
30 def LaunchBTCommand(command): | 34 def LaunchBTCommand(args, command): |
| 35 """Launches the specified browser-test command. |
| 36 |
| 37 If the execution failed because a browser-instance was not launched, retry |
| 38 once. |
| 39 Args: |
| 40 args: Command line args, used for test-case startup tasks. |
| 41 command: Browser-test command line. |
| 42 """ |
31 global TEST_FAILURE, FAILING_TESTS | 43 global TEST_FAILURE, FAILING_TESTS |
32 results = RunCommandInSubProcess(command) | 44 |
| 45 retries = 0 |
| 46 while retries <= MAX_RETRIES: |
| 47 TestCaseSetup(args) |
| 48 results = RunCommandInSubProcess(command) |
| 49 |
| 50 if SUCCESS_INDICATOR in results: |
| 51 # Test passed. |
| 52 break |
| 53 |
| 54 # Sometimes, during execution of browser-tests, a browser instance is |
| 55 # not started and the test times out. See http://crbug/480025. |
| 56 # To work around it, check if this execution failed owing to that |
| 57 # problem and retry. |
| 58 # There are 2 things to look for in the results: |
| 59 # A line saying "Still waiting for the following processes to finish", |
| 60 # and, because sometimes that line gets logged even if the test |
| 61 # eventually passes, we'll also look for "(TIMED OUT)", before retrying. |
| 62 if not ( |
| 63 BROWSER_NOT_STARTED_ERROR in results and TIME_OUT_INDICATOR in results): |
| 64 # Test failed for some other reason. Let's not retry. |
| 65 break |
| 66 retries += 1 |
33 | 67 |
34 # Check that the test passed. | 68 # Check that the test passed. |
35 if SUCCESS_INDICATOR not in results: | 69 if SUCCESS_INDICATOR not in results: |
36 TEST_FAILURE = True | 70 TEST_FAILURE = True |
37 # Add this command-line to list of tests that failed. | 71 # Add this command-line to list of tests that failed. |
38 FAILING_TESTS += command | 72 FAILING_TESTS += command |
39 | 73 |
40 | 74 |
41 def RunCommandInSubProcess(command): | 75 def RunCommandInSubProcess(command): |
42 """Creates a subprocess with command-line that is passed in. | 76 """Creates a subprocess with command-line that is passed in. |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 | 200 |
167 def PrintRunningProcesses(): | 201 def PrintRunningProcesses(): |
168 processes = psutil.get_process_list() | 202 processes = psutil.get_process_list() |
169 processes = sorted(processes, key=lambda process: process.name) | 203 processes = sorted(processes, key=lambda process: process.name) |
170 | 204 |
171 print 'List of running processes:\n' | 205 print 'List of running processes:\n' |
172 for process in processes: | 206 for process in processes: |
173 print process.name | 207 print process.name |
174 | 208 |
175 | 209 |
| 210 def TestCaseSetup(args): |
| 211 # Stop+start me2me host process. |
| 212 if not RestartMe2MeHost(): |
| 213 # Host restart failed. Don't run any more tests. |
| 214 raise Exception('Host restart failed.') |
| 215 |
| 216 # Reset the user profile directory to start each test with a clean slate. |
| 217 SetupUserProfileDir(args.me2me_manifest_file, args.it2me_manifest_file, |
| 218 args.user_profile_dir) |
| 219 |
| 220 |
176 def main(args): | 221 def main(args): |
177 | 222 |
178 InitialiseTestMachineForLinux(args.cfg_file) | 223 InitialiseTestMachineForLinux(args.cfg_file) |
179 | 224 |
180 with open(args.commands_file) as f: | 225 with open(args.commands_file) as f: |
181 for line in f: | 226 for line in f: |
182 # Reset the user profile directory to start each test with a clean slate. | |
183 SetupUserProfileDir(args.me2me_manifest_file, args.it2me_manifest_file, | |
184 args.user_profile_dir) | |
185 | |
186 # Replace the PROD_DIR value in the command-line with | 227 # Replace the PROD_DIR value in the command-line with |
187 # the passed in value. | 228 # the passed in value. |
188 line = line.replace(PROD_DIR_ID, args.prod_dir) | 229 line = line.replace(PROD_DIR_ID, args.prod_dir) |
189 # Launch specified command line for test. | 230 # Launch specified command line for test. |
190 LaunchBTCommand(line) | 231 LaunchBTCommand(args, line) |
191 # After each test, stop+start me2me host process. | |
192 if not RestartMe2MeHost(): | |
193 # Host restart failed. Don't run any more tests. | |
194 raise Exception('Host restart failed.') | |
195 | |
196 # Print list of currently running processes. | |
197 PrintRunningProcesses() | |
198 | 232 |
199 # All tests completed. Include host-logs in the test results. | 233 # All tests completed. Include host-logs in the test results. |
200 host_log_contents = '' | 234 host_log_contents = '' |
201 # There should be only 1 log file, as we delete logs on test completion. | 235 # There should be only 1 log file, as we delete logs on test completion. |
202 # Loop through matching files, just in case there are more. | 236 # Loop through matching files, just in case there are more. |
203 for log_file in glob.glob('/tmp/chrome_remote_desktop_*'): | 237 for log_file in glob.glob('/tmp/chrome_remote_desktop_*'): |
204 with open(log_file, 'r') as log: | 238 with open(log_file, 'r') as log: |
205 host_log_contents += '\nHOST LOG %s\n CONTENTS:\n%s' % ( | 239 host_log_contents += '\nHOST LOG %s\n CONTENTS:\n%s' % ( |
206 log_file, log.read()) | 240 log_file, log.read()) |
207 print host_log_contents | 241 print host_log_contents |
(...skipping 20 matching lines...) Expand all Loading... |
228 help='path to it2me host manifest file.') | 262 help='path to it2me host manifest file.') |
229 parser.add_argument( | 263 parser.add_argument( |
230 '-u', '--user_profile_dir', | 264 '-u', '--user_profile_dir', |
231 help='path to user-profile-dir, used by connect-to-host tests.') | 265 help='path to user-profile-dir, used by connect-to-host tests.') |
232 command_line_args = parser.parse_args() | 266 command_line_args = parser.parse_args() |
233 try: | 267 try: |
234 main(command_line_args) | 268 main(command_line_args) |
235 finally: | 269 finally: |
236 # Stop host and cleanup user-profile-dir. | 270 # Stop host and cleanup user-profile-dir. |
237 TestMachineCleanup(command_line_args.user_profile_dir) | 271 TestMachineCleanup(command_line_args.user_profile_dir) |
OLD | NEW |