public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Christian Marangi <ansuelsmth@gmail.com>
To: Simon Glass <sjg@chromium.org>, Tom Rini <trini@konsulko.com>,
	Christian Marangi <ansuelsmth@gmail.com>,
	Sean Anderson <seanga2@gmail.com>,
	Sughosh Ganu <sughosh.ganu@linaro.org>,
	Caleb Connolly <caleb.connolly@linaro.org>,
	Mattijs Korpershoek <mkorpershoek@baylibre.com>,
	Patrick Rudolph <patrick.rudolph@9elements.com>,
	Yang Xiwen <forbidden405@outlook.com>,
	Mikhail Kshevetskiy <mikhail.kshevetskiy@iopsys.eu>,
	Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
	Marek Vasut <marex@denx.de>,
	Michael Polyntsov <michael.polyntsov@iopsys.eu>,
	u-boot@lists.denx.de
Subject: [PATCH v2 2/8] test: dm: fix broken dm_test_ofnode_phandle_ot and get_by_phandle_ot
Date: Sun, 10 Nov 2024 12:50:21 +0100	[thread overview]
Message-ID: <20241110115054.2555-3-ansuelsmth@gmail.com> (raw)
In-Reply-To: <20241110115054.2555-1-ansuelsmth@gmail.com>

Fix broken dm_test_ofnode_phandle_ot test. They never actually worked
and were passing test by pure luck by having the same phandle index of
test.dts that coincicentally had #gpio-cells in the same index node.

It was sufficient to add a phandle to test.dts to make the test fail.

To correctly test these feature, make use oif the new OPs oftree to
parse phandle.

For consistency with the dm_test_ofnode_phandle, rework the test and
other.dts to use the same property with the other- prefix to every
node.

Also fix dm_test_ofnode_get_by_phandle_ot by making it more robust and
renaming the phandle property to other-phandle.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
---
 arch/sandbox/dts/other.dts | 24 ++++++++++-
 test/dm/ofnode.c           | 83 +++++++++++++++++++++++++++++++-------
 2 files changed, 91 insertions(+), 16 deletions(-)

diff --git a/arch/sandbox/dts/other.dts b/arch/sandbox/dts/other.dts
index 395a7923228..b32158c6569 100644
--- a/arch/sandbox/dts/other.dts
+++ b/arch/sandbox/dts/other.dts
@@ -8,13 +8,15 @@
 
 /dts-v1/;
 
