diff mbox series

[U-Boot,v3,2/4] test: Add tests for DT-manipulation functions

Message ID 20180626064651.8551-2-mario.six@gdsys.cc
State Accepted
Delegated to: Simon Glass
Headers show
Series [U-Boot,v3,1/4] core: Add functions to set properties in live-tree | expand

Commit Message

Mario Six June 26, 2018, 6:46 a.m. UTC
Add tests for the ofnode_set_enabled, ofnode_write_string, and
ofnode_write_property functions.

Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Mario Six <mario.six@gdsys.cc>

---

v2 -> v3:
* Fixed style violation

v1 -> v2:
New in v2

---
 test/dm/test-fdt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 54 insertions(+)

--
2.11.0

Comments

Simon Glass Oct. 2, 2018, 11:20 a.m. UTC | #1
On 25 June 2018 at 23:46, Mario Six <mario.six@gdsys.cc> wrote:
> Add tests for the ofnode_set_enabled, ofnode_write_string, and
> ofnode_write_property functions.
>
> Reviewed-by: Simon Glass <sjg@chromium.org>
> Signed-off-by: Mario Six <mario.six@gdsys.cc>
>
> ---
>
> v2 -> v3:
> * Fixed style violation
>
> v1 -> v2:
> New in v2
>
> ---
>  test/dm/test-fdt.c | 54 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
>  1 file changed, 54 insertions(+)

Applied to u-boot-dm, and now in mainline, thanks!
diff mbox series

Patch

diff --git a/test/dm/test-fdt.c b/test/dm/test-fdt.c
index 8196844e89a..1e3faf15227 100644
--- a/test/dm/test-fdt.c
+++ b/test/dm/test-fdt.c
@@ -14,6 +14,8 @@ 
 #include <dm/device-internal.h>
 #include <dm/uclass-internal.h>
 #include <dm/util.h>
+#include <dm/lists.h>
+#include <dm/of_access.h>
 #include <test/ut.h>

 DECLARE_GLOBAL_DATA_PTR;
@@ -461,3 +463,55 @@  static int dm_test_fdt_translation(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_fdt_translation, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);
+
+static int dm_test_fdt_livetree_writing(struct unit_test_state *uts)
+{
+	struct udevice *dev;
+	ofnode node;
+
+	if (!of_live_active()) {
+		printf("Live tree not active; ignore test\n");
+		return 0;
+	}
+
+	/* Test enabling devices */
+
+	node = ofnode_path("/usb@2");
+
+	ut_assert(!of_device_is_available(ofnode_to_np(node)));
+	ofnode_set_enabled(node, true);
+	ut_assert(of_device_is_available(ofnode_to_np(node)));
+
+	device_bind_driver_to_node(dm_root(), "usb_sandbox", "usb@2", node,
+				   &dev);
+	ut_assertok(uclass_find_device_by_seq(UCLASS_USB, 2, true, &dev));
+
+	/* Test string property setting */
+
+	ut_assert(device_is_compatible(dev, "sandbox,usb"));
+	ofnode_write_string(node, "compatible", "gdsys,super-usb");
+	ut_assert(device_is_compatible(dev, "gdsys,super-usb"));
+	ofnode_write_string(node, "compatible", "sandbox,usb");
+	ut_assert(device_is_compatible(dev, "sandbox,usb"));
+
+	/* Test setting generic properties */
+
+	/* Non-existent in DTB */
+	ut_asserteq(FDT_ADDR_T_NONE, dev_read_addr(dev));
+	/* reg = 0x42, size = 0x100 */
+	ut_assertok(ofnode_write_prop(node, "reg", 8,
+				      "\x00\x00\x00\x42\x00\x00\x01\x00"));
+	ut_asserteq(0x42, dev_read_addr(dev));
+
+	/* Test disabling devices */
+
+	device_remove(dev, DM_REMOVE_NORMAL);
+	device_unbind(dev);
+
+	ut_assert(of_device_is_available(ofnode_to_np(node)));
+	ofnode_set_enabled(node, false);
+	ut_assert(!of_device_is_available(ofnode_to_np(node)));
+
+	return 0;
+}
+DM_TEST(dm_test_fdt_livetree_writing, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT);