Commit 4324174d0308c9c81ce246a8e82d2faaefb6d973

Authored by Simon Glass
1 parent 756ac0bb15

test: dm: Add additional GPIO tests

Add tests for gpio_requestf() and for memory leaks.

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

Showing 2 changed files with 42 additions and 1 deletions Side-by-side Diff

doc/driver-model/README.txt
... ... @@ -95,7 +95,7 @@
95 95 You should see something like this:
96 96  
97 97 <...U-Boot banner...>
98   - Running 27 driver model tests
  98 + Running 29 driver model tests
99 99 Test: dm_test_autobind
100 100 Test: dm_test_autoprobe
101 101 Test: dm_test_bus_children
... ... @@ -117,6 +117,9 @@
117 117 Test: dm_test_gpio
118 118 extra-gpios: get_value: error: gpio b5 not reserved
119 119 Test: dm_test_gpio_anon
  120 + Test: dm_test_gpio_copy
  121 + Test: dm_test_gpio_leak
  122 + extra-gpios: get_value: error: gpio b5 not reserved
120 123 Test: dm_test_gpio_requestf
121 124 Test: dm_test_leak
122 125 Test: dm_test_lifecycle
... ... @@ -7,11 +7,14 @@
7 7 #include <common.h>
8 8 #include <fdtdec.h>
9 9 #include <dm.h>
  10 +#include <dm/root.h>
10 11 #include <dm/ut.h>
11 12 #include <dm/test.h>
12 13 #include <dm/util.h>
13 14 #include <asm/gpio.h>
14 15  
  16 +DECLARE_GLOBAL_DATA_PTR;
  17 +
15 18 /* Test that sandbox GPIOs work correctly */
16 19 static int dm_test_gpio(struct dm_test_state *dms)
17 20 {
... ... @@ -138,4 +141,39 @@
138 141 return 0;
139 142 }
140 143 DM_TEST(dm_test_gpio_requestf, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  144 +
  145 +/* Test that gpio_request() copies its string */
  146 +static int dm_test_gpio_copy(struct dm_test_state *dms)
  147 +{
  148 + unsigned int offset, gpio;
  149 + struct udevice *dev;
  150 + char buf[80], name[10];
  151 +
  152 + ut_assertok(gpio_lookup_name("b6", &dev, &offset, &gpio));
  153 + strcpy(name, "odd_name");
  154 + ut_assertok(gpio_request(gpio, name));
  155 + sandbox_gpio_set_direction(dev, offset, 1);
  156 + sandbox_gpio_set_value(dev, offset, 1);
  157 + ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
  158 + ut_asserteq_str("b6: output: 1 [x] odd_name", buf);
  159 + strcpy(name, "nothing");
  160 + ut_assertok(gpio_get_status(dev, offset, buf, sizeof(buf)));
  161 + ut_asserteq_str("b6: output: 1 [x] odd_name", buf);
  162 +
  163 + return 0;
  164 +}
  165 +DM_TEST(dm_test_gpio_copy, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
  166 +
  167 +/* Test that we don't leak memory with GPIOs */
  168 +static int dm_test_gpio_leak(struct dm_test_state *dms)
  169 +{
  170 + ut_assertok(dm_test_gpio(dms));
  171 + ut_assertok(dm_test_gpio_anon(dms));
  172 + ut_assertok(dm_test_gpio_requestf(dms));
  173 + ut_assertok(dm_leak_check_end(dms));
  174 +
  175 + return 0;
  176 +}
  177 +
  178 +DM_TEST(dm_test_gpio_leak, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);