From patchwork Sat Oct 4 20:29:58 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 38351 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f69.google.com (mail-ee0-f69.google.com [74.125.83.69]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id B6D0D203AD for ; Sat, 4 Oct 2014 20:30:55 +0000 (UTC) Received: by mail-ee0-f69.google.com with SMTP id b57sf1819070eek.4 for ; Sat, 04 Oct 2014 13:30:54 -0700 (PDT) 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=GQqW0epkj0CT6U3eoF9LRuLp9AeTc9CBCJWD+0eEy/M=; b=WTxDRGk85q2BBdwc8QVS2p6B9DHCrTcv4SaUudzKknFg7DtrvkdH4Fg0BHOqq0XoqI s65BxNDrdlgfRfOVvkVR2T2wx/GhULf0/MWsvaG2EiU3z8MbMeXkBnUqHnLTh2rHAi18 pjdYO1+OCaVUBCAcu6/UwEy0Y7BcPxC+LsGdjq3No0EkOyODJoR1kMg7RvzXC0mfdk2n TrOlNFIoPJBSi9UIOgCk1sKjwTKlZUsHi5ZIsXAZMXv4FZPmc6pi6Ud1XkdZ0mEZiyjm yvFlyC1ctBcNCGbjsUxvMe2DWdOYOYOQlUsv+tGww4+FM5OMTskStRiNK6+wkB/jm1I5 C8xw== X-Gm-Message-State: ALoCoQnvWNmoWngv/tdjdh2O4UG+B7+OnpOLJyAs6IWyww9cLmYsFbsthMxDYLey+WugllC2nmE5 X-Received: by 10.112.89.8 with SMTP id bk8mr2242705lbb.6.1412454654917; Sat, 04 Oct 2014 13:30:54 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.5.97 with SMTP id r1ls461068lar.84.gmail; Sat, 04 Oct 2014 13:30:54 -0700 (PDT) X-Received: by 10.112.209.2 with SMTP id mi2mr13543173lbc.51.1412454654533; Sat, 04 Oct 2014 13:30:54 -0700 (PDT) Received: from mail-lb0-f181.google.com (mail-lb0-f181.google.com [209.85.217.181]) by mx.google.com with ESMTPS id lm5si17047821lac.87.2014.10.04.13.30.54 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Sat, 04 Oct 2014 13:30:54 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) client-ip=209.85.217.181; Received: by mail-lb0-f181.google.com with SMTP id l4so2502132lbv.40 for ; Sat, 04 Oct 2014 13:30:54 -0700 (PDT) X-Received: by 10.152.42.136 with SMTP id o8mr14455310lal.71.1412454654338; Sat, 04 Oct 2014 13:30:54 -0700 (PDT) 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.112.130.169 with SMTP id of9csp76215lbb; Sat, 4 Oct 2014 13:30:53 -0700 (PDT) X-Received: by 10.70.39.9 with SMTP id l9mr8776177pdk.70.1412454652854; Sat, 04 Oct 2014 13:30:52 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id pl6si7343357pdb.111.2014.10.04.13.30.52 for ; Sat, 04 Oct 2014 13:30:52 -0700 (PDT) Received-SPF: none (google.com: devicetree-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751033AbaJDUav (ORCPT + 5 others); Sat, 4 Oct 2014 16:30:51 -0400 Received: from mail-wg0-f47.google.com ([74.125.82.47]:55318 "EHLO mail-wg0-f47.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1750956AbaJDUau (ORCPT ); Sat, 4 Oct 2014 16:30:50 -0400 Received: by mail-wg0-f47.google.com with SMTP id x13so3875737wgg.30 for ; Sat, 04 Oct 2014 13:30:49 -0700 (PDT) X-Received: by 10.194.118.201 with SMTP id ko9mr17809423wjb.9.1412454649100; Sat, 04 Oct 2014 13:30:49 -0700 (PDT) Received: from trevor.secretlab.ca (host86-166-87-213.range86-166.btcentralplus.com. [86.166.87.213]) by mx.google.com with ESMTPSA id l5sm2970614wif.3.2014.10.04.13.30.47 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 04 Oct 2014 13:30:48 -0700 (PDT) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id 8226FC41C4A; Sat, 4 Oct 2014 13:30:12 -0700 (PDT) From: Grant Likely To: devicetree@vger.kernel.org Cc: Grant Likely , Gaurav Minocha Subject: [PATCH v2 2/6] of/selftest: Test structure of device tree Date: Sat, 4 Oct 2014 21:29:58 +0100 Message-Id: <1412454602-28518-2-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1412454602-28518-1-git-send-email-grant.likely@linaro.org> References: <1412454602-28518-1-git-send-email-grant.likely@linaro.org> Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@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=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.181 as permitted sender) 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: , Add a testcase to verify that the device tree is properly constructed and the lists are in a correct order. The new testcase gets run twice; once after adding the testcase data, and once after removing it again. It is run twice to make sure adding and removing the testcase data doesn't corrupt the data structure. Signed-off-by: Grant Likely Cc: Gaurav Minocha --- drivers/of/selftest.c | 56 +++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index 883e60b04eb5..252a7eda8d6a 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c @@ -145,6 +145,53 @@ static void __init of_selftest_dynamic(void) "Adding a large property should have passed\n"); } +static int __init of_selftest_check_node_linkage(struct device_node *np) +{ + struct device_node *child, *allnext_index = np; + int count = 0, rc; + + for_each_child_of_node(np, child) { + if (child->parent != np) { + pr_err("Child node %s links to wrong parent %s\n", + child->name, np->name); + return -EINVAL; + } + + while (allnext_index && allnext_index != child) + allnext_index = allnext_index->allnext; + if (allnext_index != child) { + pr_err("Node %s is ordered differently in sibling and allnode lists\n", + child->name); + return -EINVAL; + } + + rc = of_selftest_check_node_linkage(child); + if (rc < 0) + return rc; + count += rc; + } + + return count + 1; +} + +static void __init of_selftest_check_tree_linkage(void) +{ + struct device_node *np; + int allnode_count = 0, child_count; + + if (!of_allnodes) + return; + + for_each_of_allnodes(np) + allnode_count++; + child_count = of_selftest_check_node_linkage(of_allnodes); + + selftest(child_count > 0, "Device node data structure is corrupted\n"); + selftest(child_count == allnode_count, "allnodes list size (%i) doesn't match" + "sibling lists size (%i)\n", allnode_count, child_count); + pr_debug("allnodes list size (%i); sibling lists size (%i)\n", allnode_count, child_count); +} + static void __init of_selftest_parse_phandle_with_args(void) { struct device_node *np; @@ -777,6 +824,7 @@ static int __init of_selftest(void) of_node_put(np); pr_info("start of selftest - you will see error messages\n"); + of_selftest_check_tree_linkage(); of_selftest_find_node_by_name(); of_selftest_dynamic(); of_selftest_parse_phandle_with_args(); @@ -787,12 +835,16 @@ static int __init of_selftest(void) of_selftest_parse_interrupts_extended(); of_selftest_match_node(); of_selftest_platform_populate(); - pr_info("end of selftest - %i passed, %i failed\n", - selftest_results.passed, selftest_results.failed); /* removing selftest data from live tree */ selftest_data_remove(); + /* Double check linkage after removing testcase data */ + of_selftest_check_tree_linkage(); + + pr_info("end of selftest - %i passed, %i failed\n", + selftest_results.passed, selftest_results.failed); + return 0; } late_initcall(of_selftest);