From: Bin Meng <bmeng.cn@gmail.com>
To: u-boot@lists.denx.de
Subject: [PATCH v3 5/5] test/dm: fdtdec: Add tests for fdtdec_add_reserved_memory()
Date: Tue, 9 Jun 2020 22:36:31 -0700 [thread overview]
Message-ID: <1591767391-2669-5-git-send-email-bmeng.cn@gmail.com> (raw)
In-Reply-To: <1591767391-2669-1-git-send-email-bmeng.cn@gmail.com>
From: Bin Meng <bin.meng@windriver.com>
This adds a test case to test the functionality of the fdtdec API
fdtdec_add_reserved_memory().
Signed-off-by: Bin Meng <bin.meng@windriver.com>
---
Changes in v3:
- correct typo in the comments, and some minor rewording
test/dm/fdtdec.c | 69 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/test/dm/fdtdec.c b/test/dm/fdtdec.c
index 999d712..56f6f4f 100644
--- a/test/dm/fdtdec.c
+++ b/test/dm/fdtdec.c
@@ -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);
--
2.7.4
next prev parent reply other threads:[~2020-06-10 5:36 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-06-10 5:36 [PATCH v3 1/5] fdtdec: Fix the types of addr and size in fdtdec_add_reserved_memory() Bin Meng
2020-06-10 5:36 ` [PATCH v3 2/5] fdtdec: Honor #address-cells and #size-cells " Bin Meng
2020-06-10 5:36 ` [PATCH v3 3/5] test/dm: fdtdec: Add the missing gd declaration Bin Meng
2020-06-17 3:11 ` Simon Glass
2020-06-10 5:36 ` [PATCH v3 4/5] test/dm: fdtdec: Corect a typo in dm_test_fdtdec_set_carveout() Bin Meng
2020-06-17 3:11 ` Simon Glass
2020-06-10 5:36 ` Bin Meng [this message]
2020-06-17 3:11 ` [PATCH v3 5/5] test/dm: fdtdec: Add tests for fdtdec_add_reserved_memory() Simon Glass
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1591767391-2669-5-git-send-email-bmeng.cn@gmail.com \
--to=bmeng.cn@gmail.com \
--cc=u-boot@lists.denx.de \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox