Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright 2017 Google, Inc |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <wdt.h> |
| 9 | #include <asm/state.h> |
| 10 | #include <asm/test.h> |
| 11 | #include <dm/test.h> |
Simon Glass | 0e1fad4 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 12 | #include <test/test.h> |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 13 | #include <test/ut.h> |
| 14 | |
| 15 | /* Test that watchdog driver functions are called */ |
| 16 | static int dm_test_wdt_base(struct unit_test_state *uts) |
| 17 | { |
| 18 | struct sandbox_state *state = state_get_current(); |
| 19 | struct udevice *dev; |
| 20 | const u64 timeout = 42; |
| 21 | |
| 22 | ut_assertok(uclass_get_device(UCLASS_WDT, 0, &dev)); |
Simon Glass | 9eace7f | 2017-06-07 10:28:43 -0600 | [diff] [blame] | 23 | ut_assertnonnull(dev); |
maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 24 | ut_asserteq(0, state->wdt.counter); |
| 25 | ut_asserteq(false, state->wdt.running); |
| 26 | |
| 27 | ut_assertok(wdt_start(dev, timeout, 0)); |
| 28 | ut_asserteq(timeout, state->wdt.counter); |
| 29 | ut_asserteq(true, state->wdt.running); |
| 30 | |
| 31 | uint reset_count = state->wdt.reset_count; |
| 32 | ut_assertok(wdt_reset(dev)); |
| 33 | ut_asserteq(reset_count + 1, state->wdt.reset_count); |
| 34 | ut_asserteq(true, state->wdt.running); |
| 35 | |
| 36 | ut_assertok(wdt_stop(dev)); |
| 37 | ut_asserteq(false, state->wdt.running); |
| 38 | |
| 39 | return 0; |
| 40 | } |
Simon Glass | e180c2b | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 41 | DM_TEST(dm_test_wdt_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |