diff mbox series

[18/32] test: cmd: fdt: Test fdt resize

Message ID 20230227195357.98723-18-marek.vasut+renesas@mailbox.org
State Superseded
Delegated to: Simon Glass
Headers show
Series [01/32] cmd: fdt: Import is_printable_string() from DTC to fix u32 misprint | expand

Commit Message

Marek Vasut Feb. 27, 2023, 7:53 p.m. UTC
Add 'fdt resize' test which works as follows:
- Create simple FDT with extra size 0, map it to sysmem
- 'resize' the FDT by 0x2000 bytes
- Verify the new space has been added to the FDT

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 | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)

Comments

Simon Glass March 1, 2023, 3:02 p.m. UTC | #1
On Mon, 27 Feb 2023 at 12:55, Marek Vasut
<marek.vasut+renesas@mailbox.org> wrote:
>
> Add 'fdt resize' test which works as follows:
> - Create simple FDT with extra size 0, map it to sysmem
> - 'resize' the FDT by 0x2000 bytes
> - Verify the new space has been added to the FDT
>
> 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 | 24 ++++++++++++++++++++++++
>  1 file changed, 24 insertions(+)

Reviewed-by: Simon Glass <sjg@chromium.org>
diff mbox series

Patch

diff --git a/test/cmd/fdt.c b/test/cmd/fdt.c
index 023b83eb019..266fb6e3ed0 100644
--- a/test/cmd/fdt.c
+++ b/test/cmd/fdt.c
@@ -272,6 +272,30 @@  static int fdt_test_move(struct unit_test_state *uts)
 }
 FDT_TEST(fdt_test_move, UT_TESTF_CONSOLE_REC);
 
+static int fdt_test_resize(struct unit_test_state *uts)
+{
+	char fdt[256];
+	const unsigned int newsize = 0x2000;
+	uint32_t ts;
+	ulong addr;
+
+	/* Original source DT */
+	ut_assertok(make_test_fdt(uts, fdt, sizeof(fdt)));
+	fdt_shrink_to_minimum(fdt, 0);	/* Resize with 0 extra bytes */
+	ts = fdt_totalsize(fdt);
+	addr = map_to_sysmem(fdt);
+	set_working_fdt_addr(addr);
+
+	/* Test resizing the working FDT and verify the new space was added */
+	ut_assertok(console_record_reset_enable());
+	ut_assertok(run_commandf("fdt resize %x", newsize));
+	ut_asserteq(ts + newsize, fdt_totalsize(fdt));
+	ut_assertok(ut_check_console_end(uts));
+
+	return 0;
+}
+FDT_TEST(fdt_test_resize, UT_TESTF_CONSOLE_REC);
+
 /* Test 'fdt get value' reading an fdt */
 static int fdt_test_get_value_string(struct unit_test_state *uts,
 				     const char *node, const char *prop,