diff mbox

[U-Boot,17/23] test: dm: Add additional GPIO tests

Message ID 1412443798-6436-18-git-send-email-sjg@chromium.org
State Accepted
Delegated to: Simon Glass
Headers show

Commit Message

Simon Glass Oct. 4, 2014, 5:29 p.m. UTC
Add tests for gpio_requestf() and for memory leaks.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 doc/driver-model/README.txt |  5 ++++-
 test/dm/gpio.c              | 38 ++++++++++++++++++++++++++++++++++++++
 2 files changed, 42 insertions(+), 1 deletion(-)

Comments

Simon Glass Oct. 24, 2014, 3:53 a.m. UTC | #1
On 4 October 2014 11:29, Simon Glass <sjg@chromium.org> wrote:
> Add tests for gpio_requestf() and for memory leaks.
>
> Signed-off-by: Simon Glass <sjg@chromium.org>
> ---
>
>  doc/driver-model/README.txt |  5 ++++-
>  test/dm/gpio.c              | 38 ++++++++++++++++++++++++++++++++++++++
>  2 files changed, 42 insertions(+), 1 deletion(-)

Applied to u-boot-dm/master
diff mbox

Patch

diff --git a/doc/driver-model/README.txt b/doc/driver-model/README.txt
index f4395c1..0278dda 100644
--- a/doc/driver-model/README.txt
+++ b/doc/driver-model/README.txt
@@ -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
diff --git a/test/dm/gpio.c b/test/dm/gpio.c
index 5174ced..94bd0d9 100644
--- a/test/dm/gpio.c
+++ b/test/dm/gpio.c
@@ -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);