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

Side by Side Diff: common/battor/battor/battor_wrapper.py

Issue 1920023002: [BattOr] Add real device smoke test (Closed) Base URL: git@github.com:catapult-project/catapult@master
Patch Set: Created 4 years, 7 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 2016 The Chromium Authors. All rights reserved. 1 # Copyright 2016 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 os 5 import os
6 import platform 6 import platform
7 import subprocess 7 import subprocess
8 import sys 8 import sys
9 import tempfile 9 import tempfile
10 import time 10 import time
11 11
12 from battor import battor_error 12 from battor import battor_error
13 import dependency_manager 13 import dependency_manager
14 from devil.utils import battor_device_mapping 14 from devil.utils import battor_device_mapping
15 from devil.utils import find_usb_devices 15 from devil.utils import find_usb_devices
16 16
17 sys.path.insert(
charliea (OOO until 10-5) 2016/04/29 15:11:07 I think that this should be added here: https://c
rnephew (Reviews Here) 2016/04/29 17:05:57 Will that work, this being part of common? Or do y
charliea (OOO until 10-5) 2016/04/29 17:18:17 Uhhh... sure, let's pretend like I was smart enoug
18 1, os.path.join(os.path.dirname(__file__), '..', '..', '..', 'telemetry',
19 'third_party', 'pyserial'))
20 import serial
21 from serial.tools import list_ports
17 22
18 class BattorWrapper(object): 23 class BattorWrapper(object):
19 """A class for communicating with a BattOr in python.""" 24 """A class for communicating with a BattOr in python."""
20 _START_TRACING_CMD = 'StartTracing' 25 _START_TRACING_CMD = 'StartTracing'
21 _STOP_TRACING_CMD = 'StopTracing' 26 _STOP_TRACING_CMD = 'StopTracing'
22 _SUPPORTS_CLOCKSYNC_CMD = 'SupportsExplicitClockSync' 27 _SUPPORTS_CLOCKSYNC_CMD = 'SupportsExplicitClockSync'
23 _RECORD_CLOCKSYNC_CMD = 'RecordClockSyncMarker' 28 _RECORD_CLOCKSYNC_CMD = 'RecordClockSyncMarker'
24 _SUPPORTED_PLATFORMS = ['android', 'chromeos', 'linux', 'mac', 'win'] 29 _SUPPORTED_PLATFORMS = ['android', 'chromeos', 'linux', 'mac', 'win']
25 30
26 def __init__(self, target_platform, android_device=None, battor_path=None, 31 def __init__(self, target_platform, android_device=None, battor_path=None,
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 raise TypeError('sync_id must be a string.') 126 raise TypeError('sync_id must be a string.')
122 self._SendBattorCommand('%s %s' % (self._RECORD_CLOCKSYNC_CMD, sync_id)) 127 self._SendBattorCommand('%s %s' % (self._RECORD_CLOCKSYNC_CMD, sync_id))
123 128
124 def _GetBattorPath(self, target_platform, android_device=None, 129 def _GetBattorPath(self, target_platform, android_device=None,
125 battor_path=None, battor_map_file=None, battor_map=None): 130 battor_path=None, battor_map_file=None, battor_map=None):
126 """Determines most likely path to the correct BattOr.""" 131 """Determines most likely path to the correct BattOr."""
127 if target_platform not in self._SUPPORTED_PLATFORMS: 132 if target_platform not in self._SUPPORTED_PLATFORMS:
128 raise battor_error.BattorError( 133 raise battor_error.BattorError(
129 '%s is an unsupported platform.' % target_platform) 134 '%s is an unsupported platform.' % target_platform)
130 if target_platform in ['win']: 135 if target_platform in ['win']:
131 # TODO: We need a way to automatically detect correct port. 136 for (port, desc, _) in serial.tools.list_ports.comports():
132 # crbug.com/60397 137 if 'USB Serial Port' in desc:
charliea (OOO until 10-5) 2016/04/29 15:11:07 Can you add a comment describing why this is neces
rnephew (Reviews Here) 2016/04/29 17:05:57 Done.
133 return 'COM3' 138 return port
139 raise battor_error.BattorError(
140 'Could not find BattOr attached to machine.')
134 device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap(fast=True) 141 device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap(fast=True)
135 if battor_path: 142 if battor_path:
136 if not isinstance(battor_path, basestring): 143 if not isinstance(battor_path, basestring):
137 raise battor_error.BattorError('An invalid BattOr path was specified.') 144 raise battor_error.BattorError('An invalid BattOr path was specified.')
138 return battor_path 145 return battor_path
139 146
140 if target_platform == 'android': 147 if target_platform == 'android':
141 if not android_device: 148 if not android_device:
142 raise battor_error.BattorError( 149 raise battor_error.BattorError(
143 'Must specify device for Android platform.') 150 'Must specify device for Android platform.')
(...skipping 24 matching lines...) Expand all
168 status = self._SendBattorCommandImpl(cmd, return_results=check_return) 175 status = self._SendBattorCommandImpl(cmd, return_results=check_return)
169 if check_return and not 'Done.' in status: 176 if check_return and not 'Done.' in status:
170 raise battor_error.BattorError( 177 raise battor_error.BattorError(
171 'BattOr did not complete command \'%s\' correctly.\n' 178 'BattOr did not complete command \'%s\' correctly.\n'
172 'Outputted: %s' % (cmd, status)) 179 'Outputted: %s' % (cmd, status))
173 return status 180 return status
174 181
175 def _StartShellImpl(self, battor_cmd): 182 def _StartShellImpl(self, battor_cmd):
176 return subprocess.Popen( 183 return subprocess.Popen(
177 battor_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=False) 184 battor_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=False)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698