From patchwork Tue Feb 18 22:31:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 24919 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 60EA0202B2 for ; Tue, 18 Feb 2014 22:32:10 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id kp14sf42470512pab.10 for ; Tue, 18 Feb 2014 14:32:09 -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=qhFfUrJMsBydkhjLH2GiTIX1mEtfTqz6UVOQzv6e2vI=; b=eVEjflDkiehuLJlnImyzgM6svRd2g40BaDs33gjxSd5Tenzh0ntGWoWr3jwAyKUPLb hAqbdTQmFHcEYZTR79HXbUnK1OfL5CHHrQxOkqA78sbrnkiD/map28CoaNbZyxKGipB8 ghg+h0wGnOSdOup82OBtJVkAG5NyCIyeGKIoPgO7N7my5vAQhL5X/1HukUBOFTb1j0WA NIEPQ8E7ET3MkoKbOiNvICyjHypFV/vqQSyaS+Cxast5dJSRiSow0SVwJZ7yB3T/Sbd8 97KFskdjhfUzYq0T5xzgu2e11eaRGdBZH7Rkj0yIaY1CaNQpByPX+8zx5xrh6UBJriJs ic2g== X-Gm-Message-State: ALoCoQlysJ1vGeyQHqXHGO8CNDy6AyLGKEm8IMIP704gZFkRFltnEeDcwhBSnVjL95lcQV63EVLl X-Received: by 10.66.197.167 with SMTP id iv7mr11646894pac.12.1392762729479; Tue, 18 Feb 2014 14:32:09 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.109.137 with SMTP id l9ls1449018qgf.40.gmail; Tue, 18 Feb 2014 14:32:09 -0800 (PST) X-Received: by 10.52.246.133 with SMTP id xw5mr15717418vdc.32.1392762729346; Tue, 18 Feb 2014 14:32:09 -0800 (PST) Received: from mail-ve0-f178.google.com (mail-ve0-f178.google.com [209.85.128.178]) by mx.google.com with ESMTPS id uq6si5979901vcb.0.2014.02.18.14.32.09 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Feb 2014 14:32:09 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.178 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.178; Received: by mail-ve0-f178.google.com with SMTP id oy12so14066567veb.37 for ; Tue, 18 Feb 2014 14:32:09 -0800 (PST) X-Received: by 10.52.246.133 with SMTP id xw5mr15717413vdc.32.1392762729217; Tue, 18 Feb 2014 14:32:09 -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 u4csp251616vcz; Tue, 18 Feb 2014 14:32:08 -0800 (PST) X-Received: by 10.68.133.163 with SMTP id pd3mr6803073pbb.166.1392762728373; Tue, 18 Feb 2014 14:32:08 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id yh9si19706613pab.34.2014.02.18.14.32.07; Tue, 18 Feb 2014 14:32:07 -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 S1752852AbaBRWb7 (ORCPT + 27 others); Tue, 18 Feb 2014 17:31:59 -0500 Received: from mail-wg0-f41.google.com ([74.125.82.41]:46479 "EHLO mail-wg0-f41.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752729AbaBRWb4 (ORCPT ); Tue, 18 Feb 2014 17:31:56 -0500 Received: by mail-wg0-f41.google.com with SMTP id l18so3516285wgh.0 for ; Tue, 18 Feb 2014 14:31:54 -0800 (PST) X-Received: by 10.194.71.116 with SMTP id t20mr9564426wju.51.1392762714540; Tue, 18 Feb 2014 14:31:54 -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 xt1sm48798398wjb.17.2014.02.18.14.31.52 for (version=TLSv1.1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 18 Feb 2014 14:31:53 -0800 (PST) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id 435EEC40949; Tue, 18 Feb 2014 22:31:50 +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 4/4] of: Add self test for of_match_node() Date: Tue, 18 Feb 2014 22:31:20 +0000 Message-Id: <1392762680-1498-5-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.8.3.2 In-Reply-To: <1392762680-1498-1-git-send-email-grant.likely@linaro.org> References: <1392762680-1498-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.178 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. Currently all but one test passes. There is one scenario where the empty "b/name2" node is getting matched against an entry without any device_type property at all. It is unknown why this is, but it needs to be solved before this patch can be committed. (However, this is testing the new of_match_table implementation, which still does far better than the old implementation which gets the precedence completely wrong.) Signed-off-by: Grant Likely Cc: Kevin Hau --- 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"; }; + }; + }; +};