From 4409b571ba78cf1c3ee2a986426591b26e11a06e Mon Sep 17 00:00:00 2001 From: Paul Spooren Date: Mon, 23 Jun 2025 21:23:32 +0200 Subject: [PATCH] driver: Fix SmallUBootDriver for garbage MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The SmallUBoot spits out random chars which confuse the expect function, likely breaking it. This commit ignore two short answers and thereby fixing the issue. There might be cleaner implementations but this does the trick reliably for multiple device I'm using for testing. An error how this looks without the patch: ``` CONSOLE SerialLogger.ma: SerialDriver(main) > tpl␤␍␤ INFO StepLogger: → SerialDriver.expect(pattern='ap135>') CONSOLE SerialLogger.ma: SerialDriver(main) < ap135> ␍␤ INFO StepLogger: ← SerialDriver.expect() result=(0, b'\r\n', '>, b'ap135>') [0.002s] CONSOLE SerialLogger.ma: SerialDriver(main) > echoPBTAJJAOZT; setenv serverip 192.168.1.99; echoPBTAJJAOZT␤␍␤ INFO StepLogger: → SerialDriver.expect(pattern='ap135>') CONSOLE SerialLogger.ma: SerialDriver(main) < ␍␍␤ CONSOLE SerialLogger.ma: SerialDriver(main) < ap135> echoPBTAJJAOZT; setenv serverip 192.168.1.99; echoPBTAJJAOZT␍␤ INFO StepLogger: ← SerialDriver.expect() result=(0, b' \r\r\n', '>, b'ap135>') [0.002s] INFO StepLogger: ⚠ SmallUBootDriver._await_prompt() [7.811s] exception="Unknown command 'echoPBTAJJAOZT' - try 'help'" is not in list ERROR conftest: Failed to transition to state shell Traceback (most recent call last): File "/Users/user/src/openwrt/tests/tests/conftest.py", line 93, in shell_command strategy.transition("shell") ~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "/Users/user/src/openwrt/tests/targets/../strategies/tftpstrategy.py", line 75, in transition self.transition(Status.uboot) ~~~~~~~~~~~~~~~^^^^^^^^^^^^^^ File "/Users/user/src/openwrt/tests/targets/../strategies/tftpstrategy.py", line 72, in transition self.target.activate(self.uboot) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^ File "/Users/user/src/labgrid/labgrid/labgrid/target.py", line 472, in activate client.on_activate() ~~~~~~~~~~~~~~~~~~^^ File "/Users/user/src/labgrid/labgrid/labgrid/driver/ubootdriver.py", line 61, in on_activate self._await_prompt() ~~~~~~~~~~~~~~~~~~^^ File "/Users/user/src/labgrid/labgrid/labgrid/step.py", line 215, in wrapper _result = func(*_args, **_kwargs) File "/Users/user/src/labgrid/labgrid/labgrid/driver/smallubootdriver.py", line 73, in _await_prompt self._run(command) ~~~~~~~~~^^^^^^^^^ File "/Users/user/src/labgrid/labgrid/labgrid/driver/smallubootdriver.py", line 105, in _run data = data[data.index(f"Unknown command 'echo{marker}' - try 'help'") +1 :] ~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ValueError: "Unknown command 'echoPBTAJJAOZT' - try 'help'" is not in list ``` Signed-off-by: Paul Spooren --- labgrid/driver/smallubootdriver.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/labgrid/driver/smallubootdriver.py b/labgrid/driver/smallubootdriver.py index 98327ab53..7913e498b 100644 --- a/labgrid/driver/smallubootdriver.py +++ b/labgrid/driver/smallubootdriver.py @@ -96,7 +96,10 @@ def _run(self, cmd: str, *, timeout: int = 30, codec: str = "utf-8", decodeerror cmp_command = f"echo{marker}; {cmd}; echo{marker}" self.console.sendline(cmp_command) - _, before, _, _ = self.console.expect(self.prompt, timeout=timeout) + while True: + _, before, _, _ = self.console.expect(self.prompt, timeout=timeout) + if len(before) > 4: + break data = re_vt100.sub( '', before.decode('utf-8'), count=1000000