1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (C) 2015 Google, Inc
12 #include <test/test.h>
15 /* Test that we can use particular sysreset devices */
16 static int dm_test_sysreset_base(struct unit_test_state *uts)
18 struct sandbox_state *state = state_get_current();
21 /* Device 0 is the platform data device - it should never respond */
22 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 0, &dev));
23 ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_WARM));
24 ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_COLD));
25 ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_POWER));
27 /* Device 1 is the warm sysreset device */
28 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
29 ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_WARM));
30 ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_COLD));
31 ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_POWER));
33 state->sysreset_allowed[SYSRESET_WARM] = true;
34 ut_asserteq(-EINPROGRESS, sysreset_request(dev, SYSRESET_WARM));
35 state->sysreset_allowed[SYSRESET_WARM] = false;
37 /* Device 2 is the cold sysreset device */
38 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
39 ut_asserteq(-ENOSYS, sysreset_request(dev, SYSRESET_WARM));
40 state->sysreset_allowed[SYSRESET_COLD] = false;
41 ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_COLD));
42 state->sysreset_allowed[SYSRESET_COLD] = true;
43 state->sysreset_allowed[SYSRESET_POWER] = false;
44 ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_POWER));
45 state->sysreset_allowed[SYSRESET_POWER] = true;
49 DM_TEST(dm_test_sysreset_base, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
51 static int dm_test_sysreset_get_status(struct unit_test_state *uts)
56 /* Device 1 is the warm sysreset device */
57 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
58 ut_assertok(sysreset_get_status(dev, msg, sizeof(msg)));
59 ut_asserteq_str("Reset Status: WARM", msg);
61 /* Device 2 is the cold sysreset device */
62 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
63 ut_assertok(sysreset_get_status(dev, msg, sizeof(msg)));
64 ut_asserteq_str("Reset Status: COLD", msg);
68 DM_TEST(dm_test_sysreset_get_status, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
70 /* Test that we can walk through the sysreset devices */
71 static int dm_test_sysreset_walk(struct unit_test_state *uts)
73 struct sandbox_state *state = state_get_current();
75 /* If we generate a power sysreset, we will exit sandbox! */
76 state->sysreset_allowed[SYSRESET_WARM] = false;
77 state->sysreset_allowed[SYSRESET_COLD] = false;
78 state->sysreset_allowed[SYSRESET_POWER] = false;
79 state->sysreset_allowed[SYSRESET_POWER_OFF] = false;
80 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM));
81 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD));
82 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
83 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER_OFF));
86 * Enable cold system reset - this should make cold system reset work,
87 * plus a warm system reset should be promoted to cold, since this is
88 * the next step along.
90 state->sysreset_allowed[SYSRESET_WARM] = true;
91 ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_WARM));
92 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD));
93 ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
94 state->sysreset_allowed[SYSRESET_COLD] = true;
95 state->sysreset_allowed[SYSRESET_POWER] = true;
99 DM_TEST(dm_test_sysreset_walk, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
101 static int dm_test_sysreset_get_last(struct unit_test_state *uts)
105 /* Device 1 is the warm sysreset device */
106 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
107 ut_asserteq(SYSRESET_WARM, sysreset_get_last(dev));
109 /* Device 2 is the cold sysreset device */
110 ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
111 ut_asserteq(SYSRESET_POWER, sysreset_get_last(dev));
113 /* This is device 0, the non-DT one */
114 ut_asserteq(SYSRESET_POWER, sysreset_get_last_walk());
118 DM_TEST(dm_test_sysreset_get_last, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);