diff mbox series

[v2,8/8] test: dm: add a test for class button

Message ID 1594988547-24010-8-git-send-email-philippe.reynes@softathome.com
State Superseded
Delegated to: Simon Glass
Headers show
Series [v2,1/8] dm: button: add an uclass for button | expand

Commit Message

Philippe REYNES July 17, 2020, 12:22 p.m. UTC
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>
---
Changelog:
v2:
- new commit in the serie

 test/dm/Makefile |  1 +
 test/dm/button.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 75 insertions(+)
 create mode 100644 test/dm/button.c

Comments

Simon Glass July 19, 2020, 9:32 p.m. UTC | #1
Hi Philippe,

On Fri, 17 Jul 2020 at 06:22, Philippe Reynes
<philippe.reynes@softathome.com> wrote:
>
> 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>
> ---
> Changelog:
> v2:
> - new commit in the serie
>
>  test/dm/Makefile |  1 +
>  test/dm/button.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 75 insertions(+)
>  create mode 100644 test/dm/button.c

This seems to fail with 'make qcheck'. Can you please take a look?
I've left it unapplied for now.

Regards,
Simon
Philippe REYNES July 20, 2020, 2:29 p.m. UTC | #2
Hi Simon,

> Hi Philippe,
> 
> On Fri, 17 Jul 2020 at 06:22, Philippe Reynes
> <philippe.reynes@softathome.com> wrote:
>> 
>> 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>
>> ---
>> Changelog:
>> v2:
>> - new commit in the serie
>> 
>> test/dm/Makefile | 1 +
>> test/dm/button.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> 2 files changed, 75 insertions(+)
>> create mode 100644 test/dm/button.c
> 
> This seems to fail with 'make qcheck'. Can you please take a look?
> I've left it unapplied for now.

I've tried to reproduce this issue, but make qcheck don't work for me.
I have some issues with test for binman, patman, and dtoc.

Could you provide me the log of the issue with 'make qcheck' please ?

 
> Regards,
> Simon


Regards,
Philippe
Simon Glass July 21, 2020, 2:17 p.m. UTC | #3
Hi Philippe,

On Mon, 20 Jul 2020 at 08:30, Philippe REYNES
<philippe.reynes@softathome.com> wrote:
>
> Hi Simon,
>
> > Hi Philippe,
> >
> > On Fri, 17 Jul 2020 at 06:22, Philippe Reynes
> > <philippe.reynes@softathome.com> wrote:
> >>
> >> 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>
> >> ---
> >> Changelog:
> >> v2:
> >> - new commit in the serie
> >>
> >> test/dm/Makefile | 1 +
> >> test/dm/button.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >> 2 files changed, 75 insertions(+)
> >> create mode 100644 test/dm/button.c
> >
> > This seems to fail with 'make qcheck'. Can you please take a look?
> > I've left it unapplied for now.
>
> I've tried to reproduce this issue, but make qcheck don't work for me.
> I have some issues with test for binman, patman, and dtoc.
>
> Could you provide me the log of the issue with 'make qcheck' please ?

See below. What sort of issues are you seeing? I wonder if we should
have a script to set up for running these tests fully.


======================================================= FAILURES
=======================================================
Philippe REYNES July 24, 2020, 4:28 p.m. UTC | #4
Hi Simon,

> Hi Philippe,
> 
> On Mon, 20 Jul 2020 at 08:30, Philippe REYNES
> <philippe.reynes@softathome.com> wrote:
>> 
>> Hi Simon,
>> 
>> > Hi Philippe,
>> > 
>> > On Fri, 17 Jul 2020 at 06:22, Philippe Reynes
>> > <philippe.reynes@softathome.com> wrote:
>> >> 
>> >> 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>
>> >> ---
>> >> Changelog:
>> >> v2:
>> >> - new commit in the serie
>> >> 
>> >> test/dm/Makefile | 1 +
>> >> test/dm/button.c | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>> >> 2 files changed, 75 insertions(+)
>> >> create mode 100644 test/dm/button.c
>> > 
>> > This seems to fail with 'make qcheck'. Can you please take a look?
>> > I've left it unapplied for now.
>> 
>> I've tried to reproduce this issue, but make qcheck don't work for me.
>> I have some issues with test for binman, patman, and dtoc.
>> 
>> Could you provide me the log of the issue with 'make qcheck' please ?
> 
> See below. What sort of issues are you seeing? I wonder if we should
> have a script to set up for running these tests fully.
> 
> 
> ======================================================= FAILURES
> =======================================================
> ______________________________________________
> test_button_exit_statuses
> _______________________________________________
> 
> u_boot_console = <u_boot_console_sandbox.ConsoleSandbox object at
> 0x7fe1121eef60>
> 
> @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)
> E assert 'rc:0' in "Button 'summer' not found (err=-16)\r\r\nrc:1"
> 
> test/py/tests/test_button.py:15: AssertionError
> ------------------------------------------------- Captured stdout call
> -------------------------------------------------
> => button list; echo rc:$?
> summer <inactive>
> christmas <inactive>
> rc:0
> => => button summer; echo rc:$?
> Button 'summer' not found (err=-16)
> rc:1
> =>
> ============================== 1 failed, 512 passed, 59 skipped, 105
> deselected in 43.38s ==============================


I think I have found the issue. This issue only appears after the commit
9ba84329dc45 ("sandbox, test: add test for GPIO_HOG function") that uses
gpio_a 0, 1, 2 and 3.

I've sent a patch do change the gpio used for hog on sandbox. With this
patch, I don't reproduce this issue.

> Regards,
> Simon

Regards,
Philippe
diff mbox series

Patch

diff --git a/test/dm/Makefile b/test/dm/Makefile
index 6c18fd0..092a70e 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -17,6 +17,7 @@  obj-$(CONFIG_ACPIGEN) += acpi.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 0000000..890f470
--- /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);