Skip to content

sys/shell: terminate shell on Ctrl-D#14345

Merged
fjmolinas merged 2 commits intoRIOT-OS:masterfrom
HendrikVE:pr/shell-exit-on-ctrl-d
Oct 22, 2020
Merged

sys/shell: terminate shell on Ctrl-D#14345
fjmolinas merged 2 commits intoRIOT-OS:masterfrom
HendrikVE:pr/shell-exit-on-ctrl-d

Conversation

@HendrikVE
Copy link
Contributor

Ctrl-D was not caught in a special case so it was interpreted as a standard character. Handle it now the same way like EOF and terminate the shell instance.

Related to #10788

@HendrikVE HendrikVE added Area: sys Area: System Area: tests Area: tests and testing framework 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 labels Jun 24, 2020
Comment on lines +85 to 112
shell_run_once(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);

puts("shell exited");

/* Restart the shell after the previous one exits, so that we can test
* Ctrl-D exit */
shell_run(shell_commands, line_buf, SHELL_DEFAULT_BUFSIZE);
Copy link
Contributor

Choose a reason for hiding this comment

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

I would run this in a loop instead.

Copy link
Contributor

Choose a reason for hiding this comment

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

Also in native I get an infinite loop, can we do something simililar as for #13675?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Two different behaviours are tested here. When we do ctrl-d in shell_run_once the execution returns to main of the test program. If we do ctrl-d in shell_run the shell will be respawn. I added a second test case for ctrl-d and comments to emphasize this behaviour. Do you still get an infinite loop?

@fjmolinas
Copy link
Contributor

Sorry @HendrikVE I completely lost track of this one, can you rebase?

@HendrikVE HendrikVE force-pushed the pr/shell-exit-on-ctrl-d branch from b0d99f8 to 47efe80 Compare October 12, 2020 11:16
@HendrikVE
Copy link
Contributor Author

I rebased this PR :)

@fjmolinas
Copy link
Contributor

Solves the issue, please squash @HendrikVE!

@fjmolinas fjmolinas added the CI: run tests If set, CI server will run tests on hardware for the labeled PR label Oct 21, 2020
@HendrikVE HendrikVE force-pushed the pr/shell-exit-on-ctrl-d branch from 47efe80 to 8b908e2 Compare October 21, 2020 09:39
('echo \t tabs\t\t processed \t\tlike\t \t\tspaces', '"echo""tabs""processed""like""spaces"'),

# test long line
# test unknown commands
Copy link
Contributor

Choose a reason for hiding this comment

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

This change is unrelated and the initial comment was correct (the purpose of the test line 58 is to test long lines). But the new comment could be kept and moved before line 62 (since it makes sense for this one).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not really testing long lines here, because these test strings have a fixed length. The test done by calling check_line_exceeded is better suited for this purpose, because it makes use of the shell's buffer size automatically and writes characters beyond the buffer size. Maybe we should replace the long sequence of numbers by a shorter one or by something completely different instead?

Copy link
Contributor

@aabadie aabadie Oct 21, 2020

Choose a reason for hiding this comment

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

The test done by calling check_line_exceeded is better suited for this purpose, because it makes use of the shell's buffer size automatically and writes characters beyond the buffer size.

If this case is already covered by another test then I would suggest to remove this case and only keep 'unknown_command' one. @fjmolinas what do you think ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Well its still an unrelated change, even if it makes sense, maybe you could split those into a separate commit @HendrikVE ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's in a separate commit now

@benpicco benpicco removed the CI: run tests If set, CI server will run tests on hardware for the labeled PR label Oct 21, 2020
@benpicco
Copy link
Contributor

Only unrelated failures:

Ctrl-D was not caught in a special case so it was interpreted as
a standard character. Handle it now the same way like EOF and
terminate the shell instance.
One test was removed, because the intended test case is
already covered by check_line_exceeded
@HendrikVE HendrikVE force-pushed the pr/shell-exit-on-ctrl-d branch from 8b908e2 to 7a775ec Compare October 21, 2020 15:45
@fjmolinas
Copy link
Contributor

Looks good, I'll do a small test run and ACK.

@fjmolinas
Copy link
Contributor

I ran the test on a collection of boards, only failure on arduino-mega2560, re ran and no issues https://ci.inria.fr/ci-riot-tribe/job/build-pipeline.jk/196/artifact/.

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.

@fjmolinas fjmolinas merged commit 5e7ee01 into RIOT-OS:master Oct 22, 2020
@HendrikVE HendrikVE deleted the pr/shell-exit-on-ctrl-d branch December 28, 2021 22:35
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: 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.

4 participants