[PATCH v3 7/7] test: cmd: fru: add unit test for the fru command
Jae Hyun Yoo
quic_jaehyoo at quicinc.com
Tue Aug 23 23:53:00 CEST 2022
Add test cases for the fru command.
Signed-off-by: Jae Hyun Yoo <quic_jaehyoo at quicinc.com>
---
Changes from v2:
* Newly added in v3. (Simon)
include/test/suites.h | 1 +
test/cmd/Makefile | 1 +
test/cmd/fru.c | 84 +++++++++++++++++++++++++++++++++++++++++++
test/cmd_ut.c | 6 ++++
4 files changed, 92 insertions(+)
create mode 100644 test/cmd/fru.c
diff --git a/include/test/suites.h b/include/test/suites.h
index 44025ccecd6f..1d4a8c3e4a66 100644
--- a/include/test/suites.h
+++ b/include/test/suites.h
@@ -39,6 +39,7 @@ int do_ut_compression(struct cmd_tbl *cmdtp, int flag, int argc,
int do_ut_dm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
int do_ut_env(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
+int do_ut_fru(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
int do_ut_lib(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
int do_ut_loadm(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[]);
int do_ut_log(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]);
diff --git a/test/cmd/Makefile b/test/cmd/Makefile
index c331757425ea..5995384dad91 100644
--- a/test/cmd/Makefile
+++ b/test/cmd/Makefile
@@ -8,6 +8,7 @@ endif
obj-y += mem.o
obj-$(CONFIG_CMD_ADDRMAP) += addrmap.o
obj-$(CONFIG_CMD_FDT) += fdt.o
+obj-$(CONFIG_CMD_FRU) += fru.o
obj-$(CONFIG_CMD_LOADM) += loadm.o
obj-$(CONFIG_CMD_MEM_SEARCH) += mem_search.o
obj-$(CONFIG_CMD_PINMUX) += pinmux.o
diff --git a/test/cmd/fru.c b/test/cmd/fru.c
new file mode 100644
index 000000000000..fa560622cf0b
--- /dev/null
+++ b/test/cmd/fru.c
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Executes tests for fru command
+ *
+ * Copyright (c) 2022 Qualcomm Innovation Center, Inc. All rights reserved.
+ */
+
+#include <common.h>
+#include <console.h>
+#include <mapmem.h>
+#include <test/suites.h>
+#include <test/ut.h>
+
+#define FRU_TEST(_name, _flags) UNIT_TEST(_name, _flags, fru_test)
+
+#define CMD_FRU_TEST_SRC_BUF_SIZE 1024
+
+static const char cmd_gen_b[] =
+ "fru generate -b %08lx abcd efgh ijkl mnop qrst uvwx";
+static const char cmd_gen_p[] =
+ "fru generate -p %08lx abcd efgh ijkl mnop qrst uvwx yz01 2345";
+
+static const char cmd_capture[] = "fru capture %08lx";
+
+static int fru_test_board(struct unit_test_state *uts)
+{
+ u8 fru_src[CMD_FRU_TEST_SRC_BUF_SIZE];
+ int i;
+
+ ut_assertok(console_record_reset_enable());
+ ut_assertok(run_commandf(cmd_gen_b, (ulong)map_to_sysmem(fru_src)));
+ ut_assertok(run_commandf(cmd_capture, (ulong)map_to_sysmem(fru_src)));
+ ut_assertok(run_command("fru display", 0));
+ for (i = 0; i < 11; i++)
+ ut_assert_skipline();
+ ut_assert_nextline(" Manufacturer Name: abcd");
+ ut_assert_nextline(" Product Name: efgh");
+ ut_assert_nextline(" Serial Number: ijkl");
+ ut_assert_nextline(" Part Number: mnop");
+ ut_assert_nextline(" File ID: qrst");
+ ut_assert_nextline(" Custom Type/Length: 0xc4");
+ ut_assert_nextline(" 00000000: 75 76 77 78 uvwx");
+ for (i = 0; i < 4; i++)
+ ut_assert_skipline();
+ ut_assertok(ut_check_console_end(uts));
+
+ return 0;
+}
+FRU_TEST(fru_test_board, UT_TESTF_CONSOLE_REC);
+
+static int fru_test_product(struct unit_test_state *uts)
+{
+ u8 fru_src[CMD_FRU_TEST_SRC_BUF_SIZE];
+ int i;
+
+ ut_assertok(console_record_reset_enable());
+ ut_assertok(run_commandf(cmd_gen_p, (ulong)map_to_sysmem(fru_src)));
+ ut_assertok(run_commandf(cmd_capture, (ulong)map_to_sysmem(fru_src)));
+ ut_assertok(run_command("fru display", 0));
+ for (i = 0; i < 14; i++)
+ ut_assert_skipline();
+ ut_assert_nextline(" Manufacturer Name: abcd");
+ ut_assert_nextline(" Product Name: efgh");
+ ut_assert_nextline(" Part Number: ijkl");
+ ut_assert_nextline(" Version Number: mnop");
+ ut_assert_nextline(" Serial Number: qrst");
+ ut_assert_nextline(" Asset Number: uvwx");
+ ut_assert_nextline(" File ID: yz01");
+ ut_assert_nextline(" Custom Type/Length: 0xc4");
+ ut_assert_nextline(" 00000000: 32 33 34 35 2345");
+ ut_assert_skipline();
+ ut_assertok(ut_check_console_end(uts));
+
+ return 0;
+}
+FRU_TEST(fru_test_product, UT_TESTF_CONSOLE_REC);
+
+int do_ut_fru(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
+{
+ struct unit_test *tests = UNIT_TEST_SUITE_START(fru_test);
+ const int n_ents = UNIT_TEST_SUITE_COUNT(fru_test);
+
+ return cmd_ut_category("fru", "fru_test_", tests, n_ents, argc, argv);
+}
diff --git a/test/cmd_ut.c b/test/cmd_ut.c
index 3789c6b784c0..4c163da8176c 100644
--- a/test/cmd_ut.c
+++ b/test/cmd_ut.c
@@ -80,6 +80,9 @@ static struct cmd_tbl cmd_ut_sub[] = {
#ifdef CONFIG_CMD_LOADM
U_BOOT_CMD_MKENT(loadm, CONFIG_SYS_MAXARGS, 1, do_ut_loadm, "", ""),
#endif
+#ifdef CONFIG_CMD_FRU
+ U_BOOT_CMD_MKENT(fru, CONFIG_SYS_MAXARGS, 1, do_ut_fru, "", ""),
+#endif
};
static int do_ut_all(struct cmd_tbl *cmdtp, int flag, int argc,
@@ -167,6 +170,9 @@ static char ut_help_text[] =
#endif
#ifdef CONFIG_CMD_LOADM
"ut loadm [test-name]- test of parameters and load memory blob\n"
+#endif
+#ifdef CONFIG_CMD_FRU
+ "ut fru [test-name] - test of the fru command\n"
#endif
;
#endif /* CONFIG_SYS_LONGHELP */
--
2.25.1
More information about the U-Boot
mailing list