2018-05-07 05:58:06 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2015-10-30 15:35:52 +08:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <timer.h>
|
|
|
|
#include <dm/test.h>
|
2020-09-28 22:52:23 +08:00
|
|
|
#include <dm/device-internal.h>
|
2020-07-20 00:15:37 +08:00
|
|
|
#include <test/test.h>
|
2015-10-30 15:35:52 +08:00
|
|
|
#include <test/ut.h>
|
2020-09-28 22:52:23 +08:00
|
|
|
#include <asm/cpu.h>
|
2015-10-30 15:35:52 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Basic test of the timer uclass.
|
|
|
|
*/
|
|
|
|
static int dm_test_timer_base(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
|
2020-09-28 22:52:23 +08:00
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@0", &dev));
|
2015-10-30 15:35:52 +08:00
|
|
|
ut_asserteq(1000000, timer_get_rate(dev));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 09:41:12 +08:00
|
|
|
DM_TEST(dm_test_timer_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2020-09-28 22:52:23 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Test of timebase fallback
|
|
|
|
*/
|
|
|
|
static int dm_test_timer_timebase_fallback(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
|
2021-08-28 17:42:08 +08:00
|
|
|
cpu_sandbox_set_current("cpu@1");
|
2020-09-28 22:52:23 +08:00
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@1", &dev));
|
|
|
|
ut_asserteq(3000000, timer_get_rate(dev));
|
|
|
|
ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
|
|
|
|
|
2021-08-28 17:42:08 +08:00
|
|
|
cpu_sandbox_set_current("cpu@2");
|
2020-09-28 22:52:23 +08:00
|
|
|
ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@1", &dev));
|
|
|
|
ut_asserteq(2000000, timer_get_rate(dev));
|
|
|
|
|
2021-08-28 17:42:08 +08:00
|
|
|
cpu_sandbox_set_current("cpu@1");
|
2020-09-28 22:52:23 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_timer_timebase_fallback,
|
|
|
|
UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|