public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Detlev Casanova <detlev.casanova@collabora.com>
To: u-boot@lists.denx.de
Cc: Marek Vasut <marek.vasut+renesas@mailbox.org>,
	Hai Pham <hai.pham.ud@renesas.com>,
	Tam Nguyen <tam.nguyen.xa@renesas.com>,
	Simon Glass <sjg@chromium.org>,
	Detlev Casanova <detlev.casanova@collabora.com>
Subject: [PATCH v5 3/6] sysinfo: Add a test
Date: Mon,  2 Oct 2023 11:20:07 -0400	[thread overview]
Message-ID: <20231002152142.76516-4-detlev.casanova@collabora.com> (raw)
In-Reply-To: <20231002152142.76516-1-detlev.casanova@collabora.com>

The test runs one of each subcommand and checks that the output matches
the values in the sandbox sysinfo driver.

Reviewed-by: Marek Vasut <marek.vasut+renesas@mailbox.org>
Signed-off-by: Detlev Casanova <detlev.casanova@collabora.com>
---
 configs/sandbox_defconfig |  1 +
 drivers/sysinfo/sandbox.c | 17 +++++++++++++
 test/cmd/Makefile         |  1 +
 test/cmd/test_sysinfo.c   | 51 +++++++++++++++++++++++++++++++++++++++
 4 files changed, 70 insertions(+)
 create mode 100644 test/cmd/test_sysinfo.c

diff --git a/configs/sandbox_defconfig b/configs/sandbox_defconfig
index 62bc182ca16..409e3d88012 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -129,6 +129,7 @@ CONFIG_CMD_EROFS=y
 CONFIG_CMD_EXT4_WRITE=y
 CONFIG_CMD_SQUASHFS=y
 CONFIG_CMD_MTDPARTS=y
+CONFIG_CMD_SYSINFO=y
 CONFIG_CMD_STACKPROTECTOR_TEST=y
 CONFIG_MAC_PARTITION=y
 CONFIG_AMIGA_PARTITION=y
diff --git a/drivers/sysinfo/sandbox.c b/drivers/sysinfo/sandbox.c
index d270a26aa43..cc7783907a9 100644
--- a/drivers/sysinfo/sandbox.c
+++ b/drivers/sysinfo/sandbox.c
@@ -7,9 +7,14 @@
 #include <common.h>
 #include <dm.h>
 #include <sysinfo.h>
+#include <version.h>
 
 #include "sandbox.h"
 
