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

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(
18 1, os.path.join(os.path.dirname(__file__), '..', '..', '..', 'telemetry',
19 'third_party', 'pyserial'))
20 try:
21 import serial
22 from serial.tools import list_ports
23 except:
nednguyen 2016/04/26 04:02:53 We can remove this now :-)
rnephew (Reviews Here) 2016/04/26 15:15:44 Done.
24 print
25 print '-----------------------'
26 print serial.__file__
27 print '======================='
28 raise
17 29
18 class BattorWrapper(object): 30 class BattorWrapper(object):
19 """A class for communicating with a BattOr in python.""" 31 """A class for communicating with a BattOr in python."""
20 _START_TRACING_CMD = 'StartTracing' 32 _START_TRACING_CMD = 'StartTracing'
21 _STOP_TRACING_CMD = 'StopTracing' 33 _STOP_TRACING_CMD = 'StopTracing'
22 _SUPPORTS_CLOCKSYNC_CMD = 'SupportsExplicitClockSync' 34 _SUPPORTS_CLOCKSYNC_CMD = 'SupportsExplicitClockSync'
23 _RECORD_CLOCKSYNC_CMD = 'RecordClockSyncMarker' 35 _RECORD_CLOCKSYNC_CMD = 'RecordClockSyncMarker'
24 _SUPPORTED_PLATFORMS = ['android', 'chromeos', 'linux', 'mac', 'win'] 36 _SUPPORTED_PLATFORMS = ['android', 'chromeos', 'linux', 'mac', 'win']
25 37
26 def __init__(self, target_platform, android_device=None, battor_path=None, 38 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.') 133 raise TypeError('sync_id must be a string.')
122 self._SendBattorCommand('%s %s' % (self._RECORD_CLOCKSYNC_CMD, sync_id)) 134 self._SendBattorCommand('%s %s' % (self._RECORD_CLOCKSYNC_CMD, sync_id))
123 135
124 def _GetBattorPath(self, target_platform, android_device=None, 136 def _GetBattorPath(self, target_platform, android_device=None,
125 battor_path=None, battor_map_file=None, battor_map=None): 137 battor_path=None, battor_map_file=None, battor_map=None):
126 """Determines most likely path to the correct BattOr.""" 138 """Determines most likely path to the correct BattOr."""
127 if target_platform not in self._SUPPORTED_PLATFORMS: 139 if target_platform not in self._SUPPORTED_PLATFORMS:
128 raise battor_error.BattorError( 140 raise battor_error.BattorError(
129 '%s is an unsupported platform.' % target_platform) 141 '%s is an unsupported platform.' % target_platform)
130 if target_platform in ['win']: 142 if target_platform in ['win']:
131 # TODO: We need a way to automatically detect correct port. 143 for (port, desc, _) in serial.tools.list_ports.comports():
charliea (OOO until 10-5) 2016/04/26 13:30:38 Later on, we should probably add a flag to the Bat
nednguyen 2016/04/26 15:10:57 There should be way for us to grab the "Battor 3.2
rnephew (Reviews Here) 2016/04/26 15:15:44 Acknowledged.
132 # crbug.com/60397 144 if 'USB Serial Port' in desc:
133 return 'COM3' 145 return port
146 raise battor_error.BattorError(
147 'Could not find BattOr attached to machine.')
134 device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap(fast=True) 148 device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap(fast=True)
135 if battor_path: 149 if battor_path:
136 if not isinstance(battor_path, basestring): 150 if not isinstance(battor_path, basestring):
137 raise battor_error.BattorError('An invalid BattOr path was specified.') 151 raise battor_error.BattorError('An invalid BattOr path was specified.')
138 return battor_path 152 return battor_path
139 153
140 if target_platform == 'android': 154 if target_platform == 'android':
141 if not android_device: 155 if not android_device:
142 raise battor_error.BattorError( 156 raise battor_error.BattorError(
143 'Must specify device for Android platform.') 157 'Must specify device for Android platform.')
(...skipping 24 matching lines...) Expand all
168 status = self._SendBattorCommandImpl(cmd, return_results=check_return) 182 status = self._SendBattorCommandImpl(cmd, return_results=check_return)
169 if check_return and not 'Done.' in status: 183 if check_return and not 'Done.' in status:
170 raise battor_error.BattorError( 184 raise battor_error.BattorError(
171 'BattOr did not complete command \'%s\' correctly.\n' 185 'BattOr did not complete command \'%s\' correctly.\n'
172 'Outputted: %s' % (cmd, status)) 186 'Outputted: %s' % (cmd, status))
173 return status 187 return status
174 188
175 def _StartShellImpl(self, battor_cmd): 189 def _StartShellImpl(self, battor_cmd):
176 return subprocess.Popen( 190 return subprocess.Popen(
177 battor_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=False) 191 battor_cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, shell=False)
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698