[PATCH 3/9] test: boot: bootm: Check ordinary failures

Daniel Golle daniel at makrotopia.org
Fri Nov 13 16:10:09 PST 2026


Check that a failing bootm subcommand returns -ENOSYS with the expected
console message. Force a ramdisk allocation failure and check that it
returns -ENOMEM.

Signed-off-by: Daniel Golle <daniel at makrotopia.org>
---
 test/boot/bootm.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 53 insertions(+)

diff --git a/test/boot/bootm.c b/test/boot/bootm.c
index ed60094f3c1..5f013298f8c 100644
--- a/test/boot/bootm.c
+++ b/test/boot/bootm.c
@@ -7,6 +7,8 @@
 
 #include <bootm.h>
 #include <env.h>
+#include <errno.h>
+#include <malloc.h>
 #include <asm/global_data.h>
 #include <test/test.h>
 #include <test/ut.h>
@@ -249,3 +251,54 @@ static int bootm_test_subst_both(struct unit_test_state *uts)
 	return 0;
 }
 BOOTM_TEST(bootm_test_subst_both, 0);
+
+/* Test that a failing subcommand returns its error to the caller */
+static int bootm_test_subcmd_fail(struct unit_test_state *uts)
+{
+	struct bootm_info bmi;
+	int old_state;
+	u8 old_os;
+	int ret;
+
+	bootm_init(&bmi);
+	old_state = bmi.images->state;
+	old_os = bmi.images->os.os;
+	bmi.images->os.os = IH_OS_LINUX;
+
+	ret = bootm_run_states(&bmi, BOOTM_STATE_OS_BD_T);
+
+	bmi.images->os.os = old_os;
+	bmi.images->state = old_state;
+
+	ut_asserteq(-ENOSYS, ret);
+	ut_assert_nextline("subcommand failed (err=%d)", -ENOSYS);
+	ut_assert_console_end();
+
+	return 0;
+}
+BOOTM_TEST(bootm_test_subcmd_fail, UTF_CONSOLE);
+
+static int bootm_test_ramdisk_nomem(struct unit_test_state *uts)
+{
+	ulong initrd_start, initrd_end;
+	char *old_high, *high;
+	int ret;
+
+	high = env_get("initrd_high");
+	old_high = high ? strdup(high) : NULL;
+	ut_assert(!high || old_high);
+	ut_assertok(env_set_hex("initrd_high", 0));
+
+	ret = boot_ramdisk_high(1, ~0UL, &initrd_start, &initrd_end);
+
+	ut_assertok(env_set("initrd_high", old_high));
+	free(old_high);
+
+	ut_asserteq(-ENOMEM, ret);
+	ut_assert_nextline("ramdisk - allocation error");
+	ut_assert_console_end();
+
+	return 0;
+}
+
+BOOTM_TEST(bootm_test_ramdisk_nomem, UTF_CONSOLE);
-- 
2.56.0



More information about the openwrt-devel mailing list