diff options
4 files changed, 27 insertions, 20 deletions
diff --git a/mobly/controllers/android_device.py b/mobly/controllers/android_device.py index b7f0346..97d80cc 100644 --- a/mobly/controllers/android_device.py +++ b/mobly/controllers/android_device.py @@ -919,7 +919,7 @@ class AndroidDevice(object): The name follows the pattern: - {file type},{debug_tag},{serial},{time identifier}.{ext} + {file type},{debug_tag},{serial},{model},{time identifier}.{ext} "debug_tag" is only added if it's different from the serial. "ext" is added if specified by user. @@ -943,7 +943,7 @@ class AndroidDevice(object): filename_tokens = [file_type] if self.debug_tag != self.serial: filename_tokens.append(self.debug_tag) - filename_tokens.extend([self.serial, time_str]) + filename_tokens.extend([self.serial, self.model, time_str]) filename_str = ','.join(filename_tokens) if extension_name is not None: filename_str = '%s.%s' % (filename_str, extension_name) diff --git a/mobly/controllers/android_device_lib/services/logcat.py b/mobly/controllers/android_device_lib/services/logcat.py index a27fc40..c79b89f 100644 --- a/mobly/controllers/android_device_lib/services/logcat.py +++ b/mobly/controllers/android_device_lib/services/logcat.py @@ -56,6 +56,7 @@ class Logcat(base_service.BaseService): adb_logcat_file_path: string, path to the file that the service writes adb logcat to by default. """ + OUTPUT_FILE_TYPE = 'logcat' def __init__(self, android_device, configs=None): super(Logcat, self).__init__(android_device, configs) @@ -132,11 +133,12 @@ class Logcat(base_service.BaseService): self.pause() dest_path = test_info.output_path utils.create_dir(dest_path) - filename = os.path.basename(self.adb_logcat_file_path) - shutil.move(self.adb_logcat_file_path, dest_path) - self.resume() + filename = self._ad.generate_filename(self.OUTPUT_FILE_TYPE, test_info, + 'txt') excerpt_file_path = os.path.join(dest_path, filename) - self._ad.log.debug('AdbLog excerpt created at: %s', excerpt_file_path) + shutil.move(self.adb_logcat_file_path, excerpt_file_path) + self._ad.log.debug('logcat excerpt created at: %s', excerpt_file_path) + self.resume() return [excerpt_file_path] @property diff --git a/tests/mobly/controllers/android_device_lib/services/logcat_test.py b/tests/mobly/controllers/android_device_lib/services/logcat_test.py index e4d2ca6..94416d2 100755 --- a/tests/mobly/controllers/android_device_lib/services/logcat_test.py +++ b/tests/mobly/controllers/android_device_lib/services/logcat_test.py @@ -237,9 +237,10 @@ class LogcatTest(unittest.TestCase): mock_record.begin_time = 123 test_run_info = runtime_test_info.RuntimeTestInfo( 'test_foo', test_output_dir, mock_record) - logcat_service.create_per_test_excerpt(test_run_info) + actual_path1 = logcat_service.create_output_excerpts(test_run_info)[0] expected_path1 = os.path.join(test_output_dir, 'test_foo-123', - 'adblog,fakemodel,1.txt') + 'logcat,1,fakemodel,test_foo-123.txt') + self.assertEqual(expected_path1, actual_path1) self.assertTrue(os.path.exists(expected_path1)) self.AssertFileContains(FILE_CONTENT, expected_path1) self.assertFalse(os.path.exists(logcat_service.adb_logcat_file_path)) @@ -252,9 +253,10 @@ class LogcatTest(unittest.TestCase): mock_record.begin_time = 456 test_run_info = runtime_test_info.RuntimeTestInfo( 'test_bar', test_output_dir, mock_record) - logcat_service.create_per_test_excerpt(test_run_info) + actual_path2 = logcat_service.create_output_excerpts(test_run_info)[0] expected_path2 = os.path.join(test_output_dir, 'test_bar-456', - 'adblog,fakemodel,1.txt') + 'logcat,1,fakemodel,test_bar-456.txt') + self.assertEqual(expected_path2, actual_path2) self.assertTrue(os.path.exists(expected_path2)) self.AssertFileContains(FILE_CONTENT, expected_path2) self.AssertFileDoesNotContain(FILE_CONTENT, expected_path1) @@ -289,9 +291,9 @@ class LogcatTest(unittest.TestCase): 'test_foo', test_output_dir, mock_record) actual_path1 = logcat_service.create_output_excerpts(test_run_info)[0] expected_path1 = os.path.join(test_output_dir, 'test_foo-123', - 'adblog,fakemodel,1.txt') - self.assertTrue(os.path.exists(expected_path1)) + 'logcat,1,fakemodel,test_foo-123.txt') self.assertEqual(actual_path1, expected_path1) + self.assertTrue(os.path.exists(expected_path1)) self.AssertFileContains(FILE_CONTENT, expected_path1) self.assertFalse(os.path.exists(logcat_service.adb_logcat_file_path)) # Generate some new logs and do another excerpt. @@ -305,9 +307,9 @@ class LogcatTest(unittest.TestCase): 'test_bar', test_output_dir, mock_record) actual_path2 = logcat_service.create_output_excerpts(test_run_info)[0] expected_path2 = os.path.join(test_output_dir, 'test_bar-456', - 'adblog,fakemodel,1.txt') - self.assertTrue(os.path.exists(expected_path2)) + 'logcat,1,fakemodel,test_bar-456.txt') self.assertEqual(actual_path2, expected_path2) + self.assertTrue(os.path.exists(expected_path2)) self.AssertFileContains(FILE_CONTENT, expected_path2) self.AssertFileDoesNotContain(FILE_CONTENT, expected_path1) self.assertFalse(os.path.exists(logcat_service.adb_logcat_file_path)) diff --git a/tests/mobly/controllers/android_device_test.py b/tests/mobly/controllers/android_device_test.py index 9620c99..91381ab 100755 --- a/tests/mobly/controllers/android_device_test.py +++ b/tests/mobly/controllers/android_device_test.py @@ -489,7 +489,8 @@ class AndroidDeviceTest(unittest.TestCase): ad = android_device.AndroidDevice(serial=mock_serial) get_log_file_timestamp_mock.return_value = '07-22-2019_17-53-34-450' filename = ad.generate_filename('MagicLog') - self.assertEqual(filename, 'MagicLog,1,07-22-2019_17-53-34-450') + self.assertEqual(filename, + 'MagicLog,1,fakemodel,07-22-2019_17-53-34-450') @mock.patch('mobly.controllers.android_device_lib.adb.AdbProxy', return_value=mock_android_device.MockAdbProxy('1')) @@ -505,7 +506,7 @@ class AndroidDeviceTest(unittest.TestCase): get_log_file_timestamp_mock.return_value = '07-22-2019_17-53-34-450' filename = ad.generate_filename('MagicLog') sanitize_filename_mock.assert_called_with( - 'MagicLog,1,07-22-2019_17-53-34-450') + 'MagicLog,1,fakemodel,07-22-2019_17-53-34-450') @mock.patch('mobly.controllers.android_device_lib.adb.AdbProxy', return_value=mock_android_device.MockAdbProxy('1')) @@ -518,7 +519,8 @@ class AndroidDeviceTest(unittest.TestCase): ad = android_device.AndroidDevice(serial=mock_serial) get_log_file_timestamp_mock.return_value = '07-22-2019_17-53-34-450' filename = ad.generate_filename('MagicLog', extension_name='log') - self.assertEqual(filename, 'MagicLog,1,07-22-2019_17-53-34-450.log') + self.assertEqual(filename, + 'MagicLog,1,fakemodel,07-22-2019_17-53-34-450.log') @mock.patch('mobly.controllers.android_device_lib.adb.AdbProxy', return_value=mock_android_device.MockAdbProxy('1')) @@ -532,7 +534,8 @@ class AndroidDeviceTest(unittest.TestCase): get_log_file_timestamp_mock.return_value = '07-22-2019_17-53-34-450' ad.debug_tag = 'RoleX' filename = ad.generate_filename('MagicLog') - self.assertEqual(filename, 'MagicLog,RoleX,1,07-22-2019_17-53-34-450') + self.assertEqual(filename, + 'MagicLog,RoleX,1,fakemodel,07-22-2019_17-53-34-450') @mock.patch('mobly.controllers.android_device_lib.adb.AdbProxy', return_value=mock_android_device.MockAdbProxy('1')) @@ -549,7 +552,7 @@ class AndroidDeviceTest(unittest.TestCase): 'test_xyz', '/tmp/blah/', mock_record) filename = ad.generate_filename('MagicLog', time_identifier=mock_test_info) - self.assertEqual(filename, 'MagicLog,1,test_xyz-1234567') + self.assertEqual(filename, 'MagicLog,1,fakemodel,test_xyz-1234567') @mock.patch('mobly.controllers.android_device_lib.adb.AdbProxy', return_value=mock_android_device.MockAdbProxy('1')) @@ -563,7 +566,7 @@ class AndroidDeviceTest(unittest.TestCase): get_log_file_timestamp_mock.return_value = '07-22-2019_17-53-34-450' filename = ad.generate_filename('MagicLog', time_identifier='my_special_time') - self.assertEqual(filename, 'MagicLog,1,my_special_time') + self.assertEqual(filename, 'MagicLog,1,fakemodel,my_special_time') @mock.patch('mobly.controllers.android_device_lib.adb.AdbProxy', return_value=mock_android_device.MockAdbProxy(1)) |