diff mbox series

[v4,7/7] test: mux-cmd: Add tests for the 'mux' command

Message ID 20201016104636.14138-8-p.yadav@ti.com
State Accepted
Commit 15995ac3f4840ca14340cadd45a1736bb3747893
Delegated to: Tom Rini
Headers show
Series drivers: Add a framework for MUX drivers | expand

Commit Message

Pratyush Yadav Oct. 16, 2020, 10:46 a.m. UTC
Tests tests run the three mux subcommands: list, select, and deselect,
and verify that the commands do what we expect.

Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
---

Notes:
    New in v4.

 configs/sandbox_defconfig |   1 +
 test/dm/Makefile          |   1 +
 test/dm/mux-cmd.c         | 177 ++++++++++++++++++++++++++++++++++++++
 3 files changed, 179 insertions(+)
 create mode 100644 test/dm/mux-cmd.c

Comments

Simon Glass Oct. 27, 2020, 4:52 a.m. UTC | #1
Hi Pratyush,

On Fri, 16 Oct 2020 at 04:46, Pratyush Yadav <p.yadav@ti.com> wrote:
>
> Tests tests run the three mux subcommands: list, select, and deselect,
> and verify that the commands do what we expect.
>
> Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
> ---
>
> Notes:
>     New in v4.
>
>  configs/sandbox_defconfig |   1 +
>  test/dm/Makefile          |   1 +
>  test/dm/mux-cmd.c         | 177 ++++++++++++++++++++++++++++++++++++++
>  3 files changed, 179 insertions(+)
>  create mode 100644 test/dm/mux-cmd.c
>
> diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
> index f3c4883032..e573ae075b 100644
> --- a/configs/sandbox_defconfig
> +++ b/configs/sandbox_defconfig
> @@ -55,6 +55,7 @@ CONFIG_CMD_GPT_RENAME=y
>  CONFIG_CMD_IDE=y
>  CONFIG_CMD_I2C=y
>  CONFIG_CMD_LSBLK=y
> +CONFIG_CMD_MUX=y
>  CONFIG_CMD_OSD=y
>  CONFIG_CMD_PCI=y
>  CONFIG_CMD_READ=y
> diff --git a/test/dm/Makefile b/test/dm/Makefile
> index 93484b48eb..8b3d77e34e 100644
> --- a/test/dm/Makefile
> +++ b/test/dm/Makefile
> @@ -34,6 +34,7 @@ obj-y += irq.o
>  obj-$(CONFIG_LED) += led.o
>  obj-$(CONFIG_DM_MAILBOX) += mailbox.o
>  obj-$(CONFIG_DM_MMC) += mmc.o
> +obj-$(CONFIG_CMD_MUX) += mux-cmd.o
>  obj-y += fdtdec.o
>  obj-y += ofnode.o
>  obj-y += ofread.o
> diff --git a/test/dm/mux-cmd.c b/test/dm/mux-cmd.c
> new file mode 100644
> index 0000000000..11c237b5da
> --- /dev/null
> +++ b/test/dm/mux-cmd.c
> @@ -0,0 +1,177 @@
> +// SPDX-License-Identifier: GPL-2.0
> +/*
> + * Copyright (C) 2020 Texas Instruments Inc.
> + * Pratyush Yadav <p.yadav@ti.com>
> + */
> +#include <common.h>
> +#include <dm.h>
> +#include <mux.h>
> +#include <mux-internal.h>
> +#include <dt-bindings/mux/mux.h>
> +#include <asm/test.h>
> +#include <dm/test.h>
> +#include <test/ut.h>
> +#include <console.h>
> +#include <rand.h>

Check header order

Reviewed-by: Simon Glass <sjg@chromium.org>
Tom Rini Oct. 28, 2020, 6:51 p.m. UTC | #2
On Fri, Oct 16, 2020 at 04:16:36PM +0530, Pratyush Yadav wrote:

> Tests tests run the three mux subcommands: list, select, and deselect,
> and verify that the commands do what we expect.
> 
> Signed-off-by: Pratyush Yadav <p.yadav@ti.com>
> Reviewed-by: Simon Glass <sjg@chromium.org>

Applied to u-boot/master, thanks!
diff mbox series

Patch

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index f3c4883032..e573ae075b 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -55,6 +55,7 @@  CONFIG_CMD_GPT_RENAME=y
 CONFIG_CMD_IDE=y
 CONFIG_CMD_I2C=y
 CONFIG_CMD_LSBLK=y
+CONFIG_CMD_MUX=y
 CONFIG_CMD_OSD=y
 CONFIG_CMD_PCI=y
 CONFIG_CMD_READ=y
diff --git a/test/dm/Makefile b/test/dm/Makefile
index 93484b48eb..8b3d77e34e 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -34,6 +34,7 @@  obj-y += irq.o
 obj-$(CONFIG_LED) += led.o
 obj-$(CONFIG_DM_MAILBOX) += mailbox.o
 obj-$(CONFIG_DM_MMC) += mmc.o
+obj-$(CONFIG_CMD_MUX) += mux-cmd.o
 obj-y += fdtdec.o
 obj-y += ofnode.o
 obj-y += ofread.o
