2019-12-28 18:28:33 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2019, Linaro Limited
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2019-12-28 18:28:33 +00:00
|
|
|
#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;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_rng_read, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2022-07-22 16:02:09 +00:00
|
|
|
|
|
|
|
/* Test the rng command */
|
|
|
|
static int dm_test_rng_cmd(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device(UCLASS_RNG, 0, &dev));
|
|
|
|
ut_assertnonnull(dev);
|
|
|
|
|
|
|
|
ut_assertok(console_record_reset_enable());
|
|
|
|
|
|
|
|
run_command("rng", 0);
|
|
|
|
ut_assert_nextlinen("00000000:");
|
|
|
|
ut_assert_nextlinen("00000010:");
|
|
|
|
ut_assert_nextlinen("00000020:");
|
|
|
|
ut_assert_nextlinen("00000030:");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
run_command("rng 0 10", 0);
|
|
|
|
ut_assert_nextlinen("00000000:");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
run_command("rng 20", 0);
|
|
|
|
ut_assert_nextlinen("No RNG device");
|
|
|
|
ut_assert_console_end();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_rng_cmd, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT | UT_TESTF_CONSOLE_REC);
|