summaryrefslogtreecommitdiff
path: root/test/hush
AgeCommit message (Collapse)Author
9 dayscmd: test: add bug-compatibility special case for 'test -n'Rasmus Villemoes
It turns out that there is lots of code in the wild, including in the U-Boot tree itself, which used to rely on test -n $somevar to yield false when $somevar is not defined or empty. See for example all the occurrences of 'test -n $fdtfile'. That was really only a quirk of the implementation that refused calls with argc < 3, and not because it was interpreted as test -n "$somevar" which is how this should be spelled. While not exactly conforming to POSIX, we can accomodate such scripts by special-casing a single argument "-n" to be interpreted as if it comes from code as above with empty $somevar. Since we only just added the ability to test a string for emptiness using the single-argument form, it is very unlikely that there is code doing test "$str" which would now fail if $str happens to be exactly "-n"; such a test should really always be spelled test -n "$str" Fixes: 8b0619579b2 ("cmd: test: fix handling of single-argument form of test") Reported-by: Franz Schnyder <[email protected]> Signed-off-by: Rasmus Villemoes <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2026-03-25cmd: test: fix handling of single-argument form of testRasmus Villemoes
POSIX states that 0 arguments: Exit false (1). 1 argument: Exit true (0) if $1 is not null; otherwise, exit false. and at least bash and busybox sh behave that way. The current 'argc < 3' does the right thing for a non-existing or empty argv[1], but not for a non-empty argv[1]. Fix that and add corresponding test cases. Signed-off-by: Rasmus Villemoes <[email protected]> Tested-by: Anshul Dalal <[email protected]>
2026-03-25test: add tests for left-bracket alias for 'test' commandRasmus Villemoes
Duplicate a few of the existing test cases, using the [ spelling, and also ensure that the presence of a matching ] as a separate and last argument is enforced. Signed-off-by: Rasmus Villemoes <[email protected]> Tested-by: Anshul Dalal <[email protected]>
2025-05-29global: Avoid indirect inclusion of <env.h> from <command.h>Tom Rini
The include file <command.h> does not need anything from <env.h>. Furthermore, include/env.h itself includes other headers which can lead to longer indirect inclusion paths. To prepare to remove <env.h> from <command.h> fix all of the places which had relied on this indirect inclusion to instead include <env.h> directly. Reviewed-by: Mattijs Korpershoek <[email protected]> # android, bcb Reviewed-by: Jerome Forissier <[email protected]> # spawn Signed-off-by: Tom Rini <[email protected]>
2025-01-24test: Drop the function for running hush testsSimon Glass
Use the new suite-runner to run these tests instead. Signed-off-by: Simon Glass <[email protected]>
2025-01-24test: Drop the _test suffix on linker listsSimon Glass
Most test suites have a _test suffix. This is not necessary as there is also a ut_ prefix. Drop the suffix so that (with future work) the suite name can be used as the linker-list name. Remove the suffix from the pytest regex as well, moving it to the top of the file, as it is a constant. Signed-off-by: Simon Glass <[email protected]>
2025-01-24test: Add newlines to hush-test messagesSimon Glass
A few messages lack a newline so the test output shows the next test-name on the same line. For example: Beware: this test sets local variable dollar_bar and dollar_quux and they cannot be unset!Test: hush_test_env_dollar: dollar.c This is confusing, so fix it. Signed-off-by: Simon Glass <[email protected]>
2024-10-29test/hush: Add CONFIG_CONSOLE_RECORD where requiredTom Rini
The "dollar" tests require CONFIG_CONSOLE_RECORD to be enabled so guard with that. Reviewed-by: Heinrich Schuchardt <[email protected]> Signed-off-by: Tom Rini <[email protected]>
2024-09-13Merge patch series "Bump new hush commits and fix old hush test behavior"Tom Rini
Francis Laniel <[email protected]> says: Hi! With this series, I bumped the new hush to get the latest commits from upstream. Also, I added back a reverted commit which goal was to fix a bad behavior in old hush test. I had to tweak a bit this commit, but everything worked both locally and in the CI.
2024-09-13test: hush: dollar: fix bugous behaviorIon Agorria
The dollar test was merged with bugous console behavior, and instead of fixing it, this behavior was just workarounded. This was done to keep compatibility with the existing behavior. It seems like without the fix the ut_assert_skipline(); didn't clear console and running ut_assert_skipline(); many times would give always OK. With e58bafc35fe3 ("lib: membuff: fix readline not returning line in case of overflow") the line is cleared correctly and next assert fails because now there is nothing to clean which is correct if we look the this a bit above the failing assert: if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { /* * For some strange reasons, the console is not empty after * running above command. * So, we reset it to not have side effects for other tests. */ console_record_reset_enable(); } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { ut_assert_console_end(); } Which further confirms that tests workaround the old problem and now that problem is fixed we can remove the whole if blocks and simply place ut_assert_console_end() right after ut_assert_skipline() without any conditional and will pass green. So this part of code goes from: ut_assert_skipline(); ut_assert_skipline(); if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { /* See above comments. */ console_record_reset_enable(); } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { ut_assert_console_end(); } to become: ut_assert_skipline(); if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { ut_assert_skipline(); } ut_assert_console_end(); The if block mentioned above that calls console_record_reset_enable() is completely removed as fixed by e58bafc35fe3. [flaniel: adapt second if] Signed-off-by: Ion Agorria <[email protected]> Signed-off-by: Svyatoslav Ryhel <[email protected]> Tested-by: Mattijs Korpershoek <[email protected]> Reviewed-by: Mattijs Korpershoek <[email protected]> Link: https://lore.kernel.org/r/[email protected] [mkorpershoek: reworded commit title] Signed-off-by: Mattijs Korpershoek <[email protected]> [flaniel: remove console_record_reset_enable() if] Signed-off-by: Francis Laniel <[email protected]>
2024-08-26test: hush: Use UTF_CONSOLE in testsSimon Glass
Set this flag rather than doing things manually in the test. Signed-off-by: Simon Glass <[email protected]> Reviewed-by: Mattijs Korpershoek <[email protected]>
2024-01-18Revert "test: hush: dollar: fix bugous behavior"Tom Rini
What we were doing here amounts to simplifying the code for the new hush parser, and the workarounds are required when using the old one. As we have returned to having the old parser be default for now, we must undo this so that the test passes again. This reverts commit 6c2f753f4ad3dcee60190949d1286736a6d51d17. Signed-off-by: Tom Rini <[email protected]>
2024-01-09test: hush: dollar: fix bugous behaviorIon Agorria
The dollar test was merged with bugous console behavior, and instead of fixing it, this behavior was just workarounded. It seems like without the fix the ut_assert_skipline(); didn't clear console and running ut_assert_skipline(); many times would give always OK. With lib: membuff: fix readline not returning line in case of overflow the line is cleared correctly and next assert fails because now there is nothing to clean which is correct if we look the this a bit above the failing assert: if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { /* * For some strange reasons, the console is not empty after * running above command. * So, we reset it to not have side effects for other tests. */ console_record_reset_enable(); } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { ut_assert_console_end(); } Which further confirms that tests workaround the old problem and now that problem is fixed we can remove the whole if blocks and simply place ut_assert_console_end() right after ut_assert_skipline() without any conditional and will pass green. So this part of code goes from: ut_assert_skipline(); ut_assert_skipline(); if (gd->flags & GD_FLG_HUSH_MODERN_PARSER) { /* See above comments. */ console_record_reset_enable(); } else if (gd->flags & GD_FLG_HUSH_OLD_PARSER) { ut_assert_console_end(); } to become: ut_assert_skipline(); ut_assert_console_end(); Same thing should be done with the if block mentioned above that calls console_record_reset_enable(). Signed-off-by: Ion Agorria <[email protected]> Signed-off-by: Svyatoslav Ryhel <[email protected]> Tested-by: Mattijs Korpershoek <[email protected]> Reviewed-by: Mattijs Korpershoek <[email protected]> Link: https://lore.kernel.org/r/[email protected] [mkorpershoek: reworded commit title] Signed-off-by: Mattijs Korpershoek <[email protected]>
2023-12-28Merge patch series "Modernize U-Boot shell"Tom Rini
Francis Laniel <[email protected]> says: During 2021 summer, Sean Anderson wrote a contribution to add a new shell, based on LIL, to U-Boot [1, 2]. While one of the goals of this contribution was to address the fact actual U-Boot shell, which is based on Busybox hush, is old there was a discussion about adding a new shell versus updating the actual one [3, 4]. So, in this series, with Harald Seiler, we updated the actual U-Boot shell to reflect what is currently in Busybox source code. Basically, this contribution is about taking a snapshot of Busybox shell/hush.c file (as it exists in commit 37460f5da) and adapt it to suit U-Boot needs. This contribution was written to be as backward-compatible as possible to avoid breaking the existing. So, the modern hush flavor offers the same as the actual, that is to say: 1. Variable expansion. 2. Instruction lists (;, && and ||). 3. If, then and else. 4. Loops (for, while and until). No new features offered by Busybox hush were implemented (e.g. functions). It is possible to change the parser at runtime using the "cli" command: => cli print old => cli set modern => cli print modern => cli set old The default parser is the old one. Note that to use both parser, you would need to set both CONFIG_HUSH_MODERN_PARSER and CONFIG_HUSH_OLD_PARSER. In terms of testing, new unit tests were added to ut to ensure the new behavior is the same as the old one and it does not add regression. Nonetheless, if old behavior was buggy and fixed upstream, the fix is then added to U-Boot [5]. In sandbox, all of these tests pass smoothly: => printenv board board=sandbox => ut hush Running 20 hush tests ... Failures: 0 => cli set modern => ut hush Running 20 hush tests ... Failures: 0 Thanks to the effort of Harald Seiler, I was successful booting a board: => printenv fdtfile fdtfile=amlogic/meson-gxl-s905x-libretech-cc.dtb => cli get old => boot ... root@lepotato:~# root@lepotato:~# reboot ... => cli set modern => cli get modern => printenv fdtfile fdtfile=amlogic/meson-gxl-s905x-libretech-cc.dtb => boot ... root@lepotato:~# This contribution indeed adds a lot of code and there were concern about its size [6, 7]. With regard to the amount of code added, the cli_hush_upstream.c is 13030 lines long but it seems a smaller subset is really used: gcc -D__U_BOOT__ -E common/cli_hush_upstream.c | wc -l 2870 Despite this, it is better to still have the whole upstream code for the sake of easing maintenance. With regard to memory size, I conducted some experiments for version 8 of this series and for a subset of arm64 boards and found the worst case to be 4K [8]. Tom Rini conducted more research on this and also found the increase to be acceptable [9]. If you want to review it - your review will really be appreciated - here are some information regarding the commits: * commits marked as "test:" deal with unit tests. * commit "cli: Add Busybox upstream hush.c file." copies Busybox shell/hush.c into U-Boot tree, this explain why this commit contains around 12000 additions. * commit "cli: Port Busybox 2021 hush to U-Boot." modifies previously added file to permit us to use this as new shell. The really good idea of #include'ing Busybox code into a wrapper file to define some particular functions while minimizing modifications to upstream code comes from Harald Seiler. * commit "cmd: Add new parser command" adds a new command which permits selecting parser at runtime. I am not really satisfied with the fact it calls cli_init() and cli_loop() each time the parser is set, so your reviews would be welcomed. * Other commits focus on enabling features we need (e.g. if).
2023-12-28test: hush: Fix loop tests for modern hushFrancis Laniel
Modifies return code got from while loop as modern hush always returns 0 from while loop. Reviewed-by: Simon Glass <[email protected]> Signed-off-by: Francis Laniel <[email protected]>
2023-12-28test: hush: Fix variable expansion tests for modern hushFrancis Laniel
Modifies the expected result for modern hush. Indeed, there were bugs in actual U-Boot hush which were fixed in upstream Busybox. As modern hush is based on upstream Busybox, these bugs no longer exist. Reviewed-by: Simon Glass <[email protected]> Signed-off-by: Francis Laniel <[email protected]>
2023-12-28test: hush: Fix instructions list tests for modern hushFrancis Laniel
Modifies the expected result for modern hush. Indeed, there were bugs in actual U-Boot hush which were fixed in upstream Busybox. As modern hush is based on upstream Busybox, these bugs no longer exist. Reviewed-by: Simon Glass <[email protected]> Signed-off-by: Francis Laniel <[email protected]>
2023-12-28test: hush: Test hush loopsFrancis Laniel
The added tests verifies correct behavior of for, while and until loops. Signed-off-by: Francis Laniel <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2023-12-28test: hush: Test hush commands listFrancis Laniel
Verifies behavior of commands separated by ';', '&&' and '||'. Signed-off-by: Francis Laniel <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2023-12-28test: hush: Test hush variable expansionFrancis Laniel
Verifies shell variables are replaced by their values. Reviewed-by: Simon Glass <[email protected]> Signed-off-by: Francis Laniel <[email protected]>
2023-12-28test: hush: Test hush if/elseFrancis Laniel
As asked in commit 9c6bf1715f6a ("test/py: hush_if_test: Add tests to cover octal/hex values"), this commit translates test_hush_if_test.py to a C test. Signed-off-by: Francis Laniel <[email protected]> Reviewed-by: Simon Glass <[email protected]>
2023-12-28test: Add framework to test hush behaviorFrancis Laniel
Introduce a new subcommand to ut: ut hush. For the moment, this command does nothing, future commits will add tests which will be run on command call. Note that CONFIG_HUSH_PARSER must be defined to compile this new subcommand. Signed-off-by: Francis Laniel <[email protected]> Reviewed-by: Simon Glass <[email protected]>