Received: by 2002:ab2:6309:0:b0:1fb:d597:ff75 with SMTP id s9csp463419lqt; Thu, 6 Jun 2024 08:36:33 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVsWuyM0iBegpUGSTvM6vLZe2tjcbS7ZzNVNS0FVdS/HJ+5dIz9fzVbhV7MI0CZOpWSeBFsXFAjF5B78Dv5YoNKCT8DwEjS581FAjV3ZA== X-Google-Smtp-Source: AGHT+IEOt4478qhHbAbWGWoJeVUYfrhuwK/HKqb3b5w6bCdsys5A7HDSLCAxjZ3ASMBPXOJ/9JGG X-Received: by 2002:a05:6a00:14d2:b0:702:38ee:7eb9 with SMTP id d2e1a72fcca58-703e595b1c0mr8058466b3a.7.1717688193498; Thu, 06 Jun 2024 08:36:33 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717688193; cv=pass; d=google.com; s=arc-20160816; b=KtF5ZaVV4FgNpj+GM8JYf8HJsPa9ajYBQGCB96PCfWFnyGH8eXN0uyFjC1iSbkVWLs ppJ/if7pY5D5V1JVmGNy8dx2QE6xvn5mtIhbDlHIMJxcWrVe7EYEnk3CRwSz/jr8d7JC w3BqklFqbGQpNCfnuCeNLJJujA4M8FPkHQz3dnwWkaJTpTW6YeTMKMWOFBOo7XevMhZT vPoJ+sQiQ2fA8BrChcazsOL0eUdo81m1fm9CKxsF0+JPYa9RUzTkI4t0qYvVJT7eE/LB oy63gAHRD63IchvtxLOn8D8RHhMOyNXuyLuB75UPDhrA46EQIRP0/0c1kLwdFH4LaTtM 6kCA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=user-agent:date:to:cc:from:subject:references:in-reply-to :content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:dkim-signature; bh=v6VzeKR+6Tz8haucZnPl8tVW2edRp0OhWrjcIKD47JM=; fh=TIMqekZYJqeJ30q1FY7/rGkXV6Bgk8pI9iruDxVPB6A=; b=BxScEA4/ZiXMWwKZGzG7gpClxFrvtWgxvumVTi9RBI5zNf25+hWTT4e90CycInzZAA A4/m3A+HARBQM05wud9M1uCJzQXGZPstYveslhz08lxaJA2FkDArPgtvuMe+7zdifbEY 6PQTMNp2S4JQOd/NwoR/+0hn6gttFaMhBZUnbVUUop6rqRyG3fGs4QujIAN7V5vAKSo4 YJ6u7z3zdTwBNP15pTLFBSHEUrN/6GRJoh0Wnm0PT3VUDI4TXXJk9FTfgJIGMAO6IyeU OyAx3TAlPwCSgwsdxcmFB3J7WktnkenWAHqcVVEe1a4jTkltvF6KsClSHeUJPC4EPvZA irzQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bGDQ3Nz9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-204568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204568-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6de2a280b8dsi613737a12.798.2024.06.06.08.36.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 Jun 2024 08:36:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-204568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bGDQ3Nz9; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-204568-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-204568-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id E4B8E28D507 for ; Thu, 6 Jun 2024 15:25:12 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 14485197530; Thu, 6 Jun 2024 15:23:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="bGDQ3Nz9" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 18E53195FC4; Thu, 6 Jun 2024 15:23:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717687413; cv=none; b=BLRLht+k/wqXEaC2/aGSoZepMrU441mL8XnJilNWyB+dqVXvsui/VhcB+p1P/PlUusuNyEjAInkbzSRxpPsfYnKprVbeu5THq6geIUMkgj6e1rONU+O7Js1yDz8lQ3s26pxv6UvSsStrqRHgfr8YApRSV/SclsD59svpwwT+CFo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717687413; c=relaxed/simple; bh=n8Yr0UeoP6wPmeyQGK/cVLGthNtM0TGWP7koLQxIank=; h=Message-ID:Content-Type:MIME-Version:In-Reply-To:References: Subject:From:Cc:To:Date; b=U7wc7JLUDcTd0Ul92MxvtHIi77i5bTyydXHUjRJbsJR0rrUzxekcUq5a6UyTkQbcAUheSYwzblhTwlgqsbdD7yGS/f4h59DiIGuV96oQKIOQMNQjBS5fFrGUWN4RTvrYWO+mAF1ZjlILqWGJo6HZ12Q0WIgOaDM/pre7VNp2a9A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=bGDQ3Nz9; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 7FE53C2BD10; Thu, 6 Jun 2024 15:23:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717687412; bh=n8Yr0UeoP6wPmeyQGK/cVLGthNtM0TGWP7koLQxIank=; h=In-Reply-To:References:Subject:From:Cc:To:Date:From; b=bGDQ3Nz9FJaTI03nkHRRI8Rkbmqyr8quCZRGkaHPS78qF5hhbIu4lQZVvtyfMCwaJ HNNQFCq99KG4QMX5sAPumvaa8eOxjVdP0f17ulhpsskQ7G4f0MWGcAe45aou2zPUIo puEO9reNGbm2iTeM2JO3MKqGYKuBjyDajfpZP6CH1fdj1EcSZRdM4UxCM95p1BzN+1 d2W44/s7KjAFeuSgy6+WD9SocKtMJeh7WRL68waquEN4l2jQv20b7Dcv1Jfj+I/yQc kPZbyvhjJzExje/AobiV3kGiteGFOJxgnfi5obYxJpmbDqewG2Y1hzqQkn2G+xMaPb LBWRr86Qk3guQ== Message-ID: <025da51b45c5234dc05c4bfc6b0570e5.sboyd@kernel.org> Content-Type: text/plain; charset="utf-8" Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable In-Reply-To: <20240605234720.GA3441001-robh@kernel.org> References: <20240603223811.3815762-1-sboyd@kernel.org> <20240603223811.3815762-6-sboyd@kernel.org> <20240605234720.GA3441001-robh@kernel.org> Subject: Re: [PATCH v5 05/11] of: Add a KUnit test for overlays and test managed APIs From: Stephen Boyd Cc: Michael Turquette , linux-kernel@vger.kernel.org, linux-clk@vger.kernel.org, patches@lists.linux.dev, kunit-dev@googlegroups.com, linux-kselftest@vger.kernel.org, devicetree@vger.kernel.org, Brendan Higgins , David Gow , Rae Moar , Greg Kroah-Hartman , Rafael J . Wysocki , Saravana Kannan , Daniel Latypov , Christian Marangi , Krzysztof Kozlowski , Conor Dooley , Maxime Ripard To: Rob Herring Date: Thu, 06 Jun 2024 08:23:30 -0700 User-Agent: alot/0.10 Quoting Rob Herring (2024-06-05 16:47:20) > On Mon, Jun 03, 2024 at 03:38:02PM -0700, Stephen Boyd wrote: > > diff --git a/drivers/of/Makefile b/drivers/of/Makefile > > index 2ae909adde49..abd9c578343b 100644 > > diff --git a/drivers/of/overlay_test.c b/drivers/of/overlay_test.c > > new file mode 100644 > > index 000000000000..9a8083c3a659 > > --- /dev/null > > +++ b/drivers/of/overlay_test.c > > @@ -0,0 +1,116 @@ > > +// SPDX-License-Identifier: GPL-2.0 > > +/* > > + * KUnit tests for device tree overlays > > + */ > > +#include > > +#include > > +#include > > +#include > > +#include > > + > > +#include > > +#include > > + > > +static const char * const kunit_node_name =3D "kunit-test"; > > +static const char * const kunit_compatible =3D "test,empty"; > > + > > +/* Test that of_overlay_apply_kunit() adds a node to the live tree */ > > +static void of_overlay_apply_kunit_apply(struct kunit *test) > > +{ > > + struct device_node *np; > > + > > + KUNIT_ASSERT_EQ(test, 0, > > + of_overlay_apply_kunit(test, kunit_overlay_test)); > > + > > + np =3D of_find_node_by_name(NULL, kunit_node_name); > > + KUNIT_EXPECT_NOT_ERR_OR_NULL(test, np); > > + of_node_put(np); > > +} > > + > > +/* > > + * Test that of_overlay_apply_kunit() creates platform devices with the > > + * expected device_node > > + */ > > +static void of_overlay_apply_kunit_platform_device(struct kunit *test) > > +{ > > + struct platform_device *pdev; > > + struct device_node *np; > > + > > + KUNIT_ASSERT_EQ(test, 0, > > + of_overlay_apply_kunit(test, kunit_overlay_test)); > > + > > + np =3D of_find_node_by_name(NULL, kunit_node_name); > > + of_node_put_kunit(test, np); >=20 > Moving target, but we now have of_node_put() cleanups. Would that work=20 > here instead? Do you mean cleanup.h? I don't think it will work. The assert logic is like an exception handler. If the assertion fails we basically jump out of the test and run any test exit code, including kunit resource exits. I could introduce another kunit wrapper for of_find_node_by_name() and use that here so that the reference is dropped when the test exits. >=20 > > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, np); > > + > > + pdev =3D of_find_device_by_node(np); > > + KUNIT_EXPECT_NOT_ERR_OR_NULL(test, pdev); > > + if (pdev) > > + put_device(&pdev->dev); > > +} > > + > > +static int of_overlay_bus_match_compatible(struct device *dev, const v= oid *data) > > +{ > > + return of_device_is_compatible(dev->of_node, data); > > +} > > + > > +/* Test that of_overlay_apply_kunit() cleans up after the test is fini= shed */ > > +static void of_overlay_apply_kunit_cleanup(struct kunit *test) > > +{ > > + struct kunit fake; > > + struct platform_device *pdev; > > + struct device *dev; > > + struct device_node *np; > > + > > + if (!IS_ENABLED(CONFIG_OF_OVERLAY)) > > + kunit_skip(test, "requires CONFIG_OF_OVERLAY"); > > + if (!IS_ENABLED(CONFIG_OF_EARLY_FLATTREE)) > > + kunit_skip(test, "requires CONFIG_OF_EARLY_FLATTREE for r= oot node"); > > + > > + kunit_init_test(&fake, "fake test", NULL); > > + KUNIT_ASSERT_EQ(test, fake.status, KUNIT_SUCCESS); > > + > > + KUNIT_ASSERT_EQ(test, 0, > > + of_overlay_apply_kunit(&fake, kunit_overlay_test)= ); > > + > > + np =3D of_find_node_by_name(NULL, kunit_node_name); > > + of_node_put(np); /* Not derefing 'np' after this */ > > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, np); > > + > > + pdev =3D of_find_device_by_node(np); >=20 > Don't you need to hold a ref on np until here? Oh, good catch. We need an of_find_node_by_name_kunit() wrapper then.