[U-Boot,v1,4/4] test: Add tests for the multiplexer framework
diff mbox series

Message ID 20191002124749.7503-5-jjhiblot@ti.com
State Changes Requested
Delegated to: Tom Rini
Headers show
Series
  • drivers: Add a framework for MUX drivers
Related show

Commit Message

Jean-Jacques Hiblot Oct. 2, 2019, 12:47 p.m. UTC
Provide tests to check the behavior of the multiplexer framework.
The test uses a mmio-based multiplexer.

Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

---

 arch/sandbox/dts/test.dts |  26 +++++++
 configs/sandbox_defconfig |   2 +
 test/dm/Makefile          |   1 +
 test/dm/mux-mmio.c        | 143 ++++++++++++++++++++++++++++++++++++++
 4 files changed, 172 insertions(+)
 create mode 100644 test/dm/mux-mmio.c

Comments

Tom Rini Oct. 24, 2019, 11:45 p.m. UTC | #1
On Wed, Oct 02, 2019 at 02:47:49PM +0200, Jean-Jacques Hiblot wrote:

> Provide tests to check the behavior of the multiplexer framework.
> The test uses a mmio-based multiplexer.
> 
> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>

These tests don't pass (with all of the other series applied as well,
and some warnings fixed up):
_________________________ test_ut[ut_dm_devm_mux_mmio] _________________________

u_boot_console = <u_boot_console_sandbox.ConsoleSandbox object at 0x7f2550b89890>
ut_subtest = 'dm devm_mux_mmio'

    def test_ut(u_boot_console, ut_subtest):
        """Execute a "ut" subtest."""
    
        output = u_boot_console.run_command('ut ' + ut_subtest)
>       assert output.endswith('Failures: 0')
E       assert False
E        +  where False = <built-in method endswith of str object at 0x7f2550567030>('Failures: 0')
E        +    where <built-in method endswith of str object at 0x7f2550567030> = 'Test: dm_test_devm_mux_mmio: mux-mmio.c\r\r\n/builds/u-boot/u-boot/test/dm/mux-mmio.c:110, dm_test_devm_mux_mmio(): "...ux-mmio.c:110, dm_test_devm_mux_mmio(): "b-test" = dev_b->name: Expected "b-test", got "another-test"\r\r\nFailures: 2'.endswith

test/py/tests/test_ut.py:28: AssertionError
----------------------------- Captured stdout call -----------------------------
=> ut dm devm_mux_mmio

Test: dm_test_devm_mux_mmio: mux-mmio.c

/builds/u-boot/u-boot/test/dm/mux-mmio.c:110, dm_test_devm_mux_mmio(): "b-test" = dev_b->name: Expected "b-test", got "another-test"

Test: dm_test_devm_mux_mmio: mux-mmio.c (flat tree)

/builds/u-boot/u-boot/test/dm/mux-mmio.c:110, dm_test_devm_mux_mmio(): "b-test" = dev_b->name: Expected "b-test", got "another-test"

Failures: 2

=> 

Finally, clang-7 reports:
/home/trini/u-boot/u-boot/drivers/mux/mux-uclass.c:108:34: warning: variable 'mux' is uninitialized when used here [-Wuninitialized]
        debug("%s(mux=%p)\n", __func__, mux);
                                        ^~~
