xref: /openbmc/u-boot/test/dm/bootcount.c (revision 8b21180f7db21629cb029461ced1b578e4eb8d0e)
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>
9 #include <asm/test.h>
10 #include <dm/test.h>
11 #include <test/ut.h>
12 
dm_test_bootcount(struct unit_test_state * uts)13 static int dm_test_bootcount(struct unit_test_state *uts)
14 {
15 	struct udevice *dev;
16 	u32 val;
17 
18 	ut_assertok(uclass_get_device(UCLASS_BOOTCOUNT, 0, &dev));
19 	ut_assertok(dm_bootcount_set(dev, 0));
20 	ut_assertok(dm_bootcount_get(dev, &val));
21 	ut_assert(val == 0);
22 	ut_assertok(dm_bootcount_set(dev, 0xab));
23 	ut_assertok(dm_bootcount_get(dev, &val));
24 	ut_assert(val == 0xab);
25 
26 	ut_assertok(uclass_get_device(UCLASS_BOOTCOUNT, 1, &dev));
27 	ut_assertok(dm_bootcount_set(dev, 0));
28 	ut_assertok(dm_bootcount_get(dev, &val));
29 	ut_assert(val == 0);
30 	ut_assertok(dm_bootcount_set(dev, 0xab));
31 	ut_assertok(dm_bootcount_get(dev, &val));
32 	ut_assert(val == 0xab);
33 
34 	return 0;
35 }
36 
37 DM_TEST(dm_test_bootcount, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
38 
39