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 x, return_results: 'Fail.\n' self._battor.StartShell() with self.assertRaises(battor_error.BattorError): self._battor.StartTracing()
def StartAgentTracing(self, options, _, timeout=None): """Starts tracing. Args: options: Tracing options. Raises: RuntimeError: If trace already in progress. """ if options.update_map or not path.isfile(options.serial_map): battor_device_mapping.GenerateSerialMapFile( options.serial_map, options.hub_types) self._battor_wrapper = battor_wrapper.BattorWrapper( target_platform=options.target, android_device=options.device_serial_number, battor_path=options.battor_path, battor_map_file=options.serial_map) dev_utils = device_utils.DeviceUtils(options.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 testStopTracingPass(self): self._battor = battor_wrapper.BattorWrapper('win') self._DefaultBattorReplacements() self._battor.StartShell() self._battor.StartTracing() self._battor.IsShellRunning = lambda *unused: False self._battor.StopTracing() self.assertFalse(self._battor._tracing)
def testInitAndroidWithoutBattor(self): self._battor_list = [] self._fake_map = {} battor_device_mapping.GetBattorPathFromPhoneSerial = ( self._get_battor_path_from_phone_serial) with self.assertRaises(KeyError): self._battor = battor_wrapper.BattorWrapper('android', android_device='abc')
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)
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 testInitNonAndroidWithMultipleBattor(self): self._battor_list.append('battor2') with self.assertRaises(battor_error.BattorError): self._battor = battor_wrapper.BattorWrapper('win')
def testInitNonAndroidWithBattor(self): self._battor = battor_wrapper.BattorWrapper('win') self.assertEquals(self._battor._battor_path, '/dev/battor1')
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 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 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 testInitNonAndroidWithoutBattor(self): self._battor_list = [] with self.assertRaises(battor_error.BattorError): self._battor = battor_wrapper.BattorWrapper('win')
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.IsShellRunning = lambda *unused: False with self.assertRaises(AssertionError): self._battor.StartShell()
def testStartShellPass(self): self._battor = battor_wrapper.BattorWrapper('win') self._DefaultBattorReplacements() self._battor.StartShell() self.assertIsNotNone(self._battor._battor_shell)
def testStopTracingNotRunning(self): self._battor = battor_wrapper.BattorWrapper('win') self._DefaultBattorReplacements() with self.assertRaises(AssertionError): self._battor.StopTracing()
def testStartShellFail(self): self._battor = battor_wrapper.BattorWrapper('win') self._DefaultBattorReplacements() self._battor.GetShellReturnCode = lambda *unused: 1 with self.assertRaises(AssertionError): self._battor.StartShell()