xref: /openbmc/u-boot/test/dm/wdt.c (revision e8f80a5a)
1*83d290c5STom Rini // SPDX-License-Identifier: GPL-2.0+
20753bc2dSmaxims@google.com /*
30753bc2dSmaxims@google.com  * Copyright 2017 Google, Inc
40753bc2dSmaxims@google.com  */
50753bc2dSmaxims@google.com 
60753bc2dSmaxims@google.com #include <common.h>
70753bc2dSmaxims@google.com #include <dm.h>
80753bc2dSmaxims@google.com #include <wdt.h>
90753bc2dSmaxims@google.com #include <asm/state.h>
100753bc2dSmaxims@google.com #include <asm/test.h>
110753bc2dSmaxims@google.com #include <dm/test.h>
120753bc2dSmaxims@google.com #include <test/ut.h>
130753bc2dSmaxims@google.com 
140753bc2dSmaxims@google.com /* Test that watchdog driver functions are called */
dm_test_wdt_base(struct unit_test_state * uts)150753bc2dSmaxims@google.com static int dm_test_wdt_base(struct unit_test_state *uts)
160753bc2dSmaxims@google.com {
170753bc2dSmaxims@google.com 	struct sandbox_state *state = state_get_current();
180753bc2dSmaxims@google.com 	struct udevice *dev;
190753bc2dSmaxims@google.com 	const u64 timeout = 42;
200753bc2dSmaxims@google.com 
210753bc2dSmaxims@google.com 	ut_assertok(uclass_get_device(UCLASS_WDT, 0, &dev));
229eace7f5SSimon Glass 	ut_assertnonnull(dev);
230753bc2dSmaxims@google.com 	ut_asserteq(0, state->wdt.counter);
240753bc2dSmaxims@google.com 	ut_asserteq(false, state->wdt.running);
250753bc2dSmaxims@google.com 
260753bc2dSmaxims@google.com 	ut_assertok(wdt_start(dev, timeout, 0));
270753bc2dSmaxims@google.com 	ut_asserteq(timeout, state->wdt.counter);
280753bc2dSmaxims@google.com 	ut_asserteq(true, state->wdt.running);
290753bc2dSmaxims@google.com 
300753bc2dSmaxims@google.com 	uint reset_count = state->wdt.reset_count;
310753bc2dSmaxims@google.com 	ut_assertok(wdt_reset(dev));
320753bc2dSmaxims@google.com 	ut_asserteq(reset_count + 1, state->wdt.reset_count);
330753bc2dSmaxims@google.com 	ut_asserteq(true, state->wdt.running);
340753bc2dSmaxims@google.com 
350753bc2dSmaxims@google.com 	ut_assertok(wdt_stop(dev));
360753bc2dSmaxims@google.com 	ut_asserteq(false, state->wdt.running);
370753bc2dSmaxims@google.com 
380753bc2dSmaxims@google.com 	return 0;
390753bc2dSmaxims@google.com }
400753bc2dSmaxims@google.com DM_TEST(dm_test_wdt_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
41