def testFlashBattOrDifferentGitHash(self): self._battor = battor_wrapper.BattOrWrapper('linux') self._DefaultBattOrReplacements() self._battor.StartShell() self._battor.GetFirmwareGitHash = lambda: 'bazz732' dependency_manager.DependencyManager._version_return = 'cbaa843' self.assertTrue(self._battor._FlashBattOr())
def testGetFirmwareGitHashPass(self): self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() self._battor.StartShell() self._battor.GetFirmwareGitHash = lambda: 'cbaa843' self.assertTrue( isinstance(self._battor.GetFirmwareGitHash(), basestring))
def StartAgentTracing(self, config, timeout=None): """Starts tracing. Args: config: Tracing config. Raises: RuntimeError: If trace already in progress. """ if config.update_map or not path.isfile(config.serial_map): battor_device_mapping.GenerateSerialMapFile( config.serial_map, config.hub_types) self._battor_wrapper = battor_wrapper.BattOrWrapper( target_platform=config.target, android_device=config.device_serial_number, battor_path=config.battor_path, battor_map_file=config.serial_map) dev_utils = device_utils.DeviceUtils(config.device_serial_number) self._battery_utils = battery_utils.BatteryUtils(dev_utils) self._battery_utils.SetCharging(False) atexit.register(_reenable_charging_if_needed, self._battery_utils) self._battor_wrapper.StartShell() self._battor_wrapper.StartTracing() return True
def testStartTracingDoubleStart(self): self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() self._battor.StartShell() self._battor.StartTracing() with self.assertRaises(AssertionError): self._battor.StartTracing()
def testStartTracingCommandFails(self): self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() self._battor._SendBattOrCommandImpl = lambda *unused: 'Fail.\n' self._battor.StartShell() with self.assertRaises(battor_error.BattOrError): self._battor.StartTracing()
def StartAgentTracing(self, config, timeout=None): """Starts tracing. Args: config: Tracing config. Raises: RuntimeError: If trace already in progress. AssertionError: If There is no BattOr path given and more than one BattOr is attached. """ battor_path = self._FindBattOrPath(config) self._battor_wrapper = battor_wrapper.BattOrWrapper( target_platform=config.target, android_device=config.device_serial_number, battor_path=battor_path, battor_map_file=config.serial_map) dev_utils = device_utils.DeviceUtils(config.device_serial_number) self._battery_utils = battery_utils.BatteryUtils(dev_utils) self._battery_utils.SetCharging(False) atexit.register(_reenable_charging_if_needed, self._battery_utils) self._battor_wrapper.StartShell() self._battor_wrapper.StartTracing() return True
def testStopShellPass(self): self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() self._battor.StartShell() self._fake_return_code = 0 self._battor.StopShell() self.assertIsNone(self._battor._battor_shell)
def testFlashFirmwareShellRunning(self): self._battor = battor_wrapper.BattOrWrapper('linux') self._DefaultBattOrReplacements() self._battor.FlashFirmware('hex_path', 'config_path') self._battor.StartShell() with self.assertRaises(AssertionError): self._battor.FlashFirmware('hex_path', 'config_path')
def testInitAndroidWithoutBattOr(self): self._battor_list = [] self._fake_map = {} battor_device_mapping.GetBattOrPathFromPhoneSerial = ( self._get_battor_path_from_phone_serial) with self.assertRaises(battor_error.BattOrError): self._battor = battor_wrapper.BattOrWrapper('android', android_device='abc')
def testStopTracingPass(self): self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() self._battor.StartShell() self._battor.StartTracing() self._battor.GetShellReturnCode = lambda *unused: 0 self._battor.StopTracing() self.assertFalse(self._battor._tracing)
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()
def __init__(self, platform_backend): super(BattOrTracingAgent, self).__init__(platform_backend) self._platform_backend = platform_backend android_device = (platform_backend.device if platform_backend.GetOSName() == 'android' else None) self._battery = (battery_utils.BatteryUtils(platform_backend.device) if platform_backend.GetOSName() == 'android' else None) self._battor = battor_wrapper.BattOrWrapper( platform_backend.GetOSName(), android_device=android_device, serial_log_bucket=cloud_storage.TELEMETRY_OUTPUT)
def testFullRun(self): # If battor_list is an empty list, a BattOr was expected but not found. if self._battor_list is not None and not self._battor_list: logging.critical('No BattOrs attached. Cannot run tests.') return if self._platform not in _SUPPORTED_CQ_PLATFORMS: logging.critical('Platform %s is not supported on CQ.' % self._platform) return battor_path = (None if not self._battor_list else '/dev/%s' % self._battor_list[0]) battor = battor_wrapper.BattOrWrapper(self._platform, battor_path=battor_path) try: battor.StartShell() battor.StartTracing() # TODO(rnephew): This sleep is required for now because crbug.com/602266 # causes the BattOr to crash when the trace time is too short. Once that # bug is fixed, we should remove this delay. time.sleep(1) battor.RecordClockSyncMarker('abc') # Sleep here because clock sync marker will be flaky if not. time.sleep(1) battor.StopTracing() # Below is a work around for crbug.com/603309. On this short of a trace, 5 # seconds is enough to ensure that the trace will finish flushing to the # file. The process is then killed so that BattOrWrapper knows that the # process has been closed after tracing stops. if self._platform == 'win': time.sleep(5) battor._battor_shell.kill() results = battor.CollectTraceData().splitlines() except: if battor._battor_shell is not None: battor._battor_shell.kill() battor._battor_shell = None raise self.assertTrue('# BattOr' in results[0]) self.assertTrue('# voltage_range' in results[1]) self.assertTrue('# current_range' in results[2]) self.assertTrue('# sample_rate' in results[3]) # First line with results. Should be 3 'words'. self.assertTrue(len(results[4].split()) == 3) clock_sync_found = False for entry in results: if '<abc>' in entry: clock_sync_found = True break self.assertTrue(clock_sync_found, 'BattOr Data:%s\n' % repr(results))
def testStartTracingPass(self): self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() self._battor.StartShell() self._battor.StartTracing() self.assertTrue(self._battor._tracing)
def testStartShellFail(self): self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() self._battor.GetShellReturnCode = lambda *unused: 1 with self.assertRaises(AssertionError): self._battor.StartShell()
def testStopShellTimeOutAndKill(self): self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() self._battor.StartShell() self._battor.StopShell() self.assertIsNone(self._battor._battor_shell)
def testFlashFirmwarePlatformNotSupported(self): self._cmd_helper_return = (1, 'Fail') self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() self.assertFalse(self._battor.FlashFirmware('hex_path', 'config_path'))
def testFlashFirmwarePass(self): self._battor = battor_wrapper.BattOrWrapper('linux') self._DefaultBattOrReplacements() self.assertTrue(self._battor.FlashFirmware('hex_path', 'config_path'))
def testInitBattOrPathIsBattOr(self): battor_path = 'battor/path/here' self._battor = battor_wrapper.BattOrWrapper('android', android_device='abc', battor_path=battor_path) self.assertEquals(self._battor._battor_path, battor_path)
def testFlashFirmwareFail(self): self._battor = battor_wrapper.BattOrWrapper('linux') self._DefaultBattOrReplacements() self._subprocess_check_output_code = 1 with self.assertRaises(battor_wrapper.BattOrFlashError): self._battor.FlashFirmware('hex_path', 'config_path')
def testInitAndroidWithBattOr(self): self._battor = battor_wrapper.BattOrWrapper('android', android_device='abc') self.assertEquals(self._battor._battor_path, 'abc_battor')
def testBadPlatform(self): with self.assertRaises(battor_error.BattOrError): self._battor = battor_wrapper.BattOrWrapper('unknown')
def testFlashFirmwarePlatformNotSupported(self): self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() self._battor._target_platform = 'unsupported_platform' self.assertFalse(self._battor.FlashFirmware('hex_path', 'config_path'))
def testStopShellNotStarted(self): self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() with self.assertRaises(AssertionError): self._battor.StopShell()
def testStopTracingNotRunning(self): self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() with self.assertRaises(AssertionError): self._battor.StopTracing()
def testInitNonAndroidWithBattOr(self): self._battor = battor_wrapper.BattOrWrapper('win') self.assertEquals(self._battor._battor_path, 'COM4')
def testFlashFirmwareFail(self): self._cmd_helper_return = (1, 'Fail') self._battor = battor_wrapper.BattOrWrapper('linux') self._DefaultBattOrReplacements() with self.assertRaises(battor_wrapper.BattOrFlashError): self._battor.FlashFirmware('hex_path', 'config_path')
def testInitNonAndroidWithMultipleBattOr(self): self._battor_list.append('battor2') with self.assertRaises(battor_error.BattOrError): self._battor = battor_wrapper.BattOrWrapper('linux')
def testInitNonAndroidWithoutBattOr(self): self._battor_list = [] serial.tools.list_ports.comports = lambda: [('COM4', 'None', '')] with self.assertRaises(battor_error.BattOrError): self._battor = battor_wrapper.BattOrWrapper('win')
def testGetFirmwareGitHashNotRunning(self): self._battor = battor_wrapper.BattOrWrapper('win') self._DefaultBattOrReplacements() with self.assertRaises(AssertionError): self._battor.GetFirmwareGitHash()