[PATCH 2/9] test: cmd/fdt: do not assume RNG device exists
Simon Glass
sjg at chromium.org
Fri Nov 14 13:44:08 CET 2025
Hi Heinrich,
On Sun, 9 Nov 2025 at 03:10, Heinrich Schuchardt
<heinrich.schuchardt at canonical.com> wrote:
>
> 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.
>
> Signed-off-by: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
> ---
> test/cmd/fdt.c | 20 ++++++++++++++++----
> 1 file changed, 16 insertions(+), 4 deletions(-)
>
> diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
> index a36f2dcdda8..b950123b6da 100644
> --- a/test/cmd/fdt.c
> +++ b/test/cmd/fdt.c
> @@ -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)));
But then this test isn't really making sure that the RNG code works.
We need to know whether there is supposed to be a device (as you do
below), rather than making the test vague.
For sandbox, we can assert that the device exists, so at least we keep
some coverage.
> + 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 = ");
> --
> 2.51.0
>
Regards,
Simon
More information about the U-Boot
mailing list