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: add XFA support #16061

Merged
merged 4 commits into from
Mar 9, 2021
Merged

sys/shell: add XFA support #16061

merged 4 commits into from
Mar 9, 2021

Conversation

kaspar030
Copy link
Contributor

Contribution description

This PR adds a macro that allows adding shell commands using a cross file array.

It basically allows this to be put in any file:

#include "shell.h"
static int _my_command(int argc, char **argv) {
 // ...
}

SHELL_COMMAND(my_command, "my command help text", _my_command);

Testing procedure

This PR extends the tests/shell test scripts. Running this on some more platforms (AVR, RISC-V, ...) would be helpful!
Otherwise, please give feedback on the integration / usage.

Issues/PRs references

First user of XFA.

@kaspar030 kaspar030 added 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 Area: sys Area: System labels Feb 22, 2021
sys/include/shell.h Outdated Show resolved Hide resolved
sys/shell/shell.c Show resolved Hide resolved
sys/shell/shell.c Show resolved Hide resolved
miri64
miri64 previously requested changes Feb 22, 2021
sys/include/shell.h Outdated Show resolved Hide resolved
sys/shell/shell.c Outdated Show resolved Hide resolved
sys/shell/shell.c Outdated Show resolved Hide resolved
sys/shell/shell.c Outdated Show resolved Hide resolved
sys/shell/shell.c Outdated Show resolved Hide resolved
@kaspar030
Copy link
Contributor Author

