[PATCH v2 26/32] test: cmd: fdt: Test fdt header
Marek Vasut
marek.vasut+renesas at mailbox.org
Thu Mar 2 04:08:39 CET 2023
Add 'fdt header' test which works as follows:
- Create basic FDT, map it to sysmem
- Print the FDT header
- Get all members of the FDT header into variable and
verify the variables contain correct data
The test case can be triggered using:
"
./u-boot -Dc 'ut fdt'
"
To dump the full output from commands used during test, add '-v' flag.
Signed-off-by: Marek Vasut <marek.vasut+renesas at mailbox.org>
Reviewed-by: Simon Glass <sjg at chromium.org>
---
Cc: Heinrich Schuchardt <heinrich.schuchardt at canonical.com>
Cc: Simon Glass <sjg at chromium.org>
Cc: Tom Rini <trini at konsulko.com>
---
V2: Add RB from Simon
---
test/cmd/fdt.c | 59 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 59 insertions(+)
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 509e9e8369b..7dc9e800d38 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -1074,6 +1074,65 @@ static int fdt_test_rm(struct unit_test_state *uts)
}
FDT_TEST(fdt_test_rm, UT_TESTF_CONSOLE_REC);
+static int fdt_test_header_get(struct unit_test_state *uts, char fdt[4096],
+ const char *field, const unsigned long val)
+{
+ /* Test getting valid header entry */
+ ut_assertok(console_record_reset_enable());
+ ut_assertok(run_commandf("fdt header get fvar %s", field));
+ ut_asserteq(val, env_get_hex("fvar", 0x1234));
+ ut_assertok(ut_check_console_end(uts));
+
+ /* Test getting malformed header entry */
+ ut_assertok(console_record_reset_enable());
+ ut_asserteq(1, run_commandf("fdt header get fvar typo%stypo", field));
+ ut_assertok(ut_check_console_end(uts));
+
+ return 0;
+}
+
+static int fdt_test_header(struct unit_test_state *uts)
+{
+ char fdt[256];
+ ulong addr;
+
+ ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
+ addr = map_to_sysmem(fdt);
+ set_working_fdt_addr(addr);
+
+ /* Test header print */
+ ut_assertok(console_record_reset_enable());
+ ut_assertok(run_commandf("fdt header"));
+ ut_assert_nextline("magic:\t\t\t0x%x", fdt_magic(fdt));
+ ut_assert_nextline("totalsize:\t\t0x%x (%d)", fdt_totalsize(fdt), fdt_totalsize(fdt));
+ ut_assert_nextline("off_dt_struct:\t\t0x%x", fdt_off_dt_struct(fdt));
+ ut_assert_nextline("off_dt_strings:\t\t0x%x", fdt_off_dt_strings(fdt));
+ ut_assert_nextline("off_mem_rsvmap:\t\t0x%x", fdt_off_mem_rsvmap(fdt));
+ ut_assert_nextline("version:\t\t%d", fdt_version(fdt));
+ ut_assert_nextline("last_comp_version:\t%d", fdt_last_comp_version(fdt));
+ ut_assert_nextline("boot_cpuid_phys:\t0x%x", fdt_boot_cpuid_phys(fdt));
+ ut_assert_nextline("size_dt_strings:\t0x%x", fdt_size_dt_strings(fdt));
+ ut_assert_nextline("size_dt_struct:\t\t0x%x", fdt_size_dt_struct(fdt));
+ ut_assert_nextline("number mem_rsv:\t\t0x%x", fdt_num_mem_rsv(fdt));
+ ut_assert_nextline_empty();
+ ut_assertok(ut_check_console_end(uts));
+
+ /* Test header get */
+ fdt_test_header_get(uts, fdt, "magic", fdt_magic(fdt));
+ fdt_test_header_get(uts, fdt, "totalsize", fdt_totalsize(fdt));
+ fdt_test_header_get(uts, fdt, "off_dt_struct", fdt_off_dt_struct(fdt));
+ fdt_test_header_get(uts, fdt, "off_dt_strings", fdt_off_dt_strings(fdt));
+ fdt_test_header_get(uts, fdt, "off_mem_rsvmap", fdt_off_mem_rsvmap(fdt));
+ fdt_test_header_get(uts, fdt, "version", fdt_version(fdt));
+ fdt_test_header_get(uts, fdt, "last_comp_version", fdt_last_comp_version(fdt));
+ fdt_test_header_get(uts, fdt, "boot_cpuid_phys", fdt_boot_cpuid_phys(fdt));
+ fdt_test_header_get(uts, fdt, "size_dt_strings", fdt_size_dt_strings(fdt));
+ fdt_test_header_get(uts, fdt, "size_dt_struct", fdt_size_dt_struct(fdt));
+
+ return 0;
+}
+FDT_TEST(fdt_test_header, UT_TESTF_CONSOLE_REC);
+
int do_ut_fdt(struct cmd_tbl *cmdtp, int flag, int argc, char *const argv[])
{
struct unit_test *tests = UNIT_TEST_SUITE_START(fdt_test);
--
2.39.2
More information about the U-Boot
mailing list