]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
test: reset: Add tests for the managed API
authorJean-Jacques Hiblot <jjhiblot@ti.com>
Wed, 9 Sep 2020 10:07:04 +0000 (15:37 +0530)
committerTom Rini <trini@konsulko.com>
Wed, 30 Sep 2020 15:55:22 +0000 (11:55 -0400)
The tests are basically the same as for the regular API. Except that
the reset are initialized using the managed API, and no freed manually.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
arch/sandbox/include/asm/reset.h
drivers/reset/sandbox-reset-test.c
drivers/reset/sandbox-reset.c
test/dm/reset.c

index c4205eabef122968a7bae3c37df96e4d06430c39..40d3e61c110af742d996bfb5bb08afe84688242f 100644 (file)
 struct udevice;
 
 int sandbox_reset_query(struct udevice *dev, unsigned long id);
+int sandbox_reset_is_requested(struct udevice *dev, unsigned long id);
 
 int sandbox_reset_test_get(struct udevice *dev);
+int sandbox_reset_test_get_devm(struct udevice *dev);
 int sandbox_reset_test_get_bulk(struct udevice *dev);
+int sandbox_reset_test_get_bulk_devm(struct udevice *dev);
 int sandbox_reset_test_assert(struct udevice *dev);
 int sandbox_reset_test_assert_bulk(struct udevice *dev);
 int sandbox_reset_test_deassert(struct udevice *dev);
index 9bc4a7e0ded5d52124fef291cfbd5e707037094b..10e02f1036241757ded86a0ff75558ee931252e1 100644 (file)
 #include <reset.h>
 #include <asm/io.h>
 #include <asm/reset.h>
+#include <linux/err.h>
 
 struct sandbox_reset_test {
        struct reset_ctl ctl;
        struct reset_ctl_bulk bulk;
+
+       struct reset_ctl *ctlp;
+       struct reset_ctl_bulk *bulkp;
 };
 
 int sandbox_reset_test_get(struct udevice *dev)
 {
        struct sandbox_reset_test *sbrt = dev_get_priv(dev);
 
+       sbrt->ctlp = &sbrt->ctl;
        return reset_get_by_name(dev, "test", &sbrt->ctl);
 }
 
+int sandbox_reset_test_get_devm(struct udevice *dev)
+{
+       struct sandbox_reset_test *sbrt = dev_get_priv(dev);
+       struct reset_ctl *r;
+
+       r = devm_reset_control_get(dev, "not-a-valid-reset-ctl");
+       if (!IS_ERR(r))
+               return -EINVAL;
+
+       r = devm_reset_control_get_optional(dev, "not-a-valid-reset-ctl");
+       if (r)
+               return -EINVAL;
+
+       sbrt->ctlp = devm_reset_control_get(dev, "test");
+       if (IS_ERR(sbrt->ctlp))
+               return PTR_ERR(sbrt->ctlp);
+
+       return 0;
+}
+
 int sandbox_reset_test_get_bulk(struct udevice *dev)
 {
        struct sandbox_reset_test *sbrt = dev_get_priv(dev);
 
+       sbrt->bulkp = &sbrt->bulk;
        return reset_get_bulk(dev, &sbrt->bulk);
 }
 
+int sandbox_reset_test_get_bulk_devm(struct udevice *dev)
+{
+       struct sandbox_reset_test *sbrt = dev_get_priv(dev);
+       struct reset_ctl_bulk *r;
+
+       r = devm_reset_bulk_get_optional(dev);
+       if (IS_ERR(r))
+               return PTR_ERR(r);
+
+       sbrt->bulkp = r;
+       return 0;
+}
+
 int sandbox_reset_test_assert(struct udevice *dev)
 {
        struct sandbox_reset_test *sbrt = dev_get_priv(dev);
 
-       return reset_assert(&sbrt->ctl);
+       return reset_assert(sbrt->ctlp);
 }
 
 int sandbox_reset_test_assert_bulk(struct udevice *dev)
 {
        struct sandbox_reset_test *sbrt = dev_get_priv(dev);
 
-       return reset_assert_bulk(&sbrt->bulk);
+       return reset_assert_bulk(sbrt->bulkp);
 }
 
 int sandbox_reset_test_deassert(struct udevice *dev)
 {
        struct sandbox_reset_test *sbrt = dev_get_priv(dev);
 
-       return reset_deassert(&sbrt->ctl);
+       return reset_deassert(sbrt->ctlp);
 }
 
 int sandbox_reset_test_deassert_bulk(struct udevice *dev)
 {
        struct sandbox_reset_test *sbrt = dev_get_priv(dev);
 
-       return reset_deassert_bulk(&sbrt->bulk);
+       return reset_deassert_bulk(sbrt->bulkp);
 }
 
 int sandbox_reset_test_free(struct udevice *dev)
 {
        struct sandbox_reset_test *sbrt = dev_get_priv(dev);
 
-       return reset_free(&sbrt->ctl);
+       return reset_free(sbrt->ctlp);
 }
 
 int sandbox_reset_test_release_bulk(struct udevice *dev)
 {
        struct sandbox_reset_test *sbrt = dev_get_priv(dev);
 
-       return reset_release_bulk(&sbrt->bulk);
+       return reset_release_bulk(sbrt->bulkp);
 }
 
 static const struct udevice_id sandbox_reset_test_ids[] = {
index 7a6f7f676cc48e3459aab4548adcfe34434b329a..08008d875ab73e6796c1b4d4e23e8aa02394d1f3 100644 (file)
@@ -15,6 +15,7 @@
 
 struct sandbox_reset_signal {
        bool asserted;
+       bool requested;
 };
 
 struct sandbox_reset {
@@ -23,18 +24,24 @@ struct sandbox_reset {
 
 static int sandbox_reset_request(struct reset_ctl *reset_ctl)
 {
+       struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
+
        debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
        if (reset_ctl->id >= SANDBOX_RESET_SIGNALS)
                return -EINVAL;
 
+       sbr->signals[reset_ctl->id].requested = true;
        return 0;
 }
 
 static int sandbox_reset_free(struct reset_ctl *reset_ctl)
 {
+       struct sandbox_reset *sbr = dev_get_priv(reset_ctl->dev);
+
        debug("%s(reset_ctl=%p)\n", __func__, reset_ctl);
 
+       sbr->signals[reset_ctl->id].requested = false;
        return 0;
 }
 
@@ -107,3 +114,15 @@ int sandbox_reset_query(struct udevice *dev, unsigned long id)
 
        return sbr->signals[id].asserted;
 }
+
+int sandbox_reset_is_requested(struct udevice *dev, unsigned long id)
+{
+       struct sandbox_reset *sbr = dev_get_priv(dev);
+
+       debug("%s(dev=%p, id=%ld)\n", __func__, dev, id);
+
+       if (id >= SANDBOX_RESET_SIGNALS)
+               return -EINVAL;
+
+       return sbr->signals[id].requested;
+}
index f5f366151fcd2ad7d7eb13ba84c66ecacabe8c79..fc8e9250b0d068e703a120ebffed659fe8ecb7c0 100644 (file)
@@ -5,6 +5,7 @@
 
 #include <common.h>
 #include <dm.h>
+#include <dm/device-internal.h>
 #include <log.h>
 #include <malloc.h>
 #include <reset.h>
@@ -60,12 +61,39 @@ static int dm_test_reset(struct unit_test_state *uts)
        ut_assertok(sandbox_reset_test_deassert(dev_test));
        ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
 
+       ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
        ut_assertok(sandbox_reset_test_free(dev_test));
+       ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
 
        return 0;
 }
 DM_TEST(dm_test_reset, UT_TESTF_SCAN_FDT);
 
+static int dm_test_reset_devm(struct unit_test_state *uts)
+{
+       struct udevice *dev_reset;
+       struct udevice *dev_test;
+
+       ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
+                                             &dev_reset));
+       ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
+       ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
+                                             &dev_test));
+       ut_assertok(sandbox_reset_test_get_devm(dev_test));
+
+       ut_assertok(sandbox_reset_test_assert(dev_test));
+       ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
+       ut_assertok(sandbox_reset_test_deassert(dev_test));
+       ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
+
+       ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
+       ut_assertok(device_remove(dev_test, DM_REMOVE_NORMAL));
+       ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
+
+       return 0;
+}
+DM_TEST(dm_test_reset_devm, UT_TESTF_SCAN_FDT);
+
 static int dm_test_reset_bulk(struct unit_test_state *uts)
 {
        struct udevice *dev_reset;
@@ -95,3 +123,35 @@ static int dm_test_reset_bulk(struct unit_test_state *uts)
        return 0;
 }
 DM_TEST(dm_test_reset_bulk, UT_TESTF_SCAN_FDT);
+
+static int dm_test_reset_bulk_devm(struct unit_test_state *uts)
+{
+       struct udevice *dev_reset;
+       struct udevice *dev_test;
+
+       ut_assertok(uclass_get_device_by_name(UCLASS_RESET, "reset-ctl",
+                                             &dev_reset));
+       ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
+       ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
+
+       ut_assertok(uclass_get_device_by_name(UCLASS_MISC, "reset-ctl-test",
+                                             &dev_test));
+       ut_assertok(sandbox_reset_test_get_bulk_devm(dev_test));
+
+       ut_assertok(sandbox_reset_test_assert_bulk(dev_test));
+       ut_asserteq(1, sandbox_reset_query(dev_reset, TEST_RESET_ID));
+       ut_asserteq(1, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
+
+       ut_assertok(sandbox_reset_test_deassert_bulk(dev_test));
+       ut_asserteq(0, sandbox_reset_query(dev_reset, TEST_RESET_ID));
+       ut_asserteq(0, sandbox_reset_query(dev_reset, OTHER_RESET_ID));
+
+       ut_asserteq(1, sandbox_reset_is_requested(dev_reset, OTHER_RESET_ID));
+       ut_asserteq(1, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
+       ut_assertok(device_remove(dev_test, DM_REMOVE_NORMAL));
+       ut_asserteq(0, sandbox_reset_is_requested(dev_reset, TEST_RESET_ID));
+       ut_asserteq(0, sandbox_reset_is_requested(dev_reset, OTHER_RESET_ID));
+
+       return 0;
+}
+DM_TEST(dm_test_reset_bulk_devm, UT_TESTF_SCAN_FDT);