[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20220325113148.588163-3-clement.leger@bootlin.com>
Date: Fri, 25 Mar 2022 12:31:41 +0100
From: Clément Léger <clement.leger@...tlin.com>
To: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>,
Daniel Scally <djrscally@...il.com>,
Heikki Krogerus <heikki.krogerus@...ux.intel.com>,
Sakari Ailus <sakari.ailus@...ux.intel.com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
"Rafael J . Wysocki" <rafael@...nel.org>,
Wolfram Sang <wsa@...nel.org>, Peter Rosin <peda@...ntia.se>,
Rob Herring <robh+dt@...nel.org>,
Frank Rowand <frowand.list@...il.com>,
Len Brown <lenb@...nel.org>
Cc: Hans de Goede <hdegoede@...hat.com>,
Thomas Petazzoni <thomas.petazzoni@...tlin.com>,
Alexandre Belloni <alexandre.belloni@...tlin.com>,
Allan Nielsen <allan.nielsen@...rochip.com>,
linux-kernel@...r.kernel.org, linux-acpi@...r.kernel.org,
linux-i2c@...r.kernel.org, devicetree@...r.kernel.org,
Clément Léger <clement.leger@...tlin.com>
Subject: [PATCH v3 2/9] of: unittests: add tests for of_property_read_string_array_index()
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@...tlin.com>
---
drivers/of/unittest.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
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) && \
--
2.34.1
Powered by blists - more mailing lists