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

Side by Side Diff: tools/telemetry/telemetry/core/forwarders/android_forwarder.py

Issue 806843002: Reland of Migrate DeviceUtils.ReadFile to adb_wrapper (try 3) (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: enable command line test only for android Created 5 years, 11 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 2014 The Chromium Authors. All rights reserved. 1 # Copyright 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 import logging 5 import logging
6 import os 6 import os
7 import re 7 import re
8 import socket 8 import socket
9 import struct 9 import struct
10 import subprocess 10 import subprocess
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
224 if host_platform == 'linux': 224 if host_platform == 'linux':
225 return subprocess.check_output(['ip', 'addr']).splitlines() 225 return subprocess.check_output(['ip', 'addr']).splitlines()
226 if host_platform == 'mac': 226 if host_platform == 'mac':
227 return subprocess.check_output(['ifconfig']).splitlines() 227 return subprocess.check_output(['ifconfig']).splitlines()
228 raise NotImplementedError('Platform %s not supported!' % host_platform) 228 raise NotImplementedError('Platform %s not supported!' % host_platform)
229 229
230 def _FindHostRndisInterface(self): 230 def _FindHostRndisInterface(self):
231 """Returns the name of the host-side network interface.""" 231 """Returns the name of the host-side network interface."""
232 interface_list = self._EnumerateHostInterfaces() 232 interface_list = self._EnumerateHostInterfaces()
233 ether_address = self._device.ReadFile( 233 ether_address = self._device.ReadFile(
234 '%s/f_rndis/ethaddr' % self._RNDIS_DEVICE)[0] 234 '%s/f_rndis/ethaddr' % self._RNDIS_DEVICE).strip()
235 interface_name = None 235 interface_name = None
236 for line in interface_list: 236 for line in interface_list:
237 if not line.startswith((' ', '\t')): 237 if not line.startswith((' ', '\t')):
238 interface_name = line.split(':')[-2].strip() 238 interface_name = line.split(':')[-2].strip()
239 elif ether_address in line: 239 elif ether_address in line:
240 return interface_name 240 return interface_name
241 241
242 def _WriteProtectedFile(self, file_path, contents): 242 def _WriteProtectedFile(self, file_path, contents):
243 subprocess.check_call( 243 subprocess.check_call(
244 ['/usr/bin/sudo', 'bash', '-c', 244 ['/usr/bin/sudo', 'bash', '-c',
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
315 } 315 }
316 316
317 doit & 317 doit &
318 """ % {'dev': self._RNDIS_DEVICE, 'functions': 'rndis,adb', 318 """ % {'dev': self._RNDIS_DEVICE, 'functions': 'rndis,adb',
319 'prefix': script_prefix} 319 'prefix': script_prefix}
320 self._device.WriteFile('%s.sh' % script_prefix, script) 320 self._device.WriteFile('%s.sh' % script_prefix, script)
321 # TODO(szym): run via su -c if necessary. 321 # TODO(szym): run via su -c if necessary.
322 self._device.RunShellCommand('rm %s.log' % script_prefix) 322 self._device.RunShellCommand('rm %s.log' % script_prefix)
323 self._device.RunShellCommand('. %s.sh' % script_prefix) 323 self._device.RunShellCommand('. %s.sh' % script_prefix)
324 self._WaitForDevice() 324 self._WaitForDevice()
325 result = self._device.ReadFile('%s.log' % script_prefix) 325 result = self._device.ReadFile('%s.log' % script_prefix).splitlines()
326 assert any('DONE' in line for line in result), 'RNDIS script did not run!' 326 assert any('DONE' in line for line in result), 'RNDIS script did not run!'
327 327
328 def _CheckEnableRndis(self, force): 328 def _CheckEnableRndis(self, force):
329 """Enables the RNDIS network interface, retrying if necessary. 329 """Enables the RNDIS network interface, retrying if necessary.
330 Args: 330 Args:
331 force: Disable RNDIS first, even if it appears already enabled. 331 force: Disable RNDIS first, even if it appears already enabled.
332 Returns: 332 Returns:
333 device_iface: RNDIS interface name on the device 333 device_iface: RNDIS interface name on the device
334 host_iface: corresponding interface name on the host 334 host_iface: corresponding interface name on the host
335 """ 335 """
(...skipping 186 matching lines...) Expand 10 before | Expand all | Expand 10 after
522 device_iface, host_iface = self._CheckEnableRndis(force) 522 device_iface, host_iface = self._CheckEnableRndis(force)
523 self._ConfigureNetwork(device_iface, host_iface) 523 self._ConfigureNetwork(device_iface, host_iface)
524 self.OverrideRoutingPolicy() 524 self.OverrideRoutingPolicy()
525 # Sometimes the first packet will wake up the connection. 525 # Sometimes the first packet will wake up the connection.
526 for _ in range(3): 526 for _ in range(3):
527 if self._TestConnectivity(): 527 if self._TestConnectivity():
528 return 528 return
529 force = True 529 force = True
530 self.RestoreRoutingPolicy() 530 self.RestoreRoutingPolicy()
531 raise Exception('No connectivity, giving up.') 531 raise Exception('No connectivity, giving up.')
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698