blob: 6d1f68848d52eea6b999a31583c24151d350e290 [file] [log] [blame]
Sughosh Ganu4ee08eb2019-12-28 23:58:33 +05301// SPDX-License-Identifier: GPL-2.0-or-later
2/*
3 * Copyright (c) 2019, Linaro Limited
4 */
5
6#include <common.h>
7#include <dm.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -06008#include <log.h>
Sughosh Ganu4ee08eb2019-12-28 23:58:33 +05309#include <rng.h>
10#include <dm/test.h>
11#include <test/ut.h>
12
13/* Basic test of the rng uclass */
14static int dm_test_rng_read(struct unit_test_state *uts)
15{
16 unsigned long rand1 = 0, rand2 = 0;
17 struct udevice *dev;
18
19 ut_assertok(uclass_get_device(UCLASS_RNG, 0, &dev));
20 ut_assertnonnull(dev);
21 ut_assertok(dm_rng_read(dev, &rand1, sizeof(rand1)));
22 ut_assertok(dm_rng_read(dev, &rand2, sizeof(rand2)));
23 ut_assert(rand1 != rand2);
24
25 return 0;
26}
Simon Glasse180c2b2020-07-28 19:41:12 -060027DM_TEST(dm_test_rng_read, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
Sughosh Ganude706192022-07-22 21:32:09 +053028
29/* Test the rng command */
30static int dm_test_rng_cmd(struct unit_test_state *uts)
31{
32 struct udevice *dev;
33
34 ut_assertok(uclass_get_device(UCLASS_RNG, 0, &dev));
35 ut_assertnonnull(dev);
36
37 ut_assertok(console_record_reset_enable());
38
39 run_command("rng", 0);
40 ut_assert_nextlinen("00000000:");
41 ut_assert_nextlinen("00000010:");
42 ut_assert_nextlinen("00000020:");
43 ut_assert_nextlinen("00000030:");
44 ut_assert_console_end();
45
46 run_command("rng 0 10", 0);
47 ut_assert_nextlinen("00000000:");
48 ut_assert_console_end();
49
50 run_command("rng 20", 0);
51 ut_assert_nextlinen("No RNG device");
52 ut_assert_console_end();
53
54 return 0;
55}
56DM_TEST(dm_test_rng_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);