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: cmds_json builtin command #20964

Merged
merged 2 commits into from
Nov 13, 2024

Conversation

maribu
Copy link
Member

@maribu maribu commented Nov 7, 2024

Contribution description

This adds the cmds_json builtin command that does the same as help, but provides a machine readable JSON rather than a human readable table. It is only provided when the (pseudo-)module shell_json is used.

This in turn is used in a second commit in tests/rust_libs. It would otherwise depend on the order in which shell commands are printed, which at least for XFA shell commands (as provided by rust) is not the case.

Testing procedure

Green CI: The new builtin command is tested implicitly in tests/rust_libs.

Issues/PRs references

Needed to get #20958 passed.

@maribu maribu requested review from chrysn and removed request for miri64, aabadie, leandrolanzieri and MichelRottleuthner November 7, 2024 16:44
@github-actions github-actions bot added Area: tests Area: tests and testing framework Area: build system Area: Build system Area: sys Area: System labels Nov 7, 2024
@maribu maribu 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 and removed Area: build system Area: Build system labels Nov 7, 2024
'end_test': 'ends a test',
'echo': 'prints the input command',
'empty': 'print nothing on command',
'periodic': 'periodically print command',
Copy link
Member Author

Choose a reason for hiding this comment

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

This was not tested against before. The way it was implemented before it would skip over lines in-between the given list of output lines. The test is now a bit stricter in this regard.

@riot-ci
Copy link

riot-ci commented Nov 7, 2024

Murdock results

✔️ PASSED

b605347 tests/rust_libs: use shell_builtin_cmd_help_json

Success Failures Total Runtime
10215 0 10215 16m:54s

Artifacts

@maribu maribu force-pushed the tests/rust_libs/improve-test-robustness branch from 6ad4a52 to c46c350 Compare November 8, 2024 08:03
@github-actions github-actions bot added the Area: build system Area: Build system label Nov 8, 2024
Copy link
Contributor

@mguetschow mguetschow left a comment

Choose a reason for hiding this comment

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

Ah, found the right PR for my comments :P CC @Teufelchen1

@@ -463,6 +463,7 @@ PSEUDOMODULES += shell_cmd_udptty
PSEUDOMODULES += shell_cmd_vfs
PSEUDOMODULES += shell_cmds_default
PSEUDOMODULES += shell_hooks
PSEUDOMODULES += shell_json
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be rather shell_cmd_cmds_json to match the pattern of other shell command modules?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think that can be confusing, as the others are all externally implemented shell commands (they have a description and show up in help). This is however implemented as a builtin (see below for why) and behaves differently.

sys/include/shell.h Outdated Show resolved Hide resolved
Comment on lines 378 to 381
else if (IS_USED(MODULE_SHELL_JSON) && !strcmp("cmds_json", argv[0])) {
print_commands_json(command_list);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Any reason apart from historical ones why both help and the new command are not defined using SHELL_COMMAND? This would avoid the special casing here and automatically include both in their outputs.

Copy link
Member Author

Choose a reason for hiding this comment

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

The issue is that the need to access the first parameter of shell_run_forever(). Externally implemented ones would only be able to list XFA based shell commands without accesa to that argument.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh, I see! So it's an interesting mix of statically available xfa shell command definitions and a dynamically passeable command list at runtime via shell_run_forever (and friends?).

Can you think of use cases where it is actually necessary to have the dynamic command list? Otherwise we could store it upon call to shell_run_forever as a global state.

Copy link
Member Author

Choose a reason for hiding this comment

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

I guess that would probably be fine. I think eventually the use of non-XFA shell commands will pass away over time.

Copy link
Contributor

Choose a reason for hiding this comment

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

But maybe something for another PR, I guess 👍

tests/rust_libs/tests/01-run.py Show resolved Hide resolved
@mguetschow
Copy link
Contributor

The CI complains about missing newlines in the python script: https://github.com/RIOT-OS/RIOT/actions/runs/11748909732/job/32734016006?pr=20964

This command does the same as `help`, but provides a machine readable
JSON rather than a human readable table. It is only provided when the
(pseudo-)module `shell_builtin_cmd_help_json` is used.
This increases the robustness of the test by not relying on the
order shell commands are printed in. At least for XFA based shell
commands, there is no guarantee in which order they will be shown in
the help.
@maribu maribu force-pushed the tests/rust_libs/improve-test-robustness branch from 9cead8a to b605347 Compare November 11, 2024 21:05
Copy link
Contributor

@mguetschow mguetschow 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 this!

@mguetschow mguetschow enabled auto-merge November 12, 2024 08:53
@mguetschow mguetschow added this pull request to the merge queue Nov 12, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Nov 12, 2024
@maribu maribu added this pull request to the merge queue Nov 13, 2024
Merged via the queue into RIOT-OS:master with commit b9ba3ee Nov 13, 2024
28 checks passed
@maribu
Copy link
Member Author

maribu commented Nov 13, 2024

Thx :)

@maribu maribu deleted the tests/rust_libs/improve-test-robustness branch November 13, 2024 10:13
@MrKevinWeiss MrKevinWeiss added this to the Release 2025.01 milestone Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: build system Area: Build system 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