]>
Commit | Line | Data |
---|---|---|
6f2d59cb PT |
1 | // SPDX-License-Identifier: GPL-2.0+ |
2 | /* | |
3 | * (C) 2018 Theobroma Systems Design und Consulting GmbH | |
4 | */ | |
5 | ||
6f2d59cb PT |
6 | #include <dm.h> |
7 | #include <bootcount.h> | |
f7ae49fc | 8 | #include <log.h> |
6f2d59cb PT |
9 | #include <asm/test.h> |
10 | #include <dm/test.h> | |
0e1fad43 | 11 | #include <test/test.h> |
6f2d59cb PT |
12 | #include <test/ut.h> |
13 | ||
c50b21b7 | 14 | static int dm_test_bootcount_rtc(struct unit_test_state *uts) |
6f2d59cb PT |
15 | { |
16 | struct udevice *dev; | |
17 | u32 val; | |
18 | ||
c50b21b7 NH |
19 | ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount@0", |
20 | &dev)); | |
6f2d59cb PT |
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 | ||
f692b479 MS |
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 | ||
6f2d59cb PT |
36 | return 0; |
37 | } | |
38 | ||
c50b21b7 | 39 | DM_TEST(dm_test_bootcount_rtc, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |
6f2d59cb | 40 | |
c50b21b7 NH |
41 | static int dm_test_bootcount_syscon_four_bytes(struct unit_test_state *uts) |
42 | { | |
43 | struct udevice *dev; | |
44 | u32 val; | |
45 | ||
46 | sandbox_set_enable_memio(true); | |
47 | ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount_4@0", | |
48 | &dev)); | |
49 | ut_assertok(dm_bootcount_set(dev, 0xab)); | |
50 | ut_assertok(dm_bootcount_get(dev, &val)); | |
51 | ut_assert(val == 0xab); | |
52 | ut_assertok(dm_bootcount_set(dev, 0)); | |
53 | ut_assertok(dm_bootcount_get(dev, &val)); | |
54 | ut_assert(val == 0); | |
55 | ||
56 | return 0; | |
57 | } | |
58 | ||
59 | DM_TEST(dm_test_bootcount_syscon_four_bytes, | |
60 | UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); | |
61 | ||
62 | static int dm_test_bootcount_syscon_two_bytes(struct unit_test_state *uts) | |
63 | { | |
64 | struct udevice *dev; | |
65 | u32 val; | |
66 | ||
67 | sandbox_set_enable_memio(true); | |
68 | ut_assertok(uclass_get_device_by_name(UCLASS_BOOTCOUNT, "bootcount_2@0", | |
69 | &dev)); | |
70 | ut_assertok(dm_bootcount_set(dev, 0xab)); | |
71 | ut_assertok(dm_bootcount_get(dev, &val)); | |
72 | ut_assert(val == 0xab); | |
73 | ut_assertok(dm_bootcount_set(dev, 0)); | |
74 | ut_assertok(dm_bootcount_get(dev, &val)); | |
75 | ut_assert(val == 0); | |
76 | ||
77 | return 0; | |
78 | } | |
79 | ||
80 | DM_TEST(dm_test_bootcount_syscon_two_bytes, | |
81 | UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT); |