+#define SANDBOX_BOARD_ID	0x42
+#define SANDBOX_BOARD_REV_MAJOR	U_BOOT_VERSION_NUM
+#define SANDBOX_BOARD_REV_MINOR	U_BOOT_VERSION_NUM_PATCH
+
 struct sysinfo_sandbox_priv {
 	bool called_detect;
 	int test_i1;
@@ -48,6 +53,15 @@ int sysinfo_sandbox_get_int(struct udevice *dev, int id, int *val)
 	struct sysinfo_sandbox_priv *priv = dev_get_priv(dev);
 
 	switch (id) {
+	case SYSINFO_ID_BOARD_ID:
+		*val = SANDBOX_BOARD_ID;
+		return 0;
+	case SYSINFO_ID_BOARD_REV_MAJOR:
+		*val = SANDBOX_BOARD_REV_MAJOR;
+		return 0;
+	case SYSINFO_ID_BOARD_REV_MINOR:
+		*val = SANDBOX_BOARD_REV_MINOR;
+		return 0;
 	case INT_TEST1:
 		*val = priv->test_i1;
 		/* Increments with every call */
@@ -71,6 +85,9 @@ int sysinfo_sandbox_get_str(struct udevice *dev, int id, size_t size, char *val)
 	int index = (i1 * i2) % ARRAY_SIZE(vacation_spots);
 
 	switch (id) {
+	case SYSINFO_ID_BOARD_MODEL:
+		snprintf(val, size, "sandbox");
+		return 0;
 	case STR_VACATIONSPOT:
 		/* Picks a vacation spot depending on i1 and i2 */
 		snprintf(val, size, vacation_spots[index]);
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index 6e3d7e919ef..dc8f59d87f2 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -26,6 +26,7 @@ ifdef CONFIG_SANDBOX
 obj-$(CONFIG_CMD_READ) += rw.o
 obj-$(CONFIG_CMD_SETEXPR) += setexpr.o
 obj-$(CONFIG_ARM_FFA_TRANSPORT) += armffa.o
+obj-$(CONFIG_CMD_SYSINFO) += test_sysinfo.o
 endif
 obj-$(CONFIG_CMD_TEMPERATURE) += temperature.o
 obj-$(CONFIG_CMD_WGET) += wget.o
diff --git a/test/cmd/test_sysinfo.c b/test/cmd/test_sysinfo.c
new file mode 100644
index 00000000000..7ba6dd0df89
--- /dev/null
+++ b/test/cmd/test_sysinfo.c
@@ -0,0 +1,51 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Tests for sysinfo command
+ *
+ * Copyright 2023, Detlev Casanova <detlev.casanova@collabora.com>
+ */
+
+#include <common.h>
+#include <command.h>
+#include <asm/global_data.h>
+#include <display_options.h>
+#include <test/lib.h>
+#include <test/test.h>
+#include <test/ut.h>
+#include <version.h>
+
+DECLARE_GLOBAL_DATA_PTR;
+
+#define REV_(x, y) #x "." #y
+#define REV(x, y) REV_(x, y)
+
+struct test_data {
+	char *cmd;
+	char *expected;
+};
+
+static struct test_data sysinfo_data[] = {
+	{"sysinfo model", "sandbox"},
+	{"sysinfo id", "0x42"},
+	{"sysinfo revision", REV(U_BOOT_VERSION_NUM, U_BOOT_VERSION_NUM_PATCH)},
+};
+
+static int lib_test_sysinfo(struct unit_test_state *uts)
+{
+	int i;
+
+	for (i = 0; i < ARRAY_SIZE(sysinfo_data); ++i) {
+		ut_silence_console(uts);
+		console_record_reset_enable();
+		ut_assertok(run_command(sysinfo_data[i].cmd, 0));
+		ut_unsilence_console(uts);
+		console_record_readline(uts->actual_str,
+					sizeof(uts->actual_str));
+		ut_asserteq_str(sysinfo_data[i].expected, uts->actual_str);
+		ut_assertok(ut_check_console_end(uts));
+	}
+
+	return 0;
+}
+
+LIB_TEST(lib_test_sysinfo, 0);
-- 
2.41.0


  parent reply	other threads:[~2023-10-02 15:22 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-10-02 15:20 [PATCH v5 0/6] Introduce the sysinfo command Detlev Casanova
2023-10-02 15:20 ` [PATCH v5 1/6] sysinfo: Add IDs for board id and revision Detlev Casanova
2023-10-02 18:56   ` Simon Glass
2023-10-16 17:37   ` Heinrich Schuchardt
2023-10-16 18:11     ` Marek Vasut
2023-10-18 17:00     ` Detlev Casanova
2023-10-02 15:20 ` [PATCH v5 2/6] cmd: Add a sysinfo command Detlev Casanova
2023-10-02 18:56   ` Simon Glass
2023-10-16 14:21     ` Detlev Casanova
2023-10-16 21:54       ` Simon Glass
2023-10-02 15:20 ` Detlev Casanova [this message]
2023-10-02 18:56   ` [PATCH v5 3/6] sysinfo: Add a test Simon Glass
2023-10-02 15:20 ` [PATCH v5 4/6] sysinfo: Add documentation Detlev Casanova
2023-10-02 18:56   ` Simon Glass
2023-10-16 18:02   ` Heinrich Schuchardt
2023-10-02 15:20 ` [PATCH v5 5/6] sysinfo: rcar3: Use int instead of char for revision Detlev Casanova
2023-10-07 21:32   ` Marek Vasut
2023-10-02 15:20 ` [PATCH v5 6/6] sysinfo: rcar3: Implement BOARD_ID and BOARD_REV_* Detlev Casanova
2023-10-07 21:35   ` Marek Vasut
2023-10-16 17:03     ` Detlev Casanova
2023-10-16 18:12       ` Marek Vasut

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20231002152142.76516-4-detlev.casanova@collabora.com \
    --to=detlev.casanova@collabora.com \
    --cc=hai.pham.ud@renesas.com \
    --cc=marek.vasut+renesas@mailbox.org \
    --cc=sjg@chromium.org \
    --cc=tam.nguyen.xa@renesas.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox