[PATCH v6 7/7] test: rng: Add a UT testcase for the rng command
Ilias Apalodimas
ilias.apalodimas at linaro.org
Wed Jul 6 15:32:28 CEST 2022
On Mon, Jul 04, 2022 at 07:04:44PM +0530, Sughosh Ganu wrote:
> The 'rng' command dumps a number of random bytes on the console. Add a
> set of tests for the 'rng' command. The test function performs basic
> sanity testing of the command.
>
> Since a unit test is being added for the command, enable it by default
> in the sandbox platforms.
>
> Reviewed-by: Simon Glass <sjg at chromium.org>
> Signed-off-by: Sughosh Ganu <sughosh.ganu at linaro.org>
> ---
> cmd/Kconfig | 1 +
> test/dm/rng.c | 29 +++++++++++++++++++++++++++++
> 2 files changed, 30 insertions(+)
>
> diff --git a/cmd/Kconfig b/cmd/Kconfig
> index 09193b61b9..eee5d44348 100644
> --- a/cmd/Kconfig
> +++ b/cmd/Kconfig
> @@ -1916,6 +1916,7 @@ config CMD_GETTIME
> config CMD_RNG
> bool "rng command"
> depends on DM_RNG
> + default y if SANDBOX
> select HEXDUMP
> help
> Print bytes from the hardware random number generator.
> diff --git a/test/dm/rng.c b/test/dm/rng.c
> index 5b34c93ed6..6d1f68848d 100644
> --- a/test/dm/rng.c
> +++ b/test/dm/rng.c
> @@ -25,3 +25,32 @@ static int dm_test_rng_read(struct unit_test_state *uts)
> return 0;
> }
> DM_TEST(dm_test_rng_read, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
> +
> +/* Test the rng command */
> +static int dm_test_rng_cmd(struct unit_test_state *uts)
> +{
> + struct udevice *dev;
> +
> + ut_assertok(uclass_get_device(UCLASS_RNG, 0, &dev));
> + ut_assertnonnull(dev);
> +
> + ut_assertok(console_record_reset_enable());
> +
> + run_command("rng", 0);
> + ut_assert_nextlinen("00000000:");
> + ut_assert_nextlinen("00000010:");
> + ut_assert_nextlinen("00000020:");
> + ut_assert_nextlinen("00000030:");
> + ut_assert_console_end();
> +
> + run_command("rng 0 10", 0);
> + ut_assert_nextlinen("00000000:");
> + ut_assert_console_end();
> +
> + run_command("rng 20", 0);
> + ut_assert_nextlinen("No RNG device");
> + ut_assert_console_end();
> +
> + return 0;
> +}
> +DM_TEST(dm_test_rng_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
> --
> 2.25.1
>
Acked-by: Ilias Apalodimas <ilias.apalodimas at linaro.org>
More information about the U-Boot
mailing list