Skip to content

driver: Fix SmallUBootDriver for garbage #1700

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aparcar
Copy link
Contributor

@aparcar aparcar commented Jul 23, 2025

Description

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', <re.Match object; span=(2, 8), match=b'ap135>'>, 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', <re.Match object; span=(4, 10), match=b'ap135>'>, 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

Checklist

  • Documentation for the feature
  • Tests for the feature
  • The arguments and description in doc/configuration.rst have been updated
  • Add a section on how to use the feature to doc/usage.rst
  • Add a section on how to use the feature to doc/development.rst
  • PR has been tested
  • Man pages have been regenerated

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', <re.Match object; span=(2, 8), match=b'ap135>'>, 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', <re.Match object; span=(4, 10), match=b'ap135>'>, 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 <[email protected]>
Copy link

codecov bot commented Jul 23, 2025

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 55.6%. Comparing base (4398da7) to head (4409b57).

✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
labgrid/driver/smallubootdriver.py 0.0% 4 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff            @@
##           master   #1700     +/-   ##
========================================
- Coverage    55.6%   55.6%   -0.1%     
========================================
  Files         172     172             
  Lines       13471   13474      +3     
========================================
  Hits         7500    7500             
- Misses       5971    5974      +3     
Flag Coverage Δ
3.10 55.6% <0.0%> (-0.1%) ⬇️
3.11 55.6% <0.0%> (-0.1%) ⬇️
3.12 55.6% <0.0%> (-0.1%) ⬇️
3.13 55.6% <0.0%> (-0.1%) ⬇️
3.9 55.6% <0.0%> (-0.1%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder when the extra characters appear.?Is it before the echo is sent, or after?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants