
Hi Marek,
On Mon, 27 Feb 2023 at 12:55, Marek Vasut marek.vasut+renesas@mailbox.org wrote:
Add 'fdt get addr' test which works as follows:
- Create fuller FDT, map it to sysmem
- Get address of various properties
- Compare addresses calculated by UT and fdt command
This test is special in that it has to go through gruesome remapping scheme where the test calculates:
- pointer offsets of the generated FDT root and the property being tested
- map_sysmem() result of environment variable "fdtaddr" and the one set by the test matching address of property being tested
- difference between the later and the former, to obtain offset of the DT property from start of DT
The offsets must match in both the UT and the tested U-Boot, if they do not, the test fails.
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@mailbox.org
Cc: Heinrich Schuchardt heinrich.schuchardt@canonical.com Cc: Simon Glass sjg@chromium.org Cc: Tom Rini trini@konsulko.com
test/cmd/fdt.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+)
Reviewed-by: Simon Glass sjg@chromium.org
diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c index fa95241c8f2..e829052bfd9 100644 --- a/test/cmd/fdt.c +++ b/test/cmd/fdt.c @@ -624,6 +624,72 @@ static int fdt_test_get_name(struct unit_test_state *uts) } FDT_TEST(fdt_test_get_name, UT_TESTF_CONSOLE_REC);
+static int fdt_test_get_addr_common(struct unit_test_state *uts, char *fdt,
const char *path, const char *prop)
+{
unsigned int offset;
int path_offset;
void *prop_ptr;
int len = 0;
ut_assert((path_offset = fdt_path_offset(fdt, path)) >= 0);
I would suggest doing the assigning in a previous line, same below.
ut_assertnonnull(prop_ptr = (void *)fdt_getprop(fdt, path_offset,
prop, &len));
offset = (char *)prop_ptr - fdt;
ut_assertok(console_record_reset_enable());
ut_assertok(run_commandf("fdt get addr pstr %s %s", path, prop));
ut_asserteq((ulong)map_sysmem(env_get_hex("fdtaddr", 0x1234), 0),
(ulong)(map_sysmem(env_get_hex("pstr", 0x1234), 0) - offset));
ut_assertok(ut_check_console_end(uts));
return 0;
+}
[..]
Regards, SImon