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

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

Issue 761903003: Update from https://crrev.com/306655 (Closed) Base URL: git@github.com:domokit/mojo.git@master
Patch Set: Created 6 years 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 hashlib
9 import os
10 from os.path import expanduser
11 import shutil
12 import socket
8 import subprocess 13 import subprocess
9 14
10 PROD_DIR_ID = '$(PROD_DIR)' 15 BROWSER_TEST_ID = 'browser_tests'
16 PROD_DIR_ID = '#PROD_DIR#'
17 HOST_HASH_VALUE = hashlib.md5(socket.gethostname()).hexdigest()
18 SUCCESS_INDICATOR = 'SUCCESS: all tests passed.'
19 NATIVE_MESSAGING_DIR = 'NativeMessagingHosts'
20 CRD_ID = 'chrome-remote-desktop' # Used in a few file/folder names
11 21
12 22
13 def LaunchCommand(command): 23 def LaunchCommand(command):
14
15 cmd_line = [command] 24 cmd_line = [command]
16 try: 25 try:
17 p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, shell=True) 26 p = subprocess.Popen(cmd_line, stdout=subprocess.PIPE, shell=True)
18 results, err = p.communicate() 27 results, err = p.communicate()
19 if 'SUCCESS: all tests passed.' not in results: 28 # Check that the test passed.
20 raise Exception('Test failed\n%s\n%s' % (results, err)) 29 if SUCCESS_INDICATOR not in results:
30 raise Exception(
31 'Test failed. Command:%s\nResults:%s\nError:%s\n' %
32 (command, results, err))
21 except subprocess.CalledProcessError, e: 33 except subprocess.CalledProcessError, e:
22 raise Exception('Exception %s running command %s' % (e, command)) 34 raise Exception('Exception %s running command %s' % (e, command))
23 else: 35 else:
24 print results 36 print results
25 37
26 38
39 def InitialiseTestMachineForLinux(cfg_file, manifest_file, user_profile_dir):
40 """Sets up a Linux machine for connect-to-host browser-tests.
41
42 Copy over me2me host-config and manifest files to expected locations.
43 By default, the Linux me2me host expects the host-config file to be under
44 $HOME/.config/chrome-remote-desktop
45 Its name is expected to have a hash that is specific to a machine.
46
47 When a user launches the remoting web-app, the native-message host process is
48 started. For this to work, the manifest file for me2me host is expected to be
49 in a specific folder under the user-profile dir.
50
51 This function performs both the above tasks.
52
53 TODO(anandc):
54 Once we have Linux machines in the swarming lab already installed with the
55 me2me host, this function should also perform the step of starting the host.
56 That is gated on this CL: https://chromereviews.googleplex.com/123957013/, and
57 then having base images in the chrome-labs be updated with it.
58
59 Args:
60 cfg_file: location of test account's host-config file.
61 manifest_file: location of me2me host manifest file.
62 user_profile_dir: user-profile-dir to be used by the connect-to-host tests.
63 """
64
65 # First get home directory on current machine.
66 home_dir = expanduser('~')
67 default_config_file_location = os.path.join(home_dir, '.config', CRD_ID)
68 if os.path.exists(default_config_file_location):
69 shutil.rmtree(default_config_file_location)
70 os.makedirs(default_config_file_location)
71
72 # Copy over test host-config to expected location, with expected file-name.
73 # The file-name should contain a hash-value that is machine-specific.
74 default_config_file_name = 'host#%s.json' % HOST_HASH_VALUE
75 config_file_src = os.path.join(os.getcwd(), cfg_file)
76 shutil.copyfile(
77 config_file_src,
78 os.path.join(default_config_file_location, default_config_file_name))
79
80 # Next, create a user-profile dir, and place the me2me manifest.json file in
81 # the expected location for native-messating-host to work properly.
82 native_messaging_folder = os.path.join(user_profile_dir, NATIVE_MESSAGING_DIR)
83
84 if os.path.exists(native_messaging_folder):
85 shutil.rmtree(native_messaging_folder)
86 os.makedirs(native_messaging_folder)
87
88 manifest_file_src = os.path.join(os.getcwd(), manifest_file)
89 manifest_file_dest = (
90 os.path.join(native_messaging_folder, os.path.basename(manifest_file)))
91 shutil.copyfile(manifest_file_src, manifest_file_dest)
92
93
27 def main(): 94 def main():
28
29 parser = argparse.ArgumentParser() 95 parser = argparse.ArgumentParser()
30 parser.add_argument('-f', '--file', 96 parser.add_argument('-f', '--commands_file',
31 help='path to file listing commands to be launched.') 97 help='path to file listing commands to be launched.')
32 parser.add_argument('-p', '--prod_dir', 98 parser.add_argument('-p', '--prod_dir',
33 help='path to folder having product and test binaries.') 99 help='path to folder having product and test binaries.')
100 parser.add_argument('-c', '--cfg_file',
101 help='path to test host config file.')
102 parser.add_argument('-m', '--manifest_file',
103 help='path to me2me host manifest file.')
104 parser.add_argument(
105 '-u', '--user_profile_dir',
106 help='path to user-profile-dir, used by connect-to-host tests.')
34 107
35 args = parser.parse_args() 108 args = parser.parse_args()
36 109
37 with open(args.file) as f: 110 InitialiseTestMachineForLinux(args.cfg_file, args.manifest_file,
111 args.user_profile_dir)
112
113 with open(args.commands_file) as f:
38 for line in f: 114 for line in f:
39 # Replace the PROD_DIR value in the command-line with 115 # Replace the PROD_DIR value in the command-line with
40 # the passed in value. 116 # the passed in value.
41 line = line.replace(PROD_DIR_ID, args.prod_dir) 117 line = line.replace(PROD_DIR_ID, args.prod_dir)
42 LaunchCommand(line) 118 LaunchCommand(line)
43 119
44 if __name__ == '__main__': 120 if __name__ == '__main__':
45 main() 121 main()
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