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

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

Issue 874393008: Run all specified Chromoting browser_tests, instead of exiting on first failure. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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
« no previous file with comments | « no previous file | no next file » | 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) 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 24
24 25
25 def LaunchBTCommand(command): 26 def LaunchBTCommand(command):
26 results, error = RunCommandInSubProcess(command) 27 global TEST_FAILURE
28 results = RunCommandInSubProcess(command)
27 29
28 # Check that the test passed. 30 # Check that the test passed.
29 if SUCCESS_INDICATOR not in results: 31 if SUCCESS_INDICATOR not in results:
30 # Obtain contents of Chromoting host logs. 32 TEST_FAILURE = True
31 log_contents = ''
32 # There should be only 1 log file, as we delete logs on test completion.
33 # Loop through matching files, just in case there are more.
34 for log_file in glob.glob('/tmp/chrome_remote_desktop_*'):
35 with open(log_file, 'r') as log:
36 log_contents += '\nHOST LOG %s CONTENTS:\n%s' % (log_file, log.read())
37 print log_contents
38 raise Exception(
39 'Test failed. Command:%s\nResults:%s\nError:%s\n' %
40 (command, results, error))
41 33
42 34
43 def RunCommandInSubProcess(command): 35 def RunCommandInSubProcess(command):
44 """Creates a subprocess with command-line that is passed in. 36 """Creates a subprocess with command-line that is passed in.
45 37
46 Args: 38 Args:
47 command: The text of command to be executed. 39 command: The text of command to be executed.
48 Returns: 40 Returns:
49 results: stdout contents of executing the command. 41 results: stdout contents of executing the command.
50 error: stderr contents. 42 error: stderr contents.
Jamie 2015/01/30 19:30:38 Delete this line.
anandc 2015/02/02 05:57:27 Done.
51 """ 43 """
52 44
53 cmd_line = [command] 45 cmd_line = [command]
54 try: 46 try:
55 p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, shell=True) 47 p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, shell=True)
56 results, error = p.communicate() 48 results, error = p.communicate()
57 except subprocess.CalledProcessError, e: 49 except subprocess.CalledProcessError, e:
58 raise Exception('Exception %s running command %s\nError: %s' % 50 raise Exception('Exception %s running command %s\nError: %s' %
59 (e, command, error)) 51 (e, command, error))
60 else: 52 else:
61 print results 53 print results
62 return results, error 54 return results
anandc 2015/01/30 14:31:30 I've confirmed that not returning the "error" vari
63 55
64 56
65 def TestCleanUp(user_profile_dir): 57 def TestCleanUp(user_profile_dir):
66 """Cleans up test machine so as not to impact other tests. 58 """Cleans up test machine so as not to impact other tests.
67 59
68 Args: 60 Args:
69 user_profile_dir: the user-profile folder used by Chromoting tests. 61 user_profile_dir: the user-profile folder used by Chromoting tests.
70 62
71 """ 63 """
72 # Stop the host service. 64 # Stop the host service.
73 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop') 65 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop')
74 66
75 # Cleanup any host logs. 67 # Cleanup any host logs.
76 RunCommandInSubProcess('rm /tmp/chrome_remote_desktop_*') 68 RunCommandInSubProcess('rm /tmp/chrome_remote_desktop_*')
77 69
78 # Remove the user-profile dir 70 # Remove the user-profile dir
79 if os.path.exists(user_profile_dir): 71 if os.path.exists(user_profile_dir):
80 shutil.rmtree(user_profile_dir) 72 shutil.rmtree(user_profile_dir)
81 73
82 74
83 def InitialiseTestMachineForLinux(cfg_file): 75 def InitialiseTestMachineForLinux(cfg_file):
84 """Sets up a Linux machine for connect-to-host browser-tests. 76 """Sets up a Linux machine for connect-to-host browser-tests.
85 77
86 Copy over me2me host-config to expected locations. 78 Copy over me2me host-config to expected locations.
87 By default, the Linux me2me host expects the host-config file to be under 79 By default, the Linux me2me host expects the host-config file to be under
88 $HOME/.config/chrome-remote-desktop 80 $HOME/.config/chrome-remote-desktop
89 Its name is expected to have a hash that is specific to a machine. 81 Its name is expected to have a hash that is specific to a machine.
90 82
91 TODO(anandc):
92 Once we have Linux machines in the swarming lab already installed with the
93 me2me host, this function should also perform the step of starting the host.
94 That is gated on this CL: https://chromereviews.googleplex.com/123957013/, and
95 then having base images in the chrome-labs be updated with it.
96
97 Args: 83 Args:
98 cfg_file: location of test account's host-config file. 84 cfg_file: location of test account's host-config file.
99 """ 85 """
100 86
101 # First get home directory on current machine. 87 # First get home directory on current machine.
102 home_dir = expanduser('~') 88 home_dir = expanduser('~')
103 default_config_file_location = os.path.join(home_dir, '.config', CRD_ID) 89 default_config_file_location = os.path.join(home_dir, '.config', CRD_ID)
104 if os.path.exists(default_config_file_location): 90 if os.path.exists(default_config_file_location):
105 shutil.rmtree(default_config_file_location) 91 shutil.rmtree(default_config_file_location)
106 os.makedirs(default_config_file_location) 92 os.makedirs(default_config_file_location)
107 93
108 # Copy over test host-config to expected location, with expected file-name. 94 # Copy over test host-config to expected location, with expected file-name.
109 # The file-name should contain a hash-value that is machine-specific. 95 # The file-name should contain a hash-value that is machine-specific.
110 default_config_file_name = 'host#%s.json' % HOST_HASH_VALUE 96 default_config_file_name = 'host#%s.json' % HOST_HASH_VALUE
111 config_file_src = os.path.join(os.getcwd(), cfg_file) 97 config_file_src = os.path.join(os.getcwd(), cfg_file)
112 shutil.copyfile( 98 shutil.copyfile(
113 config_file_src, 99 config_file_src,
114 os.path.join(default_config_file_location, default_config_file_name)) 100 os.path.join(default_config_file_location, default_config_file_name))
115 101
116 # Finally, start chromoting host. 102 # Finally, start chromoting host.
117 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start') 103 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start')
118 104
119 105
120 def SetupUserProfileDir(me2me_manifest_file, it2me_manifest_file, 106 def SetupUserProfileDir(me2me_manifest_file, it2me_manifest_file,
121 user_profile_dir): 107 user_profile_dir):
122 """Sets up the Google Chrome user profile directory 108 """Sets up the Google Chrome user profile directory.
123 109
124 Delete the previous user profile directory if exists and create a new one. 110 Delete the previous user profile directory if exists and create a new one.
125 This invalidates any state changes by the previous test so each test can start 111 This invalidates any state changes by the previous test so each test can start
126 with the same environment. 112 with the same environment.
127 113
128 When a user launches the remoting web-app, the native messaging host process 114 When a user launches the remoting web-app, the native messaging host process
129 is started. For this to work, this function places the me2me and it2me native 115 is started. For this to work, this function places the me2me and it2me native
130 messaging host manifest files in a specific folder under the user-profile dir. 116 messaging host manifest files in a specific folder under the user-profile dir.
131 117
132 Args: 118 Args:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 for line in f: 158 for line in f:
173 # Reset the user profile directory to start each test with a clean slate. 159 # Reset the user profile directory to start each test with a clean slate.
174 SetupUserProfileDir(args.me2me_manifest_file, args.it2me_manifest_file, 160 SetupUserProfileDir(args.me2me_manifest_file, args.it2me_manifest_file,
175 args.user_profile_dir) 161 args.user_profile_dir)
176 162
177 # Replace the PROD_DIR value in the command-line with 163 # Replace the PROD_DIR value in the command-line with
178 # the passed in value. 164 # the passed in value.
179 line = line.replace(PROD_DIR_ID, args.prod_dir) 165 line = line.replace(PROD_DIR_ID, args.prod_dir)
180 LaunchBTCommand(line) 166 LaunchBTCommand(line)
181 167
168 # Was there any test failure?
169 if TEST_FAILURE:
170 # Obtain contents of Chromoting host logs.
171 log_contents = ''
172 # There should be only 1 log file, as we delete logs on test completion.
173 # Loop through matching files, just in case there are more.
174 for log_file in glob.glob('/tmp/chrome_remote_desktop_*'):
175 with open(log_file, 'r') as log:
176 log_contents += '\nHOST LOG %s\n CONTENTS:\n%s' % (log_file, log.read())
177 print log_contents
178 raise Exception('At least one test failed.')
anandc 2015/01/30 14:31:30 Test logs contain all information written by brows
179
182 # Now, stop host, and cleanup user-profile-dir 180 # Now, stop host, and cleanup user-profile-dir
183 TestCleanUp(args.user_profile_dir) 181 TestCleanUp(args.user_profile_dir)
184 182
185 if __name__ == '__main__': 183 if __name__ == '__main__':
186 main() 184 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698