1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117
|
// SPDX-License-Identifier: GPL-2.0+
/*
* Copyright (C) 2015 Google, Inc
*/
#include <dm.h>
#include <sysreset.h>
#include <asm/state.h>
#include <asm/test.h>
#include <dm/test.h>
#include <test/test.h>
#include <test/ut.h>
/* Test that we can use particular sysreset devices */
static int dm_test_sysreset_base(struct unit_test_state *uts)
{
struct sandbox_state *state = state_get_current();
struct udevice *dev;
/* Device 0 is the platform data device - it should never respond */
ut_assertok(uclass_get_device(UCLASS_SYSRESET, 0, &dev));
ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_WARM));
ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_COLD));
ut_asserteq(-ENODEV, sysreset_request(dev, SYSRESET_POWER));
/* Device 1 is the warm sysreset device */
ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_WARM));
ut_asserteq(-EPROTONOSUPPORT, sysreset_request(dev, SYSRESET_COLD));
ut_asserteq(-EPROTONOSUPPORT, sysreset_request(dev, SYSRESET_POWER));
state->sysreset_allowed[SYSRESET_WARM] = true;
ut_asserteq(-EINPROGRESS, sysreset_request(dev, SYSRESET_WARM));
state->sysreset_allowed[SYSRESET_WARM] = false;
/* Device 2 is the cold sysreset device */
ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
ut_asserteq(-EPROTONOSUPPORT, sysreset_request(dev, SYSRESET_WARM));
state->sysreset_allowed[SYSRESET_COLD] = false;
ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_COLD));
state->sysreset_allowed[SYSRESET_COLD] = true;
state->sysreset_allowed[SYSRESET_POWER] = false;
ut_asserteq(-EACCES, sysreset_request(dev, SYSRESET_POWER));
state->sysreset_allowed[SYSRESET_POWER] = true;
return 0;
}
DM_TEST(dm_test_sysreset_base, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_sysreset_get_status(struct unit_test_state *uts)
{
struct udevice *dev;
char msg[64];
/* Device 1 is the warm sysreset device */
ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
ut_assertok(sysreset_get_status(dev, msg, sizeof(msg)));
ut_asserteq_str("Reset Status: WARM", msg);
/* Device 2 is the cold sysreset device */
ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
ut_assertok(sysreset_get_status(dev, msg, sizeof(msg)));
ut_asserteq_str("Reset Status: COLD", msg);
return 0;
}
DM_TEST(dm_test_sysreset_get_status, UTF_SCAN_PDATA | UTF_SCAN_FDT);
/* Test that we can walk through the sysreset devices */
static int dm_test_sysreset_walk(struct unit_test_state *uts)
{
struct sandbox_state *state = state_get_current();
/* If we generate a power sysreset, we will exit sandbox! */
state->sysreset_allowed[SYSRESET_WARM] = false;
state->sysreset_allowed[SYSRESET_COLD] = false;
state->sysreset_allowed[SYSRESET_POWER] = false;
state->sysreset_allowed[SYSRESET_POWER_OFF] = false;
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_WARM));
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD));
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER_OFF));
/*
* Enable cold system reset - this should make cold system reset work,
* plus a warm system reset should be promoted to cold, since this is
* the next step along.
*/
state->sysreset_allowed[SYSRESET_WARM] = true;
ut_asserteq(-EINPROGRESS, sysreset_walk(SYSRESET_WARM));
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_COLD));
ut_asserteq(-EACCES, sysreset_walk(SYSRESET_POWER));
state->sysreset_allowed[SYSRESET_COLD] = true;
state->sysreset_allowed[SYSRESET_POWER] = true;
return 0;
}
DM_TEST(dm_test_sysreset_walk, UTF_SCAN_PDATA | UTF_SCAN_FDT);
static int dm_test_sysreset_get_last(struct unit_test_state *uts)
{
struct udevice *dev;
/* Device 1 is the warm sysreset device */
ut_assertok(uclass_get_device(UCLASS_SYSRESET, 1, &dev));
ut_asserteq(SYSRESET_WARM, sysreset_get_last(dev));
/* Device 2 is the cold sysreset device */
ut_assertok(uclass_get_device(UCLASS_SYSRESET, 2, &dev));
ut_asserteq(SYSRESET_POWER, sysreset_get_last(dev));
/* This is device 0, the non-DT one */
ut_asserteq(SYSRESET_POWER, sysreset_get_last_walk());
return 0;
}
DM_TEST(dm_test_sysreset_get_last, UTF_SCAN_PDATA | UTF_SCAN_FDT);
|