Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) 2018 Theobroma Systems Design und Consulting GmbH |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <dm.h> |
| 8 | #include <bootcount.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 9 | #include <log.h> |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 10 | #include <asm/test.h> |
| 11 | #include <dm/test.h> |
Simon Glass | 75c4d41 | 2020-07-19 10:15:37 -0600 | [diff] [blame] | 12 | #include <test/test.h> |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 13 | #include <test/ut.h> |
| 14 | |
| 15 | static int dm_test_bootcount(struct unit_test_state *uts) |
| 16 | { |
| 17 | struct udevice *dev; |
| 18 | u32 val; |
| 19 | |
| 20 | ut_assertok(uclass_get_device(UCLASS_BOOTCOUNT, 0, &dev)); |
| 21 | ut_assertok(dm_bootcount_set(dev, 0)); |
| 22 | ut_assertok(dm_bootcount_get(dev, &val)); |
| 23 | ut_assert(val == 0); |
| 24 | ut_assertok(dm_bootcount_set(dev, 0xab)); |
| 25 | ut_assertok(dm_bootcount_get(dev, &val)); |
| 26 | ut_assert(val == 0xab); |
| 27 | |
Michal Simek | 4f18f92 | 2020-05-28 11:48:55 +0200 | [diff] [blame] | 28 | ut_assertok(uclass_get_device(UCLASS_BOOTCOUNT, 1, &dev)); |
| 29 | ut_assertok(dm_bootcount_set(dev, 0)); |
| 30 | ut_assertok(dm_bootcount_get(dev, &val)); |
| 31 | ut_assert(val == 0); |
| 32 | ut_assertok(dm_bootcount_set(dev, 0xab)); |
| 33 | ut_assertok(dm_bootcount_get(dev, &val)); |
| 34 | ut_assert(val == 0xab); |
| 35 | |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 36 | return 0; |
| 37 | } |
| 38 | |
Simon Glass | 974dccd | 2020-07-28 19:41:12 -0600 | [diff] [blame] | 39 | DM_TEST(dm_test_bootcount, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
Philipp Tomsich | 1fc5330 | 2018-12-14 21:14:29 +0100 | [diff] [blame] | 40 | |