I merged the IS_USED suggestions (they're in a fixup now).

@kaspar030
Copy link
Contributor Author

Somehow the IS_USED make this a bit messy, as the top-level definition is either always there or not available for within the IS_USED blocks. @miri64 do you mind if I revert that?

@miri64
Copy link
Member

miri64 commented Feb 23, 2021

Somehow the IS_USED make this a bit messy, as the top-level definition is either always there or not available for within the IS_USED blocks. @miri64 do you mind if I revert that?

I am not sure what you mean by "top-level definition" or how IS_USED() makes things more messy than using defined() or #ifdef.

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

Do you mean this?

sys/shell/shell.c Outdated Show resolved Hide resolved
sys/shell/shell.c Outdated Show resolved Hide resolved
Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

Alternatively, this would also work, if that is less messy in your opinion but still be within the coding conventions.

sys/shell/shell.c Outdated Show resolved Hide resolved
sys/shell/shell.c Outdated Show resolved Hide resolved
@kaspar030
Copy link
Contributor Author

I am not sure what you mean by "top-level definition" or how IS_USED() makes things more messy than using defined() or #ifdef.

I mean this:

 43 #if IS_USED(MODULE_SHELL_COMMAND_XFA)                                                                                          
 44 /* define shell command cross file array */                                                                                     45 XFA_INIT_CONST(shell_command_t*, shell_commands_xfa);                                                                          
 46 #endif                                                                                                                         

I am not sure what you mean by "top-level definition" or how IS_USED() makes things more messy than using defined() or #ifdef.

I had used C if instead of preprocessor if whithin a function, which failed because it was missing a file-level definition (which is also behind preprocessor #if).

@miri64 miri64 dismissed their stale review February 23, 2021 08:35

LGTM from my side now. I am a bit wary about an optional feature extension (shell_commands_xfa) being added to the main test for the base feature (shell), but it is not a blocking thing for me. What do @HendrikVE or @fjmolinas (as the people who last worked on that test) think about this?

@miri64 miri64 requested a review from HendrikVE February 23, 2021 08:36
@miri64
Copy link
Member

miri64 commented Feb 23, 2021

I am a bit wary about an optional feature extension (shell_commands_xfa) being added to the main test for the base feature (shell), but it is not a blocking thing for me. What do @HendrikVE or @fjmolinas (as the people who last worked on that test) think about this?

To make things perfectly clear, this is just about moving the tests introduced here to their own application.

@kaspar030
Copy link
Contributor Author

To make things perfectly clear, this is just about moving the tests introduced here to their own application.

"just"

How about we make this un-optional again. This is supposed to be a huge improvement in how we organize code. We don't expect any problems. I tagged this "experimental" because XFA is kinda new and the API might change. I don't want to dance around this by IS_USED and a seperate test application.

@miri64 do you see something wrong with the general approach?

If not, again, I'd rather have this non-optional and get maximum exposure (fail fast), so we quickly see if the approach is viable.

@miri64
Copy link
Member

miri64 commented Feb 23, 2021

How about we make this un-optional again. This is supposed to be a huge improvement in how we organize code. We don't expect any problems. I tagged this "experimental" because XFA is kinda new and the API might change. I don't want to dance around this by IS_USED and a seperate test application.

Again, I don't mind it really to be in there. It just is my inner alarm bells ringing adding an (optional) experimental feature to what seems to me like a very central test (after all the shell is very important to our testing).

@miri64 do you see something wrong with the general approach?

Nope.

If not, again, I'd rather have this non-optional and get maximum exposure (fail fast), so we quickly see if the approach is viable.

Again, IMHO this can be merged as is, I just want some more input by people who actually worked with the shell more in-depth. If there is no problem from there side or no input, this can go in ASAP.

@kaspar030
Copy link
Contributor Author

again, I'd rather have this non-optional and get maximum exposure (fail fast), so we quickly see if the approach is viable.

Let's not hide this but expose it to the max, so we can have confidence at the end of the release cycle that the approach is viable.

@chrysn
Copy link
Member

chrysn commented Feb 23, 2021

While just familiarizing myself with XFA I support this being nonoptional. Fewer pseudomodules, less ifdef, and if XFA does as I remember it being advertised, as long as nothing hooks in it's a no-op (as in absent, not as in the ASM instruction) when built.

@kaspar030
Copy link
Contributor Author

and if XFA does as I remember it being advertised, as long as nothing hooks in it's a no-op (as in absent, not as in the ASM instruction) when built.

Hm, did we advertize that? I think the loops iterating XFAs will not optimize out, as the array lengths are determined at runtime.

@miri64
Copy link
Member

miri64 commented Feb 23, 2021

Fewer pseudomodules, less ifdef, and if XFA does as I remember it being advertised, as long as nothing hooks in it's a no-op (as in absent, not as in the ASM instruction) when built.

Mh... but doesn't this make it problematic when a user expects it to be there, but it isn't? With a pseudomodule we have at least a chance to warn the user about missing functionality.

@kaspar030
Copy link
Contributor Author

I realized I didn't make the shell commands defined by SHELL_COMMANDS() "const", so they ended up in RAM. Latest commit fixes that.

@kaspar030
Copy link
Contributor Author

  • squashed

@fjmolinas would you give this another test run? I added a "const" in the macro which should get some testing...

@kaspar030 kaspar030 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 Mar 2, 2021
@fjmolinas
Copy link
Contributor

* squashed

@fjmolinas would you give this another test run? I added a "const" in the macro which should get some testing...

All good, I had a failure on nucleo-l433rc but that failures is in master as well.

Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

Only a minor comment left. Please squash.

tests/shell/main.c Outdated Show resolved Hide resolved
@miri64 miri64 added Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines labels Mar 9, 2021
Copy link
Member

@miri64 miri64 left a comment

Choose a reason for hiding this comment

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

ACK, this PR was previously tested by @fjmolinas and retested after the latest rework. If Murdock is happy, this can go in.

@kaspar030 kaspar030 merged commit 010ba56 into RIOT-OS:master Mar 9, 2021
@kaspar030 kaspar030 deleted the xfa_shell branch March 9, 2021 13:47
@kaspar030
Copy link
Contributor Author

Thanks everyone!

@chrysn
Copy link
Member

chrysn commented Apr 2, 2021

Just for better understanding this: Why are the pointers to the command structs kept in XFA, and nit the command structs right away? Seems to me like a useless indirection, but maybe I missed the reason in the discussion.

@kaspar030 kaspar030 added this to the Release 2021.04 milestone Apr 23, 2021
@kaspar030 kaspar030 added the Release notes: added Set on PRs that have been processed into the release notes for the current release. label Apr 28, 2021
@kaspar030
Copy link
Contributor Author

Just for better understanding this: Why are the pointers to the command structs kept in XFA, and nit the command structs right away? Seems to me like a useless indirection, but maybe I missed the reason in the discussion.

hm, I didn't think much about this. I think both are fine. keeping just pointers in XFA makes the size of the shell command thingie show up together with the .data of the module defining it. And, the xfa itself has to be volatile, whereas the data pointed to doesn't.

Would changing this make anything easier?

@chrysn
Copy link
Member

chrysn commented Feb 16, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: sys Area: System CI: ready for build If set, CI server will compile all applications for all available boards for the labeled PR Release notes: added Set on PRs that have been processed into the release notes for the current release. Reviewed: 1-fundamentals The fundamentals of the PR were reviewed according to the maintainer guidelines Reviewed: 2-code-design The code design of the PR was reviewed according to the maintainer guidelines Reviewed: 3-testing The PR was tested according to the maintainer guidelines Reviewed: 4-code-style The adherence to coding conventions by the PR were reviewed according to the maintainer guidelines Reviewed: 5-documentation The documentation details of the PR were reviewed according to the maintainer guidelines 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.

6 participants