From f7080a93436d0ba92958173ad0c0324a0edb2520 Mon Sep 17 00:00:00 2001 From: Jason Zhang Date: Tue, 11 Feb 2025 23:51:47 +0800 Subject: [PATCH] [otci] normalize ADB shell output for consistent line splitting (#11231) This commit adds compatibility to support these kinds of devices, so that the shell() function can always return expected split lines in list. --- tools/otci/otci/command_handlers.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tools/otci/otci/command_handlers.py b/tools/otci/otci/command_handlers.py index e3b7a2632..7018a38f3 100644 --- a/tools/otci/otci/command_handlers.py +++ b/tools/otci/otci/command_handlers.py @@ -330,8 +330,15 @@ class OtbrAdbCommandRunner(OTCommandHandler): 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()