From patchwork Tue Nov 4 13:37:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Grant Likely X-Patchwork-Id: 40148 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-ee0-f70.google.com (mail-ee0-f70.google.com [74.125.83.70]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id D826B21894 for ; Tue, 4 Nov 2014 13:38:08 +0000 (UTC) Received: by mail-ee0-f70.google.com with SMTP id b57sf4095877eek.1 for ; Tue, 04 Nov 2014 05:38:07 -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:sender:precedence:list-id:x-original-sender :x-original-authentication-results:mailing-list:list-post:list-help :list-archive:list-unsubscribe; bh=YQJa8+VNbVlWHe8cQiZ6cMfTVz1iB8ta9/Wl0wSaAos=; b=KxfjnpSzhUulJFP8839sVRH1u2DZ1A0DaK4HG2QWjP7bsJY/9awwCS/koJTuRBK14p oWTDL6oN5Pp/Eg/1UHuhnbp5Ry+P+5/+jVCvwBTRIBzzFU8f15S5FqAVSbRUH9Wep+qq jMREWe5miW5BMiKhdAD2K1wtR0kXDXaBw4VA6P/pCryudPSlFQW0ui+ghpx21Vltyo+y mVf+QxPk6ROqKRLWMXRGl7IpBYtb3olqyyylXRx/TEAO32FyidAYZRAT9qErA8LDjDI/ 3ld58a5ZMdxd6V0rLh7HJkr8rndQdA+Eef2s5T2vRAfR6D3hm1+d0Y/QpcaHGdtAPzJQ RIXA== X-Gm-Message-State: ALoCoQlfRJHKOszsD3OudXCfRO/ZyvzNySwylTtx0WPCBpva8ZqSqc0HmHI4OmhDx4zQxqTSyw9Q X-Received: by 10.112.138.202 with SMTP id qs10mr8597175lbb.5.1415108287365; Tue, 04 Nov 2014 05:38:07 -0800 (PST) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.152.42.137 with SMTP id o9ls7056lal.17.gmail; Tue, 04 Nov 2014 05:38:06 -0800 (PST) X-Received: by 10.112.218.101 with SMTP id pf5mr23267106lbc.46.1415108286712; Tue, 04 Nov 2014 05:38:06 -0800 (PST) Received: from mail-lb0-f175.google.com (mail-lb0-f175.google.com. [209.85.217.175]) by mx.google.com with ESMTPS id y2si702809lbo.100.2014.11.04.05.38.06 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Tue, 04 Nov 2014 05:38:06 -0800 (PST) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.217.175 as permitted sender) client-ip=209.85.217.175; Received: by mail-lb0-f175.google.com with SMTP id n15so3136447lbi.6 for ; Tue, 04 Nov 2014 05:38:06 -0800 (PST) X-Received: by 10.112.130.41 with SMTP id ob9mr58416295lbb.74.1415108286619; Tue, 04 Nov 2014 05:38:06 -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.112.184.201 with SMTP id ew9csp115656lbc; Tue, 4 Nov 2014 05:38:05 -0800 (PST) X-Received: by 10.68.200.100 with SMTP id jr4mr50469047pbc.69.1415108285019; Tue, 04 Nov 2014 05:38:05 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id ws9si328196pab.91.2014.11.04.05.38.04 for ; Tue, 04 Nov 2014 05:38:05 -0800 (PST) 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 S1753964AbaKDNiD (ORCPT + 4 others); Tue, 4 Nov 2014 08:38:03 -0500 Received: from mail-wi0-f169.google.com ([209.85.212.169]:54180 "EHLO mail-wi0-f169.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753875AbaKDNiB (ORCPT ); Tue, 4 Nov 2014 08:38:01 -0500 Received: by mail-wi0-f169.google.com with SMTP id n3so8718244wiv.0 for ; Tue, 04 Nov 2014 05:38:00 -0800 (PST) X-Received: by 10.180.8.34 with SMTP id o2mr23402776wia.23.1415108280310; Tue, 04 Nov 2014 05:38:00 -0800 (PST) Received: from trevor.secretlab.ca (host81-159-9-229.range81-159.btcentralplus.com. [81.159.9.229]) by mx.google.com with ESMTPSA id j8sm12307609wib.10.2014.11.04.05.37.58 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Nov 2014 05:37:59 -0800 (PST) Received: by trevor.secretlab.ca (Postfix, from userid 1000) id 788CDC408F6; Tue, 4 Nov 2014 13:37:55 +0000 (GMT) From: Grant Likely To: devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Grant Likely Subject: [PATCH 1/2] of/unittest: Remove test devices after adding them Date: Tue, 4 Nov 2014 13:37:52 +0000 Message-Id: <1415108273-4536-1-git-send-email-grant.likely@linaro.org> X-Mailer: git-send-email 1.9.1 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.175 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: , The of_platform_populate() test cases don't remove the test devices after they are added. Fix this by adding tests for of_platform_depopulate(). At the same time rework the selftest() macro to return the test result value. This makes it easy to use the macro inside an if() condition. Signed-off-by: Grant Likely --- drivers/of/selftest.c | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/drivers/of/selftest.c b/drivers/of/selftest.c index bf7d99317a94..082bb2b6a5ad 100644 --- a/drivers/of/selftest.c +++ b/drivers/of/selftest.c @@ -30,15 +30,17 @@ static struct device_node *nodes[NO_OF_NODES]; static int last_node_index; static bool selftest_live_tree; -#define selftest(result, fmt, ...) { \ - if (!(result)) { \ +#define selftest(result, fmt, ...) ({ \ + bool failed = !(result); \ + if (failed) { \ selftest_results.failed++; \ pr_err("FAIL %s():%i " fmt, __func__, __LINE__, ##__VA_ARGS__); \ } else { \ selftest_results.passed++; \ pr_debug("pass %s():%i\n", __func__, __LINE__); \ } \ -} + failed; \ +}) static void __init of_selftest_find_node_by_name(void) { @@ -694,10 +696,13 @@ static void __init of_selftest_match_node(void) } } +struct device test_bus = { + .init_name = "unittest-bus", +}; static void __init of_selftest_platform_populate(void) { - int irq; - struct device_node *np, *child; + int irq, rc; + struct device_node *np, *child, *grandchild; struct platform_device *pdev; struct of_device_id match[] = { { .compatible = "test-device", }, @@ -722,20 +727,32 @@ static void __init of_selftest_platform_populate(void) irq = platform_get_irq(pdev, 0); selftest(irq < 0 && irq != -EPROBE_DEFER, "device parsing error failed - %d\n", irq); - np = of_find_node_by_path("/testcase-data/platform-tests"); - if (!np) { - pr_err("No testcase data in device tree\n"); + if (selftest(np = of_find_node_by_path("/testcase-data/platform-tests"), + "No testcase data in device tree\n")); + return; + + if (selftest(!(rc = device_register(&test_bus)), + "testbus registration failed; rc=%i\n", rc)); return; - } for_each_child_of_node(np, child) { - struct device_node *grandchild; - of_platform_populate(child, match, NULL, NULL); + of_platform_populate(child, match, NULL, &test_bus); for_each_child_of_node(child, grandchild) selftest(of_find_device_by_node(grandchild), "Could not create device for node '%s'\n", grandchild->name); } + + of_platform_depopulate(&test_bus); + for_each_child_of_node(np, child) { + for_each_child_of_node(child, grandchild) + selftest(!of_find_device_by_node(grandchild), + "device didn't get destroyed '%s'\n", + grandchild->name); + } + + device_unregister(&test_bus); + of_node_put(np); } /**