]> git.ipfire.org Git - thirdparty/u-boot.git/commitdiff
test: cmd/fdt: do not assume RNG device exists
authorHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Sun, 9 Nov 2025 10:10:03 +0000 (11:10 +0100)
committerHeinrich Schuchardt <heinrich.schuchardt@canonical.com>
Fri, 21 Nov 2025 18:18:22 +0000 (19:18 +0100)
In fdt_test_chosen() currently we test if DM_RNG is configured.
CONFIG_DM_RNG=y does not imply that a RNG device actually exists.
For instance QEMU may be called with -device virtio-rng-device or not.
The current test framework evicts the virtio RNG device even if QEMU is
called with -device virtio-rng-device.

In the fdt_test_chosen() check if a RNG device exists.
Ignore 'No RNG device' messages.

Acked-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt@canonical.com>
test/cmd/fdt.c

index a36f2dcdda8c65896f7c6d708833a1e9ab86cf00..b950123b6da9dec15542243149c07d770880f248 100644 (file)
@@ -10,6 +10,7 @@
 #include <fdt_support.h>
 #include <mapmem.h>
 #include <asm/global_data.h>
+#include <dm/uclass.h>
 #include <linux/libfdt.h>
 #include <test/ut.h>
 
@@ -1267,6 +1268,7 @@ static int fdt_test_chosen(struct unit_test_state *uts)
 {
        const char *env_bootargs = env_get("bootargs");
        char fdt[8192];
+       struct udevice *dev;
        ulong addr;
 
        ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt), &addr));
@@ -1280,11 +1282,16 @@ static int fdt_test_chosen(struct unit_test_state *uts)
        /* Test add new chosen node without initrd */
        ut_assertok(run_commandf("fdt chosen"));
        ut_assertok(run_commandf("fdt print /chosen"));
-       ut_assert_nextline("chosen {");
+       ut_assert(0 < console_record_readline(uts->actual_str,
+                                             sizeof(uts->actual_str)));
+       if (!strcmp("No RNG device", uts->actual_str))
+               ut_assert(0 < console_record_readline(uts->actual_str,
+                                                     sizeof(uts->actual_str)));
+       ut_asserteq_str("chosen {", uts->actual_str);
        ut_assert_nextlinen("\tu-boot,version = "); /* Ignore the version string */
        if (env_bootargs)
                ut_assert_nextline("\tbootargs = \"%s\";", env_bootargs);
-       if (IS_ENABLED(CONFIG_DM_RNG) &&
+       if (!uclass_get_device(UCLASS_RNG, 0, &dev) &&
            !IS_ENABLED(CONFIG_MEASURED_BOOT) &&
            !IS_ENABLED(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT))
                ut_assert_nextlinen("\tkaslr-seed = ");
@@ -1294,7 +1301,12 @@ static int fdt_test_chosen(struct unit_test_state *uts)
        /* Test add new chosen node with initrd */
        ut_assertok(run_commandf("fdt chosen 0x1234 0x5678"));
        ut_assertok(run_commandf("fdt print /chosen"));
-       ut_assert_nextline("chosen {");
+       ut_assert(0 < console_record_readline(uts->actual_str,
+                                             sizeof(uts->actual_str)));
+       if (!strcmp("No RNG device", uts->actual_str))
+               ut_assert(0 < console_record_readline(uts->actual_str,
+                                                     sizeof(uts->actual_str)));
+       ut_asserteq_str("chosen {", uts->actual_str);
        ut_assert_nextline("\tlinux,initrd-end = <0x%08x 0x%08x>;",
                           upper_32_bits(0x1234 + 0x5678 - 1),
                           lower_32_bits(0x1234 + 0x5678 - 1));
@@ -1303,7 +1315,7 @@ static int fdt_test_chosen(struct unit_test_state *uts)
        ut_assert_nextlinen("\tu-boot,version = "); /* Ignore the version string */
        if (env_bootargs)
                ut_assert_nextline("\tbootargs = \"%s\";", env_bootargs);
-       if (IS_ENABLED(CONFIG_DM_RNG) &&
+       if (!uclass_get_device(UCLASS_RNG, 0, &dev) &&
            !IS_ENABLED(CONFIG_MEASURED_BOOT) &&
            !IS_ENABLED(CONFIG_ARMV8_SEC_FIRMWARE_SUPPORT))
                ut_assert_nextlinen("\tkaslr-seed = ");