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

Side by Side Diff: testing/chromoting/browser_tests_launcher.py

Issue 1108173002: Roll //build, //native_client, and a few more targets of opportunity. Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Test fix 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
OLDNEW
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 BROWSER_TEST_ID = 'browser_tests' 16 BROWSER_TEST_ID = 'browser_tests'
17 PROD_DIR_ID = '#PROD_DIR#' 17 PROD_DIR_ID = '#PROD_DIR#'
18 HOST_HASH_VALUE = hashlib.md5(socket.gethostname()).hexdigest() 18 HOST_HASH_VALUE = hashlib.md5(socket.gethostname()).hexdigest()
19 SUCCESS_INDICATOR = 'SUCCESS: all tests passed.' 19 SUCCESS_INDICATOR = 'SUCCESS: all tests passed.'
20 NATIVE_MESSAGING_DIR = 'NativeMessagingHosts' 20 NATIVE_MESSAGING_DIR = 'NativeMessagingHosts'
21 CRD_ID = 'chrome-remote-desktop' # Used in a few file/folder names 21 CRD_ID = 'chrome-remote-desktop' # Used in a few file/folder names
22 CHROMOTING_HOST_PATH = '/opt/google/chrome-remote-desktop/chrome-remote-desktop' 22 CHROMOTING_HOST_PATH = '/opt/google/chrome-remote-desktop/chrome-remote-desktop'
23 TEST_FAILURE = False 23 TEST_FAILURE = False
24 FAILING_TESTS = ''
25 HOST_READY_INDICATOR = 'Host ready to receive connections.'
24 26
25 27
26 def LaunchBTCommand(command): 28 def LaunchBTCommand(command):
27 global TEST_FAILURE 29 global TEST_FAILURE, FAILING_TESTS
28 results = RunCommandInSubProcess(command) 30 results = RunCommandInSubProcess(command)
29 31
30 # Check that the test passed. 32 # Check that the test passed.
31 if SUCCESS_INDICATOR not in results: 33 if SUCCESS_INDICATOR not in results:
32 TEST_FAILURE = True 34 TEST_FAILURE = True
35 # Add this command-line to list of tests that failed.
36 FAILING_TESTS += command
33 37
34 38
35 def RunCommandInSubProcess(command): 39 def RunCommandInSubProcess(command):
36 """Creates a subprocess with command-line that is passed in. 40 """Creates a subprocess with command-line that is passed in.
37 41
38 Args: 42 Args:
39 command: The text of command to be executed. 43 command: The text of command to be executed.
40 Returns: 44 Returns:
41 results: stdout contents of executing the command. 45 results: stdout contents of executing the command.
42 """ 46 """
43 47
44 cmd_line = [command] 48 cmd_line = [command]
45 try: 49 try:
46 p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, shell=True) 50 results = subprocess.check_output(cmd_line, stderr=subprocess.STDOUT,
47 results, error = p.communicate() 51 shell=True)
48 except subprocess.CalledProcessError, e: 52 except subprocess.CalledProcessError, e:
49 raise Exception('Exception %s running command %s\nError: %s' % 53 results = e.output
50 (e, command, error)) 54 finally:
51 else:
52 print results 55 print results
53 return results 56 return results
54 57
55 58
56 def TestCleanUp(user_profile_dir): 59 def TestMachineCleanup(user_profile_dir):
57 """Cleans up test machine so as not to impact other tests. 60 """Cleans up test machine so as not to impact other tests.
58 61
59 Args: 62 Args:
60 user_profile_dir: the user-profile folder used by Chromoting tests. 63 user_profile_dir: the user-profile folder used by Chromoting tests.
61 64
62 """ 65 """
63 # Stop the host service. 66 # Stop the host service.
64 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop') 67 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop')
65 68
66 # Cleanup any host logs. 69 # Cleanup any host logs.
67 RunCommandInSubProcess('rm /tmp/chrome_remote_desktop_*') 70 RunCommandInSubProcess('rm /tmp/chrome_remote_desktop_*')
68 71
69 # Remove the user-profile dir 72 # Remove the user-profile dir
70 if os.path.exists(user_profile_dir): 73 if os.path.exists(user_profile_dir):
71 shutil.rmtree(user_profile_dir) 74 shutil.rmtree(user_profile_dir)
72 75
73 76
74 def InitialiseTestMachineForLinux(cfg_file): 77 def InitialiseTestMachineForLinux(cfg_file):
75 """Sets up a Linux machine for connect-to-host browser-tests. 78 """Sets up a Linux machine for connect-to-host browser-tests.
76 79
77 Copy over me2me host-config to expected locations. 80 Copy over me2me host-config to expected locations.
78 By default, the Linux me2me host expects the host-config file to be under 81 By default, the Linux me2me host expects the host-config file to be under
79 $HOME/.config/chrome-remote-desktop 82 $HOME/.config/chrome-remote-desktop
80 Its name is expected to have a hash that is specific to a machine. 83 Its name is expected to have a hash that is specific to a machine.
81 84
82 Args: 85 Args:
83 cfg_file: location of test account's host-config file. 86 cfg_file: location of test account's host-config file.
87
88 Raises:
89 Exception: if host did not start properly.
84 """ 90 """
85 91
86 # First get home directory on current machine. 92 # First get home directory on current machine.
87 home_dir = expanduser('~') 93 home_dir = expanduser('~')
88 default_config_file_location = os.path.join(home_dir, '.config', CRD_ID) 94 default_config_file_location = os.path.join(home_dir, '.config', CRD_ID)
89 if os.path.exists(default_config_file_location): 95 if os.path.exists(default_config_file_location):
90 shutil.rmtree(default_config_file_location) 96 shutil.rmtree(default_config_file_location)
91 os.makedirs(default_config_file_location) 97 os.makedirs(default_config_file_location)
92 98
93 # Copy over test host-config to expected location, with expected file-name. 99 # Copy over test host-config to expected location, with expected file-name.
94 # The file-name should contain a hash-value that is machine-specific. 100 # The file-name should contain a hash-value that is machine-specific.
95 default_config_file_name = 'host#%s.json' % HOST_HASH_VALUE 101 default_config_file_name = 'host#%s.json' % HOST_HASH_VALUE
96 config_file_src = os.path.join(os.getcwd(), cfg_file) 102 config_file_src = os.path.join(os.getcwd(), cfg_file)
97 shutil.copyfile( 103 shutil.copyfile(
98 config_file_src, 104 config_file_src,
99 os.path.join(default_config_file_location, default_config_file_name)) 105 os.path.join(default_config_file_location, default_config_file_name))
100 106
101 # Finally, start chromoting host. 107 # Make sure chromoting host is running.
102 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start') 108 if not RestartMe2MeHost():
109 # Host start failed. Don't run any tests.
110 raise Exception('Host restart failed.')
111
112
113 def RestartMe2MeHost():
114 """Stops and starts the Me2Me host on the test machine.
115
116 Waits to confirm that host is ready to receive connections before returning.
117
118 Returns:
119 True: if HOST_READY_INDICATOR is found in stdout, indicating host is ready.
120 False: if HOST_READY_INDICATOR not found in stdout.
121 """
122
123 # Stop chromoting host.
124 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop')
125 # Start chromoting host.
126 results = RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start')
127 # Confirm that the start process completed, and we got:
128 # "Host ready to receive connections." in the log.
129 if HOST_READY_INDICATOR not in results:
130 return False
131 return True
103 132
104 133
105 def SetupUserProfileDir(me2me_manifest_file, it2me_manifest_file, 134 def SetupUserProfileDir(me2me_manifest_file, it2me_manifest_file,
106 user_profile_dir): 135 user_profile_dir):
107 """Sets up the Google Chrome user profile directory. 136 """Sets up the Google Chrome user profile directory.
108 137
109 Delete the previous user profile directory if exists and create a new one. 138 Delete the previous user profile directory if exists and create a new one.
110 This invalidates any state changes by the previous test so each test can start 139 This invalidates any state changes by the previous test so each test can start
111 with the same environment. 140 with the same environment.
112 141
(...skipping 13 matching lines...) Expand all
126 os.makedirs(native_messaging_folder) 155 os.makedirs(native_messaging_folder)
127 156
128 manifest_files = [me2me_manifest_file, it2me_manifest_file] 157 manifest_files = [me2me_manifest_file, it2me_manifest_file]
129 for manifest_file in manifest_files: 158 for manifest_file in manifest_files:
130 manifest_file_src = os.path.join(os.getcwd(), manifest_file) 159 manifest_file_src = os.path.join(os.getcwd(), manifest_file)
131 manifest_file_dest = ( 160 manifest_file_dest = (
132 os.path.join(native_messaging_folder, os.path.basename(manifest_file))) 161 os.path.join(native_messaging_folder, os.path.basename(manifest_file)))
133 shutil.copyfile(manifest_file_src, manifest_file_dest) 162 shutil.copyfile(manifest_file_src, manifest_file_dest)
134 163
135 164
136 def main(): 165 def main(args):
137 parser = argparse.ArgumentParser()
138 parser.add_argument('-f', '--commands_file',
139 help='path to file listing commands to be launched.')
140 parser.add_argument('-p', '--prod_dir',
141 help='path to folder having product and test binaries.')
142 parser.add_argument('-c', '--cfg_file',
143 help='path to test host config file.')
144 parser.add_argument('--me2me_manifest_file',
145 help='path to me2me host manifest file.')
146 parser.add_argument('--it2me_manifest_file',
147 help='path to it2me host manifest file.')
148 parser.add_argument(
149 '-u', '--user_profile_dir',
150 help='path to user-profile-dir, used by connect-to-host tests.')
151
152 args = parser.parse_args()
153 166
154 InitialiseTestMachineForLinux(args.cfg_file) 167 InitialiseTestMachineForLinux(args.cfg_file)
155 168
156 with open(args.commands_file) as f: 169 with open(args.commands_file) as f:
157 for line in f: 170 for line in f:
158 # Reset the user profile directory to start each test with a clean slate. 171 # Reset the user profile directory to start each test with a clean slate.
159 SetupUserProfileDir(args.me2me_manifest_file, args.it2me_manifest_file, 172 SetupUserProfileDir(args.me2me_manifest_file, args.it2me_manifest_file,
160 args.user_profile_dir) 173 args.user_profile_dir)
161 174
162 # Replace the PROD_DIR value in the command-line with 175 # Replace the PROD_DIR value in the command-line with
163 # the passed in value. 176 # the passed in value.
164 line = line.replace(PROD_DIR_ID, args.prod_dir) 177 line = line.replace(PROD_DIR_ID, args.prod_dir)
178 # Launch specified command line for test.
165 LaunchBTCommand(line) 179 LaunchBTCommand(line)
180 # After each test, stop+start me2me host process.
181 if not RestartMe2MeHost():
182 # Host restart failed. Don't run any more tests.
183 raise Exception('Host restart failed.')
184
185 # All tests completed. Include host-logs in the test results.
186 host_log_contents = ''
187 # There should be only 1 log file, as we delete logs on test completion.
188 # Loop through matching files, just in case there are more.
189 for log_file in glob.glob('/tmp/chrome_remote_desktop_*'):
190 with open(log_file, 'r') as log:
191 host_log_contents += '\nHOST LOG %s\n CONTENTS:\n%s' % (
192 log_file, log.read())
193 print host_log_contents
166 194
167 # Was there any test failure? 195 # Was there any test failure?
168 if TEST_FAILURE: 196 if TEST_FAILURE:
169 # Obtain contents of Chromoting host logs. 197 print '++++++++++AT LEAST 1 TEST FAILED++++++++++'
170 log_contents = '' 198 print FAILING_TESTS.rstrip('\n')
171 # There should be only 1 log file, as we delete logs on test completion. 199 print '++++++++++++++++++++++++++++++++++++++++++'
172 # Loop through matching files, just in case there are more.
173 for log_file in glob.glob('/tmp/chrome_remote_desktop_*'):
174 with open(log_file, 'r') as log:
175 log_contents += '\nHOST LOG %s\n CONTENTS:\n%s' % (log_file, log.read())
176 print log_contents
177 raise Exception('At least one test failed.') 200 raise Exception('At least one test failed.')
178 201
179 # Now, stop host, and cleanup user-profile-dir 202 if __name__ == '__main__':
180 TestCleanUp(args.user_profile_dir)
181 203
182 if __name__ == '__main__': 204 parser = argparse.ArgumentParser()
183 main() 205 parser.add_argument('-f', '--commands_file',
206 help='path to file listing commands to be launched.')
207 parser.add_argument('-p', '--prod_dir',
208 help='path to folder having product and test binaries.')
209 parser.add_argument('-c', '--cfg_file',
210 help='path to test host config file.')
211 parser.add_argument('--me2me_manifest_file',
212 help='path to me2me host manifest file.')
213 parser.add_argument('--it2me_manifest_file',
214 help='path to it2me host manifest file.')
215 parser.add_argument(
216 '-u', '--user_profile_dir',
217 help='path to user-profile-dir, used by connect-to-host tests.')
218 command_line_args = parser.parse_args()
219 try:
220 main(command_line_args)
221 finally:
222 # Stop host and cleanup user-profile-dir.
223 TestMachineCleanup(command_line_args.user_profile_dir)
OLDNEW
« no previous file with comments | « testing/chromoting/browser_test_commands_linux.txt ('k') | testing/chromoting/chromoting_integration_tests.isolate » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698