diff --git a/test/dm/mux-cmd.c b/test/dm/mux-cmd.c
new file mode 100644
index 0000000000..11c237b5da
--- /dev/null
+++ b/test/dm/mux-cmd.c
@@ -0,0 +1,177 @@ 
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2020 Texas Instruments Inc.
+ * Pratyush Yadav <p.yadav@ti.com>
+ */
+#include <common.h>
+#include <dm.h>
+#include <mux.h>
+#include <mux-internal.h>
+#include <dt-bindings/mux/mux.h>
+#include <asm/test.h>
+#include <dm/test.h>
+#include <test/ut.h>
+#include <console.h>
+#include <rand.h>
+
+#define BUF_SIZE		256
+
+/* Test 'mux list' */
+static int dm_test_cmd_mux_list(struct unit_test_state *uts)
+{
+	char str[BUF_SIZE], *tok;
+	struct udevice *dev;
+	struct mux_chip *chip;
+	struct mux_control *mux;
+	int i;
+	unsigned long val;
+
+	sandbox_set_enable_memio(true);
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_MUX, "a-mux-controller",
+					      &dev));
+	chip = dev_get_uclass_priv(dev);
+	ut_assertnonnull(chip);
+
+	run_command("mux list", 0);
+	ut_assert_nextline("a-mux-controller:");
+
+	/*
+	 * Check the table header to make sure we are not out of sync with the
+	 * code in the command. If we are, catch it early.
+	 */
+	console_record_readline(str, BUF_SIZE);
+	tok = strtok(str, " ");
+	ut_asserteq_str("ID", tok);
+
+	tok = strtok(NULL, " ");
+	ut_asserteq_str("Selected", tok);
+
+	tok = strtok(NULL, " ");
+	ut_asserteq_str("Current", tok);
+	tok = strtok(NULL, " ");
+	ut_asserteq_str("State", tok);
+
+	tok = strtok(NULL, " ");
+	ut_asserteq_str("Idle", tok);
+	tok = strtok(NULL, " ");
+	ut_asserteq_str("State", tok);
+
+	tok = strtok(NULL, " ");
+	ut_asserteq_str("Num", tok);
+	tok = strtok(NULL, " ");
+	ut_asserteq_str("States", tok);
+
+	for (i = 0; i < chip->controllers; i++) {
+		mux = &chip->mux[i];
+
+		console_record_readline(str, BUF_SIZE);
+
+		/*
+		 * Check if the ID printed matches with the ID of the chip we
+		 * have.
+		 */
+		tok = strtok(str, " ");
+		ut_assertok(strict_strtoul(tok, 10, &val));
+		ut_asserteq(i, val);
+
+		/* Check if mux selection state matches. */
+		tok = strtok(NULL, " ");
+		if (mux->in_use) {
+			ut_asserteq_str("yes", tok);
+		} else {
+			ut_asserteq_str("no", tok);
+		}
+
+		/* Check if the current state matches. */
+		tok = strtok(NULL, " ");
+		if (mux->cached_state == MUX_IDLE_AS_IS) {
+			ut_asserteq_str("unknown", tok);
+		} else {
+			ut_assertok(strict_strtoul(tok, 16, &val));
+			ut_asserteq(mux->cached_state, val);
+		}
+
+		/* Check if the idle state matches */
+		tok = strtok(NULL, " ");
+		if (mux->idle_state == MUX_IDLE_AS_IS) {
+			ut_asserteq_str("as-is", tok);
+		} else {
+			ut_assertok(strict_strtoul(tok, 16, &val));
+			ut_asserteq(mux->idle_state, val);
+		}
+
+		/* Check if the number of states matches */
+		tok = strtok(NULL, " ");
+		ut_assertok(strict_strtoul(tok, 16, &val));
+		ut_asserteq(mux->states, val);
+	}
+
+	return 0;
+}
+DM_TEST(dm_test_cmd_mux_list, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+static int dm_test_cmd_mux_select(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	struct mux_chip *chip;
+	struct mux_control *mux;
+	char cmd[BUF_SIZE];
+	unsigned int i, state;
+
+	sandbox_set_enable_memio(true);
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_MUX, "a-mux-controller",
+					      &dev));
+	chip = dev_get_uclass_priv(dev);
+	ut_assertnonnull(chip);
+
+	srand(get_ticks() + rand());
+	for (i = 0; i < chip->controllers; i++) {
+		mux = &chip->mux[i];
+
+		state = rand() % mux->states;
+
+		snprintf(cmd, BUF_SIZE, "mux select a-mux-controller %x %x", i,
+			 state);
+		run_command(cmd, 0);
+		ut_asserteq(!!mux->in_use, true);
+		ut_asserteq(state, mux->cached_state);
+
+		ut_assertok(mux_control_deselect(mux));
+	}
+
+	return 0;
+}
+DM_TEST(dm_test_cmd_mux_select, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
+
+static int dm_test_cmd_mux_deselect(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	struct mux_chip *chip;
+	struct mux_control *mux;
+	char cmd[BUF_SIZE];
+	unsigned int i, state;
+
+	sandbox_set_enable_memio(true);
+
+	ut_assertok(uclass_get_device_by_name(UCLASS_MUX, "a-mux-controller",
+					      &dev));
+	chip = dev_get_uclass_priv(dev);
+	ut_assertnonnull(chip);
+
+	srand(get_ticks() + rand());
+	for (i = 0; i < chip->controllers; i++) {
+		mux = &chip->mux[i];
+
+		state = rand() % mux->states;
+		ut_assertok(mux_control_select(mux, state));
+
+		snprintf(cmd, BUF_SIZE, "mux deselect a-mux-controller %d", i);
+		run_command(cmd, 0);
+		ut_asserteq(!!mux->in_use, false);
+	}
+
+	return 0;
+}
+DM_TEST(dm_test_cmd_mux_deselect, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);