From patchwork Fri Aug 11 15:42:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 109902 Delivered-To: patch@linaro.org Received: by 10.140.95.78 with SMTP id h72csp1080034qge; Fri, 11 Aug 2017 08:42:48 -0700 (PDT) X-Received: by 10.84.137.129 with SMTP id 1mr18175836pln.251.1502466168499; Fri, 11 Aug 2017 08:42:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1502466168; cv=none; d=google.com; s=arc-20160816; b=yMuiZkpy6eyKSNF7yJY82PYfW8k3y5gL3K6yAKxifAIWBGYkAuznmY1kOOq4qGdnGZ ys390p4hZECkaCshyleAOqpax6ZvzcThFsG/NVo7z9QSzg2dK5/xqy4JW5nG3Ofzf87S 7bhDcKFG+Swdx9QObe/RJZegJnJ2J5ZD5F3CEJWMF5zSnmfrPL9p0jmd/P35EmSYSvft Ex2Q6BOm2XXA78QAjMGfl5cdQzB20KCT+O5MsESec5O14GBdH9KWnjqmccHIG8ZM3DTO H8VElHix223bePFllIDiV/nmwxQ31mNqhsGd/lKXsoAwZheRFzn1lfi++KpTnEtVokdV KRsQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=KUxhc8bIg8uaGWXkFQ0N7RCA4kcR3JQmucJTMyg81rM=; b=PBFS9eKFtpqGHY1oHcPVYWhFTx1KDM4XoFs2sSJtk8NoCsrstFyz3lNtRgJq/k3wPd ppTsYXCqN5afPqCjZcotuTz4HOF2DRLGptGSre8ieCIiIBF15YAAkMKxc4EBPrcGFfkj qJCCzZA+KKCreah1CFsmSvNBW19eBEo+waS1bmUIj+tmK4xnBFwFSTyemx3DWLOiDk6y 9Pwr+a+N4OvmKsIKRC1Im1Ybyl0EgsZ67Y9wUKLGKj9t3SeQFb2tDDkQG7t7dnN6FAAD 88Zm2EQHvSZqSa+Yx2iDuP4VgYidNjYR5BMVMRJnNIvS77UlmdkEk2kt8hJkZPXXJCLs P8jQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kec54pTF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g6si636516pgf.799.2017.08.11.08.42.48; Fri, 11 Aug 2017 08:42:48 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kec54pTF; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752949AbdHKPmp (ORCPT + 25 others); Fri, 11 Aug 2017 11:42:45 -0400 Received: from mail-pf0-f169.google.com ([209.85.192.169]:36422 "EHLO mail-pf0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752631AbdHKPmm (ORCPT ); Fri, 11 Aug 2017 11:42:42 -0400 Received: by mail-pf0-f169.google.com with SMTP id c28so17263507pfe.3 for ; Fri, 11 Aug 2017 08:42:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KUxhc8bIg8uaGWXkFQ0N7RCA4kcR3JQmucJTMyg81rM=; b=kec54pTFWeMw4kBcPIBEFl2w8XX3RSOWcnhp7Zd6TsWFKi/RBRG27Fxo8By35To8nd mWwdSAc/hMugWaRtBhyGJl3vvcTeR0Bf1Pj8wsKU65c8vuYoPPWHiATLbYdxR5OMpRwH vTppOUHVLRcUzBvFv3ACCSMFX2bRgBktmcoME= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=KUxhc8bIg8uaGWXkFQ0N7RCA4kcR3JQmucJTMyg81rM=; b=Nqt4EhXGKZVWMbqDt1TV5rNHoPt8/aCdeFKUPJbMLjXjRUy0stKfc20Hn+Sn0KQvBO lU6oGRdc1/uaiVvoNpi+VLGeIp2UFTe/Fvok6GA+5EkRBPVA1kRhVci3OOFoZnu3rCdi ICCuDT1kg9EDngFx9ViNnKGn5uCGfcd7yNpR4Qw2ylLzM2aBguzKUhFgyaS/iVMExV0v d8GuUDQoa4zalba+jkYaYl0q53xmLXiVV+swkcLqw/9jzYAl1iLEEyUZed4vDNHEvJE5 n/uiUzwtNM/7lNPgUThLG2TgsyX+4+aOGqB1vKxMiTnDKGNS0B+WE/DN2b19e7HZDO1r RZlw== X-Gm-Message-State: AHYfb5gyqp64dnJ905bbu3xciBNBN9MWrOLWSFRZAbfAi5O0VMyUoaAq NUIiTKeaOQ078GYF X-Received: by 10.99.109.207 with SMTP id i198mr15600515pgc.375.1502466162057; Fri, 11 Aug 2017 08:42:42 -0700 (PDT) Received: from localhost.localdomain (i-global254.qualcomm.com. [199.106.103.254]) by smtp.gmail.com with ESMTPSA id a63sm2351071pfc.165.2017.08.11.08.42.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 11 Aug 2017 08:42:41 -0700 (PDT) From: Stephen Boyd To: Rob Herring , Frank Rowand Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, Russell King - ARM Linux , devicetree-spec@vger.kernel.org, Pantelis Antoniou , Linus Walleij , Mark Brown Subject: [PATCH v4 3/4] of: unittest: Add phandle remapping test Date: Fri, 11 Aug 2017 08:42:35 -0700 Message-Id: <20170811154236.12891-4-stephen.boyd@linaro.org> X-Mailer: git-send-email 2.14.GIT In-Reply-To: <20170811154236.12891-1-stephen.boyd@linaro.org> References: <20170811154236.12891-1-stephen.boyd@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Test the functionality of of_parse_phandle_with_args_map(). Cc: Pantelis Antoniou Cc: Linus Walleij Cc: Mark Brown Signed-off-by: Stephen Boyd --- drivers/of/unittest-data/testcases.dts | 11 +++ drivers/of/unittest-data/tests-phandle.dtsi | 25 ++++++ drivers/of/unittest.c | 120 ++++++++++++++++++++++++++++ 3 files changed, 156 insertions(+) -- 2.7.4 diff --git a/drivers/of/unittest-data/testcases.dts b/drivers/of/unittest-data/testcases.dts index 12f7c3d649c8..173b96f39cd0 100644 --- a/drivers/of/unittest-data/testcases.dts +++ b/drivers/of/unittest-data/testcases.dts @@ -26,12 +26,23 @@ / { __local_fixups__ { testcase-data { phandle-tests { + provider4 { + phandle-map = <0x00000008 0x00000018 + 0x00000024 0x0000003c + 0x00000050 0x00000064>; + }; consumer-a { phandle-list = <0x00000000 0x00000008 0x00000018 0x00000028 0x00000034 0x00000038>; phandle-list-bad-args = <0x00000000 0x0000000c>; }; + consumer-b { + phandle-list = <0x00000000 0x00000008 + 0x00000018 0x00000024 + 0x00000030 0x00000034>; + phandle-list-bad-args = <0x00000000 0x0000000c>; + }; }; interrupts { intmap0 { diff --git a/drivers/of/unittest-data/tests-phandle.dtsi b/drivers/of/unittest-data/tests-phandle.dtsi index 5b1527e8a7fb..59e297f497d1 100644 --- a/drivers/of/unittest-data/tests-phandle.dtsi +++ b/drivers/of/unittest-data/tests-phandle.dtsi @@ -25,6 +25,18 @@ #phandle-cells = <3>; }; + provider4: provider4 { + #phandle-cells = <2>; + phandle-map = <0 1 &provider1 3>, + <4 0 &provider0>, + <16 5 &provider3 3 5 0>, + <200 8 &provider2 23 6>, + <19 0 &provider2 15 0>, + <2 3 &provider3 2 5 3>; + phandle-map-mask = <0xff 0xf>; + phandle-map-pass-thru = <0x0 0xf0>; + }; + consumer-a { phandle-list = <&provider1 1>, <&provider2 2 0>, @@ -43,6 +55,19 @@ unterminated-string = [40 41 42 43]; unterminated-string-list = "first", "second", [40 41 42 43]; }; + + consumer-b { + phandle-list = <&provider1 1>, + <&provider4 2 3>, + <0>, + <&provider4 4 0x100>, + <&provider4 0 0x61>, + <&provider0>, + <&provider4 19 0x20>; + phandle-list-bad-phandle = <12345678 0 0>; + phandle-list-bad-args = <&provider2 1 0>, + <&provider4 0>; + }; }; }; }; diff --git a/drivers/of/unittest.c b/drivers/of/unittest.c index 0107fc680335..c6091d1e55de 100644 --- a/drivers/of/unittest.c +++ b/drivers/of/unittest.c @@ -443,6 +443,125 @@ static void __init of_unittest_parse_phandle_with_args(void) unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); } +static void __init of_unittest_parse_phandle_with_args_map(void) +{ + struct device_node *np, *p0, *p1, *p2, *p3; + struct of_phandle_args args; + int i, rc; + + np = of_find_node_by_path("/testcase-data/phandle-tests/consumer-b"); + if (!np) { + pr_err("missing testcase data\n"); + return; + } + + p0 = of_find_node_by_path("/testcase-data/phandle-tests/provider0"); + if (!p0) { + pr_err("missing testcase data\n"); + return; + } + + p1 = of_find_node_by_path("/testcase-data/phandle-tests/provider1"); + if (!p1) { + pr_err("missing testcase data\n"); + return; + } + + p2 = of_find_node_by_path("/testcase-data/phandle-tests/provider2"); + if (!p2) { + pr_err("missing testcase data\n"); + return; + } + + p3 = of_find_node_by_path("/testcase-data/phandle-tests/provider3"); + if (!p3) { + pr_err("missing testcase data\n"); + return; + } + + rc = of_count_phandle_with_args(np, "phandle-list", "#phandle-cells"); + unittest(rc == 7, "of_count_phandle_with_args() returned %i, expected 7\n", rc); + + for (i = 0; i < 8; i++) { + bool passed = true; + + rc = of_parse_phandle_with_args_map(np, "phandle-list", + "phandle", i, &args); + + /* Test the values from tests-phandle.dtsi */ + switch (i) { + case 0: + passed &= !rc; + passed &= (args.np == p1); + passed &= (args.args_count == 1); + passed &= (args.args[0] == 1); + break; + case 1: + passed &= !rc; + passed &= (args.np == p3); + passed &= (args.args_count == 3); + passed &= (args.args[0] == 2); + passed &= (args.args[1] == 5); + passed &= (args.args[2] == 3); + break; + case 2: + passed &= (rc == -ENOENT); + break; + case 3: + passed &= !rc; + passed &= (args.np == p0); + passed &= (args.args_count == 0); + break; + case 4: + passed &= !rc; + passed &= (args.np == p1); + passed &= (args.args_count == 1); + passed &= (args.args[0] == 3); + break; + case 5: + passed &= !rc; + passed &= (args.np == p0); + passed &= (args.args_count == 0); + break; + case 6: + passed &= !rc; + passed &= (args.np == p2); + passed &= (args.args_count == 2); + passed &= (args.args[0] == 15); + passed &= (args.args[1] == 0x20); + break; + case 7: + passed &= (rc == -ENOENT); + break; + default: + passed = false; + } + + unittest(passed, "index %i - data error on node %s rc=%i\n", + i, args.np->full_name, rc); + } + + /* Check for missing list property */ + rc = of_parse_phandle_with_args_map(np, "phandle-list-missing", + "phandle", 0, &args); + unittest(rc == -ENOENT, "expected:%i got:%i\n", -ENOENT, rc); + + /* Check for missing cells,map,mask property */ + rc = of_parse_phandle_with_args_map(np, "phandle-list", + "phandle-missing", 0, &args); + unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); + + /* Check for bad phandle in list */ + rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-phandle", + "phandle", 0, &args); + unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); + + /* Check for incorrectly formed argument list */ + rc = of_parse_phandle_with_args_map(np, "phandle-list-bad-args", + "phandle", 1, &args); + unittest(rc == -EINVAL, "expected:%i got:%i\n", -EINVAL, rc); +} + static void __init of_unittest_property_string(void) { const char *strings[4]; @@ -2326,6 +2445,7 @@ static int __init of_unittest(void) of_unittest_find_node_by_name(); of_unittest_dynamic(); of_unittest_parse_phandle_with_args(); + of_unittest_parse_phandle_with_args_map(); of_unittest_printf(); of_unittest_property_string(); of_unittest_property_copy();