Sughosh Ganu | 912893d | 2019-12-28 23:58:33 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright (c) 2019, Linaro Limited |
| 4 | */ |
| 5 | |
Sughosh Ganu | 912893d | 2019-12-28 23:58:33 +0530 | [diff] [blame] | 6 | #include <dm.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 7 | #include <log.h> |
Sughosh Ganu | 912893d | 2019-12-28 23:58:33 +0530 | [diff] [blame] | 8 | #include <rng.h> |
| 9 | #include <dm/test.h> |
| 10 | #include <test/ut.h> |
| 11 | |
| 12 | /* Basic test of the rng uclass */ |
| 13 | static 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 Glass | 1a92f83 | 2024-08-22 07:57:48 -0600 | [diff] [blame] | 26 | DM_TEST(dm_test_rng_read, UTF_SCAN_PDATA | UTF_SCAN_FDT); |
Sughosh Ganu | 6daac6b | 2022-07-22 21:32:09 +0530 | [diff] [blame] | 27 | |
| 28 | /* Test the rng command */ |
| 29 | static 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 | |
Sughosh Ganu | 6daac6b | 2022-07-22 21:32:09 +0530 | [diff] [blame] | 36 | run_command("rng", 0); |
| 37 | ut_assert_nextlinen("00000000:"); |
| 38 | ut_assert_nextlinen("00000010:"); |
| 39 | ut_assert_nextlinen("00000020:"); |
| 40 | ut_assert_nextlinen("00000030:"); |
| 41 | ut_assert_console_end(); |
| 42 | |
| 43 | run_command("rng 0 10", 0); |
| 44 | ut_assert_nextlinen("00000000:"); |
| 45 | ut_assert_console_end(); |
| 46 | |
| 47 | run_command("rng 20", 0); |
| 48 | ut_assert_nextlinen("No RNG device"); |
| 49 | ut_assert_console_end(); |
| 50 | |
| 51 | return 0; |
| 52 | } |
Simon Glass | 11fcfa3 | 2024-08-22 07:57:50 -0600 | [diff] [blame] | 53 | DM_TEST(dm_test_rng_cmd, UTF_SCAN_PDATA | UTF_SCAN_FDT | UTF_CONSOLE); |