[PATCH v3 7/8] test: rng: Add basic test for random number generator(rng) uclass
Patrick DELAUNAY
patrick.delaunay at st.com
Mon Dec 16 13:42:09 CET 2019
Hi,
> -----Original Message-----
> From: U-Boot <u-boot-bounces at lists.denx.de> On Behalf Of Sughosh Ganu
> Sent: vendredi 13 décembre 2019 08:14
> To: u-boot at lists.denx.de
> Subject: [PATCH v3 7/8] test: rng: Add basic test for random number
> generator(rng) uclass
>
> Add a unit test for testing the rng uclass functionality using the sandbox rng
> driver.
>
> Signed-off-by: Sughosh Ganu <sughosh.ganu at linaro.org>
> Reviewed-by: Patrice Chotard <patrice.chotard at st.com>
> ---
> test/dm/Makefile | 1 +
> test/dm/rng.c | 26 ++++++++++++++++++++++++++
> 2 files changed, 27 insertions(+)
> create mode 100644 test/dm/rng.c
>
> diff --git a/test/dm/Makefile b/test/dm/Makefile index 0c2fd5c..f61bf65 100644
> --- a/test/dm/Makefile
> +++ b/test/dm/Makefile
> @@ -65,4 +65,5 @@ obj-$(CONFIG_VIRTIO_SANDBOX) += virtio.o
> obj-$(CONFIG_DMA) += dma.o
> obj-$(CONFIG_DM_MDIO) += mdio.o
> obj-$(CONFIG_DM_MDIO_MUX) += mdio_mux.o
> +obj-$(CONFIG_DM_RNG) += rng.o
> endif
> diff --git a/test/dm/rng.c b/test/dm/rng.c new file mode 100644 index
> 0000000..879e80a
> --- /dev/null
> +++ b/test/dm/rng.c
> @@ -0,0 +1,26 @@
> +// SPDX-License-Identifier: GPL-2.0-or-later
> +/*
> + * Copyright (c) 2019, Linaro Limited
> + */
> +
> +#include <common.h>
> +#include <dm.h>
> +#include <rng.h>
> +#include <dm/test.h>
> +#include <test/ut.h>
> +
> +/* Basic test of the rng uclass */
> +static int dm_test_rng_read(struct unit_test_state *uts) {
> + unsigned long val1 = 0, val2 = 0;
> + struct udevice *dev;
> +
> + ut_assertok(uclass_get_device(UCLASS_RNG, 0, &dev));
> + ut_assertnonnull(dev);
> + dm_rng_read(dev, &val1, sizeof(val1));
> + dm_rng_read(dev, &val2, sizeof(val2));
Test return:
ut_assertok(dm_rng_read(dev, &val1, sizeof(val1)));
ut_assertok(dm_rng_read(dev, &val2, sizeof(val2)))
> + ut_assert(val1 != val2);
You can also check the values as the sandbox driver use only the 2 next values :
ut_asserteq(0x21524110, val1);
ut_asserteq(0xDEADBEEF, val2);
> + return 0;
> +}
> +DM_TEST(dm_test_rng_read, DM_TESTF_SCAN_PDATA |
> DM_TESTF_SCAN_FDT);
> --
> 2.7.4
Regards
Patrick
More information about the U-Boot
mailing list