+#include <dt-bindings/gpio/gpio.h>
+
 / {
 	compatible = "sandbox-other";
 	#address-cells = <1>;
 	#size-cells = <1>;
 
 	node {
-		target = <&target 3 4>;
+		other-phandle = <&target>;
 
 		subnode {
 			compatible = "sandbox-other2";
@@ -25,9 +27,27 @@
 		};
 	};
 
+	other-a-test {
+		other-test-gpios = <&other_gpio_a 1>, <&other_gpio_a 4>,
+			<&other_gpio_b 5 GPIO_ACTIVE_HIGH 3 2 1>,
+			<0>, <&other_gpio_a 12>;
+		other-phandle-value = <&other_gpio_c 10>, <0xFFFFFFFF 20>, <&other_gpio_a 30>;
+	};
+
+	other_gpio_a: other-gpio-a {
+		#gpio-cells = <1>;
+	};
+
+	other_gpio_b: other-gpio-b {
+		#gpio-cells = <5>;
+	};
+
+	other_gpio_c: other-gpio-c {
+		#gpio-cells = <2>;
+	};
+
 	target: target {
 		compatible = "sandbox-other2";
-		#gpio-cells = <2>;
 		str-prop = "other";
 		reg = <0x8000 0x100>;
 		status = "disabled";
diff --git a/test/dm/ofnode.c b/test/dm/ofnode.c
index ce996567c3c..24b67bbe2b9 100644
--- a/test/dm/ofnode.c
+++ b/test/dm/ofnode.c
@@ -141,9 +141,16 @@ static int dm_test_ofnode_get_by_phandle_ot(struct unit_test_state *uts)
 {
 	oftree otree = get_other_oftree(uts);
 	ofnode node;
+	u32 idx;
+	int ret;
 
-	ut_assert(ofnode_valid(oftree_get_by_phandle(oftree_default(), 1)));
-	node = oftree_get_by_phandle(otree, 1);
+	node = oftree_path(otree, "/node");
+	ut_assert(ofnode_valid(node));
+
+	ret = ofnode_read_u32(node, "other-phandle", &idx);
+	ut_assertok(ret);
+
+	node = oftree_get_by_phandle(otree, idx);
 	ut_assert(ofnode_valid(node));
 	ut_asserteq_str("target", ofnode_get_name(node));
 
@@ -349,30 +356,78 @@ static int dm_test_ofnode_phandle(struct unit_test_state *uts)
 }
 DM_TEST(dm_test_ofnode_phandle, UTF_SCAN_PDATA | UTF_SCAN_FDT);
 
-/* test ofnode_count_/parse_phandle_with_args() with 'other' tree */
+/* test oftree_count_/parse_phandle_with_args() with 'other' tree */
 static int dm_test_ofnode_phandle_ot(struct unit_test_state *uts)
 {
 	oftree otree = get_other_oftree(uts);
 	struct ofnode_phandle_args args;
 	ofnode node;
 	int ret;
+	const char prop[] = "other-test-gpios";
+	const char cell[] = "#gpio-cells";
+	const char prop2[] = "other-phandle-value";
 
-	node = oftree_path(otree, "/node");
+	node = oftree_path(otree, "/other-a-test");
+	ut_assert(ofnode_valid(node));
 
-	/* Test ofnode_count_phandle_with_args with cell name */
-	ret = ofnode_count_phandle_with_args(node, "missing", "#gpio-cells", 0);
+	/* Test oftree_count_phandle_with_args with cell name */
+	ret = oftree_count_phandle_with_args(otree, node, "missing", cell, 0);
 	ut_asserteq(-ENOENT, ret);
-	ret = ofnode_count_phandle_with_args(node, "target", "#invalid", 0);
+	ret = oftree_count_phandle_with_args(otree, node, prop, "#invalid", 0);
 	ut_asserteq(-EINVAL, ret);
-	ret = ofnode_count_phandle_with_args(node, "target", "#gpio-cells", 0);
-	ut_asserteq(1, ret);
+	ret = oftree_count_phandle_with_args(otree, node, prop, cell, 0);
+	ut_asserteq(5, ret);
+
+	/* Test oftree_parse_phandle_with_args with cell name */
+	ret = oftree_parse_phandle_with_args(otree, node, "missing", cell, 0, 0,
+					     &args);
+	ut_asserteq(-ENOENT, ret);
+	ret = oftree_parse_phandle_with_args(otree, node, prop, "#invalid", 0, 0,
+					     &args);
+	ut_asserteq(-EINVAL, ret);
+	ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 0, &args);
+	ut_assertok(ret);
+	ut_asserteq(1, args.args_count);
+	ut_asserteq(1, args.args[0]);
+	ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 1, &args);
+	ut_assertok(ret);
+	ut_asserteq(1, args.args_count);
+	ut_asserteq(4, args.args[0]);
+	ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 2, &args);
+	ut_assertok(ret);
+	ut_asserteq(5, args.args_count);
+	ut_asserteq(5, args.args[0]);
+	ut_asserteq(1, args.args[4]);
+	ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 3, &args);
+	ut_asserteq(-ENOENT, ret);
+	ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 4, &args);
+	ut_assertok(ret);
+	ut_asserteq(1, args.args_count);
+	ut_asserteq(12, args.args[0]);
+	ret = oftree_parse_phandle_with_args(otree, node, prop, cell, 0, 5, &args);
+	ut_asserteq(-ENOENT, ret);
+
+	/* Test oftree_count_phandle_with_args with cell count */
+	ret = oftree_count_phandle_with_args(otree, node, "missing", NULL, 2);
+	ut_asserteq(-ENOENT, ret);
+	ret = oftree_count_phandle_with_args(otree, node, prop2, NULL, 1);
+	ut_asserteq(3, ret);
 
