maxims@google.com | 0753bc2 | 2017-04-17 12:00:21 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2017 Google, Inc |
| 3 | * |
| 4 | * SPDX-License-Identifier: GPL-2.0+ |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <dm.h> |
| 9 | #include <wdt.h> |
| 10 | #include <asm/state.h> |
| 11 | #include <asm/test.h> |
| 12 | #include <dm/test.h> |
| 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)); |
| 23 | ut_asserteq(0, state->wdt.counter); |
| 24 | ut_asserteq(false, state->wdt.running); |
| 25 | |
| 26 | ut_assertok(wdt_start(dev, timeout, 0)); |
| 27 | ut_asserteq(timeout, state->wdt.counter); |
| 28 | ut_asserteq(true, state->wdt.running); |
| 29 | |
| 30 | uint reset_count = state->wdt.reset_count; |
| 31 | ut_assertok(wdt_reset(dev)); |
| 32 | ut_asserteq(reset_count + 1, state->wdt.reset_count); |
| 33 | ut_asserteq(true, state->wdt.running); |
| 34 | |
| 35 | ut_assertok(wdt_stop(dev)); |
| 36 | ut_asserteq(false, state->wdt.running); |
| 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | DM_TEST(dm_test_wdt_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |