diff options
Diffstat (limited to 'catapult/common/battor/battor')
4 files changed, 73 insertions, 52 deletions
diff --git a/catapult/common/battor/battor/battor_binary_dependencies.json b/catapult/common/battor/battor/battor_binary_dependencies.json index 58c203ec..23be1a30 100644 --- a/catapult/common/battor/battor/battor_binary_dependencies.json +++ b/catapult/common/battor/battor/battor_binary_dependencies.json @@ -5,35 +5,28 @@ "cloud_storage_base_folder": "binary_dependencies/battor", "cloud_storage_bucket": "chromium-telemetry", "file_info": { - "darwin_x86_64": { + "mac_x86_64": { "cloud_storage_hash": "6de6324c279ea75c79c68cab4c2ddcc68da1b286", "download_path": "../bin/darwin/x86_64/avrdude", "local_paths": [ "../bin/override/avrdude" ] }, - "linux2_x86_64": { + "linux_x86_64": { "cloud_storage_hash": "db29526605f6f95a75ab33f4060b8c330152de69", - "download_path": "../bin/linux2/x86_64/avrdude", + "download_path": "../bin/linux/x86_64/avrdude", "local_paths": [ "../bin/override/avrdude" ] }, - "win32_AMD64": { - "cloud_storage_hash": "517aa73b093e254007076cf5ac7afb94151df2ed", - "download_path": "../bin/win/x86_64/avrdude.exe", - "local_paths": [ - "../bin/override/avrdude.exe" - ] - }, - "win32_x86": { + "win_AMD64": { "cloud_storage_hash": "517aa73b093e254007076cf5ac7afb94151df2ed", "download_path": "../bin/win/x86_64/avrdude.exe", "local_paths": [ "../bin/override/avrdude.exe" ] }, - "win_AMD64": { + "win_x86": { "cloud_storage_hash": "517aa73b093e254007076cf5ac7afb94151df2ed", "download_path": "../bin/win/x86_64/avrdude.exe", "local_paths": [ @@ -59,37 +52,30 @@ "cloud_storage_base_folder": "binary_dependencies/battor", "cloud_storage_bucket": "chromium-telemetry", "file_info": { - "darwin_x86_64": { - "cloud_storage_hash": "276b3507a1c617c01734d85a2133ed200f2a477b", + "mac_x86_64": { + "cloud_storage_hash": "154613804a1855a4871422bf99aa8e0dd0d7f62e", "download_path": "../bin/darwin/x86_64/battor_agent", "local_paths": [ "../bin/override/battor_agent" ] }, - "linux2_x86_64": { - "cloud_storage_hash": "582cfe85971ca84aa75cf078bafb737d0cbdfb31", - "download_path": "../bin/linux2/x86_64/battor_agent", + "linux_x86_64": { + "cloud_storage_hash": "f53e15b97301e9dab00e893800ec67a98e9f13ea", + "download_path": "../bin/linux/x86_64/battor_agent", "local_paths": [ "../bin/override/battor_agent" ] }, - "win32_AMD64": { - "cloud_storage_hash": "609c5f79a03b347ddbfd6e544d229a56851c0f66", - "download_path": "../bin/win/AMD64/battor_agent.exe", - "local_paths": [ - "../bin/override/battor_agent.exe" - ] - }, - "win32_x86": { - "cloud_storage_hash": "609c5f79a03b347ddbfd6e544d229a56851c0f66", + "win_AMD64": { + "cloud_storage_hash": "4095a9159dd189ec591679e43b14d34ae30335eb", "download_path": "../bin/win/x86_64/battor_agent.exe", "local_paths": [ "../bin/override/battor_agent.exe" ] }, - "win_AMD64": { - "cloud_storage_hash": "609c5f79a03b347ddbfd6e544d229a56851c0f66", - "download_path": "../bin/win/AMD64/battor_agent.exe", + "win_x86": { + "cloud_storage_hash": "4095a9159dd189ec591679e43b14d34ae30335eb", + "download_path": "../bin/win/x86_64/battor_agent.exe", "local_paths": [ "../bin/override/battor_agent.exe" ] @@ -101,12 +87,12 @@ "cloud_storage_bucket": "chromium-telemetry", "file_info": { "default": { - "cloud_storage_hash": "da987f879c341bf2f928dc0f65cc6477c2d32bbc", + "cloud_storage_hash": "0649655f78698368a16a4e9ec37967b80528fdbf", "download_path": "../bin/battor/battor_firmware.hex", "local_paths": [ "../bin/override/battor_firmware.hex" ], - "version_in_cs": "3c3ce4d" + "version_in_cs": "de05458" } } } diff --git a/catapult/common/battor/battor/battor_wrapper.py b/catapult/common/battor/battor/battor_wrapper.py index 6947f837..93aed8b0 100644 --- a/catapult/common/battor/battor/battor_wrapper.py +++ b/catapult/common/battor/battor/battor_wrapper.py @@ -2,7 +2,6 @@ # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. -import atexit import datetime import os import logging @@ -15,6 +14,7 @@ import time from battor import battor_error import py_utils +from py_utils import atexit_with_log from py_utils import cloud_storage import dependency_manager from devil.utils import battor_device_mapping @@ -27,7 +27,20 @@ from serial.tools import list_ports DEFAULT_SHELL_CLOSE_TIMEOUT_S = 60 -def IsBattOrConnected(test_platform, android_device=None, +def IsBattOrConnected(*args, **kwargs): + """Returns True if BattOr is detected. + + See _IsBattOrConnected below for arguments. + """ + is_connected = _IsBattOrConnected(*args, **kwargs) + if is_connected: + logging.info('BattOr power monitor is connected.') + else: + logging.info('BattOr power monitor is not connected.') + return is_connected + + +def _IsBattOrConnected(test_platform, android_device=None, android_device_map=None, android_device_file=None): """Returns True if BattOr is detected.""" if test_platform == 'android': @@ -38,11 +51,8 @@ def IsBattOrConnected(test_platform, android_device=None, if not android_device_map: device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap() if device_tree: - logging.warning('Device tree:') for _, node in sorted(device_tree.iteritems()): node.Display() - else: - logging.warning('Empty device tree.') if len(battor_device_mapping.GetBattOrList(device_tree)) == 1: return True if android_device_file: @@ -51,9 +61,7 @@ def IsBattOrConnected(test_platform, android_device=None, else: try: android_device_map = battor_device_mapping.GenerateSerialMap() - logging.warning('Android device map: %s', android_device_map) except battor_error.BattOrError: - logging.exception('Error generating serial map') return False # If neither if statement above is triggered, it means that an @@ -129,7 +137,8 @@ class BattOrWrapper(object): self._dm = dependency_manager.DependencyManager( [dependency_manager.BaseConfig(config)]) self._battor_agent_binary = self._dm.FetchPath( - 'battor_agent_binary', '%s_%s' % (sys.platform, platform.machine())) + 'battor_agent_binary', + '%s_%s' % (py_utils.GetHostOsName(), py_utils.GetHostArchName())) self._autoflash = autoflash self._serial_log_bucket = serial_log_bucket @@ -143,7 +152,7 @@ class BattOrWrapper(object): self._target_platform = target_platform self._git_hash = None - atexit.register(self.KillBattOrShell) + atexit_with_log.Register(self.KillBattOrShell) def _FlashBattOr(self): assert self._battor_shell, ( @@ -164,6 +173,7 @@ class BattOrWrapper(object): except ValueError: logging.exception('Git hash returned from BattOr was not as expected: %s' % self._git_hash) + self.StopShell() finally: if not self._battor_shell: @@ -208,10 +218,11 @@ class BattOrWrapper(object): assert not self._tracing, 'Attempting to stop a BattOr shell while tracing.' timeout = timeout if timeout else DEFAULT_SHELL_CLOSE_TIMEOUT_S - self._SendBattOrCommand(self._EXIT_CMD, check_return=False) try: + self._SendBattOrCommand(self._EXIT_CMD, check_return=False) py_utils.WaitFor(lambda: self.GetShellReturnCode() != None, timeout) - except py_utils.TimeoutException: + except: + # If graceful shutdown failed, resort to a simple kill command. self.KillBattOrShell() finally: self._battor_shell = None @@ -233,8 +244,7 @@ class BattOrWrapper(object): self._trace_results_path = temp_file.name temp_file.close() self._SendBattOrCommand( - '%s %s' % (self._STOP_TRACING_CMD, self._trace_results_path), - check_return=False) + '%s %s' % (self._STOP_TRACING_CMD, self._trace_results_path)) self._tracing = False self._stop_tracing_time = int(time.time()) @@ -245,6 +255,12 @@ class BattOrWrapper(object): seconds. Returns: Trace data in form of a list. """ + if not self._stop_tracing_time or not self._start_tracing_time: + raise battor_error.BattOrError( + 'No start or stop time detected when collecting BattOr trace.\n' + 'Start: %s \n Stop: %s' % (self._start_tracing_time, + self._stop_tracing_time)) + # The BattOr shell terminates after returning the results. if timeout is None: timeout = self._stop_tracing_time - self._start_tracing_time @@ -295,7 +311,6 @@ class BattOrWrapper(object): return port if target_platform in ['android', 'linux']: - device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap(fast=True) if battor_path: if not isinstance(battor_path, basestring): raise battor_error.BattOrError( @@ -315,6 +330,7 @@ class BattOrWrapper(object): serial_map=battor_map) # Not Android and no explicitly passed BattOr. + device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap(fast=True) battors = battor_device_mapping.GetBattOrList(device_tree) if len(battors) != 1: raise battor_error.BattOrError( diff --git a/catapult/common/battor/battor/battor_wrapper_devicetest.py b/catapult/common/battor/battor/battor_wrapper_devicetest.py index 4ca59a79..29c36e7e 100644 --- a/catapult/common/battor/battor/battor_wrapper_devicetest.py +++ b/catapult/common/battor/battor/battor_wrapper_devicetest.py @@ -16,6 +16,7 @@ if __name__ == '__main__': from battor import battor_wrapper from devil.utils import battor_device_mapping from devil.utils import find_usb_devices +import py_utils from py_utils import cloud_storage @@ -23,16 +24,12 @@ _SUPPORTED_CQ_PLATFORMS = ['win', 'linux', 'mac'] class BattOrWrapperDeviceTest(unittest.TestCase): def setUp(self): - test_platform = platform.system() + self._platform = py_utils.GetHostOsName() self._battor_list = None - if 'Win' in test_platform: - self._platform = 'win' - elif 'Linux' in test_platform: - self._platform = 'linux' + + if self._platform == 'linux': device_tree = find_usb_devices.GetBusNumberToDeviceTreeMap() self._battor_list = battor_device_mapping.GetBattOrList(device_tree) - elif 'Darwin' in test_platform: - self._platform = 'mac' if not battor_wrapper.IsBattOrConnected(self._platform): self._battor_list = [] diff --git a/catapult/common/battor/battor/battor_wrapper_unittest.py b/catapult/common/battor/battor/battor_wrapper_unittest.py index 3e48a336..7e14c349 100644 --- a/catapult/common/battor/battor/battor_wrapper_unittest.py +++ b/catapult/common/battor/battor/battor_wrapper_unittest.py @@ -359,6 +359,28 @@ class BattOrWrapperTest(unittest.TestCase): dependency_manager.DependencyManager._version_return = 'cbaa843' self.assertTrue(self._battor._FlashBattOr()) + def testCollectTraceDataNoStartTime(self): + self._battor = battor_wrapper.BattOrWrapper('linux') + self._DefaultBattOrReplacements() + self._battor.StartShell() + self._battor.StartTracing() + self._battor.GetShellReturnCode = lambda *unused: 0 + self._battor.StopTracing() + self._battor._start_tracing_time = None + with self.assertRaises(battor_error.BattOrError): + self._battor.CollectTraceData() + + def testCollectTraceDataNoStopTime(self): + self._battor = battor_wrapper.BattOrWrapper('linux') + self._DefaultBattOrReplacements() + self._battor.StartShell() + self._battor.StartTracing() + self._battor.GetShellReturnCode = lambda *unused: 0 + self._battor.StopTracing() + self._battor._stop_tracing_time = None + with self.assertRaises(battor_error.BattOrError): + self._battor.CollectTraceData() + if __name__ == '__main__': logging.getLogger().setLevel(logging.DEBUG) |