
Hi Detlev,
On Mon, 2 Oct 2023 at 09:22, Detlev Casanova detlev.casanova@collabora.com wrote:
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
Reviewed-by: Simon Glass sjg@chromium.org
nits below
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)},
I would prefer that write out the lines in code. I don't think it helps much to put these in a table.
+};
+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();
drop those two lines
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_assert_nextline(sysinfo_data[i].expected, uts->actual_str);
ut_assertok(ut_check_console_end(uts));
}
return 0;
+}
+LIB_TEST(lib_test_sysinfo, 0);
Add UT_TESTF_CONSOLE_REC
-- 2.41.0
Regards, Simon