-	ret = ofnode_parse_phandle_with_args(node, "target", "#gpio-cells", 0,
-					     0, &args);
+	/* Test oftree_parse_phandle_with_args with cell count */
+	ret = oftree_parse_phandle_with_args(otree, node, prop2, NULL, 1, 0, &args);
 	ut_assertok(ret);
-	ut_asserteq(2, args.args_count);
-	ut_asserteq(3, args.args[0]);
-	ut_asserteq(4, args.args[1]);
+	ut_asserteq(1, ofnode_valid(args.node));
+	ut_asserteq(1, args.args_count);
+	ut_asserteq(10, args.args[0]);
+	ret = oftree_parse_phandle_with_args(otree, node, prop2, NULL, 1, 1, &args);
+	ut_asserteq(-EINVAL, ret);
+	ret = oftree_parse_phandle_with_args(otree, node, prop2, NULL, 1, 2, &args);
+	ut_assertok(ret);
+	ut_asserteq(1, ofnode_valid(args.node));
+	ut_asserteq(1, args.args_count);
+	ut_asserteq(30, args.args[0]);
+	ret = oftree_parse_phandle_with_args(otree, node, prop2, NULL, 1, 3, &args);
+	ut_asserteq(-ENOENT, ret);
 
 	return 0;
 }
-- 
2.45.2


  parent reply	other threads:[~2024-11-10 11:51 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-11-10 11:50 [PATCH v2 0/8] led: update LED boot/activity to new property implementation Christian Marangi
2024-11-10 11:50 ` [PATCH v2 1/8] dm: core: implement oftree variant of parse_phandle OPs Christian Marangi
2024-11-20 13:46   ` Simon Glass
2024-11-10 11:50 ` Christian Marangi [this message]
2024-11-20 13:46   ` [PATCH v2 2/8] test: dm: fix broken dm_test_ofnode_phandle_ot and get_by_phandle_ot Simon Glass
2024-11-10 11:50 ` [PATCH v2 3/8] dm: core: implement ofnode/tree_parse_phandle() helper Christian Marangi
2024-11-20 13:48   ` Simon Glass
2024-11-10 11:50 ` [PATCH v2 4/8] test: dm: Expand dm_test_ofnode_phandle(_ot) with new ofnode/tree_parse_phandle Christian Marangi
2024-11-20 13:48   ` Simon Glass
2024-11-10 11:50 ` [PATCH v2 5/8] dm: core: implement phandle ofnode_options helper Christian Marangi
2024-11-20 13:48   ` Simon Glass
2024-11-10 11:50 ` [PATCH v2 6/8] test: dm: Add test for ofnode options phandle helper Christian Marangi
2024-11-20 13:48   ` Simon Glass
2024-11-10 11:50 ` [PATCH v2 7/8] led: update LED boot/activity to new property implementation Christian Marangi
2024-11-10 11:50 ` [PATCH v2 8/8] test: dm: Update test for LED activity and boot Christian Marangi
2024-11-20 13:48   ` Simon Glass
2024-11-13 18:00 ` [PATCH v2 0/8] led: update LED boot/activity to new property implementation Tom Rini
2024-11-13 20:24   ` Christian Marangi
2024-11-23  2:41     ` Tom Rini
2024-12-06 17:30       ` Christian Marangi
2024-12-06 17:56         ` Tom Rini
2024-12-06 22:30 ` Tom Rini

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=20241110115054.2555-3-ansuelsmth@gmail.com \
    --to=ansuelsmth@gmail.com \
    --cc=caleb.connolly@linaro.org \
    --cc=forbidden405@outlook.com \
    --cc=marex@denx.de \
    --cc=michael.polyntsov@iopsys.eu \
    --cc=mikhail.kshevetskiy@iopsys.eu \
    --cc=mkorpershoek@baylibre.com \
    --cc=patrick.rudolph@9elements.com \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=seanga2@gmail.com \
    --cc=sjg@chromium.org \
    --cc=sughosh.ganu@linaro.org \
    --cc=trini@konsulko.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