OLD | NEW |
1 # Copyright 2017 The Chromium Authors. All rights reserved. | 1 # Copyright 2017 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 """Start and stop Web Page Replay.""" | 5 """Start and stop Web Page Replay.""" |
6 | 6 |
7 from py_utils import atexit_with_log | 7 from py_utils import atexit_with_log |
8 import logging | 8 import logging |
9 import os | 9 import os |
10 import re | 10 import re |
11 import signal | 11 import signal |
12 import subprocess | 12 import subprocess |
13 import sys | 13 import sys |
14 import tempfile | 14 import tempfile |
15 import urllib | 15 import urllib |
16 | 16 |
17 from telemetry.core import util | 17 from telemetry.core import util |
18 from telemetry.internal import forwarders | 18 from telemetry.internal import forwarders |
19 from telemetry.internal.util import binary_manager | 19 from telemetry.internal.util import binary_manager |
20 | 20 |
21 import py_utils | 21 import py_utils |
22 | 22 |
| 23 |
23 _WPR_DIR = os.path.abspath(os.path.join( | 24 _WPR_DIR = os.path.abspath(os.path.join( |
24 util.GetCatapultDir(), 'web_page_replay_go')) | 25 util.GetCatapultDir(), 'web_page_replay_go')) |
| 26 _WPR_KEY_FILE = os.path.join(_WPR_DIR, 'wpr_key.pem') |
| 27 _WPR_CERT_FILE = os.path.join(_WPR_DIR, 'wpr_cert.pem') |
| 28 |
25 | 29 |
26 class ReplayError(Exception): | 30 class ReplayError(Exception): |
27 """Catch-all exception for the module.""" | 31 """Catch-all exception for the module.""" |
28 pass | 32 pass |
29 | 33 |
30 | 34 |
31 class ReplayNotFoundError(ReplayError): | 35 class ReplayNotFoundError(ReplayError): |
32 def __init__(self, label, path): | 36 def __init__(self, label, path): |
33 super(ReplayNotFoundError, self).__init__() | 37 super(ReplayNotFoundError, self).__init__() |
34 self.args = (label, path) | 38 self.args = (label, path) |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
111 assert ((android_device_id is None and adb_path is None) or | 115 assert ((android_device_id is None and adb_path is None) or |
112 (android_device_id is not None and adb_path is not None)), ( | 116 (android_device_id is not None and adb_path is not None)), ( |
113 'android_device_id and adb_path must be both specified or ' | 117 'android_device_id and adb_path must be both specified or ' |
114 'not specified') | 118 'not specified') |
115 go_binary_path = cls._GetGoBinaryPath() | 119 go_binary_path = cls._GetGoBinaryPath() |
116 if android_device_id is None: | 120 if android_device_id is None: |
117 subprocess.check_call([go_binary_path, 'installroot']) | 121 subprocess.check_call([go_binary_path, 'installroot']) |
118 else: | 122 else: |
119 subprocess.check_call( | 123 subprocess.check_call( |
120 [go_binary_path, 'installroot', | 124 [go_binary_path, 'installroot', |
| 125 '--https_cert_file=%s' % _WPR_CERT_FILE, |
| 126 '--https_key_file=%s' % _WPR_KEY_FILE, |
121 '--android_device_id=%s' % android_device_id, | 127 '--android_device_id=%s' % android_device_id, |
122 '--adb_binary_path=%s' % adb_path]) | 128 '--adb_binary_path=%s' % adb_path]) |
123 | 129 |
124 @classmethod | 130 @classmethod |
125 def RemoveRootCertificate(cls, android_device_id=None, adb_path=None): | 131 def RemoveRootCertificate(cls, android_device_id=None, adb_path=None): |
126 """Remove installed root certificate on the host machine or on remote | 132 """Remove installed root certificate on the host machine or on remote |
127 Android device. | 133 Android device. |
128 | 134 |
129 Args: | 135 Args: |
130 android_device_id: a string id of the Android device. | 136 android_device_id: a string id of the Android device. |
131 adb_path: path to adb binary to use for issuing commands to the device. | 137 adb_path: path to adb binary to use for issuing commands to the device. |
132 This is specified iff android_device_id is specified. | 138 This is specified iff android_device_id is specified. |
133 """ | 139 """ |
134 assert ((android_device_id is None and adb_path is None) or | 140 assert ((android_device_id is None and adb_path is None) or |
135 (android_device_id is not None and adb_path is not None)), ( | 141 (android_device_id is not None and adb_path is not None)), ( |
136 'android_device_id and adb_path must be both specified or ' | 142 'android_device_id and adb_path must be both specified or ' |
137 'not specified') | 143 'not specified') |
138 go_binary_path = cls._GetGoBinaryPath() | 144 go_binary_path = cls._GetGoBinaryPath() |
139 if android_device_id is None: | 145 if android_device_id is None: |
140 subprocess.check_call([go_binary_path, 'removeroot']) | 146 subprocess.check_call([go_binary_path, 'removeroot']) |
141 else: | 147 else: |
142 subprocess.check_call( | 148 subprocess.check_call( |
143 [go_binary_path, 'removeroot', | 149 [go_binary_path, 'removeroot', |
| 150 '--https_cert_file=%s' % _WPR_CERT_FILE, |
| 151 '--https_key_file=%s' % _WPR_KEY_FILE, |
144 '--android_device_id=%s' % android_device_id, | 152 '--android_device_id=%s' % android_device_id, |
145 '--adb_binary_path=%s' % adb_path]) | 153 '--adb_binary_path=%s' % adb_path]) |
146 | 154 |
147 @property | 155 @property |
148 def http_port(self): | 156 def http_port(self): |
149 if not self._IsStarted(): | 157 if not self._IsStarted(): |
150 return None | 158 return None |
151 return self._started_ports['http'] | 159 return self._started_ports['http'] |
152 | 160 |
153 @property | 161 @property |
154 def https_port(self): | 162 def https_port(self): |
155 if not self._IsStarted(): | 163 if not self._IsStarted(): |
156 return None | 164 return None |
157 return self._started_ports['https'] | 165 return self._started_ports['https'] |
158 | 166 |
159 @staticmethod | 167 @staticmethod |
160 def _GetCommandLine(go_binary_path, http_port, https_port, | 168 def _GetCommandLine(go_binary_path, http_port, https_port, |
161 replay_options, archive_path): | 169 replay_options, archive_path): |
162 """Set WPR command-line options. Can be overridden if needed.""" | 170 """Set WPR command-line options. Can be overridden if needed.""" |
163 for option in replay_options: | 171 for option in replay_options: |
164 if option not in ['--record', '--replay', '--inject_scripts=']: | 172 if option not in ['--record', '--replay', '--inject_scripts=']: |
165 raise ValueError("Invalid replay options %s" % replay_options) | 173 raise ValueError("Invalid replay options %s" % replay_options) |
166 cmd_line = [go_binary_path] | 174 cmd_line = [go_binary_path] |
167 if '--record' in replay_options: | 175 if '--record' in replay_options: |
168 cmd_line.append('record') | 176 cmd_line.append('record') |
169 else: | 177 else: |
170 cmd_line.append('replay') | 178 cmd_line.append('replay') |
171 key_file = os.path.join(_WPR_DIR, 'wpr_key.pem') | |
172 cert_file = os.path.join(_WPR_DIR, 'wpr_cert.pem') | |
173 inject_script = os.path.join(_WPR_DIR, 'deterministic.js') | 179 inject_script = os.path.join(_WPR_DIR, 'deterministic.js') |
174 cmd_line.extend([ | 180 cmd_line.extend([ |
175 '--http_port=%s' % http_port, | 181 '--http_port=%s' % http_port, |
176 '--https_port=%s' % https_port, | 182 '--https_port=%s' % https_port, |
177 '--https_key_file=%s' % key_file, | 183 '--https_key_file=%s' % _WPR_KEY_FILE, |
178 '--https_cert_file=%s' % cert_file]) | 184 '--https_cert_file=%s' % _WPR_CERT_FILE]) |
179 if '--inject_scripts=' in replay_options: | 185 if '--inject_scripts=' in replay_options: |
180 cmd_line.append('--inject_scripts=') | 186 cmd_line.append('--inject_scripts=') |
181 else: | 187 else: |
182 cmd_line.append('--inject_scripts=%s' % inject_script) | 188 cmd_line.append('--inject_scripts=%s' % inject_script) |
183 cmd_line.append(archive_path) | 189 cmd_line.append(archive_path) |
184 return cmd_line | 190 return cmd_line |
185 | 191 |
186 def _CheckPath(self, label, path): | 192 def _CheckPath(self, label, path): |
187 if not os.path.exists(path): | 193 if not os.path.exists(path): |
188 raise ReplayNotFoundError(label, path) | 194 raise ReplayNotFoundError(label, path) |
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
382 On posix system, running this function before starting replay fixes a | 388 On posix system, running this function before starting replay fixes a |
383 bug that shows up when Telemetry is run as a background command from a | 389 bug that shows up when Telemetry is run as a background command from a |
384 script. https://crbug.com/254572. | 390 script. https://crbug.com/254572. |
385 | 391 |
386 Background: Signal masks on Linux are inherited from parent | 392 Background: Signal masks on Linux are inherited from parent |
387 processes. If anything invoking us accidentally masks SIGINT | 393 processes. If anything invoking us accidentally masks SIGINT |
388 (e.g. by putting a process in the background from a shell script), | 394 (e.g. by putting a process in the background from a shell script), |
389 sending a SIGINT to the child will fail to terminate it. | 395 sending a SIGINT to the child will fail to terminate it. |
390 """ | 396 """ |
391 signal.signal(signal.SIGINT, signal.SIG_DFL) | 397 signal.signal(signal.SIGINT, signal.SIG_DFL) |
OLD | NEW |