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 v4 3/6] sysinfo: Add a test
Date: Thu, 20 Jul 2023 10:49:44 -0400 [thread overview]
Message-ID: <20230720145010.84791-4-detlev.casanova@collabora.com> (raw)
In-Reply-To: <20230720145010.84791-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 19cc6701e62..a51762aa3ae 100644
--- a/configs/sandbox_defconfig
+++ b/configs/sandbox_defconfig
@@ -130,6 +130,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 a3cf983739e..d3ac5bf2d5e 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -24,6 +24,7 @@ obj-$(CONFIG_CMD_SEAMA) += seama.o
ifdef CONFIG_SANDBOX
obj-$(CONFIG_CMD_READ) += rw.o
obj-$(CONFIG_CMD_SETEXPR) += setexpr.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
next prev parent reply other threads:[~2023-07-20 14:50 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-07-20 14:49 [PATCH v4 0/6] Introduce the sysinfo command Detlev Casanova
2023-07-20 14:49 ` [PATCH v4 1/6] sysinfo: Add IDs for board id and revision Detlev Casanova
2023-07-20 14:49 ` [PATCH v4 2/6] cmd: Add a sysinfo command Detlev Casanova
2023-07-20 14:49 ` Detlev Casanova [this message]
2023-07-20 14:49 ` [PATCH v4 4/6] sysinfo: Add documentation Detlev Casanova
2023-07-20 14:49 ` [PATCH v4 5/6] sysinfo: rcar3: Use int instead of char for revision Detlev Casanova
2023-07-20 14:49 ` [PATCH v4 6/6] sysinfo: rcar3: Implement BOARD_ID and BOARD_REV_* Detlev Casanova
2023-08-08 14:21 ` [PATCH v4 0/6] Introduce the sysinfo command Peter Robinson
2023-08-08 14:27 ` Detlev Casanova
2023-08-08 14:31 ` Peter Robinson
2023-08-08 14:48 ` 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=20230720145010.84791-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