diff mbox series

[v6,7/8] test: rng: Add basic test for random number generator(rng) uclass

Message ID 1577456594-22884-8-git-send-email-sughosh.ganu@linaro.org
State Superseded, archived
Delegated to: Heinrich Schuchardt
Headers show
Series Add a random number generator uclass | expand

Commit Message

Sughosh Ganu Dec. 27, 2019, 2:23 p.m. UTC
Add a unit test for testing the rng uclass functionality using the
sandbox rng driver.

Signed-off-by: Sughosh Ganu <sughosh.ganu@linaro.org>
Reviewed-by: Patrice Chotard <patrice.chotard@st.com>
---
* Change the test checking logic based on changes made in the sandbox
  rng driver, which returns 0 on a successful read.

 test/dm/Makefile |  1 +
 test/dm/rng.c    | 26 ++++++++++++++++++++++++++
 2 files changed, 27 insertions(+)
 create mode 100644 test/dm/rng.c

Comments

Heinrich Schuchardt Dec. 28, 2019, 6:11 a.m. UTC | #1
On 12/27/19 3:23 PM, Sughosh Ganu wrote:
> Add a unit test for testing the rng uclass functionality using the
> sandbox rng driver.
>
> Signed-off-by: Sughosh Ganu<sughosh.ganu@linaro.org>
> Reviewed-by: Patrice Chotard<patrice.chotard@st.com>

Reviewed-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
diff mbox series

Patch

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..ce20e2d
--- /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 rand1 = 0, rand2 = 0;
+	struct udevice *dev;
+
+	ut_assertok(uclass_get_device(UCLASS_RNG, 0, &dev));
+	ut_assertnonnull(dev);
+	ut_assertok(dm_rng_read(dev, &rand1, sizeof(rand1)));
+	ut_assertok(dm_rng_read(dev, &rand2, sizeof(rand2)));
+	ut_assert(rand1 != rand2);
+
+	return 0;
+}
+DM_TEST(dm_test_rng_read, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);