diff mbox series

[v3,2/9] of: unittests: add tests for of_property_read_string_array_index()

Message ID 20220325113148.588163-3-clement.leger@bootlin.com (mailing list archive)
State Handled Elsewhere, archived
Headers show
Series introduce fwnode in the I2C subsystem | expand

Commit Message

Clément Léger March 25, 2022, 11:31 a.m. UTC
Add testing for of_property_read_string_array_index() function which
allows to retrieve a string array starting at a specified offset. These
tests are testing some basic use-case for this function.

Signed-off-by: Clément Léger <clement.leger@bootlin.com>
---
 drivers/of/unittest.c | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Rob Herring (Arm) March 29, 2022, 11:32 p.m. UTC | #1
On Fri, 25 Mar 2022 12:31:41 +0100, Clément Léger wrote:
> Add testing for of_property_read_string_array_index() function which
> allows to retrieve a string array starting at a specified offset. These
> tests are testing some basic use-case for this function.
> 
> Signed-off-by: Clément Léger <clement.leger@bootlin.com>
> ---
>  drivers/of/unittest.c | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
> 

Reviewed-by: Rob Herring <robh@kernel.org>
diff mbox series

Patch

diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c
index 2c2fb161b572..d39ec2f5d2c5 100644
--- a/drivers/of/unittest.c
+++ b/drivers/of/unittest.c
@@ -759,6 +759,26 @@  static void __init of_unittest_property_string(void)
 	strings[1] = NULL;
 	rc = of_property_read_string_array(np, "phandle-list-names", strings, 1);
 	unittest(rc == 1 && strings[1] == NULL, "Overwrote end of string array; rc=%i, str='%s'\n", rc, strings[1]);
+
+	/* of_property_read_string_array_index() tests */
+	rc = of_property_read_string_array_index(np, "string-property", strings, 4, 0);
+	unittest(rc == 1, "Incorrect string count; rc=%i\n", rc);
+	rc = of_property_read_string_array_index(np, "string-property", strings, 4, 1);
+	unittest(rc == -ENODATA, "Incorrect return value; rc=%i\n", rc);
+	rc = of_property_read_string_array_index(np, "phandle-list-names", strings, 2, 0);
+	unittest(rc == 2 && !strcmp(strings[0], "first") && !strcmp(strings[1], "second"),
+		 "of_property_read_string_array_index() failure; rc=%i\n", rc);
+	rc = of_property_read_string_array_index(np, "phandle-list-names", strings, 2, 1);
+	unittest(rc == 2 && !strcmp(strings[0], "second") && !strcmp(strings[1], "third"),
+		 "of_property_read_string_array_index() failure; rc=%i\n", rc);
+	rc = of_property_read_string_array_index(np, "phandle-list-names", strings, 4, 1);
+	unittest(rc == 2 && !strcmp(strings[0], "second") && !strcmp(strings[1], "third"),
+		 "of_property_read_string_array_index() failure; rc=%i\n", rc);
+	rc = of_property_read_string_array_index(np, "phandle-list-names", strings, 1, 2);
+	unittest(rc == 1 && !strcmp(strings[0], "third"),
+		 "of_property_read_string_array_index() failure; rc=%i\n", rc);
+	rc = of_property_read_string_array_index(np, "phandle-list-names", strings, 1, 3);
+	unittest(rc == -ENODATA, "Incorrect return value; rc=%i\n", rc);
 }
 
 #define propcmp(p1, p2) (((p1)->length == (p2)->length) && \