예제 #1
0
 def test_take_logcat_with_extra_params(self, get_timestamp_mock,
                                        stop_proc_mock, start_proc_mock,
                                        create_dir_mock, FastbootProxy,
                                        MockAdbProxy):
     """Verifies the steps of collecting adb logcat on an AndroidDevice
     object, including various function calls and the expected behaviors of
     the calls.
     """
     mock_serial = '1'
     get_timestamp_mock.return_value = '123'
     ad = android_device.AndroidDevice(serial=mock_serial)
     configs = logcat.Config()
     configs.logcat_params = '-b radio'
     logcat_service = logcat.Logcat(ad, configs)
     logcat_service.start()
     # Verify start did the correct operations.
     self.assertTrue(logcat_service._adb_logcat_process)
     expected_log_path = os.path.join(
         logging.log_path, 'AndroidDevice%s' % ad.serial,
         'logcat,%s,fakemodel,123.txt' % ad.serial)
     create_dir_mock.assert_called_with(os.path.dirname(expected_log_path))
     adb_cmd = '"adb" -s %s logcat -v threadtime -b radio >> %s'
     start_proc_mock.assert_called_with(
         adb_cmd % (ad.serial, '"%s"' % expected_log_path), shell=True)
     self.assertEqual(logcat_service.adb_logcat_file_path,
                      expected_log_path)
예제 #2
0
 def test_update_config_while_running(self, stop_proc_mock, start_proc_mock,
                                      create_dir_mock, FastbootProxy,
                                      MockAdbProxy):
     mock_serial = '1'
     ad = android_device.AndroidDevice(serial=mock_serial)
     logcat_service = logcat.Logcat(ad)
     logcat_service.start()
     new_config = logcat.Config(logcat_params='-blah',
                                output_file_path='some/path/file.txt')
     with self.assertRaisesRegex(
             logcat.Error,
             'Logcat thread is already running, cannot start another one'):
         logcat_service.update_config(new_config)
     self.assertTrue(logcat_service.is_alive)
예제 #3
0
 def test_pause_and_resume(self, clear_adb_mock, stop_proc_mock,
                           start_proc_mock, create_dir_mock, FastbootProxy,
                           MockAdbProxy):
     mock_serial = '1'
     ad = android_device.AndroidDevice(serial=mock_serial)
     logcat_service = logcat.Logcat(ad, logcat.Config(clear_log=True))
     logcat_service.start()
     clear_adb_mock.assert_called_once_with()
     self.assertTrue(logcat_service.is_alive)
     logcat_service.pause()
     self.assertFalse(logcat_service.is_alive)
     stop_proc_mock.assert_called_with('process')
     self.assertIsNone(logcat_service._adb_logcat_process)
     clear_adb_mock.reset_mock()
     logcat_service.resume()
     self.assertTrue(logcat_service.is_alive)
     clear_adb_mock.assert_not_called()
예제 #4
0
 def test_update_config(self, stop_proc_mock, start_proc_mock,
                        create_dir_mock, FastbootProxy, MockAdbProxy):
     mock_serial = '1'
     ad = android_device.AndroidDevice(serial=mock_serial)
     logcat_service = logcat.Logcat(ad)
     logcat_service.start()
     logcat_service.stop()
     new_log_params = '-a -b -c'
     new_file_path = 'some/path/log.txt'
     new_config = logcat.Config(logcat_params=new_log_params,
                                output_file_path=new_file_path)
     logcat_service.update_config(new_config)
     logcat_service.start()
     self.assertTrue(logcat_service._adb_logcat_process)
     create_dir_mock.assert_has_calls([mock.call('some/path')])
     expected_adb_cmd = ('"adb" -s 1 logcat -v threadtime -a -b -c >> '
                         '"some/path/log.txt"')
     start_proc_mock.assert_called_with(expected_adb_cmd, shell=True)
     self.assertEqual(logcat_service.adb_logcat_file_path,
                      'some/path/log.txt')