From patchwork Wed Feb 19 14:14:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 24960 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ie0-f199.google.com (mail-ie0-f199.google.com [209.85.223.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id C71332054E for ; Wed, 19 Feb 2014 14:16:28 +0000 (UTC) Received: by mail-ie0-f199.google.com with SMTP id rl12sf1624349iec.6 for ; Wed, 19 Feb 2014 06:16:28 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:cc:subject :date:message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=4HAkoas/VVod68s9AoLtYEXaqj4pnWdcnZ34OPzOx7k=; b=jDXX8QmUk6AACT+oA8xt90SIqizxzhMnjcF2FxfpOwV8UWxzQxqQdjiODIuW6SlW/3 UgHdsaRYBA3XAMi44R9WBipNgqCtm7W82OZj0vH6pDVNfwbLfJ31puKBA1HEyHtyGD5W BnJ7LFGZ83xqjhs+6Sr0sP02Q9fiTTe6N0u131kVLv8kys3DdLN0L2nSfbsAHe42BAWR rj6nsDxdGHRi2e2dkLLWOsAXVqz856h6tpY9JcuYAK5ERe7lQ7PRDR7EkmhPetq3KnVX oYCvArLcOcqTqlRlxJL81g5h85mzjI0dJ8bZ1dY32tmST+6jWHBtthOO2/GD2Npv5gWd hGtQ== X-Gm-Message-State: ALoCoQliTtBid1Ax4MoxKRDebhFlP9zzkB+YGizl+S+ouurRsb7AWvbWj6zBJovKBF3pjvKHb5Hl X-Received: by 10.182.17.69 with SMTP id m5mr15081514obd.6.1392819388253; Wed, 19 Feb 2014 06:16:28 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.47.9 with SMTP id l9ls107750qga.13.gmail; Wed, 19 Feb 2014 06:16:28 -0800 (PST) X-Received: by 10.52.116.171 with SMTP id jx11mr485772vdb.88.1392819388137; Wed, 19 Feb 2014 06:16:28 -0800 (PST) Received: from mail-ve0-f182.google.com (mail-ve0-f182.google.com [209.85.128.182]) by mx.google.com with ESMTPS id wm4si131064vcb.4.2014.02.19.06.16.28 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Feb 2014 06:16:28 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.182; Received: by mail-ve0-f182.google.com with SMTP id jy13so432227veb.27 for ; Wed, 19 Feb 2014 06:16:28 -0800 (PST) X-Received: by 10.220.192.71 with SMTP id dp7mr1929915vcb.45.1392819388035; Wed, 19 Feb 2014 06:16:28 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp300713vcz; Wed, 19 Feb 2014 06:16:27 -0800 (PST) X-Received: by 10.68.11.199 with SMTP id s7mr40184225pbb.12.1392819386793; Wed, 19 Feb 2014 06:16:26 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id b4si383702pbe.118.2014.02.19.06.16.25; Wed, 19 Feb 2014 06:16:26 -0800 (PST) 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; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753955AbaBSOPK (ORCPT + 27 others); Wed, 19 Feb 2014 09:15:10 -0500 Received: from mail-we0-f173.google.com ([74.125.82.173]:51748 "EHLO mail-we0-f173.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753930AbaBSOPG (ORCPT ); Wed, 19 Feb 2014 09:15:06 -0500 Received: by mail-we0-f173.google.com with SMTP id x48so376111wes.32 for ; Wed, 19 Feb 2014 06:15:04 -0800 (PST) X-Received: by 10.180.96.102 with SMTP id dr6mr1705446wib.19.1392819304813; Wed, 19 Feb 2014 06:15:04 -0800 (PST) Received: from trevor.secretlab.ca (host109-153-23-84.range109-153.btcentralplus.com. [109.153.23.84]) by mx.google.com with ESMTPSA id pm2sm52772380wic.0.2014.02.19.06.15.03 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 19 Feb 2014 06:15:03 -0800 (PST) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id 02573C40B2B; Wed, 19 Feb 2014 14:14:57 +0000 (GMT) From: Grant Likely To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Kevin Hao , Rob Herring , Sebastian Hesselbarth , Grant Likely Subject: [PATCH v4 4/4] of: Add self test for of_match_node() Date: Wed, 19 Feb 2014 14:14:50 +0000 Message-Id: <1392819290-1044-5-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1392819290-1044-1-git-send-email-grant.likely@linaro.org> References: <1392819290-1044-1-git-send-email-grant.likely@linaro.org> Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: grant.likely@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.182 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , Adds a selftest function for the of_match_node function. of_match_node is supposed to handle precedence for the compatible property as well as the name and device_type values. This patch adds some test case data and a function that makes sure each test node matches against the correct entry of an of_device_id table. This code was written to verify the new of_match_node() implementation that is an earlier part of this series. Signed-off-by: Grant Likely Cc: Kevin Hao --- drivers/of/selftest.c | 67 +++++++++++++++++++++++++++++++ drivers/of/testcase-data/testcases.dtsi | 1 + drivers/of/testcase-data/tests-match.dtsi | 19 +++++++++ 3 files changed, 87 insertions(+) create mode 100644 drivers/of/testcase-data/tests-match.dtsi diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index e21012bde639..6643d1920985 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c @@ -300,6 +300,72 @@ static void __init of_selftest_parse_interrupts_extended(void) of_node_put(np); } +static struct of_device_id match_node_table[] = { + { .data = "A", .name = "name0", }, /* Name alone is lowest priority */ + { .data = "B", .type = "type1", }, /* followed by type alone */ + + { .data = "Ca", .name = "name2", .type = "type1", }, /* followed by both together */ + { .data = "Cb", .name = "name2", }, /* Only match when type doesn't match */ + { .data = "Cc", .name = "name2", .type = "type2", }, + + { .data = "E", .compatible = "compat3" }, + { .data = "G", .compatible = "compat2", }, + { .data = "H", .compatible = "compat2", .name = "name5", }, + { .data = "I", .compatible = "compat2", .type = "type1", }, + { .data = "J", .compatible = "compat2", .type = "type1", .name = "name8", }, + { .data = "K", .compatible = "compat2", .name = "name9", }, + {} +}; + +static struct { + const char *path; + const char *data; +} match_node_tests[] = { + { .path = "/testcase-data/match-node/name0", .data = "A", }, + { .path = "/testcase-data/match-node/name1", .data = "B", }, + { .path = "/testcase-data/match-node/a/name2", .data = "Ca", }, + { .path = "/testcase-data/match-node/b/name2", .data = "Cb", }, + { .path = "/testcase-data/match-node/c/name2", .data = "Cc", }, + { .path = "/testcase-data/match-node/name3", .data = "E", }, + { .path = "/testcase-data/match-node/name4", .data = "G", }, + { .path = "/testcase-data/match-node/name5", .data = "H", }, + { .path = "/testcase-data/match-node/name6", .data = "G", }, + { .path = "/testcase-data/match-node/name7", .data = "I", }, + { .path = "/testcase-data/match-node/name8", .data = "J", }, + { .path = "/testcase-data/match-node/name9", .data = "K", }, +}; + +static void __init of_selftest_match_node(void) +{ + struct device_node *np; + const struct of_device_id *match; + int i; + + for (i = 0; i < ARRAY_SIZE(match_node_tests); i++) { + np = of_find_node_by_path(match_node_tests[i].path); + if (!np) { + selftest(0, "missing testcase node %s\n", + match_node_tests[i].path); + continue; + } + + match = of_match_node(match_node_table, np); + if (!match) { + selftest(0, "%s didn't match anything\n", + match_node_tests[i].path); + continue; + } + + if (strcmp(match->data, match_node_tests[i].data) != 0) { + selftest(0, "%s got wrong match. expected %s, got %s\n", + match_node_tests[i].path, match_node_tests[i].data, + (const char *)match->data); + continue; + } + selftest(1, "passed"); + } +} + static int __init of_selftest(void) { struct device_node *np; @@ -316,6 +382,7 @@ static int __init of_selftest(void) of_selftest_property_match_string(); of_selftest_parse_interrupts(); of_selftest_parse_interrupts_extended(); + of_selftest_match_node(); pr_info("end of selftest - %i passed, %i failed\n", selftest_results.passed, selftest_results.failed); return 0; diff --git a/drivers/of/testcase-data/testcases.dtsi b/drivers/of/testcase-data/testcases.dtsi index 3cc2f55534ac..3a5b75a8e4d7 100644 --- a/drivers/of/testcase-data/testcases.dtsi +++ b/drivers/of/testcase-data/testcases.dtsi @@ -1,2 +1,3 @@ #include "tests-phandle.dtsi" #include "tests-interrupts.dtsi" +#include "tests-match.dtsi" diff --git a/drivers/of/testcase-data/tests-match.dtsi b/drivers/of/testcase-data/tests-match.dtsi new file mode 100644 index 000000000000..c9e541129534 --- /dev/null +++ b/drivers/of/testcase-data/tests-match.dtsi @@ -0,0 +1,19 @@ + +/ { + testcase-data { + match-node { + name0 { }; + name1 { device_type = "type1"; }; + a { name2 { device_type = "type1"; }; }; + b { name2 { }; }; + c { name2 { device_type = "type2"; }; }; + name3 { compatible = "compat3"; }; + name4 { compatible = "compat2", "compat3"; }; + name5 { compatible = "compat2", "compat3"; }; + name6 { compatible = "compat1", "compat2", "compat3"; }; + name7 { compatible = "compat2"; device_type = "type1"; }; + name8 { compatible = "compat2"; device_type = "type1"; }; + name9 { compatible = "compat2"; }; + }; + }; +};