-
Notifications
You must be signed in to change notification settings - Fork 2k
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: correctly detect and handle long lines #13195
Conversation
12af92c
to
ce3ebb4
Compare
ce3ebb4
to
f6d093f
Compare
…RIOT-OS#13195) 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. Co-authored-by: Hendrik van Essen <[email protected]> sys/shell: rephrase/reformat some comments tests/shell: add test case for shell's buffer size Co-authored-by: Juan Carrano <[email protected]> tests/shell: avoid sending an extra empty line on native Co-authored-by: Juan Carrano <[email protected]> tests/shell: check for startup message Co-authored-by: Juan Carrano <[email protected]> tests/shell: check for shell prompt Co-authored-by: Juan Carrano <[email protected]> tests/shell: fix test case for line cancelling 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. Co-authored-by: Juan Carrano <[email protected]> tests/shell: add test case for exceeding lines Co-authored-by: Juan Carrano <[email protected]> tests/shell: remove redundant parentheses
RIOT-OS#13195) 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. Co-authored-by: Hendrik van Essen <[email protected]> sys/shell: rephrase/reformat some comments tests/shell: add test case for shell's buffer size Co-authored-by: Juan Carrano <[email protected]> tests/shell: avoid sending an extra empty line on native Co-authored-by: Juan Carrano <[email protected]> tests/shell: check for startup message Co-authored-by: Juan Carrano <[email protected]> tests/shell: check for shell prompt Co-authored-by: Juan Carrano <[email protected]> tests/shell: fix test case for line cancelling 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. Co-authored-by: Juan Carrano <[email protected]> tests/shell: add test case for exceeding lines Co-authored-by: Juan Carrano <[email protected]> tests/shell: remove redundant parentheses
f6d093f
to
4944089
Compare
@smlng @kaspar030 Since you guys already had a look at #10635, you may also have (instead) a look at this successor PR please? :) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for taking over @HendrikVE! Some styling comments, otherwise looks good. Will test asap.
sys/shell/shell.c
Outdated
#ifndef SHELL_NO_ECHO | ||
_putchar('\r'); | ||
_putchar('\n'); | ||
#endif | ||
|
||
/* return 1 if line is empty, 0 otherwise */ | ||
return c == ETX || line_buf_ptr == buf; | ||
return (length_exceeded)? ERROR_READLINE_EXCEEDED : curr_pos; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return (length_exceeded)? ERROR_READLINE_EXCEEDED : curr_pos; | |
return (length_exceeded) ? ERROR_READLINE_EXCEEDED : curr_pos; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Gonna add the space :)
sys/shell/shell.c
Outdated
@@ -1,5 +1,5 @@ | |||
/* | |||
* Copyright (C) 2009, Freie Universitaet Berlin (FUB). | |||
* Copyright (C) 2020 Freie Universität Berlin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea here, but can copyright be updated like this? Should both years?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably, I will change it to Copyright (C) 2009-2020 Freie Universität Berlin
then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe Copyright (C) 2009, 2020 Freie Universität Berlin
, but again I have no proper knowledge of how this should be formated hahaha
Since shell is used in a lot of tests I will trigger running all tests to be sure. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have some comments on the test script and on the new prints.
tests/shell/tests/01-run.py
Outdated
# looks like the nrf52dk runs in to undefined behaviour when sending more | ||
# than 64 bytes over UART |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets still skip the test but improve the message, feel free to improve, but something like:
# looks like the nrf52dk runs in to undefined behaviour when sending more | |
# than 64 bytes over UART | |
# There is an issue with nrf52dk when the Virtual COM port is connected and sending more than 64 bytes over | |
# UART. If no terminal is connected to the Virtual COM and interfacing directly to the nrf52832 UART pins the | |
# issue is not present. |
tests/shell/tests/01-run.py
Outdated
child.sendline(cmd) | ||
for line in expected: | ||
child.expect_exact(line) | ||
|
||
|
||
def check_startup(child): | ||
child.expect('test_shell.\r\n') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will make it work for boards even if there is no reset
called before starting the test (some boards can't be reset with make reset
)
child.expect('test_shell.\r\n') | |
child.sendline(CONTROL_C) | |
child.expect_exact(PROMPT) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, thank you. I totally ignored the possibility ^^
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think about using test_utils_interactive_sync()
as introduced in 1cb8bd4 ?
sys/shell/shell.c
Outdated
break; | ||
|
||
case 0: | ||
puts("shell: line is empty"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this should be removed, a terminal should not print a message on an empty line, it wasn't the case before.
puts("shell: line is empty"); |
I think they are unrelated to your changes. But we did change the terminal to use I will need to investigate that. Because IMO it might be related to the change to |
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. Co-authored-by: Hendrik van Essen <[email protected]>
Co-authored-by: Juan Carrano <[email protected]>
Co-authored-by: Juan Carrano <[email protected]>
Co-authored-by: Juan Carrano <[email protected]>
Co-authored-by: Juan Carrano <[email protected]>
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. Co-authored-by: Juan Carrano <[email protected]>
Co-authored-by: Juan Carrano <[email protected]>
8f1777c
to
574c173
Compare
@HendrikVE I rebased and fixed |
fixed shell is too big for atmega32u4 based boards
574c173
to
e38e3c5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ACK, fixes the issue, we ran all tests on murdock and although there where failures they are unrelated.
GO!, Thanks for the good work and the patience @HendrikVE! as well as taking over for @jcarrano |
Thank you very much for your review @fjmolinas, I really appreciate that! Also thanks @jcarrano for your initial work ;) |
Contribution description
With this PR I simply copied PR #10635 authored by @jcarrano. Since he left the team, I hereby offer to take care of rebasing and implement required changes.
The numeric value for EOF is (-1). This caused the shell to return the same code when EOF was encountered and when the line length 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.
Testing procedure
This PR adds a test to
tests/shell
. It adds a command to retrieve buffer size and then forces an extremely long line. This is failing right now because of a bug in the shell, which is fixed with this PR.In case of problems with testing on a real board, please refer to #10639 first.
Issues/PRs references
Copy of #10635
Dependency for #13196 and #13197