diff mbox series

[v2,2/2] test: fdtdec: test fdtdec_set_carveout()

Message ID 20200403104304.32616-3-laurentiu.tudor@nxp.com
State Accepted
Commit 528d6b37ae81a6111e53fb8717a95b802c72a476
Headers show
Series fdtdec: support multiple phandles in memory carveout | expand

Commit Message

Laurentiu Tudor April 3, 2020, 10:43 a.m. UTC
Add a new test for fdtdec_set_carveout().

Signed-off-by: Laurentiu Tudor <laurentiu.tudor at nxp.com>
---
 test/dm/Makefile |  1 +
 test/dm/fdtdec.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 61 insertions(+)
 create mode 100644 test/dm/fdtdec.c

Comments

Simon Glass April 8, 2020, 2:57 a.m. UTC | #1
On Fri, 3 Apr 2020 at 04:43, Laurentiu Tudor <laurentiu.tudor at nxp.com> wrote:
>
> Add a new test for fdtdec_set_carveout().
>
> Signed-off-by: Laurentiu Tudor <laurentiu.tudor at nxp.com>
> ---
>  test/dm/Makefile |  1 +
>  test/dm/fdtdec.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 61 insertions(+)
>  create mode 100644 test/dm/fdtdec.c

Reviewed-by: Simon Glass <sjg at chromium.org>
Simon Glass April 10, 2020, 7:31 p.m. UTC | #2
On Fri, 3 Apr 2020 at 04:43, Laurentiu Tudor <laurentiu.tudor at nxp.com> wrote:
>
> Add a new test for fdtdec_set_carveout().
>
> Signed-off-by: Laurentiu Tudor <laurentiu.tudor at nxp.com>
> ---
>  test/dm/Makefile |  1 +
>  test/dm/fdtdec.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++
>  2 files changed, 61 insertions(+)
>  create mode 100644 test/dm/fdtdec.c

Reviewed-by: Simon Glass <sjg at chromium.org>

Applied to u-boot-dm/next, thanks!
diff mbox series

Patch

diff --git a/test/dm/Makefile b/test/dm/Makefile
index dd1ceff86c..53caa29fbb 100644
--- a/test/dm/Makefile
+++ b/test/dm/Makefile
@@ -31,6 +31,7 @@  obj-$(CONFIG_LED) += led.o
 obj-$(CONFIG_DM_MAILBOX) += mailbox.o
 obj-$(CONFIG_DM_MMC) += mmc.o
 obj-y += ofnode.o
+obj-y += fdtdec.o
 obj-$(CONFIG_OSD) += osd.o
 obj-$(CONFIG_DM_VIDEO) += panel.o
 obj-$(CONFIG_DM_PCI) += pci.o
diff --git a/test/dm/fdtdec.c b/test/dm/fdtdec.c
new file mode 100644
index 0000000000..6636af48d7
--- /dev/null
+++ b/test/dm/fdtdec.c
@@ -0,0 +1,60 @@ 
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2020 NXP
+ */
+
+#include <common.h>
+#include <dm.h>
+#include <dm/of_extra.h>
+#include <dm/test.h>
+#include <test/ut.h>
+
+static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts)
+{
+	struct fdt_memory resv;
+	void *blob;
+	const fdt32_t *prop;
+	int blob_sz, len, offset;
+
+	blob_sz = fdt_totalsize(gd->fdt_blob) + 4096;
+	blob = malloc(blob_sz);
+	ut_assertnonnull(blob);
+
+	/* Make a writtable copy of the fdt blob */
+	ut_assertok(fdt_open_into(gd->fdt_blob, blob, blob_sz));
+
+	resv.start = 0x1000;
+	resv.end = 0x2000;
+	ut_assertok(fdtdec_set_carveout(blob, "/a-test",
+					"memory-region", 2, "test_resv1",
+					&resv));
+
+	resv.start = 0x10000;
+	resv.end = 0x20000;
+	ut_assertok(fdtdec_set_carveout(blob, "/a-test",
+					"memory-region", 1, "test_resv2",
+					&resv));
+
+	resv.start = 0x100000;
+	resv.end = 0x200000;
+	ut_assertok(fdtdec_set_carveout(blob, "/a-test",
+					"memory-region", 0, "test_resv3",
+					&resv));
+
+	offset = fdt_path_offset(blob, "/a-test");
+	ut_assert(offset > 0);
+	prop = fdt_getprop(blob, offset, "memory-region", &len);
+	ut_assertnonnull(prop);
+
+	ut_asserteq(len, 12);
+	ut_assert(fdt_node_offset_by_phandle(blob, fdt32_to_cpu(prop[0])) > 0);
+	ut_assert(fdt_node_offset_by_phandle(blob, fdt32_to_cpu(prop[1])) > 0);
+	ut_assert(fdt_node_offset_by_phandle(blob, fdt32_to_cpu(prop[2])) > 0);
+
+	free(blob);
+
+	return 0;
+}
+DM_TEST(dm_test_fdtdec_set_carveout,
+	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
+