Skip to content

Commit

Permalink
[otci] normalize ADB shell output for consistent line splitting (open…
Browse files Browse the repository at this point in the history
…thread#11231)

This commit adds compatibility to support these kinds of devices, so
that the shell() function can always return expected split lines in
list.
  • Loading branch information
zesonzhang authored Feb 11, 2025
1 parent a2d65a1 commit f7080a9
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions tools/otci/otci/command_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,15 @@ def execute_platform_command(self, cmd: str, timeout: float = 10) -> List[str]:
return self.shell(cmd, timeout=timeout)

def shell(self, cmd: str, timeout: float) -> List[str]:
return self.__adb.shell(cmd, transport_timeout_s=timeout, read_timeout_s=timeout,
timeout_s=timeout).splitlines()
raw_out = self.__adb.shell(cmd, transport_timeout_s=timeout, read_timeout_s=timeout, timeout_s=timeout)

# Normalize ADB shell output for consistent line splitting.
# The ADB client may perform automatic newline conversion, potentially replace the '\n' with '\r\n'.
# In some scenarios, this can result in sequences like '\r\r\n'. This line replaces '\r\r\n' with
# standard CRLF '\r\n' to mitigate issues with line-based processing and `splitlines()`.
out = raw_out.replace('\r\r\n', '\r\n')

return out.splitlines()

def close(self):
self.__adb.close()
Expand Down

0 comments on commit f7080a9

Please sign in to comment.