Skip to contentSkip to conversation

test/dm: fdtdec: Add the missing gd declaration

PATCH New Bin Meng 2 participants 6 messages Jun 23, 2020 – Jul 6, 2020

lore
Share & tools
lore

Bin Meng

author
#0 lore raw

PATCH v4 1/3 test/dm: fdtdec: Add the missing gd declaration

From: Bin Meng <[email protected]>

Add DECLARE_GLOBAL_DATA_PTR since it is referenced in the test codes.

---

Changes in v4:
- drop the first 2 patches that are already applied
- rebase against u-boot/next branch

 test/dm/fdtdec.c | 2 ++
 1 file changed, 2 insertions(+)
test/dm/fdtdec.c +2 -0
index b2f75b5..c2f7b94 100644
@@ -9,6 +9,8 @@
 #include <dm/test.h>
 #include <test/ut.h>
 
+DECLARE_GLOBAL_DATA_PTR;
+
 static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts)
 {
 	struct fdt_memory resv;
Signature · 1 line
2.7.4
author
#1 lore raw

PATCH v4 2/3 test/dm: fdtdec: Corect a typo in dm_test_fdtdec_set_carveout()

From: Bin Meng <[email protected]>

It should be "writable".

---

(no changes since v1)

 test/dm/fdtdec.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
test/dm/fdtdec.c +1 -1
index c2f7b94..999d712 100644
@@ -22,7 +22,7 @@ static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts)
 	blob = malloc(blob_sz);
 	ut_assertnonnull(blob);
 
-	/* Make a writtable copy of the fdt blob */
+	/* Make a writable copy of the fdt blob */
 	ut_assertok(fdt_open_into(gd->fdt_blob, blob, blob_sz));
 
 	resv.start = 0x1000;
Signature · 1 line
2.7.4
author
#3 lore raw

PATCH v4 3/3 test/dm: fdtdec: Add tests for fdtdec_add_reserved_memory()

In reply to Bin Meng

From: Bin Meng <[email protected]>

This adds a test case to test the functionality of the fdtdec API fdtdec_add_reserved_memory().

---

(no changes since v3)

Changes in v3:
- correct typo in the comments, and some minor rewording

 test/dm/fdtdec.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)
test/dm/fdtdec.c +69 -0
index 999d712..56f6f4f 100644
@@ -59,3 +59,72 @@ static int dm_test_fdtdec_set_carveout(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_fdtdec_set_carveout,
 	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
+
+static int dm_test_fdtdec_add_reserved_memory(struct unit_test_state *uts)
+{
+	struct fdt_memory resv;
+	fdt_addr_t addr;
+	fdt_size_t size;
+	void *blob;
+	int blob_sz, parent, subnode;
+	uint32_t phandle, phandle1;
+
+	blob_sz = fdt_totalsize(gd->fdt_blob) + 128;
+	blob = malloc(blob_sz);
+	ut_assertnonnull(blob);
+
+	/* Make a writable copy of the fdt blob */
+	ut_assertok(fdt_open_into(gd->fdt_blob, blob, blob_sz));
+
+	/* Insert a memory region in /reserved-memory node */
+	resv.start = 0x1000;
+	resv.end = 0x1fff;
+	ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region",
+					       &resv, &phandle));
+
+	/* Test /reserve-memory and its subnode should exist */
+	parent = fdt_path_offset(blob, "/reserved-memory");
+	ut_assert(parent > 0);
+	subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region");
+	ut_assert(subnode > 0);
+
+	/* Test reg property of /reserved-memory/rsvd_region node */
+	addr = fdtdec_get_addr_size_auto_parent(blob, parent, subnode,
+						"reg", 0, &size, false);
+	ut_assert(addr == resv.start);
+	ut_assert(size == resv.end -  resv.start + 1);
+
+	/* Insert another memory region in /reserved-memory node */
+	subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region1");
+	ut_assert(subnode < 0);
+
+	resv.start = 0x2000;
+	resv.end = 0x2fff;
+	ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region1",
+					       &resv, &phandle1));
+	subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region1");
+	ut_assert(subnode > 0);
+
+	/* phandles must be different */
+	ut_assert(phandle != phandle1);
+
+	/*
+	 * Insert a 3rd memory region with the same addr/size as the 1st one,
+	 * but a new node should not be inserted due to the same addr/size.
+	 */
+	resv.start = 0x1000;
+	resv.end = 0x1fff;
+	ut_assertok(fdtdec_add_reserved_memory(blob, "rsvd_region2",
+					       &resv, &phandle1));
+	subnode = fdt_path_offset(blob, "/reserved-memory/rsvd_region2");
+	ut_assert(subnode < 0);
+
+	/* phandle must be same as the 1st one */
+	ut_assert(phandle == phandle1);
+
+	free(blob);
+
+	return 0;
+}
+DM_TEST(dm_test_fdtdec_add_reserved_memory,
+	DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT | DM_TESTF_FLAT_TREE);
Signature · 1 line
2.7.4
#4 lore raw

PATCH v4 3/3 test/dm: fdtdec: Add tests for fdtdec_add_reserved_memory()

From: Bin Meng <[email protected]>

This adds a test case to test the functionality of the fdtdec API fdtdec_add_reserved_memory().

---

(no changes since v3)

Changes in v3:
- correct typo in the comments, and some minor rewording

 test/dm/fdtdec.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 69 insertions(+)

Applied to u-boot-dm/next, thanks!

#5 lore raw

PATCH v4 1/3 test/dm: fdtdec: Add the missing gd declaration

In reply to Bin Meng

From: Bin Meng <[email protected]>

Add DECLARE_GLOBAL_DATA_PTR since it is referenced in the test codes.

---

Changes in v4:
- drop the first 2 patches that are already applied
- rebase against u-boot/next branch

 test/dm/fdtdec.c | 2 ++
 1 file changed, 2 insertions(+)

Applied to u-boot-dm/next, thanks!