timer.c 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015 Thomas Chou <thomas@wytron.com.tw>
  4. */
  5. #include <common.h>
  6. #include <dm.h>
  7. #include <timer.h>
  8. #include <dm/test.h>
  9. #include <dm/device-internal.h>
  10. #include <test/test.h>
  11. #include <test/ut.h>
  12. #include <asm/cpu.h>
  13. /*
  14. * Basic test of the timer uclass.
  15. */
  16. static int dm_test_timer_base(struct unit_test_state *uts)
  17. {
  18. struct udevice *dev;
  19. ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@0", &dev));
  20. ut_asserteq(1000000, timer_get_rate(dev));
  21. return 0;
  22. }
  23. DM_TEST(dm_test_timer_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
  24. /*
  25. * Test of timebase fallback
  26. */
  27. static int dm_test_timer_timebase_fallback(struct unit_test_state *uts)
  28. {
  29. struct udevice *dev;
  30. cpu_sandbox_set_current("cpu-test1");
  31. ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@1", &dev));
  32. ut_asserteq(3000000, timer_get_rate(dev));
  33. ut_assertok(device_remove(dev, DM_REMOVE_NORMAL));
  34. cpu_sandbox_set_current("cpu-test2");
  35. ut_assertok(uclass_get_device_by_name(UCLASS_TIMER, "timer@1", &dev));
  36. ut_asserteq(2000000, timer_get_rate(dev));
  37. cpu_sandbox_set_current("cpu-test1");
  38. return 0;
  39. }
  40. DM_TEST(dm_test_timer_timebase_fallback,
  41. UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);