test: dm: Add additional GPIO tests
Add tests for gpio_requestf() and for memory leaks. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
756ac0bb15
commit
4324174d03
|
@ -95,7 +95,7 @@ are provided in test/dm. To run them, try:
|
||||||
You should see something like this:
|
You should see something like this:
|
||||||
|
|
||||||
<...U-Boot banner...>
|
<...U-Boot banner...>
|
||||||
Running 27 driver model tests
|
Running 29 driver model tests
|
||||||
Test: dm_test_autobind
|
Test: dm_test_autobind
|
||||||
Test: dm_test_autoprobe
|
Test: dm_test_autoprobe
|
||||||
Test: dm_test_bus_children
|
Test: dm_test_bus_children
|
||||||
|
@ -117,6 +117,9 @@ You should see something like this:
|
||||||
Test: dm_test_gpio
|
Test: dm_test_gpio
|
||||||
extra-gpios: get_value: error: gpio b5 not reserved
|
extra-gpios: get_value: error: gpio b5 not reserved
|
||||||
Test: dm_test_gpio_anon
|
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_gpio_requestf
|
||||||
Test: dm_test_leak
|
Test: dm_test_leak
|
||||||
Test: dm_test_lifecycle
|
Test: dm_test_lifecycle
|
||||||
|
|
|
@ -7,11 +7,14 @@
|
||||||
#include <common.h>
|
#include <common.h>
|
||||||
#include <fdtdec.h>
|
#include <fdtdec.h>
|
||||||
#include <dm.h>
|
#include <dm.h>
|
||||||
|
#include <dm/root.h>
|
||||||
#include <dm/ut.h>
|
#include <dm/ut.h>
|
||||||
#include <dm/test.h>
|
#include <dm/test.h>
|
||||||
#include <dm/util.h>
|
#include <dm/util.h>
|
||||||
#include <asm/gpio.h>
|
#include <asm/gpio.h>
|
||||||
|
|
||||||
|
DECLARE_GLOBAL_DATA_PTR;
|
||||||
|
|
||||||
/* Test that sandbox GPIOs work correctly */
|
/* Test that sandbox GPIOs work correctly */
|
||||||
static int dm_test_gpio(struct dm_test_state *dms)
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
DM_TEST(dm_test_gpio_requestf, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
|
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);
|
||||||
|
|
Loading…
Reference in New Issue