labgrid-client: Add an internal console#1870
Conversation
At present if a console device is used by a strategy driver it is then removed by the client immediately afterwards. If the 'console' command is used, this means that any console data is lost. This is done so that the console device is release for microcom, so move the logic in with the microcom logic. With the forthcoming internal terminal, it will not be needed. Signed-off-by: Simon Glass <sjg@chromium.org>
It is useful to be able to see if a place is allowed without raising an error and needing a try...except block. Add a function to handle this and update _check_allowed() to use it. This will be used by the updated terminal suport. Signed-off-by: Simon Glass <sjg@chromium.org>
There is quite a lot of code here, so move the terminal function into its own file. This will make it easier to extend it later. Signed-off-by: Simon Glass <sjg@chromium.org>
At present Labgrid uses microcom as its console. This has some limitations: - console output is lost between when the board is reset and microcom connects - txdelay cannot be handled in microcom, meaning that boards may fail to receive expected output - the console may echo a few characters back to the caller in the time between when 'labgrid-client console' is executed and when microcom starts (which causes failures with U-Boot test system) For many use cases, microcom is more than is needed, so provide a simple internal terminal which resolved the above problems. It is enabled by a '-i' option to the 'console' command, as well as an environment variable, so that it can be adjustly without updating a lot of scripts. To exit, press Ctrl-] twice, quickly. Series-changes: 4 - Get internal console working with qemu - Show a prompt when starting, to indicate it is waiting for the board Signed-off-by: Simon Glass <sjg@chromium.org>
Add unit tests for the terminal handling in term.py, covering the external console launch (microcom and telnet fallback), the internal console read/write loop, and terminal setup and teardown. Also add tests for the new is_allowed() helper and the new parser argument for the internal console. Use real pipes for stdin rather than mocking os.read(), giving more realistic coverage of the keystroke and txdelay paths. The exit-char deadline test uses a threading.Event to synchronise with the run loop, avoiding brittle fixed sleeps. Fix an UnboundLocalError in term.internal() where log_fd could be referenced in the finally block before being assigned. Also fix a duplicate --logfile append in term.external() when using microcom. Signed-off-by: Simon Glass <sjg@chromium.org> Co-developed-by: Claude Opus 4.6 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #1870 +/- ##
========================================
+ Coverage 46.0% 48.1% +2.1%
========================================
Files 180 181 +1
Lines 14439 14541 +102
========================================
+ Hits 6654 7008 +354
+ Misses 7785 7533 -252
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
|
While I do agree with the concept of an internal console for labgrid-client, my expectation is more in line to use existing modules like Python Prompt Toolkit instead of writing our own terminal handling from scratch. |
OK I will take a look |
The microcom-based console used by
labgrid-clienthas a few limitations:labgrid-client consolestarting and microcom attaching, a few characters can echo back to the caller, which can break test systems which rely on output.For many use cases, microcom is more than is needed. This PR adds a small internal terminal that solves the above. Enable it with:
labgrid-client console -i(or--internal), orLG_CONSOLE=internalin the environment, so existing scripts can opt in without being rewrittenPress
Ctrl-]twice (quickly) to exit.Refactoring done along the way:
labgrid/util/term.py, keepingclient.pythinner_check_allowed()into a side-effect-freeis_allowed()plus the existing raise-on-failure helper, so the new terminal loop can poll without try/exceptWhat is the feature used for? Console access in environments where microcom is unavailable or its limitations bite: U-Boot tests, post-reset capture, and any flow that needs txdelay.
How does labgrid benefit? No external dependency for a basic console, plus clean handoff between strategy-driver use and interactive use without losing data.
How was it verified? Used the internal console against a QEMU target end-to-end. The unit tests under
tests/test_term.pyandtests/test_client_unit.pycover both the external (microcom/telnet) and internal paths: keystroke handling, txdelay, exit-char deadline, logfile output, listen-only mode and check-allowed termination.No hardware-specific changes.
Checklist