diff options
author | Tom Rini <trini@konsulko.com> | 2020-07-29 21:16:08 -0400 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2020-07-29 21:16:08 -0400 |
commit | 719f42190d5f0238cb01ef2ffba8af2285f7bc7a (patch) | |
tree | c789716a82ab552e0d0c1a9242fda7c41b04c238 /test | |
parent | 7cb2060b4e63a89c50739dc8a9fcd5d73f86f0be (diff) | |
parent | b9390ce51cb46f4b4acda320e7ea8e0bd120e4b8 (diff) |
Merge tag 'dm-pull-28jul20' of git://git.denx.de/u-boot-dm
Use binman instead of one of the Rockchip build scripts
Refactor to allow any arch to create SPI-flash images
New button uclass
Diffstat (limited to 'test')
-rw-r--r-- | test/dm/Makefile | 1 | ||||
-rw-r--r-- | test/dm/button.c | 74 | ||||
-rw-r--r-- | test/dm/gpio.c | 12 | ||||
-rw-r--r-- | test/py/tests/test_button.py | 19 |
4 files changed, 100 insertions, 6 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); diff --git a/test/dm/gpio.c b/test/dm/gpio.c index 29701389fc..b7ee8fc3ca 100644 --- a/test/dm/gpio.c +++ b/test/dm/gpio.c @@ -114,21 +114,21 @@ static int dm_test_gpio(struct unit_test_state *uts) /* add gpio hog tests */ ut_assertok(gpio_hog_lookup_name("hog_input_active_low", &desc)); ut_asserteq(GPIOD_IS_IN | GPIOD_ACTIVE_LOW, desc->flags); - ut_asserteq(0, desc->offset); + ut_asserteq(10, desc->offset); ut_asserteq(1, dm_gpio_get_value(desc)); ut_assertok(gpio_hog_lookup_name("hog_input_active_high", &desc)); ut_asserteq(GPIOD_IS_IN, desc->flags); - ut_asserteq(1, desc->offset); + ut_asserteq(11, desc->offset); ut_asserteq(0, dm_gpio_get_value(desc)); ut_assertok(gpio_hog_lookup_name("hog_output_low", &desc)); ut_asserteq(GPIOD_IS_OUT, desc->flags); - ut_asserteq(2, desc->offset); + ut_asserteq(12, desc->offset); ut_asserteq(0, dm_gpio_get_value(desc)); ut_assertok(dm_gpio_set_value(desc, 1)); ut_asserteq(1, dm_gpio_get_value(desc)); ut_assertok(gpio_hog_lookup_name("hog_output_high", &desc)); ut_asserteq(GPIOD_IS_OUT, desc->flags); - ut_asserteq(3, desc->offset); + ut_asserteq(13, desc->offset); ut_asserteq(1, dm_gpio_get_value(desc)); ut_assertok(dm_gpio_set_value(desc, 0)); ut_asserteq(0, dm_gpio_get_value(desc)); @@ -137,8 +137,8 @@ static int dm_test_gpio(struct unit_test_state *uts) ut_assertok(gpio_lookup_name("hog_input_active_low", &dev, &offset, &gpio)); ut_asserteq_str(dev->name, "base-gpios"); - ut_asserteq(0, offset); - ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 0, gpio); + ut_asserteq(10, offset); + ut_asserteq(CONFIG_SANDBOX_GPIO_COUNT + 10, gpio); ut_assert(gpio_lookup_name("hog_not_exist", &dev, &offset, &gpio)); diff --git a/test/py/tests/test_button.py b/test/py/tests/test_button.py new file mode 100644 index 0000000000..98067a98f2 --- /dev/null +++ b/test/py/tests/test_button.py @@ -0,0 +1,19 @@ +# SPDX-License-Identifier: GPL-2.0+ + +import pytest + +@pytest.mark.boardspec('sandbox') +@pytest.mark.buildconfigspec('cmd_button') +def test_button_exit_statuses(u_boot_console): + """Test that non-input button commands correctly return the command + success/failure status.""" + + expected_response = 'rc:0' + response = u_boot_console.run_command('button list; echo rc:$?') + assert(expected_response in response) + response = u_boot_console.run_command('button summer; echo rc:$?') + assert(expected_response in response) + + expected_response = 'rc:1' + response = u_boot_console.run_command('button nonexistent-button; echo rc:$?') + assert(expected_response in response) |