U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: u-boot@lists.denx.de
Subject: [PATCH 06/20] dm: Add a C test for of-platdata properties
Date: Sat,  3 Oct 2020 11:31:28 -0600	[thread overview]
Message-ID: <20201003173142.3213123-7-sjg@chromium.org> (raw)
In-Reply-To: <20201003173142.3213123-1-sjg@chromium.org>

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(+)

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);
-- 
2.28.0.806.g8561365e88-goog

  parent reply	other threads:[~2020-10-03 17:31 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-10-03 17:31 [PATCH 00/20] dm: Enhance of-platdata to support parent devices Simon Glass
2020-10-03 17:31 ` [PATCH 01/20] sandbox: Drop ad-hoc device declarations in SPL Simon Glass
2020-10-27  1:01   ` Simon Glass
2020-10-03 17:31 ` [PATCH 02/20] dtoc: Document the return value of scan_structs() Simon Glass
2020-10-27  1:01   ` Simon Glass
2020-10-03 17:31 ` [PATCH 03/20] dtoc: Order the structures internally by name Simon Glass
2020-10-27  1:01   ` Simon Glass
2020-10-03 17:31 ` [PATCH 04/20] dm: core: Allow dm_warn() to be used in SPL Simon Glass
2020-10-27  1:01   ` Simon Glass
2020-10-03 17:31 ` [PATCH 05/20] dtoc: Fix widening of int to bytes Simon Glass
2020-10-27  1:01   ` Simon Glass
2020-10-03 17:31 ` Simon Glass [this message]
2020-10-30  3:34   ` [PATCH 06/20] dm: Add a C test for of-platdata properties Simon Glass
2020-10-03 17:31 ` [PATCH 07/20] sandbox: Allow selection of SPL unit tests Simon Glass
2020-10-30  3:34   ` Simon Glass
2020-10-03 17:31 ` [PATCH 08/20] dm: test: Drop of-platdata pytest Simon Glass
2020-10-03 17:31 ` [PATCH 09/20] dm: test: Add a check that all devices have a dev value Simon Glass
2020-10-30  3:34   ` Simon Glass
2020-10-03 17:31 ` [PATCH 10/20] dm: test: Add a test for of-platdata phandles Simon Glass
2020-10-30  3:34   ` Simon Glass
2020-10-03 17:31 ` [PATCH 11/20] dm: Use an allocated array for run-time device info Simon Glass
2020-10-30  3:34   ` Simon Glass
2020-10-03 17:31 ` [PATCH 12/20] sandbox: Fix up building for of-platdata Simon Glass
2020-10-30  3:34   ` Simon Glass
2020-10-03 17:31 ` [PATCH 13/20] dm: Support parent devices with of-platdata Simon Glass
2020-10-30  3:34   ` Simon Glass
2020-10-03 17:31 ` [PATCH 14/20] dm: Add a test for of-platdata parent information Simon Glass
2020-10-30  3:34   ` Simon Glass
2020-10-03 17:31 ` [PATCH 15/20] dm: core: Convert #ifdef to if() in root.c Simon Glass
2020-10-30  3:34   ` Simon Glass
2020-11-04 12:55   ` Michal Simek
2020-11-04 13:59     ` Tom Rini
2020-11-04 14:33       ` Michal Simek
2020-10-03 17:31 ` [PATCH 16/20] x86: apl: Enable SPI flash in TPL with APL_SPI_FLASH_BOOT Simon Glass
2020-10-30  3:34   ` Simon Glass
2020-10-03 17:31 ` [PATCH 17/20] x86: apl: Take advantage of the of-platdata parent support Simon Glass
2020-10-30  3:34   ` Simon Glass
2020-10-03 17:31 ` [PATCH 18/20] dm: Use driver_info index instead of pointer Simon Glass
2020-10-30  3:34   ` Simon Glass
2020-10-03 17:31 ` [PATCH 19/20] dm: Don't allow U_BOOT_DEVICE() when of-platdata is used Simon Glass
2020-10-30  3:34   ` Simon Glass
2020-10-03 17:31 ` [PATCH 20/20] dm: doc: Update the of-platadata documentation Simon Glass
2020-10-30  3:34   ` 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=20201003173142.3213123-7-sjg@chromium.org \
    --to=sjg@chromium.org \
    --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