[Skiboot] [PATCH 1/4] core/test: Test that device paths/names function as expected.

Daniel Axtens dja at axtens.net
Fri Feb 27 16:06:32 AEDT 2015


Test dt_get_path/dt_find_by_name/dt_find_by_path all respond as expected.

Signed-off-by: Daniel Axtens <dja at axtens.net>
---
 core/test/run-device.c | 65 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 file changed, 61 insertions(+), 4 deletions(-)

diff --git a/core/test/run-device.c b/core/test/run-device.c
index fa9e951..e2ce340 100644
--- a/core/test/run-device.c
+++ b/core/test/run-device.c
@@ -33,33 +33,90 @@ static inline bool fake_is_rodata(const void *p)
 #include "../../ccan/list/list.c" /* For list_check */
 #include <assert.h>
 
+static void check_path(const struct dt_node *node, const char * expected_path)
+{
+	char * path;
+	path = dt_get_path(node);
+	if (strcmp(path, expected_path) != 0) {
+		printf("check_path: expected %s, got %s\n", expected_path, path);
+	}
+	assert(strcmp(path, expected_path) == 0);
+	free(path);
+}
+
 int main(void)
 {
-	struct dt_node *root, *c1, *c2, *gc1, *gc2, *gc3, *ggc1, *i;
+	struct dt_node *root, *c1, *c2, *gc1, *gc2, *gc3, *ggc1;
+	struct dt_node *addrs, *addr1, *addr2;
+	struct dt_node *i;
 	const struct dt_property *p;
 	struct dt_property *p2;
 	unsigned int n;
 
 	root = dt_new_root("root");
 	assert(!list_top(&root->properties, struct dt_property, list));
+	check_path(root, "/root");
+
 	c1 = dt_new(root, "c1");
 	assert(!list_top(&c1->properties, struct dt_property, list));
+	check_path(c1, "root/c1");
+	assert(dt_find_by_name(root, "c1") == c1);
+	assert(dt_find_by_path(root, "/c1") == c1);
+
 	c2 = dt_new(root, "c2");
 	assert(!list_top(&c2->properties, struct dt_property, list));
+	check_path(c2, "root/c2");
+	assert(dt_find_by_name(root, "c2") == c2);
+	assert(dt_find_by_path(root, "/c2") == c2);
+
 	gc1 = dt_new(c1, "gc1");
 	assert(!list_top(&gc1->properties, struct dt_property, list));
+	check_path(gc1, "root/c1/gc1");
+	assert(dt_find_by_name(root, "gc1") == gc1);
+	assert(dt_find_by_path(root, "/c1/gc1") == gc1);
+
 	gc2 = dt_new(c1, "gc2");
 	assert(!list_top(&gc2->properties, struct dt_property, list));
+	check_path(gc2, "root/c1/gc2");
+	assert(dt_find_by_name(root, "gc2") == gc2);
+	assert(dt_find_by_path(root, "/c1/gc2") == gc2);
+
 	gc3 = dt_new(c1, "gc3");
 	assert(!list_top(&gc3->properties, struct dt_property, list));
+	check_path(gc3, "root/c1/gc3");
+	assert(dt_find_by_name(root, "gc3") == gc3);
+	assert(dt_find_by_path(root, "/c1/gc3") == gc3);
+
 	ggc1 = dt_new(gc1, "ggc1");
 	assert(!list_top(&ggc1->properties, struct dt_property, list));
-
+	check_path(ggc1, "root/c1/gc1/ggc1");
+	assert(dt_find_by_name(root, "ggc1") == ggc1);
+	assert(dt_find_by_path(root, "/c1/gc1/ggc1") == ggc1);
+
+	addrs = dt_new(root, "addrs");
+	assert(!list_top(&addrs->properties, struct dt_property, list));
+	check_path(addrs, "root/addrs");
+	assert(dt_find_by_name(root, "addrs") == addrs);
+	assert(dt_find_by_path(root, "/addrs") == addrs);
+
+	addr1 = dt_new_addr(addrs, "addr", 0x1337);
+	assert(!list_top(&addr1->properties, struct dt_property, list));
+	check_path(addr1, "root/addrs/addr at 1337");
+	assert(dt_find_by_name(root, "addr at 1337") == addr1);
+	assert(dt_find_by_path(root, "/addrs/addr at 1337") == addr1);
+
+	addr2 = dt_new_2addr(addrs, "2addr", 0xdead, 0xbeef);
+	assert(!list_top(&addr2->properties, struct dt_property, list));
+	check_path(addr2, "root/addrs/2addr at dead,beef");
+	assert(dt_find_by_name(root, "2addr at dead,beef") == addr2);
+	assert(dt_find_by_path(root, "/addrs/2addr at dead,beef") == addr2);
+
+	/* Test walking the tree, checking and setting values */
 	for (n = 0, i = dt_first(root); i; i = dt_next(root, i), n++) {
 		assert(!list_top(&i->properties, struct dt_property, list));
 		dt_add_property_cells(i, "visited", 1);
 	}
-	assert(n == 6);
+	assert(n == 9);
 
 	for (n = 0, i = dt_first(root); i; i = dt_next(root, i), n++) {
 		p = list_top(&i->properties, struct dt_property, list);
@@ -67,7 +124,7 @@ int main(void)
 		assert(p->len == sizeof(u32));
 		assert(fdt32_to_cpu(*(u32 *)p->prop) == 1);
 	}
-	assert(n == 6);
+	assert(n == 9);
 
 	dt_add_property_cells(c1, "some-property", 1, 2, 3);
 	p = dt_find_property(c1, "some-property");
-- 
2.1.4



More information about the Skiboot mailing list