def testTempFileNotWritten(self): """Tests that device temp files work successfully even if not written to.""" temp_file = android_commands.DeviceTempFile(self.ac) temp_file.close() self.assertFalse(self.ac.FileExistsOnDevice(temp_file.name)) with android_commands.DeviceTempFile(self.ac) as with_temp_file: pass self.assertFalse(self.ac.FileExistsOnDevice(with_temp_file.name))
def testNaming(self): """Tests that returned filenames are as requested.""" temp_file = android_commands.DeviceTempFile(self.ac, prefix="cat") self.assertTrue(os.path.basename(temp_file.name).startswith("cat")) temp_file = android_commands.DeviceTempFile(self.ac, suffix="dog") self.assertTrue(temp_file.name.endswith("dog")) temp_file = android_commands.DeviceTempFile(self.ac, prefix="cat", suffix="dog") self.assertTrue(os.path.basename(temp_file.name).startswith("cat")) self.assertTrue(temp_file.name.endswith("dog"))
def testTempFileDeleted(self): """Tests that DeviceTempFile deletes files when closed.""" temp_file = android_commands.DeviceTempFile(self.ac) self.assertFalse(self.ac.FileExistsOnDevice(temp_file.name)) self.ac.SetFileContents(temp_file.name, "contents") self.assertTrue(self.ac.FileExistsOnDevice(temp_file.name)) temp_file.close() self.assertFalse(self.ac.FileExistsOnDevice(temp_file.name)) with android_commands.DeviceTempFile(self.ac) as with_temp_file: self.assertFalse(self.ac.FileExistsOnDevice(with_temp_file.name)) self.ac.SetFileContents(with_temp_file.name, "contents") self.assertTrue(self.ac.FileExistsOnDevice(with_temp_file.name)) self.assertFalse(self.ac.FileExistsOnDevice(with_temp_file.name))
def __init__(self, device, perf_binary, categories): self._device = device self._output_file = android_commands.DeviceTempFile( self._device.old_interface, prefix='perf_output') self._log_file = tempfile.TemporaryFile() device_param = (['-s', self._device.old_interface.GetDevice()] if self._device.old_interface.GetDevice() else []) cmd = ['adb'] + device_param + \ ['shell', perf_binary, 'record', '--output', self._output_file.name] + _PERF_OPTIONS if categories: cmd += ['--event', ','.join(categories)] self._perf_control = perf_control.PerfControl(self._device) self._perf_control.SetPerfProfilingMode() self._perf_process = subprocess.Popen(cmd, stdout=self._log_file, stderr=subprocess.STDOUT)
def __init__(self, device, perf_binary, categories): self._device = device self._output_file = android_commands.DeviceTempFile( self._device.old_interface, prefix='perf_output') self._log_file = tempfile.TemporaryFile() # TODO(jbudorick) Look at providing a way to unhandroll this once the # adb rewrite has fully landed. device_param = (['-s', str(self._device)] if str(self._device) else []) cmd = ['adb'] + device_param + \ ['shell', perf_binary, 'record', '--output', self._output_file.name] + _PERF_OPTIONS if categories: cmd += ['--event', ','.join(categories)] self._perf_control = perf_control.PerfControl(self._device) self._perf_control.SetPerfProfilingMode() self._perf_process = subprocess.Popen(cmd, stdout=self._log_file, stderr=subprocess.STDOUT)