From patchwork Fri Oct 16 10:46:36 2020
Content-Type: text/plain; charset="utf-8"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
X-Patchwork-Submitter: Pratyush Yadav
X-Patchwork-Id: 1383233
X-Patchwork-Delegate: trini@ti.com
Return-Path:
X-Original-To: incoming@patchwork.ozlabs.org
Delivered-To: patchwork-incoming@bilbo.ozlabs.org
Authentication-Results: ozlabs.org;
spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de
(client-ip=85.214.62.61; helo=phobos.denx.de;
envelope-from=u-boot-bounces@lists.denx.de; receiver=)
Authentication-Results: ozlabs.org;
dmarc=pass (p=quarantine dis=none) header.from=ti.com
Authentication-Results: ozlabs.org;
dkim=pass (1024-bit key;
unprotected) header.d=ti.com header.i=@ti.com header.a=rsa-sha256
header.s=ti-com-17Q1 header.b=jW+lXlfI;
dkim-atps=neutral
Received: from phobos.denx.de (phobos.denx.de [85.214.62.61])
(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
key-exchange X25519 server-signature RSA-PSS (4096 bits))
(No client certificate requested)
by ozlabs.org (Postfix) with ESMTPS id 4CCND13NWkz9sTK
for ; Fri, 16 Oct 2020 21:48:17 +1100 (AEDT)
Received: from h2850616.stratoserver.net (localhost [IPv6:::1])
by phobos.denx.de (Postfix) with ESMTP id 9B6DB82443;
Fri, 16 Oct 2020 12:47:03 +0200 (CEST)
Authentication-Results: phobos.denx.de;
dmarc=pass (p=quarantine dis=none) header.from=ti.com
Authentication-Results: phobos.denx.de;
spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de
Authentication-Results: phobos.denx.de;
dkim=pass (1024-bit key;
unprotected) header.d=ti.com header.i=@ti.com header.b="jW+lXlfI";
dkim-atps=neutral
Received: by phobos.denx.de (Postfix, from userid 109)
id BF60782431; Fri, 16 Oct 2020 12:46:58 +0200 (CEST)
X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de
X-Spam-Level:
X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,
DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,RCVD_IN_MSPIKE_H4,
RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham
autolearn_force=no version=3.4.2
Received: from fllv0015.ext.ti.com (fllv0015.ext.ti.com [198.47.19.141])
(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
(No client certificate requested)
by phobos.denx.de (Postfix) with ESMTPS id ED72E81BD2
for ; Fri, 16 Oct 2020 12:46:55 +0200 (CEST)
Authentication-Results: phobos.denx.de;
dmarc=pass (p=quarantine dis=none) header.from=ti.com
Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=p.yadav@ti.com
Received: from lelv0265.itg.ti.com ([10.180.67.224])
by fllv0015.ext.ti.com (8.15.2/8.15.2) with ESMTP id 09GAksvn067555;
Fri, 16 Oct 2020 05:46:54 -0500
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com;
s=ti-com-17Q1; t=1602845214;
bh=tu+da23BaI0VQ+YpVtJmMGmwScv8per1jszkq7cthRo=;
h=From:To:CC:Subject:Date:In-Reply-To:References;
b=jW+lXlfIFrQYXi4bwmwxR4jostmK8VJkgOwABuYSOKwi+6lIX23GW4J9XGvFUFA3O
yyQabfqysMTbU8Bw3xKxm69Ux23G3rzgxaWMCQxLV/6Vgi2WjCfAkfPZ6TqVvf03yo
+mZtk5+DwjY5dpx0YjRiwo8K6kofPDU2rurQIdqk=
Received: from DLEE109.ent.ti.com (dlee109.ent.ti.com [157.170.170.41])
by lelv0265.itg.ti.com (8.15.2/8.15.2) with ESMTPS id 09GAksEM121859
(version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL);
Fri, 16 Oct 2020 05:46:54 -0500
Received: from DLEE115.ent.ti.com (157.170.170.26) by DLEE109.ent.ti.com
(157.170.170.41) with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3; Fri, 16
Oct 2020 05:46:53 -0500
Received: from lelv0326.itg.ti.com (10.180.67.84) by DLEE115.ent.ti.com
(157.170.170.26) with Microsoft SMTP Server (version=TLS1_2,
cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1979.3 via
Frontend Transport; Fri, 16 Oct 2020 05:46:53 -0500
Received: from pratyush-OptiPlex-790.dhcp.ti.com (ileax41-snat.itg.ti.com
[10.172.224.153])
by lelv0326.itg.ti.com (8.15.2/8.15.2) with ESMTP id 09GAkbSj016923;
Fri, 16 Oct 2020 05:46:52 -0500
From: Pratyush Yadav
To: Tom Rini
CC: Pratyush Yadav , , Simon Glass
, Vignesh Raghavendra
Subject: [PATCH v4 7/7] test: mux-cmd: Add tests for the 'mux' command
Date: Fri, 16 Oct 2020 16:16:36 +0530
Message-ID: <20201016104636.14138-8-p.yadav@ti.com>
X-Mailer: git-send-email 2.28.0
In-Reply-To: <20201016104636.14138-1-p.yadav@ti.com>
References: <20201016104636.14138-1-p.yadav@ti.com>
MIME-Version: 1.0
X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180
X-BeenThere: u-boot@lists.denx.de
X-Mailman-Version: 2.1.34
Precedence: list
List-Id: U-Boot discussion
List-Unsubscribe: ,
List-Archive:
List-Post:
List-Help:
List-Subscribe: ,
Errors-To: u-boot-bounces@lists.denx.de
Sender: "U-Boot"
X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de
X-Virus-Status: Clean
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
Reviewed-by: Simon Glass
---
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
+ */
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+
+#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);