From patchwork Fri Mar 25 11:31:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= X-Patchwork-Id: 12791503 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3C8F9C433EF for ; Fri, 25 Mar 2022 11:34:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1356470AbiCYLfr (ORCPT ); Fri, 25 Mar 2022 07:35:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54328 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356159AbiCYLfm (ORCPT ); Fri, 25 Mar 2022 07:35:42 -0400 Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C6628A9956; Fri, 25 Mar 2022 04:34:07 -0700 (PDT) Received: (Authenticated sender: clement.leger@bootlin.com) by mail.gandi.net (Postfix) with ESMTPSA id 7BC6120004; Fri, 25 Mar 2022 11:34:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1648208046; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=t7jG696msxIP+uipvIAwEjfKw2CtLhwybjn43oZI2Bk=; b=E3Y78V/6ViYdGor+Zi7veNZ75Wfj/6aczWRtwfYm5OXuROosQ4A/pbVfUSZKKK5GRycOtL qaHuoPi6N4oMqcCXh673Ct+qZIcMuKPfXZ7Qq/ZNaZM9k+JFbtptl4R7PrruN+4O57muPg usFJ2JhCQOpfUN7s5Qgzy3/jIyoamSeUWpMs8UWGOfOfGF9x04bO1sbf4aNHWrYghDoIC0 J2+lGqph+k5iIxjZKiawakTGONCrAGeBX3opz5XnujJa79N92j1kw41AvbN95KEIOZa4Td mD7gCqP4DmV6Fng7+x4MxpHihzGnAyH3Keea2diZ8rYx7d6UHPvvs8+us945wg== From: =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= To: Andy Shevchenko , Daniel Scally , Heikki Krogerus , Sakari Ailus , Greg Kroah-Hartman , "Rafael J . Wysocki" , Wolfram Sang , Peter Rosin , Rob Herring , Frank Rowand , Len Brown Cc: Hans de Goede , Thomas Petazzoni , Alexandre Belloni , Allan Nielsen , linux-kernel@vger.kernel.org, linux-acpi@vger.kernel.org, linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, =?utf-8?b?Q2zDqW1lbnQgTMOpZ2Vy?= Subject: [PATCH v3 2/9] of: unittests: add tests for of_property_read_string_array_index() Date: Fri, 25 Mar 2022 12:31:41 +0100 Message-Id: <20220325113148.588163-3-clement.leger@bootlin.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220325113148.588163-1-clement.leger@bootlin.com> References: <20220325113148.588163-1-clement.leger@bootlin.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org 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 Reviewed-by: Rob Herring --- 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) && \