[PATCH v3 2/2] test: cmd: add a test for bootd
Mehmet Fide <[email protected]>
| Newsgroups | gmane.comp.boot-loaders.u-boot.general,gmane.comp.boot-loaders.u-boot |
|---|---|
| Message-ID | <[email protected]> |
From: Mehmet Fide <[email protected]> There is no test for the bootd command. Add one to the cmd suite that covers the documented behaviour: bootd and its "boot" alias run the command held in the bootcmd environment variable, and the return value of bootd is the one of that command. Also assert the recursion guard in cmd_process(), which is part of the code bootd carries. Reviewed-by: Simon Glass <[email protected]> Signed-off-by: Mehmet Fide <[email protected]> --- Changes in v3: - Replace the unknown-command negative case with "false". The deliberate "Unknown command" console output matches test.py's unknown_command bad pattern, so every test.py CI job failed the test (reported by Tom Rini). "false" fails without printing; that section is now gated on CONFIG_HUSH_PARSER, which is what builds cmd/test.c providing the command. - Trim the comments to the style of the neighbouring tests. test/cmd/Makefile | 1 + test/cmd/bootd.c | 58 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 test/cmd/bootd.c diff --git a/test/cmd/Makefile b/test/cmd/Makefile index 8d36463879d..e734933d5f7 100644 --- a/test/cmd/Makefile +++ b/test/cmd/Makefile @@ -17,6 +17,7 @@ ifdef CONFIG_CONSOLE_RECORD obj-$(CONFIG_CMD_ACPI) += acpi.o endif obj-$(CONFIG_CMD_BDI) += bdinfo.o +obj-$(CONFIG_CMD_BOOTD) += bootd.o obj-$(CONFIG_CMD_CONFIG) += config.o obj-$(CONFIG_COREBOOT_SYSINFO) += coreboot.o obj-$(CONFIG_CMD_FDT) += fdt.o diff --git a/test/cmd/bootd.c b/test/cmd/bootd.c new file mode 100644 index 00000000000..fb08eb358a6 --- /dev/null +++ b/test/cmd/bootd.c @@ -0,0 +1,58 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Tests for the bootd command + * + * Copyright 2026 Mehmet Fide <[email protected]> + */ + +#include <command.h> +#include <console.h> +#include <env.h> +#include <malloc.h> +#include <test/cmd.h> +#include <test/test.h> +#include <test/ut.h> + +static int cmd_bootd_test(struct unit_test_state *uts) +{ + char *const argv[] = { "bootd", NULL }; + const char *old = env_get("bootcmd"); + char *saved = NULL; + int repeatable = 0; + + if (old) { + saved = strdup(old); + ut_assertnonnull(saved); + } + + /* bootd runs the command held in bootcmd */ + ut_assertok(env_set("bootcmd", "echo hello bootd")); + ut_assertok(run_command("bootd", 0)); + ut_assert_nextline("hello bootd"); + ut_assert_console_end(); + + /* the "boot" alias does the same */ + ut_assertok(run_command("boot", 0)); + ut_assert_nextline("hello bootd"); + ut_assert_console_end(); + + /* the return value is the one of the command in bootcmd */ + if (IS_ENABLED(CONFIG_HUSH_PARSER)) { + ut_assertok(env_set("bootcmd", "false")); + ut_asserteq(1, run_command("bootd", 0)); + ut_assert_console_end(); + } + + /* a bootd reached from bootd is refused rather than recursing */ + ut_assertok(env_set("bootcmd", "echo bootcmd must not run")); + ut_asserteq(CMD_RET_FAILURE, + cmd_process(CMD_FLAG_BOOTD, 1, argv, &repeatable, NULL)); + ut_assert_nextline("'bootd' recursion detected"); + ut_assert_console_end(); + + ut_assertok(env_set("bootcmd", saved)); + free(saved); + + return 0; +} +CMD_TEST(cmd_bootd_test, UTF_CONSOLE); -- 2.54.0