diff mbox series

[06/20] dm: Add a C test for of-platdata properties

Message ID 20201003173142.3213123-7-sjg@chromium.org
State Accepted
Commit b325248c9368c518d68d00d700404eeac801c98d
Delegated to: Simon Glass
Headers show
Series dm: Enhance of-platdata to support parent devices | expand

Commit Message

Simon Glass Oct. 3, 2020, 5:31 p.m. UTC
At present properties are tested in a roundabout way. The driver's probe()
method writes out the values of the properties and the Python test checks
the output from U-Boot SPL.

Add a C test which checks these values more directly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

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

Comments

Simon Glass Oct. 30, 2020, 3:34 a.m. UTC | #1
At present properties are tested in a roundabout way. The driver's probe()
method writes out the values of the properties and the Python test checks
the output from U-Boot SPL.

Add a C test which checks these values more directly.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

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

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

Patch

diff --git a/test/dm/of_platdata.c b/test/dm/of_platdata.c
index 7a864eb0fb3..8763005ea9a 100644
--- a/test/dm/of_platdata.c
+++ b/test/dm/of_platdata.c
@@ -2,6 +2,7 @@ 
 
 #include <common.h>
 #include <dm.h>
+#include <dt-structs.h>
 #include <dm/test.h>
 #include <test/test.h>
 #include <test/ut.h>
@@ -17,3 +18,71 @@  static int dm_test_of_platdata_base(struct unit_test_state *uts)
 	return 0;
 }
 DM_TEST(dm_test_of_platdata_base, UT_TESTF_SCAN_PDATA);
+
+/* Test that we can read properties from a device */
+static int dm_test_of_platdata_props(struct unit_test_state *uts)
+{
+	struct dtd_sandbox_spl_test *plat;
+	struct udevice *dev;
+	int i;
+
+	ut_assertok(uclass_first_device_err(UCLASS_MISC, &dev));
+	plat = dev_get_platdata(dev);
+	ut_assert(plat->boolval);
+	ut_asserteq(1, plat->intval);
+	ut_asserteq(4, ARRAY_SIZE(plat->intarray));
+	ut_asserteq(2, plat->intarray[0]);
+	ut_asserteq(3, plat->intarray[1]);
+	ut_asserteq(4, plat->intarray[2]);
+	ut_asserteq(0, plat->intarray[3]);
+	ut_asserteq(5, plat->byteval);
+	ut_asserteq(3, ARRAY_SIZE(plat->bytearray));
+	ut_asserteq(6, plat->bytearray[0]);
+	ut_asserteq(0, plat->bytearray[1]);
+	ut_asserteq(0, plat->bytearray[2]);
+	ut_asserteq(9, ARRAY_SIZE(plat->longbytearray));
+	for (i = 0; i < ARRAY_SIZE(plat->longbytearray); i++)
+		ut_asserteq(9 + i, plat->longbytearray[i]);
+	ut_asserteq_str("message", plat->stringval);
+	ut_asserteq(3, ARRAY_SIZE(plat->stringarray));
+	ut_asserteq_str("multi-word", plat->stringarray[0]);
+	ut_asserteq_str("message", plat->stringarray[1]);
+	ut_asserteq_str("", plat->stringarray[2]);
+
+	ut_assertok(uclass_next_device_err(&dev));
+	plat = dev_get_platdata(dev);
+	ut_assert(!plat->boolval);
+	ut_asserteq(3, plat->intval);
+	ut_asserteq(5, plat->intarray[0]);
+	ut_asserteq(0, plat->intarray[1]);
+	ut_asserteq(0, plat->intarray[2]);
+	ut_asserteq(0, plat->intarray[3]);
+	ut_asserteq(8, plat->byteval);
+	ut_asserteq(3, ARRAY_SIZE(plat->bytearray));
+	ut_asserteq(1, plat->bytearray[0]);
+	ut_asserteq(0x23, plat->bytearray[1]);
+	ut_asserteq(0x34, plat->bytearray[2]);
+	for (i = 0; i < ARRAY_SIZE(plat->longbytearray); i++)
+		ut_asserteq(i < 4 ? 9 + i : 0, plat->longbytearray[i]);
+	ut_asserteq_str("message2", plat->stringval);
+	ut_asserteq_str("another", plat->stringarray[0]);
+	ut_asserteq_str("multi-word", plat->stringarray[1]);
+	ut_asserteq_str("message", plat->stringarray[2]);
+
+	ut_assertok(uclass_next_device_err(&dev));
+	plat = dev_get_platdata(dev);
+	ut_assert(!plat->boolval);
+	ut_asserteq_str("one", plat->stringarray[0]);
+	ut_asserteq_str("", plat->stringarray[1]);
+	ut_asserteq_str("", plat->stringarray[2]);
+
+	ut_assertok(uclass_next_device_err(&dev));
+	plat = dev_get_platdata(dev);
+	ut_assert(!plat->boolval);
+	ut_asserteq_str("spl", plat->stringarray[0]);
+
+	ut_asserteq(-ENODEV, uclass_next_device_err(&dev));
+
+	return 0;
+}
+DM_TEST(dm_test_of_platdata_props, UT_TESTF_SCAN_PDATA);