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

sys/shell: Make echoing and prompt runtime-configurable. #12087

Closed
wants to merge 9 commits into from

Conversation

jcarrano
Copy link
Contributor

Contribution description

This adds a persistent state to the shell that stores the echo configuration and the prompt character. Both can be changed by the user with special built in commmands

  • @eon: turn echo on.
  • @eoff: turn echo off.
  • @ps x: make x the prompt character. @ps (without any char) disables the prompt.

This is implemented in a way that does not consume any additional RAM- it only adds some bytes to the code. A couple of bytes are stolen from the user supplied buffer to store this new configurations.

The default state us given by the same compile time defines as before so this change is backwards compatible.

This will make the shell better suited for automated testing:

  • Once can change the prompt to a special character that is unlikely to occur in normal output so the test script will never lose synchronization.
  • Turning echo off helps prevent the script being confused by mistaking the echo by real output.

Testing procedure

TODO: I should add some test vectors.

Issues/PRs references

Part of #10994 .
Depends on: #10635 .
I made #12085 to fend off accusations that this will increase code size.

@jcarrano jcarrano added Type: new feature The issue requests / The PR implemements a new feature for RIOT Area: sys Area: System labels Aug 26, 2019
@miri64
Copy link
Member

miri64 commented Aug 26, 2019

I think @ps is too easily confused with ps. Why not use @prompt?

@jcarrano
Copy link
Contributor Author

I chose ps because of the $PS1 shell variable. I can use @prompt, no problem. I was anticipating complaints with respect to code size, so I preemptively chose a short string.

The test for the line cancellation (ctrl-c) functionality was unable to
detect error because of the way pexpect matches output.

While working on the long line shell bug, a regression was about to be
introduced because of this. This commit fixes the test by directly reading from
the child process and expects an exact response.

To make the test more robust, the newline handling was changed in native,
where an extra empty line was being sent with each character.
Add a command to retrieve buffer size and then force an extremely long
line. This is failing right now because of a bug in the shell.

The terminal was changed to socat, as pyterm messes up the I/O and makes
testing impossible.
The numeric value for EOF is (-1). This caused the shell to return
the same code when EOF was encountered and when the line lenght was
exceeded. Additionally, if the line length is exceeded, the correct
behaviour is to consume the remaining characters until the end of
the line, to prevent the following line from containing (potentially
dangerous) garbage.
@jcarrano
Copy link
Contributor Author

I discovered some bugs in #10635 that were introduced during rebasing. I rebased this on top of the fixed branch.

There was some code added to "prevent putchar from being inlined", which
supposedly enlarged the code size.

It does not seem to have any effect: both before and after the change the
size is the same:

$ BOARD=samr21-xpro make -c tests/shell all
  ......
   text	   data	    bss	    dec	    hex	filename
  10416	    140	   2612	  13168	   3370	/home/jcarrano/source/vanillaRIOT/tests/shell/bin/samr21-xpro/tests_shell.elf

It makes sense: the compiler is not _that_ dumb.
ifdefs in the middle of code reduce readability and debugability and
should be avoided.
This adds a persistent state to the shell that stores the echo configuration
and the prompt character. Both can be changed by the user with special built
in commmands

- @eon: turn echo on.
- @eon: turn echo off.
- @ps x: make x the prompt character. "@ps" (without any char) disables
  the prompt.

This is implemented in a way that does not consume any additional RAM- it
only adds some bytes to the code. A couple of bytes are stolen from the
user supplied buffer to store this new configurations.

The default state us given by the same compile time defines as before so
this change is backwards compatible.
@jcarrano jcarrano added the State: waiting for other PR State: The PR requires another PR to be merged first label Aug 28, 2019
@stale
Copy link

stale bot commented Feb 28, 2020

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions.

@stale stale bot added the State: stale State: The issue / PR has no activity for >185 days label Feb 28, 2020
@stale stale bot closed this Mar 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: sys Area: System State: stale State: The issue / PR has no activity for >185 days State: waiting for other PR State: The PR requires another PR to be merged first Type: new feature The issue requests / The PR implemements a new feature for RIOT
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants