Merge tag 'dm-9oct18' of git://git.denx.de/u-boot-dm
[platform/kernel/u-boot.git] / test / dm / sysreset.c
index 5e94c07..e1b7bf5 100644 (file)
@@ -1,7 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * Copyright (C) 2015 Google, Inc
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <common.h>
@@ -46,6 +45,25 @@ static int dm_test_sysreset_base(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_sysreset_base, DM_TESTF_SCAN_PDATA | DM_TESTF_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, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
 /* Test that we can walk through the sysreset devices */
 static int dm_test_sysreset_walk(struct unit_test_state *uts)
 {
@@ -53,6 +71,7 @@ static int dm_test_sysreset_walk(struct unit_test_state *uts)
 
        /* If we generate a power sysreset, we will exit sandbox! */
        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));
@@ -72,3 +91,22 @@ static int dm_test_sysreset_walk(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_sysreset_walk, DM_TESTF_SCAN_PDATA | DM_TESTF_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_COLD, sysreset_get_last(dev));
+
+       /* This is device 0, the non-DT one */
+       ut_asserteq(SYSRESET_COLD, sysreset_get_last_walk());
+
+       return 0;
+}
+DM_TEST(dm_test_sysreset_get_last, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);