diff options
author | Simon Glass <sjg@chromium.org> | 2014-10-04 11:29:51 -0600 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2014-10-23 19:29:53 -0600 |
commit | 4324174d0308c9c81ce246a8e82d2faaefb6d973 (patch) | |
tree | bc1ea0350bd8118f6a060ae7449cea3ec4ec3d50 /test | |
parent | 756ac0bb1526c8c661ad3ff673cd17c7602ab46e (diff) | |
download | u-boot-imx-4324174d0308c9c81ce246a8e82d2faaefb6d973.zip u-boot-imx-4324174d0308c9c81ce246a8e82d2faaefb6d973.tar.gz u-boot-imx-4324174d0308c9c81ce246a8e82d2faaefb6d973.tar.bz2 |
test: dm: Add additional GPIO tests
Add tests for gpio_requestf() and for memory leaks.
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'test')
-rw-r--r-- | test/dm/gpio.c | 38 |
1 files changed, 38 insertions, 0 deletions
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); |