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: correctly detect and handle long lines #13195

Merged
merged 10 commits into from
Mar 30, 2020

Conversation

HendrikVE
Copy link
Contributor

@HendrikVE HendrikVE commented Jan 24, 2020

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

@benpicco benpicco added Area: sys Area: System Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Jan 25, 2020
HendrikVE pushed a commit to HendrikVE/RIOT that referenced this pull request Feb 9, 2020
…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 <hendrik.ve@fu-berlin.de>

sys/shell: rephrase/reformat some comments

tests/shell: add test case for shell's buffer size

Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>

tests/shell: avoid sending an extra empty line on native

Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>

tests/shell: check for startup message

Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>

tests/shell: check for shell prompt

Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>

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 <j.carrano@fu-berlin.de>

tests/shell: add test case for exceeding lines

Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>

tests/shell: remove redundant parentheses
HendrikVE pushed a commit to HendrikVE/RIOT that referenced this pull request Feb 9, 2020
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 <hendrik.ve@fu-berlin.de>

sys/shell: rephrase/reformat some comments

tests/shell: add test case for shell's buffer size

Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>

tests/shell: avoid sending an extra empty line on native

Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>

tests/shell: check for startup message

Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>

tests/shell: check for shell prompt

Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>

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 <j.carrano@fu-berlin.de>

tests/shell: add test case for exceeding lines

Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>

tests/shell: remove redundant parentheses
@benpicco benpicco added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR labels Feb 10, 2020
@HendrikVE HendrikVE added Area: tests Area: tests and testing framework Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation labels Feb 10, 2020
@HendrikVE
Copy link
Contributor Author

@smlng @kaspar030 Since you guys already had a look at #10635, you may also have (instead) a look at this successor PR please? :)

Copy link
Contributor

@fjmolinas fjmolinas left a 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.

#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;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return (length_exceeded)? ERROR_READLINE_EXCEEDED : curr_pos;
return (length_exceeded) ? ERROR_READLINE_EXCEEDED : curr_pos;

Copy link
Contributor Author

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 Show resolved Hide resolved
@@ -1,5 +1,5 @@
/*
* Copyright (C) 2009, Freie Universitaet Berlin (FUB).
* Copyright (C) 2020 Freie Universität Berlin
Copy link
Contributor

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?

Copy link
Contributor Author

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

Copy link
Contributor

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

sys/shell/shell.c Show resolved Hide resolved
sys/shell/shell.c Show resolved Hide resolved
sys/shell/shell.c Show resolved Hide resolved
@fjmolinas fjmolinas requested a review from kaspar030 March 2, 2020 09:13
@fjmolinas fjmolinas added CI: disable test cache If set, CI will always run all tests regardless of whether they have been run successfully before CI: run tests If set, CI server will run tests on hardware for the labeled PR labels Mar 2, 2020
@fjmolinas
Copy link
Contributor

Since shell is used in a lot of tests I will trigger running all tests to be sure.

Copy link
Contributor

@fjmolinas fjmolinas left a 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.

Comment on lines 93 to 94
# looks like the nrf52dk runs in to undefined behaviour when sending more
# than 64 bytes over UART
Copy link
Contributor

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:

Suggested change
# 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.

child.sendline(cmd)
for line in expected:
child.expect_exact(line)


def check_startup(child):
child.expect('test_shell.\r\n')
Copy link
Contributor

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)

Suggested change
child.expect('test_shell.\r\n')
child.sendline(CONTROL_C)
child.expect_exact(PROMPT)

Copy link
Contributor Author

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 ^^

Copy link
Contributor Author

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 ?

break;

case 0:
puts("shell: line is empty");
Copy link
Contributor

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.

Suggested change
puts("shell: line is empty");

sys/shell/shell.c Show resolved Hide resolved
@HendrikVE HendrikVE requested a review from aabadie as a code owner March 4, 2020 12:00
@fjmolinas
Copy link
Contributor

Ok, so the CI has some failed tests, but all of them are timeouts for nrf52dk.

I think they are unrelated to your changes. But we did change the terminal to use socat instead of picocom, and I wonder if that change caused instability for nrf52dk? I would say your changes are indeed unrelated to those failures though. The failed tests have not been the same in the different runs either. And I've seen that on other PR's as well.

I will need to investigate that. Because IMO it might be related to the change to socat. But this might as well just be exposing a bug in nrf52dk. If for some reason we are forced to change back to picocom we can remove theassert on the garbage test, until we figure things out. but lets not delay this any further.

@fjmolinas fjmolinas added CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR and removed CI: run tests If set, CI server will run tests on hardware for the labeled PR CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR CI: disable test cache If set, CI will always run all tests regardless of whether they have been run successfully before labels Mar 28, 2020
jcarrano and others added 9 commits March 30, 2020 12:26
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 <hendrik.ve@fu-berlin.de>
Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>
Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>
Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>
Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>
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 <j.carrano@fu-berlin.de>
Co-authored-by: Juan Carrano <j.carrano@fu-berlin.de>
@fjmolinas
Copy link
Contributor

@HendrikVE I rebased and fixed Makefile.ci, I pushed directly to your branch. I hope that is OK.

fixed shell is too big for atmega32u4 based boards
Copy link
Contributor

@fjmolinas fjmolinas left a 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.

@fjmolinas
Copy link
Contributor

GO!, Thanks for the good work and the patience @HendrikVE! as well as taking over for @jcarrano

@fjmolinas fjmolinas merged commit e738508 into RIOT-OS:master Mar 30, 2020
@HendrikVE
Copy link
Contributor Author

Thank you very much for your review @fjmolinas, I really appreciate that! Also thanks @jcarrano for your initial work ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: sys Area: System Area: tests Area: tests and testing framework CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Type: bug The issue reports a bug / The PR fixes a bug (including spelling errors) Type: cleanup The issue proposes a clean-up / The PR cleans-up parts of the codebase / documentation Type: enhancement The issue suggests enhanceable parts / The PR enhances parts of the codebase / documentation
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants