diff options
author | Philippe Reynes <philippe.reynes@softathome.com> | 2020-07-24 19:19:52 +0300 |
---|---|---|
committer | Simon Glass <sjg@chromium.org> | 2020-07-29 04:30:39 +0300 |
commit | 1d310001dc47bd2582d03d05a167b5adf7d4f3b8 (patch) | |
tree | b30774acbb155914410a98777f82160e843aaea5 /test | |
parent | a6c6f0f0c8880b2f3d04784eef49f85b78d0f29e (diff) | |
download | u-boot-1d310001dc47bd2582d03d05a167b5adf7d4f3b8.tar.xz |
test: dm: add a test for class button
Add a test to confirm that we can read button state
using the button-gpio driver.
Signed-off-by: Philippe Reynes <philippe.reynes@softathome.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/dm/Makefile | 1 | ||||
-rw-r--r-- | test/dm/button.c | 74 |
2 files changed, 75 insertions, 0 deletions
diff --git a/test/dm/Makefile b/test/dm/Makefile index 839111791b..864c8d0b4c 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -19,6 +19,7 @@ obj-$(CONFIG_ACPIGEN) += acpi_dp.o obj-$(CONFIG_SOUND) += audio.o obj-$(CONFIG_BLK) += blk.o obj-$(CONFIG_BOARD) += board.o +obj-$(CONFIG_BUTTON) += button.o obj-$(CONFIG_DM_BOOTCOUNT) += bootcount.o obj-$(CONFIG_CLK) += clk.o clk_ccf.o obj-$(CONFIG_DEVRES) += devres.o diff --git a/test/dm/button.c b/test/dm/button.c new file mode 100644 index 0000000000..890f470d97 --- /dev/null +++ b/test/dm/button.c @@ -0,0 +1,74 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Copyright (C) 2020 Philippe Reynes <philippe.reynes@softathome.com> + * + * Based on led.c + */ + +#include <common.h> +#include <dm.h> +#include <button.h> +#include <asm/gpio.h> +#include <dm/test.h> +#include <test/ut.h> + +/* Base test of the button uclass */ +static int dm_test_button_base(struct unit_test_state *uts) +{ + struct udevice *dev; + + /* Get the top-level device */ + ut_assertok(uclass_get_device(UCLASS_BUTTON, 0, &dev)); + ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, &dev)); + ut_assertok(uclass_get_device(UCLASS_BUTTON, 2, &dev)); + ut_asserteq(-ENODEV, uclass_get_device(UCLASS_BUTTON, 3, &dev)); + + return 0; +} +DM_TEST(dm_test_button_base, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test of the button uclass using the button_gpio driver */ +static int dm_test_button_gpio(struct unit_test_state *uts) +{ + const int offset = 3; + struct udevice *dev, *gpio; + + /* + * Check that we can manipulate an BUTTON. BUTTON 1 is connected to GPIO + * bank gpio_a, offset 3. + */ + ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, &dev)); + ut_assertok(uclass_get_device(UCLASS_GPIO, 1, &gpio)); + + ut_asserteq(0, sandbox_gpio_set_value(gpio, offset, 0)); + ut_asserteq(0, sandbox_gpio_get_value(gpio, offset)); + ut_asserteq(BUTTON_OFF, button_get_state(dev)); + + ut_asserteq(0, sandbox_gpio_set_value(gpio, offset, 1)); + ut_asserteq(1, sandbox_gpio_get_value(gpio, offset)); + ut_asserteq(BUTTON_ON, button_get_state(dev)); + + return 0; +} +DM_TEST(dm_test_button_gpio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); + +/* Test obtaining an BUTTON by label */ +static int dm_test_button_label(struct unit_test_state *uts) +{ + struct udevice *dev, *cmp; + + ut_assertok(button_get_by_label("summer", &dev)); + ut_asserteq(1, device_active(dev)); + ut_assertok(uclass_get_device(UCLASS_BUTTON, 1, &cmp)); + ut_asserteq_ptr(dev, cmp); + + ut_assertok(button_get_by_label("christmas", &dev)); + ut_asserteq(1, device_active(dev)); + ut_assertok(uclass_get_device(UCLASS_BUTTON, 2, &cmp)); + ut_asserteq_ptr(dev, cmp); + + ut_asserteq(-ENODEV, button_get_by_label("spring", &dev)); + + return 0; +} +DM_TEST(dm_test_button_label, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); |