Skip to content
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

Add a basic shell to ZMK and use it for testing #2014

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

ecstatic-morse
Copy link

Includes #1318.

Running tests using the shell allows testing multiple input sequences for a single configuration without rebuilding the configuration each time. As an example, I've converted the toggle-layer test to use ZMK shell commands.

petejohanson and others added 7 commits November 13, 2023 21:22
* Allow tap/press/release of a given key position
  within the Zephyr shell.
* By default, don't generate any events for the native
  posix board DTS, to allow native builds outside
  of the testing use case.
We should probably move this into .conf files, or wait for Zephyr 3.4
and its EXTRA_DTC_OVERLAY_FILE.
- require bash and use subroutines
- write intermediate output to stderr instead of stdout
- strip ANSI escape sequences from the logs
- add option to run tests via ZMK shell commands
@ecstatic-morse
Copy link
Author

ecstatic-morse commented Nov 14, 2023

This works as-is but I'm not happy with the way configuration is handled currently. Initially I wanted to use EXTRA_DTC_OVERLAY_FILE to enable/disable the exit-after property of the kscan-mock driver, but that config option requires Zephyr 3.4. It doesn't feel like exit-after belongs in Kconfig, and although we could abuse board revisions for this, that feels a bit dirty. For now I just check whether events is populated and only exit from kscan-mock if at least one event is specified.

Also, as a side-effect of the bug mentioned here, I don't believe it's possible to handle command sequences longer than CONFIG_SHELL_BACKEND_SERIAL_RX_RING_BUFFER_SIZE. After that is fixed (by upgrading or patching Zephyr) we should be able to use something like pv -qB 1024 to avoid overflowing the ring buffer.

Obviously low priority, but this should speed up writing and running tests quite a bit.

Comment on lines +91 to +102
# This convoluted invocation is needed to work around some quirks in
# Zephyr's serial shell driver:
#
# - When stdin is closed while CONFIG_NATIVE_UART_0_ON_STDINOUT is enabled,
# reading from the UART driver returns the same byte over and over
# (instead of blocking).
# - The shell driver reads from the UART driver greedily until it blocks
# (instead of stopping on newlines or when the ring buffer is full).
#
# This means that piping directly to the Zephyr executable causes it to
# enter an infinite loop. To work around this, we sleep inside a process
# substitution to keep the pipe open until the Zephyr executable exits.
Copy link
Author

Choose a reason for hiding this comment

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

This is fixed in zephyrproject-rtos/zephyr#51244, so upgrading Zephyr means we can replace this with a pipe and remove the sleep.

@caksoylar caksoylar added enhancement New feature or request tests labels Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants