]> git.kernelconcepts.de Git - karo-tx-uboot.git/commitdiff
test: dm: Add additional GPIO tests
authorSimon Glass <sjg@chromium.org>
Sat, 4 Oct 2014 17:29:51 +0000 (11:29 -0600)
committerSimon Glass <sjg@chromium.org>
Fri, 24 Oct 2014 01:29:53 +0000 (19:29 -0600)
Add tests for gpio_requestf() and for memory leaks.

Signed-off-by: Simon Glass <sjg@chromium.org>
doc/driver-model/README.txt
test/dm/gpio.c

index f4395c188afb3437cbd86f0321000b71e2c91db6..0278dda4d77045a7dbcc8400b1d5593252b4f514 100644 (file)
@@ -95,7 +95,7 @@ are provided in test/dm. To run them, try:
 You should see something like this:
 
     <...U-Boot banner...>
-    Running 27 driver model tests
+    Running 29 driver model tests
     Test: dm_test_autobind
     Test: dm_test_autoprobe
     Test: dm_test_bus_children
@@ -117,6 +117,9 @@ You should see something like this:
     Test: dm_test_gpio
     extra-gpios: get_value: error: gpio b5 not reserved
     Test: dm_test_gpio_anon
+    Test: dm_test_gpio_copy
+    Test: dm_test_gpio_leak
+    extra-gpios: get_value: error: gpio b5 not reserved
     Test: dm_test_gpio_requestf
     Test: dm_test_leak
     Test: dm_test_lifecycle
index 5174cede2478669e8b4840ef4822a7b3d6bfd0bd..94bd0d99dc0bc1fa9b5c7033690ab6de7cc29b41 100644 (file)
@@ -7,11 +7,14 @@
 #include <common.h>
 #include <fdtdec.h>
 #include <dm.h>
+#include <dm/root.h>
 #include <dm/ut.h>
 #include <dm/test.h>
 #include <dm/util.h>
 #include <asm/gpio.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 /* Test that sandbox GPIOs work correctly */
 static int dm_test_gpio(struct dm_test_state *dms)
 {
@@ -138,3 +141,38 @@ static int dm_test_gpio_requestf(struct dm_test_state *dms)
        return 0;
 }
 DM_TEST(dm_test_gpio_requestf, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that gpio_request() copies its string */
+static int dm_test_gpio_copy(struct dm_test_state *dms)
+{
+       unsigned int offset, gpio;
+       struct udevice *dev;
+       char buf[80], name[10];
+
+       ut_assertok(gpio_lookup_name("b6", &dev, &offset, &gpio));
+       strcpy(name, "odd_name");
+       ut_assertok(gpio_request(gpio, name));
+       sandbox_gpio_set_direction(dev, offset, 1);
+       sandbox_gpio_set_value(dev, offset, 1);
+       ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+       ut_asserteq_str("b6: output: 1 [x] odd_name", buf);
+       strcpy(name, "nothing");
+       ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
+       ut_asserteq_str("b6: output: 1 [x] odd_name", buf);
+
+       return 0;
+}
+DM_TEST(dm_test_gpio_copy, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that we don't leak memory with GPIOs */
+static int dm_test_gpio_leak(struct dm_test_state *dms)
+{
+       ut_assertok(dm_test_gpio(dms));
+       ut_assertok(dm_test_gpio_anon(dms));
+       ut_assertok(dm_test_gpio_requestf(dms));
+       ut_assertok(dm_leak_check_end(dms));
+
+       return 0;
+}
+
+DM_TEST(dm_test_gpio_leak, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);