/home/trini/u-boot/u-boot/include/log.h:188:28: note: expanded from macro 'debug'
        debug_cond(_DEBUG, fmt, ##args)
                                  ^~~~
/home/trini/u-boot/u-boot/include/log.h:168:41: note: expanded from macro 'debug_cond'
                        log(LOG_CATEGORY, LOGL_DEBUG, fmt, ##args); \
                                                             ^~~~
/home/trini/u-boot/u-boot/include/log.h:139:25: note: expanded from macro 'log'
                      pr_fmt(_fmt), ##_args); \
                                      ^~~~~
/home/trini/u-boot/u-boot/drivers/mux/mux-uclass.c:105:25: note: initialize the variable 'mux' to silence this warning
        struct mux_control *mux;
                               ^
                                = NULL

Thanks!
Jean-Jacques Hiblot Oct. 25, 2019, 9:32 a.m. UTC | #2
Hi Tom,

On 25/10/2019 01:45, Tom Rini wrote:
> On Wed, Oct 02, 2019 at 02:47:49PM +0200, Jean-Jacques Hiblot wrote:
>
>> Provide tests to check the behavior of the multiplexer framework.
>> The test uses a mmio-based multiplexer.
>>
>> Signed-off-by: Jean-Jacques Hiblot <jjhiblot@ti.com>
> These tests don't pass (with all of the other series applied as well,
> and some warnings fixed up):
> _________________________ test_ut[ut_dm_devm_mux_mmio] _________________________
>
> u_boot_console = <u_boot_console_sandbox.ConsoleSandbox object at 0x7f2550b89890>
> ut_subtest = 'dm devm_mux_mmio'
>
>      def test_ut(u_boot_console, ut_subtest):
>          """Execute a "ut" subtest."""
>      
>          output = u_boot_console.run_command('ut ' + ut_subtest)
>>        assert output.endswith('Failures: 0')
> E       assert False
> E        +  where False = <built-in method endswith of str object at 0x7f2550567030>('Failures: 0')
> E        +    where <built-in method endswith of str object at 0x7f2550567030> = 'Test: dm_test_devm_mux_mmio: mux-mmio.c\r\r\n/builds/u-boot/u-boot/test/dm/mux-mmio.c:110, dm_test_devm_mux_mmio(): "...ux-mmio.c:110, dm_test_devm_mux_mmio(): "b-test" = dev_b->name: Expected "b-test", got "another-test"\r\r\nFailures: 2'.endswith

There has been some changes in the regmap support for sandbox. I'll 
rebase on top of master and send an updated version.

Thanks

JJ

>
> test/py/tests/test_ut.py:28: AssertionError
> ----------------------------- Captured stdout call -----------------------------
> => ut dm devm_mux_mmio
>
> Test: dm_test_devm_mux_mmio: mux-mmio.c
>
> /builds/u-boot/u-boot/test/dm/mux-mmio.c:110, dm_test_devm_mux_mmio(): "b-test" = dev_b->name: Expected "b-test", got "another-test"
>
> Test: dm_test_devm_mux_mmio: mux-mmio.c (flat tree)
>
> /builds/u-boot/u-boot/test/dm/mux-mmio.c:110, dm_test_devm_mux_mmio(): "b-test" = dev_b->name: Expected "b-test", got "another-test"
>
> Failures: 2
>
> =>
>
> Finally, clang-7 reports:
> /home/trini/u-boot/u-boot/drivers/mux/mux-uclass.c:108:34: warning: variable 'mux' is uninitialized when used here [-Wuninitialized]
>          debug("%s(mux=%p)\n", __func__, mux);
>                                          ^~~
> /home/trini/u-boot/u-boot/include/log.h:188:28: note: expanded from macro 'debug'
>          debug_cond(_DEBUG, fmt, ##args)
>                                    ^~~~
> /home/trini/u-boot/u-boot/include/log.h:168:41: note: expanded from macro 'debug_cond'
>                          log(LOG_CATEGORY, LOGL_DEBUG, fmt, ##args); \
>                                                               ^~~~
> /home/trini/u-boot/u-boot/include/log.h:139:25: note: expanded from macro 'log'
>                        pr_fmt(_fmt), ##_args); \
>                                        ^~~~~
> /home/trini/u-boot/u-boot/drivers/mux/mux-uclass.c:105:25: note: initialize the variable 'mux' to silence this warning
>          struct mux_control *mux;
>                                 ^
>                                  = NULL
>
> Thanks!

Patch
diff mbox series

diff --git a/arch/sandbox/dts/test.dts b/arch/sandbox/dts/test.dts
index 044895586a..a502dc8bd7 100644
--- a/arch/sandbox/dts/test.dts
+++ b/arch/sandbox/dts/test.dts
@@ -1,3 +1,5 @@ 
+#include <dt-bindings/mux/mux.h>
+
 /dts-v1/;
 
 / {
@@ -89,6 +91,11 @@ 
 			<&gpio_b 9 0xc 3 2 1>;
 		int-value = <1234>;
 		uint-value = <(-1234)>;
+
+		mux-controls = <&muxcontroller0 0>, <&muxcontroller0 1>,
+			       <&muxcontroller0 2>, <&muxcontroller0 3>;
+		mux-control-names = "mux0", "mux1", "mux2", "mux3";
+		mux-syscon = <&syscon3>;
 	};
 
 	junk {
@@ -125,6 +132,9 @@ 
 		compatible = "denx,u-boot-fdt-test";
 		ping-expect = <3>;
 		ping-add = <3>;
+
+		mux-controls = <&muxcontroller0 0>;
+		mux-control-names = "mux0";
 	};
 
 	phy_provider0: gen_phy@0 {
@@ -640,6 +650,22 @@ 
 			0x58 8>;
 	};
 
+	syscon3: syscon@3 {
+		compatible = "simple-mfd", "syscon";
+		reg = <0x000100 0x10>;
+
+		muxcontroller0: a-mux-controller {
+			compatible = "mmio-mux";
+			#mux-control-cells = <1>;
+
+			mux-reg-masks = <0x0 0x30>, /* 0: reg 0x0, bits 5:4 */
+					<0x3 0x1E>, /* 1: reg 0x3, bits 4:1 */
+					<0x1 0xFF>; /* 2: reg 0x1, bits 7:0 */
+			idle-states = <MUX_IDLE_AS_IS>, <0x02>, <0x73>;
+			u-boot,mux-autoprobe;
+		};
+	};
+
 	timer {
 		compatible = "sandbox,timer";
 		clock-frequency = <1000000>;
diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index f77b9e8a7d..aa5d89dfc2 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -143,6 +143,8 @@  CONFIG_SPI_FLASH_SPANSION=y
 CONFIG_SPI_FLASH_STMICRO=y
 CONFIG_SPI_FLASH_SST=y
 CONFIG_SPI_FLASH_WINBOND=y
+CONFIG_MULTIPLEXER=y
+CONFIG_MUX_MMIO=y
 CONFIG_DM_ETH=y
 CONFIG_NVME=y
 CONFIG_PCI=y
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 55a7940053..5fedcb8a7a 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -46,6 +46,7 @@  obj-$(CONFIG_DM_SPI_FLASH) += sf.o
 obj-$(CONFIG_SMEM) += smem.o
 obj-$(CONFIG_DM_SPI) += spi.o
 obj-y += syscon.o
+obj-$(CONFIG_MUX_MMIO) += mux-mmio.o
 obj-$(CONFIG_DM_USB) += usb.o
 obj-$(CONFIG_DM_PMIC) += pmic.o
 obj-$(CONFIG_DM_REGULATOR) += regulator.o
diff --git a/test/dm/mux-mmio.c b/test/dm/mux-mmio.c
new file mode 100644
index 0000000000..8a19281614
--- /dev/null
+++ b/test/dm/mux-mmio.c
@@ -0,0 +1,143 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright (C) 2017-2018 Texas Instruments Incorporated - http://www.ti.com/
+ * Jean-Jacques Hiblot <jjhiblot@ti.com>
+ */
+
+#include <common.h>
+#include <fdtdec.h>
+#include <dm.h>
+#include <mux.h>
+#include <regmap.h>
+#include <syscon.h>
+#include <asm/test.h>
+#include <dm/root.h>
+#include <dm/test.h>
+#include <dm/util.h>
+#include <test/ut.h>
+
+/* Test that mmio mux work correctly */
+static int dm_test_mux_mmio(struct unit_test_state *uts)
+{
+	struct udevice *dev, *dev_b;
+	struct regmap *map;
+	struct mux_control *ctl0_a, *ctl0_b;
+	struct mux_control *ctl1;
+	struct mux_control *ctl_err;
+	u32 val;
+	int i;
+
+	ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
+	ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 1, &dev_b));
+	ut_asserteq_str("a-test", dev->name);
+	ut_asserteq_str("b-test", dev_b->name);
+	map = syscon_regmap_lookup_by_phandle(dev, "mux-syscon");
+	ut_assert(!IS_ERR(map));
+	ut_assert(map);
+
+	/* check default states */
+	ut_assertok(regmap_read(map, 3, &val));
+	ut_asserteq(0x02, (val & 0x1E) >> 1);
+	ut_assertok(regmap_read(map, 1, &val));
+	ut_asserteq(0x73, (val & 0xFF) >> 0);
+
+	ut_assertok(mux_control_get(dev, "mux0", &ctl0_a));
+	ut_assertok(mux_control_get(dev, "mux1", &ctl1));
+	ut_asserteq(-ERANGE, mux_control_get(dev, "mux3", &ctl_err));
+	ut_asserteq(-ENODATA, mux_control_get(dev, "dummy", &ctl_err));
+	ut_assertok(mux_control_get(dev_b, "mux0", &ctl0_b));
+
+	for (i = 0; i < mux_control_states(ctl0_a); i++) {
+		/* select a new state and verify the value in the regmap */
+		ut_assertok(mux_control_select(ctl0_a, i));
+		ut_assertok(regmap_read(map, 0, &val));
+		ut_asserteq(i, (val & 0x30) >> 4);
+		/*
+		 * deselect the mux and verify that the value in the regmap
+		 * reflects the idle state (fixed to MUX_IDLE_AS_IS)
+		 */
+		ut_assertok(mux_control_deselect(ctl0_a));
+		ut_assertok(regmap_read(map, 0, &val));
+		ut_asserteq(i, (val & 0x30) >> 4);
+	}
+
+	for (i = 0; i < mux_control_states(ctl1); i++) {
+		/* select a new state and verify the value in the regmap */
+		ut_assertok(mux_control_select(ctl1, i));
+		ut_assertok(regmap_read(map, 3, &val));
+		ut_asserteq(i, (val & 0x1E) >> 1);
+		/*
+		 * deselect the mux and verify that the value in the regmap
+		 * reflects the idle state (fixed to 2)
+		 */
+		ut_assertok(mux_control_deselect(ctl1));
+		ut_assertok(regmap_read(map, 3, &val));
+		ut_asserteq(2, (val & 0x1E) >> 1);
+	}
+
+	// try unbalanced selection/deselection
+	ut_assertok(mux_control_select(ctl0_a, 0));
+	ut_asserteq(-EBUSY, mux_control_select(ctl0_a, 1));
+	ut_asserteq(-EBUSY, mux_control_select(ctl0_a, 0));
+	ut_assertok(mux_control_deselect(ctl0_a));
+
+	// try concurent selection
+	ut_assertok(mux_control_select(ctl0_a, 0));
+	ut_assert(mux_control_select(ctl0_b, 0));
+	ut_assertok(mux_control_deselect(ctl0_a));
+	ut_assertok(mux_control_select(ctl0_b, 0));
+	ut_assert(mux_control_select(ctl0_a, 0));
+	ut_assertok(mux_control_deselect(ctl0_b));
+	ut_assertok(mux_control_select(ctl0_a, 0));
+	ut_assertok(mux_control_deselect(ctl0_a));
+
+	return 0;
+}
+DM_TEST(dm_test_mux_mmio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+/* Test that managed API for mux work correctly */
+static int dm_test_devm_mux_mmio(struct unit_test_state *uts)
+{
+	struct udevice *dev, *dev_b;
+	struct mux_control *ctl0_a, *ctl0_b;
+	struct mux_control *ctl1;
+	struct mux_control *ctl_err;
+
+	ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 0, &dev));
+	ut_assertok(uclass_get_device(UCLASS_TEST_FDT, 1, &dev_b));
+	ut_asserteq_str("a-test", dev->name);
+	ut_asserteq_str("b-test", dev_b->name);
+
+	ctl0_a = devm_mux_control_get(dev, "mux0");
+	ut_assertok(IS_ERR(ctl0_a));
+	ut_assert(ctl0_a);
+	ctl1 = devm_mux_control_get(dev, "mux1");
+	ut_assertok(IS_ERR(ctl1));
+	ut_assert(ctl1);
+	ctl_err = devm_mux_control_get(dev, "mux3");
+	ut_asserteq(-ERANGE, PTR_ERR(ctl_err));
+	ctl_err = devm_mux_control_get(dev, "dummy");
+	ut_asserteq(-ENODATA, PTR_ERR(ctl_err));
+
+	ctl0_b = devm_mux_control_get(dev_b, "mux0");
+	ut_assertok(IS_ERR(ctl0_b));
+	ut_assert(ctl0_b);
+
+	/* try concurent selection */
+	ut_assertok(mux_control_select(ctl0_a, 0));
+	ut_assert(mux_control_select(ctl0_b, 0));
+	ut_assertok(mux_control_deselect(ctl0_a));
+	ut_assertok(mux_control_select(ctl0_b, 0));
+	ut_assert(mux_control_select(ctl0_a, 0));
+	ut_assertok(mux_control_deselect(ctl0_b));
+
+	/* removed one device and check that the mux is released */
+	ut_assertok(mux_control_select(ctl0_a, 0));
+	ut_assert(mux_control_select(ctl0_b, 0));
+	device_remove(dev, DM_REMOVE_NORMAL);
+	ut_assertok(mux_control_select(ctl0_b, 0));
+
+	device_remove(dev_b, DM_REMOVE_NORMAL);
+	return 0;
+}
+DM_TEST(dm_test_devm_mux_mmio, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);