Skip to content

Fix byte offsets of lines returned by LogcatProcessor.tail - #1033

Merged
xpconanfan merged 2 commits into
google:masterfrom
kwy404:fix-logcat-tail-offset
Sep 24, 2026
Merged

xpconanfan merged 2 commits into
google:masterfrom
kwy404:fix-logcat-tail-offset

Conversation

@kwy404

@kwy404 kwy404 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

tail() reads the file backwards in 64KB blocks. For every block except the one at the start of the file, the offset of the first complete line did not count the newline after the partial remainder, so all lines in that block got a position one byte too early.

In practice this means that for logcat files over 64KB, a line logged after now() and read back with tail() compares as earlier than the now() marker. The added test covers that case, and offsets from tail() now match those from get_lines().

For every block except the one at the start of the file, the offset of
the first line did not count the newline after the partial remainder,
so all lines in that block were placed one byte too early.
@xpconanfan

Copy link
Copy Markdown
Collaborator

Nice catch! It seems like can compute current_offset directly inside the if remaining > 0: / else: branches above so we don't need to check if remaining > 0: twice?

          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

@kwy404

kwy404 commented Sep 24, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, that reads better. Applied in 2d63b39, the offset is now set in each branch and the second check is gone.

@xpconanfan xpconanfan added the bug label Sep 24, 2026
@xpconanfan xpconanfan added this to the Mobly Release 1.14 milestone Sep 24, 2026
@xpconanfan
xpconanfan merged commit 8eec426 into google:master Sep 24, 2026
19 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants