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