Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mobly/controllers/android_device_lib/logcat_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,12 +487,13 @@ def tail(
if remaining > 0:
remainder = split[0]
lines_chunk = split[1:]
current_offset = remaining + len(remainder) + 1
else:
remainder = b''
lines_chunk = split
current_offset = 0

# Calculate offsets and parse lines in reverse order within this block
current_offset = remaining + len(remainder)
block_lines: list[tuple[int, LogLine]] = []
for line_bytes in lines_chunk:
line_offset = current_offset
Expand Down
15 changes: 15 additions & 0 deletions tests/mobly/controllers/android_device_lib/services/logcat_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -901,6 +901,21 @@ def test_tail_recent_logs(self):
self.assertEqual(recent_logs[-1].tag, 'BtGatt')
self.assertEqual(recent_logs[-1].level, 'F')

def test_tail_position_in_large_file(self):
# Make the file larger than the block size tail() reads at a time.
self._append_log(
'08-09 22:00:05.000 1000 1030 I Filler: padding\n' * 2000
)
start = self.logcat_service.now()
self._append_log(
'08-09 22:00:06.000 1000 1030 I WifiService: Disconnected from'
' wlan0\n'
)

last_line = self.logcat_service.tail(num_lines=1)[0]
self.assertEqual(last_line.message, 'Disconnected from wlan0')
self.assertTrue(last_line.position > start)

def test_now_and_bounded_query(self):
# Take position marker before triggering an action
start = self.logcat_service.now()
Expand Down
Loading