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

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

Issue 895853003: Update from https://crrev.com/314320 (Closed) Base URL: https://github.com/domokit/mojo.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 | « testing/buildbot/chromium.fyi.json ('k') | testing/commit_queue/config.json » ('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) 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.
51 """ 42 """
52 43
53 cmd_line = [command] 44 cmd_line = [command]
54 try: 45 try:
55 p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, shell=True) 46 p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, shell=True)
56 results, error = p.communicate() 47 results, error = p.communicate()
57 except subprocess.CalledProcessError, e: 48 except subprocess.CalledProcessError, e:
58 raise Exception('Exception %s running command %s\nError: %s' % 49 raise Exception('Exception %s running command %s\nError: %s' %
59 (e, command, error)) 50 (e, command, error))
60 else: 51 else:
61 print results 52 print results
62 return results, error 53 return results
63 54
64 55
65 def TestCleanUp(user_profile_dir): 56 def TestCleanUp(user_profile_dir):
66 """Cleans up test machine so as not to impact other tests. 57 """Cleans up test machine so as not to impact other tests.
67 58
68 Args: 59 Args:
69 user_profile_dir: the user-profile folder used by Chromoting tests. 60 user_profile_dir: the user-profile folder used by Chromoting tests.
70 61
71 """ 62 """
72 # Stop the host service. 63 # Stop the host service.
73 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop') 64 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --stop')
74 65
75 # Cleanup any host logs. 66 # Cleanup any host logs.
76 RunCommandInSubProcess('rm /tmp/chrome_remote_desktop_*') 67 RunCommandInSubProcess('rm /tmp/chrome_remote_desktop_*')
77 68
78 # Remove the user-profile dir 69 # Remove the user-profile dir
79 if os.path.exists(user_profile_dir): 70 if os.path.exists(user_profile_dir):
80 shutil.rmtree(user_profile_dir) 71 shutil.rmtree(user_profile_dir)
81 72
82 73
83 def InitialiseTestMachineForLinux(cfg_file): 74 def InitialiseTestMachineForLinux(cfg_file):
84 """Sets up a Linux machine for connect-to-host browser-tests. 75 """Sets up a Linux machine for connect-to-host browser-tests.
85 76
86 Copy over me2me host-config to expected locations. 77 Copy over me2me host-config to expected locations.
87 By default, the Linux me2me host expects the host-config file to be under 78 By default, the Linux me2me host expects the host-config file to be under
88 $HOME/.config/chrome-remote-desktop 79 $HOME/.config/chrome-remote-desktop
89 Its name is expected to have a hash that is specific to a machine. 80 Its name is expected to have a hash that is specific to a machine.
90 81
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: 82 Args:
98 cfg_file: location of test account's host-config file. 83 cfg_file: location of test account's host-config file.
99 """ 84 """
100 85
101 # First get home directory on current machine. 86 # First get home directory on current machine.
102 home_dir = expanduser('~') 87 home_dir = expanduser('~')
103 default_config_file_location = os.path.join(home_dir, '.config', CRD_ID) 88 default_config_file_location = os.path.join(home_dir, '.config', CRD_ID)
104 if os.path.exists(default_config_file_location): 89 if os.path.exists(default_config_file_location):
105 shutil.rmtree(default_config_file_location) 90 shutil.rmtree(default_config_file_location)
106 os.makedirs(default_config_file_location) 91 os.makedirs(default_config_file_location)
107 92
108 # Copy over test host-config to expected location, with expected file-name. 93 # 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. 94 # The file-name should contain a hash-value that is machine-specific.
110 default_config_file_name = 'host#%s.json' % HOST_HASH_VALUE 95 default_config_file_name = 'host#%s.json' % HOST_HASH_VALUE
111 config_file_src = os.path.join(os.getcwd(), cfg_file) 96 config_file_src = os.path.join(os.getcwd(), cfg_file)
112 shutil.copyfile( 97 shutil.copyfile(
113 config_file_src, 98 config_file_src,
114 os.path.join(default_config_file_location, default_config_file_name)) 99 os.path.join(default_config_file_location, default_config_file_name))
115 100
116 # Finally, start chromoting host. 101 # Finally, start chromoting host.
117 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start') 102 RunCommandInSubProcess(CHROMOTING_HOST_PATH + ' --start')
118 103
119 104
120 def SetupUserProfileDir(me2me_manifest_file, it2me_manifest_file, 105 def SetupUserProfileDir(me2me_manifest_file, it2me_manifest_file,
121 user_profile_dir): 106 user_profile_dir):
122 """Sets up the Google Chrome user profile directory 107 """Sets up the Google Chrome user profile directory.
123 108
124 Delete the previous user profile directory if exists and create a new one. 109 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 110 This invalidates any state changes by the previous test so each test can start
126 with the same environment. 111 with the same environment.
127 112
128 When a user launches the remoting web-app, the native messaging host process 113 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 114 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. 115 messaging host manifest files in a specific folder under the user-profile dir.
131 116
132 Args: 117 Args:
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
172 for line in f: 157 for line in f:
173 # Reset the user profile directory to start each test with a clean slate. 158 # Reset the user profile directory to start each test with a clean slate.
174 SetupUserProfileDir(args.me2me_manifest_file, args.it2me_manifest_file, 159 SetupUserProfileDir(args.me2me_manifest_file, args.it2me_manifest_file,
175 args.user_profile_dir) 160 args.user_profile_dir)
176 161
177 # Replace the PROD_DIR value in the command-line with 162 # Replace the PROD_DIR value in the command-line with
178 # the passed in value. 163 # the passed in value.
179 line = line.replace(PROD_DIR_ID, args.prod_dir) 164 line = line.replace(PROD_DIR_ID, args.prod_dir)
180 LaunchBTCommand(line) 165 LaunchBTCommand(line)
181 166
167 # Was there any test failure?
168 if TEST_FAILURE:
169 # Obtain contents of Chromoting host logs.
170 log_contents = ''
171 # There should be only 1 log file, as we delete logs on test completion.
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.')
178
182 # Now, stop host, and cleanup user-profile-dir 179 # Now, stop host, and cleanup user-profile-dir
183 TestCleanUp(args.user_profile_dir) 180 TestCleanUp(args.user_profile_dir)
184 181
185 if __name__ == '__main__': 182 if __name__ == '__main__':
186 main() 183 main()
OLDNEW
« no previous file with comments | « testing/buildbot/chromium.fyi.json ('k') | testing/commit_queue/config.json » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698