Received: by 2002:ab2:6f44:0:b0:1fd:c486:4f03 with SMTP id l4csp228573lqq; Thu, 13 Jun 2024 00:57:20 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUreXqvZkAMJQvf4YNxG8mVp/BKkZV/WOSDTYAsI5BYku6w+3jG0zkcnhUZA4nAvb+1Q3tGXuclWgyrmPcNf3HrAE7BxDk+p9lvguKtGA== X-Google-Smtp-Source: AGHT+IGmcJ9fOLVq0j6eL84fsA5d8S95Hs3eFY+wn1c/s/PtNpqfa1nFm03ar4+7/0AZmfh2Iv2k X-Received: by 2002:a05:6e02:12ec:b0:374:8214:4ba7 with SMTP id e9e14a558f8ab-375cd12ec9cmr45317615ab.6.1718265440450; Thu, 13 Jun 2024 00:57:20 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1718265440; cv=pass; d=google.com; s=arc-20160816; b=Rty9yc1VWLeSJjmkXc2KWfOQjW4s1h2+OTwunHnPvI4r3syYezv60zJJOmdoSk61uy NX/QEpctkPeqnERAsJQOb4Q/r01TY76Y2QVzScPet1T+q9XaUzPOj6rXolnsZ95cADQ0 f8Ixg46ZzskcGkqiZjV9fVYQo30xmHLJyIV8y8+39kIyY5DIMFYJP+rAzRZy9jJ0jOLi 6o/P8OWdvrqmu53TtVqWgr7PA0vrZ6oiR+e5+087SjYTX2I6p4fktvzZnJHu8YOWPnFv 4rTOsnMiwN7WaFq+npW5WuzN7NXnE9efaDQlOLMbatgVTtOhaS15O3PMk/O4BbA7mK+R N6DA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :dkim-signature; bh=X5/lRMBvWFGZCVTxugxUO95FpncjZ0x5jae1ArQ2/OM=; fh=/3T+jFn7ItNFWXIT4i5NLU2Vz4E64Lfq3WMc/dm4OLY=; b=nraLuOMa/YKbCTvcYAk3IqwQjUhtrnT22/Tammh43JkVZe3Sp1/u4jeNVxbiepZyou WI5iNO+Aw+aq0rR7zeOgBn4kvn7ITDsN5sdQ1YkXAxfIO8y+BsSKOdc0q9R5/5WBJkT4 acWeLvym7LJNdHmRMXbOnSG6NssYrixvdAJeobCwgTJO67wxxjzAO4BruVCGEX6G1UqL MakxKDw/nFCcPbTQBGsgXUxvqxswTkS3FDEBGfkminwFzbUo2LnGsBMTeexHLUuihN6o LvLMqC6+y9pg6WbPzciwPwRw5djcF23qZWOPTQVOrI2r7lipEDGT39a3aRpIGuVCQq1+ /4cg==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=nRhnv7uX; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-212759-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212759-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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-6fee310c70bsi781619a12.312.2024.06.13.00.57.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 00:57:20 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-212759-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=@google.com header.s=20230601 header.b=nRhnv7uX; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-212759-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-212759-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com 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 021B72810EE for ; Thu, 13 Jun 2024 07:57:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id AC7C413CF96; Thu, 13 Jun 2024 07:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="nRhnv7uX" Received: from mail-qt1-f170.google.com (mail-qt1-f170.google.com [209.85.160.170]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 478EB13CAB0 for ; Thu, 13 Jun 2024 07:56:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.160.170 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718265385; cv=none; b=kidtro0J1PULdUsguPddyZJBnfuh0ZlrHKfuKLNxKgo6rH7jHzwlTQ2N8qAO4zK1E8Smn5Yx6EwWoxvivuMrgVIfSnZS4DUmr5VAiAraw2j6KC+uS4KNZ0nqc9dldM55xHwKhToJswIKrCLrw0VMfrUQOPUohWcmBp4xjpFGhQo= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718265385; c=relaxed/simple; bh=mKJ8MVgQMOmFwVb3pfWeGzTO3e0B42TiOD92ZaMLcz8=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=TEAfy//8Gsd/k0/8NJLYD2Mz68CVFQwQpf9qI/VSq2pgRGw0/KAUOZFlTtLM69W6ymbZwqTmMVKelPJB2wh8ur3WauBowG3HQhK4RyLC+0gCB8r+yiK6vmGy/3elCR+cokMPaTIO56Sy3hyCCa8yKDbiKGnqMAcDqSSGCHG9PVU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=nRhnv7uX; arc=none smtp.client-ip=209.85.160.170 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-qt1-f170.google.com with SMTP id d75a77b69052e-4400cc0dad1so350091cf.0 for ; Thu, 13 Jun 2024 00:56:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1718265382; x=1718870182; darn=vger.kernel.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=X5/lRMBvWFGZCVTxugxUO95FpncjZ0x5jae1ArQ2/OM=; b=nRhnv7uXp61OSsEMYDY0xq2nwU2hK2aBXRu9FgfbXm+HBmRYXddsIpSNqtDouyDvti h8acW+26S7z4dsDHts8QujSDUzA+1ji61AGXIbdrBYDCUHFUZ+mGwpAB7Xl2gTV9jBuc CEDoGDxH0clpnX72Subeb8ZrVFwulrQ88BeYLQduVg4KkorVKUwrKY0hopWmSpvkbrp4 NPqMplmMkG5GXbKHYR6Kok6fWLzesfPku5hZ4N3uzDzHqIf1aNEYfLrQ4Q6mb6AES+mr M3zLwAbzh9NpeT6Jbuqw0sve904anIT25BJ0+/yiwjdaupjDTkmmdvuI3dkjnDkRWQq3 AUnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718265382; x=1718870182; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=X5/lRMBvWFGZCVTxugxUO95FpncjZ0x5jae1ArQ2/OM=; b=vW6zFpe/U/jCUPY9kXrp5F0uBRixE5ayv0+odauw5YLI1UiRiAf9bYHvWIIsM3nzl3 cSAs6zTMacKJqYnDqxTVSP+jIseSkOyl4OlzoV4P93gIkkH+8uV8ewgccjfjr7tr0G3g mupRPDpcvNSTdYUoSATnXK6gibCXVEEM07joqC1OoQ1+VuJB+l1e4Lq2sfY8rEzNnjHA ckq+0or4xlqy5Vucw2gYlIcBWebZSZkO8X447vMQUo8OnPxXPpR/dLBHrjuxx8ZG63Ia CUZXONe4ujBNJpv4hCluvSv+WCSI0qDYrNBUSez5C2LCgEonOB9EG1CvzKRJxC7z85KZ w2ag== X-Forwarded-Encrypted: i=1; AJvYcCWqI1iT0yN8dem0OizsjxpmlNXeSXSCCZmwPUCd5182fVm5lmU7Pzy8KKt726RUNzrvnwZsU1dIZCDT1afMdJ35CkvDZp7S3BbBzI6U X-Gm-Message-State: AOJu0YwUbhcOi9ewlYbpLP+aEkaOW1MzCp3kXU1c+TJBhTUuckVT8BmU NJZ0mWRCvxofKa/WX/DulcDmSjXeO1ArkbvFSqMGr1L+9GQ7SZ2vQ1Z0sKSa8ymH1Im+ta6eSAE yjwNPlpv6Zj7u0jOC8+v1+36Hx4Q8EMt6k71s X-Received: by 2002:a05:622a:4c19:b0:43d:85ae:bee with SMTP id d75a77b69052e-441e2424be3mr2081941cf.7.1718265381757; Thu, 13 Jun 2024 00:56:21 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240603223811.3815762-1-sboyd@kernel.org> <20240603223811.3815762-12-sboyd@kernel.org> In-Reply-To: <20240603223811.3815762-12-sboyd@kernel.org> From: David Gow Date: Thu, 13 Jun 2024 15:56:08 +0800 Message-ID: Subject: Re: [PATCH v5 11/11] clk: Add KUnit tests for clks registered with struct clk_parent_data To: 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 , Rae Moar , Greg Kroah-Hartman , "Rafael J . Wysocki" , Rob Herring , Saravana Kannan , Daniel Latypov , Christian Marangi , Krzysztof Kozlowski , Conor Dooley , Maxime Ripard Content-Type: multipart/signed; protocol="application/pkcs7-signature"; micalg=sha-256; boundary="000000000000bffdcb061ac0d570" --000000000000bffdcb061ac0d570 Content-Type: text/plain; charset="UTF-8" On Tue, 4 Jun 2024 at 06:38, Stephen Boyd wrote: > > Test that clks registered with 'struct clk_parent_data' work as > intended and can find their parents. > > Cc: Christian Marangi > Cc: Brendan Higgins > Cc: David Gow > Cc: Rae Moar > Signed-off-by: Stephen Boyd > --- This seems good to me overall, but will break if we can't compile the dtbo.o file. Maybe these need to live behind a #if IS_ENABLED(CONFIG_OF) or equivalent. Also, there's a cast to kunit_action_t* which needs to use a wrapper. Otherwise, Reviewed-by: David Gow Cheers, -- David > drivers/clk/Kconfig | 1 + > drivers/clk/Makefile | 3 +- > drivers/clk/clk_parent_data_test.h | 10 + > drivers/clk/clk_test.c | 451 +++++++++++++++++++- > drivers/clk/kunit_clk_parent_data_test.dtso | 28 ++ > 5 files changed, 491 insertions(+), 2 deletions(-) > create mode 100644 drivers/clk/clk_parent_data_test.h > create mode 100644 drivers/clk/kunit_clk_parent_data_test.dtso > > diff --git a/drivers/clk/Kconfig b/drivers/clk/Kconfig > index f649f2a0279c..c33fdf9fdcd6 100644 > --- a/drivers/clk/Kconfig > +++ b/drivers/clk/Kconfig > @@ -508,6 +508,7 @@ config CLK_KUNIT_TEST > tristate "Basic Clock Framework Kunit Tests" if !KUNIT_ALL_TESTS > depends on KUNIT > default KUNIT_ALL_TESTS > + select OF_OVERLAY if OF > help > Kunit tests for the common clock framework. > > diff --git a/drivers/clk/Makefile b/drivers/clk/Makefile > index 7b57e3d22cee..ed4e1a0e6943 100644 > --- a/drivers/clk/Makefile > +++ b/drivers/clk/Makefile > @@ -2,7 +2,8 @@ > # common clock types > obj-$(CONFIG_HAVE_CLK) += clk-devres.o clk-bulk.o clkdev.o > obj-$(CONFIG_COMMON_CLK) += clk.o > -obj-$(CONFIG_CLK_KUNIT_TEST) += clk_test.o > +obj-$(CONFIG_CLK_KUNIT_TEST) += clk_test.o \ > + kunit_clk_parent_data_test.dtbo.o This breaks if CONFIG_OF isn't enabled, as there's no rule to compile it: make[5]: *** No rule to make target 'drivers/clk/kunit_clk_parent_data_test.dtbo.o', needed by 'drivers/clk/modules.order'. Stop. > obj-$(CONFIG_COMMON_CLK) += clk-divider.o > obj-$(CONFIG_COMMON_CLK) += clk-fixed-factor.o > obj-$(CONFIG_COMMON_CLK) += clk-fixed-rate.o > diff --git a/drivers/clk/clk_parent_data_test.h b/drivers/clk/clk_parent_data_test.h > new file mode 100644 > index 000000000000..eedd53ae910d > --- /dev/null > +++ b/drivers/clk/clk_parent_data_test.h > @@ -0,0 +1,10 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +#ifndef _CLK_PARENT_DATA_TEST_H > +#define _CLK_PARENT_DATA_TEST_H > + > +#define CLK_PARENT_DATA_1MHZ_NAME "1mhz_fixed_legacy" > +#define CLK_PARENT_DATA_PARENT1 "parent_fwname" > +#define CLK_PARENT_DATA_PARENT2 "50" > +#define CLK_PARENT_DATA_50MHZ_NAME "50_clk" > + > +#endif > diff --git a/drivers/clk/clk_test.c b/drivers/clk/clk_test.c > index 39e2b5ff4f51..bdf3c4bb2243 100644 > --- a/drivers/clk/clk_test.c > +++ b/drivers/clk/clk_test.c > @@ -4,12 +4,19 @@ > */ > #include > #include > +#include > +#include > > /* Needed for clk_hw_get_clk() */ > #include "clk.h" > > +#include > +#include > +#include > #include > > +#include "clk_parent_data_test.h" > + > static const struct clk_ops empty_clk_ops = { }; > > #define DUMMY_CLOCK_INIT_RATE (42 * 1000 * 1000) > @@ -2659,6 +2666,446 @@ static struct kunit_suite clk_mux_no_reparent_test_suite = { > .test_cases = clk_mux_no_reparent_test_cases, > }; > > +struct clk_register_clk_parent_data_test_case { > + const char *desc; > + struct clk_parent_data pdata; > +}; > + > +static void > +clk_register_clk_parent_data_test_case_to_desc( > + const struct clk_register_clk_parent_data_test_case *t, char *desc) > +{ > + strcpy(desc, t->desc); > +} > + > +static const struct clk_register_clk_parent_data_test_case > +clk_register_clk_parent_data_of_cases[] = { > + { > + /* > + * Test that a clk registered with a struct device_node can > + * find a parent based on struct clk_parent_data::index. > + */ > + .desc = "clk_parent_data_of_index_test", > + .pdata.index = 0, > + }, > + { > + /* > + * Test that a clk registered with a struct device_node can > + * find a parent based on struct clk_parent_data::fwname. > + */ > + .desc = "clk_parent_data_of_fwname_test", > + .pdata.fw_name = CLK_PARENT_DATA_PARENT1, > + }, > + { > + /* > + * Test that a clk registered with a struct device_node can > + * find a parent based on struct clk_parent_data::name. > + */ > + .desc = "clk_parent_data_of_name_test", > + /* The index must be negative to indicate firmware not used */ > + .pdata.index = -1, > + .pdata.name = CLK_PARENT_DATA_1MHZ_NAME, > + }, > + { > + /* > + * Test that a clk registered with a struct device_node can > + * find a parent based on struct > + * clk_parent_data::{fw_name,name}. > + */ > + .desc = "clk_parent_data_of_fwname_name_test", > + .pdata.fw_name = CLK_PARENT_DATA_PARENT1, > + .pdata.name = "not_matching", > + }, > + { > + /* > + * Test that a clk registered with a struct device_node can > + * find a parent based on struct clk_parent_data::{index,name}. > + * Index takes priority. > + */ > + .desc = "clk_parent_data_of_index_name_priority_test", > + .pdata.index = 0, > + .pdata.name = "not_matching", > + }, > + { > + /* > + * Test that a clk registered with a struct device_node can > + * find a parent based on struct > + * clk_parent_data::{index,fwname,name}. The fw_name takes > + * priority over index and name. > + */ > + .desc = "clk_parent_data_of_index_fwname_name_priority_test", > + .pdata.index = 1, > + .pdata.fw_name = CLK_PARENT_DATA_PARENT1, > + .pdata.name = "not_matching", > + }, > +}; > + > +KUNIT_ARRAY_PARAM(clk_register_clk_parent_data_of_test, clk_register_clk_parent_data_of_cases, > + clk_register_clk_parent_data_test_case_to_desc) > + > +/** > + * struct clk_register_clk_parent_data_of_ctx - Context for clk_parent_data OF tests > + * @np: device node of clk under test > + * @hw: clk_hw for clk under test > + */ > +struct clk_register_clk_parent_data_of_ctx { > + struct device_node *np; > + struct clk_hw hw; > +}; > + > +static int clk_register_clk_parent_data_of_test_init(struct kunit *test) > +{ > + struct clk_register_clk_parent_data_of_ctx *ctx; > + > + KUNIT_ASSERT_EQ(test, 0, > + of_overlay_apply_kunit(test, kunit_clk_parent_data_test)); > + > + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); > + if (!ctx) > + return -ENOMEM; > + test->priv = ctx; > + > + ctx->np = of_find_compatible_node(NULL, NULL, "test,clk-parent-data"); > + if (!ctx->np) > + return -ENODEV; > + > + return kunit_add_action_or_reset(test, (kunit_action_t *)&of_node_put, ctx->np); We should use an action wrapper here (KUNIT_DEFINE_ACTION_WRAPPER()), as casting function pointers to kunit_action_t* breaks control-flow integrity. > +} > + > +/* > + * Test that a clk registered with a struct device_node can find a parent based on > + * struct clk_parent_data when the hw member isn't set. > + */ > +static void clk_register_clk_parent_data_of_test(struct kunit *test) > +{ > + struct clk_register_clk_parent_data_of_ctx *ctx = test->priv; > + struct clk_hw *parent_hw; > + const struct clk_register_clk_parent_data_test_case *test_param; > + struct clk_init_data init = { }; > + struct clk *expected_parent, *actual_parent; > + > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->np); > + > + expected_parent = of_clk_get_kunit(test, ctx->np, 0); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, expected_parent); > + > + test_param = test->param_value; > + init.parent_data = &test_param->pdata; > + init.num_parents = 1; > + init.name = "parent_data_of_test_clk"; > + init.ops = &clk_dummy_single_parent_ops; > + ctx->hw.init = &init; > + KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, ctx->np, &ctx->hw)); > + > + parent_hw = clk_hw_get_parent(&ctx->hw); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent_hw); > + > + actual_parent = clk_hw_get_clk_kunit(test, parent_hw, __func__); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, actual_parent); > + > + KUNIT_EXPECT_TRUE(test, clk_is_match(expected_parent, actual_parent)); > +} > + > +static struct kunit_case clk_register_clk_parent_data_of_test_cases[] = { > + KUNIT_CASE_PARAM(clk_register_clk_parent_data_of_test, > + clk_register_clk_parent_data_of_test_gen_params), > + {} > +}; > + > +/* > + * Test suite for registering clks with struct clk_parent_data and a struct > + * device_node. > + */ > +static struct kunit_suite clk_register_clk_parent_data_of_suite = { > + .name = "clk_register_clk_parent_data_of", > + .init = clk_register_clk_parent_data_of_test_init, > + .test_cases = clk_register_clk_parent_data_of_test_cases, > +}; > + > +/** > + * struct clk_register_clk_parent_data_device_ctx - Context for clk_parent_data device tests > + * @dev: device of clk under test > + * @hw: clk_hw for clk under test > + * @pdrv: driver to attach to find @dev > + */ > +struct clk_register_clk_parent_data_device_ctx { > + struct device *dev; > + struct clk_hw hw; > + struct platform_driver pdrv; > +}; > + > +static inline struct clk_register_clk_parent_data_device_ctx * > +clk_register_clk_parent_data_driver_to_test_context(struct platform_device *pdev) > +{ > + return container_of(to_platform_driver(pdev->dev.driver), > + struct clk_register_clk_parent_data_device_ctx, pdrv); > +} > + > +static int clk_register_clk_parent_data_device_probe(struct platform_device *pdev) > +{ > + struct clk_register_clk_parent_data_device_ctx *ctx; > + > + ctx = clk_register_clk_parent_data_driver_to_test_context(pdev); > + ctx->dev = &pdev->dev; > + > + return 0; > +} > + > +static void clk_register_clk_parent_data_device_driver(struct kunit *test) > +{ > + struct clk_register_clk_parent_data_device_ctx *ctx = test->priv; > + static const struct of_device_id match_table[] = { > + { .compatible = "test,clk-parent-data" }, > + { } > + }; > + > + ctx->pdrv.probe = clk_register_clk_parent_data_device_probe; > + ctx->pdrv.driver.of_match_table = match_table; > + ctx->pdrv.driver.name = __func__; > + ctx->pdrv.driver.owner = THIS_MODULE; > + > + KUNIT_ASSERT_EQ(test, 0, kunit_platform_driver_register(test, &ctx->pdrv)); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx->dev); > +} > + > +static const struct clk_register_clk_parent_data_test_case > +clk_register_clk_parent_data_device_cases[] = { > + { > + /* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::index. > + */ > + .desc = "clk_parent_data_device_index_test", > + .pdata.index = 1, > + }, > + { > + /* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::fwname. > + */ > + .desc = "clk_parent_data_device_fwname_test", > + .pdata.fw_name = CLK_PARENT_DATA_PARENT2, > + }, > + { > + /* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::name. > + */ > + .desc = "clk_parent_data_device_name_test", > + /* The index must be negative to indicate firmware not used */ > + .pdata.index = -1, > + .pdata.name = CLK_PARENT_DATA_50MHZ_NAME, > + }, > + { > + /* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::{fw_name,name}. > + */ > + .desc = "clk_parent_data_device_fwname_name_test", > + .pdata.fw_name = CLK_PARENT_DATA_PARENT2, > + .pdata.name = "not_matching", > + }, > + { > + /* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::{index,name}. Index > + * takes priority. > + */ > + .desc = "clk_parent_data_device_index_name_priority_test", > + .pdata.index = 1, > + .pdata.name = "not_matching", > + }, > + { > + /* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::{index,fwname,name}. > + * The fw_name takes priority over index and name. > + */ > + .desc = "clk_parent_data_device_index_fwname_name_priority_test", > + .pdata.index = 0, > + .pdata.fw_name = CLK_PARENT_DATA_PARENT2, > + .pdata.name = "not_matching", > + }, > +}; > + > +KUNIT_ARRAY_PARAM(clk_register_clk_parent_data_device_test, > + clk_register_clk_parent_data_device_cases, > + clk_register_clk_parent_data_test_case_to_desc) > + > +/* > + * Test that a clk registered with a struct device can find a parent based on > + * struct clk_parent_data when the hw member isn't set. > + */ > +static void clk_register_clk_parent_data_device_test(struct kunit *test) > +{ > + struct clk_register_clk_parent_data_device_ctx *ctx; > + const struct clk_register_clk_parent_data_test_case *test_param; > + struct clk_hw *parent_hw; > + struct clk_init_data init = { }; > + struct clk *expected_parent, *actual_parent; > + > + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); > + test->priv = ctx; > + > + clk_register_clk_parent_data_device_driver(test); > + > + expected_parent = clk_get_kunit(test, ctx->dev, "50"); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, expected_parent); > + > + test_param = test->param_value; > + init.parent_data = &test_param->pdata; > + init.num_parents = 1; > + init.name = "parent_data_device_test_clk"; > + init.ops = &clk_dummy_single_parent_ops; > + ctx->hw.init = &init; > + KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, ctx->dev, &ctx->hw)); > + > + parent_hw = clk_hw_get_parent(&ctx->hw); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent_hw); > + > + actual_parent = clk_hw_get_clk_kunit(test, parent_hw, __func__); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, actual_parent); > + > + KUNIT_EXPECT_TRUE(test, clk_is_match(expected_parent, actual_parent)); > +} > + > +static const struct clk_register_clk_parent_data_test_case > +clk_register_clk_parent_data_device_hw_cases[] = { > + { > + /* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::hw. > + */ > + .desc = "clk_parent_data_device_hw_index_test", > + /* The index must be negative to indicate firmware not used */ > + .pdata.index = -1, > + }, > + { > + /* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::hw when > + * struct clk_parent_data::fw_name is set. > + */ > + .desc = "clk_parent_data_device_hw_fwname_test", > + .pdata.fw_name = CLK_PARENT_DATA_PARENT2, > + }, > + { > + /* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::hw when struct > + * clk_parent_data::name is set. > + */ > + .desc = "clk_parent_data_device_hw_name_test", > + /* The index must be negative to indicate firmware not used */ > + .pdata.index = -1, > + .pdata.name = CLK_PARENT_DATA_50MHZ_NAME, > + }, > + { > + /* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::hw when struct > + * clk_parent_data::{fw_name,name} are set. > + */ > + .desc = "clk_parent_data_device_hw_fwname_name_test", > + .pdata.fw_name = CLK_PARENT_DATA_PARENT2, > + .pdata.name = "not_matching", > + }, > + { > + /* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::hw when struct > + * clk_parent_data::index is set. The hw pointer takes > + * priority. > + */ > + .desc = "clk_parent_data_device_hw_index_priority_test", > + .pdata.index = 0, > + }, > + { > + /* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::hw when > + * struct clk_parent_data::{index,fwname,name} are set. > + * The hw pointer takes priority over everything else. > + */ > + .desc = "clk_parent_data_device_hw_index_fwname_name_priority_test", > + .pdata.index = 0, > + .pdata.fw_name = CLK_PARENT_DATA_PARENT2, > + .pdata.name = "not_matching", > + }, > +}; > + > +KUNIT_ARRAY_PARAM(clk_register_clk_parent_data_device_hw_test, > + clk_register_clk_parent_data_device_hw_cases, > + clk_register_clk_parent_data_test_case_to_desc) > + > +/* > + * Test that a clk registered with a struct device can find a > + * parent based on struct clk_parent_data::hw. > + */ > +static void clk_register_clk_parent_data_device_hw_test(struct kunit *test) > +{ > + struct clk_register_clk_parent_data_device_ctx *ctx; > + const struct clk_register_clk_parent_data_test_case *test_param; > + struct clk_dummy_context *parent; > + struct clk_hw *parent_hw; > + struct clk_parent_data pdata = { }; > + struct clk_init_data init = { }; > + > + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, ctx); > + test->priv = ctx; > + > + clk_register_clk_parent_data_device_driver(test); > + > + parent = kunit_kzalloc(test, sizeof(*parent), GFP_KERNEL); > + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent); > + > + parent_hw = &parent->hw; > + parent_hw->init = CLK_HW_INIT_NO_PARENT("parenlookst-clk", > + &clk_dummy_rate_ops, 0); > + > + KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, ctx->dev, parent_hw)); > + > + test_param = test->param_value; > + memcpy(&pdata, &test_param->pdata, sizeof(pdata)); > + pdata.hw = parent_hw; > + init.parent_data = &pdata; > + init.num_parents = 1; > + init.ops = &clk_dummy_single_parent_ops; > + init.name = "parent_data_device_hw_test_clk"; > + ctx->hw.init = &init; > + KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, ctx->dev, &ctx->hw)); > + > + KUNIT_EXPECT_PTR_EQ(test, parent_hw, clk_hw_get_parent(&ctx->hw)); > +} > + > +static struct kunit_case clk_register_clk_parent_data_device_test_cases[] = { > + KUNIT_CASE_PARAM(clk_register_clk_parent_data_device_test, > + clk_register_clk_parent_data_device_test_gen_params), > + KUNIT_CASE_PARAM(clk_register_clk_parent_data_device_hw_test, > + clk_register_clk_parent_data_device_hw_test_gen_params), > + {} > +}; > + > +static int clk_register_clk_parent_data_device_init(struct kunit *test) > +{ > + KUNIT_ASSERT_EQ(test, 0, > + of_overlay_apply_kunit(test, kunit_clk_parent_data_test)); > + > + return 0; > +} > + > +/* > + * Test suite for registering clks with struct clk_parent_data and a struct > + * device. > + */ > +static struct kunit_suite clk_register_clk_parent_data_device_suite = { > + .name = "clk_register_clk_parent_data_device", > + .init = clk_register_clk_parent_data_device_init, > + .test_cases = clk_register_clk_parent_data_device_test_cases, > +}; > + > kunit_test_suites( > &clk_leaf_mux_set_rate_parent_test_suite, > &clk_test_suite, > @@ -2671,7 +3118,9 @@ kunit_test_suites( > &clk_range_test_suite, > &clk_range_maximize_test_suite, > &clk_range_minimize_test_suite, > + &clk_register_clk_parent_data_of_suite, > + &clk_register_clk_parent_data_device_suite, > &clk_single_parent_mux_test_suite, > - &clk_uncached_test_suite > + &clk_uncached_test_suite, > ); > MODULE_LICENSE("GPL v2"); > diff --git a/drivers/clk/kunit_clk_parent_data_test.dtso b/drivers/clk/kunit_clk_parent_data_test.dtso > new file mode 100644 > index 000000000000..7d3ed9a5a2e8 > --- /dev/null > +++ b/drivers/clk/kunit_clk_parent_data_test.dtso > @@ -0,0 +1,28 @@ > +// SPDX-License-Identifier: GPL-2.0 > +/dts-v1/; > +/plugin/; > + > +#include "clk_parent_data_test.h" > + > +&{/} { > + fixed_50: kunit-clock-50MHz { > + compatible = "fixed-clock"; > + #clock-cells = <0>; > + clock-frequency = <50000000>; > + clock-output-names = CLK_PARENT_DATA_50MHZ_NAME; > + }; > + > + fixed_parent: kunit-clock-1MHz { > + compatible = "fixed-clock"; > + #clock-cells = <0>; > + clock-frequency = <1000000>; > + clock-output-names = CLK_PARENT_DATA_1MHZ_NAME; > + }; > + > + kunit-clock-controller { > + compatible = "test,clk-parent-data"; > + clocks = <&fixed_parent>, <&fixed_50>; > + clock-names = CLK_PARENT_DATA_PARENT1, CLK_PARENT_DATA_PARENT2; > + #clock-cells = <1>; > + }; > +}; > -- > https://git.kernel.org/pub/scm/linux/kernel/git/clk/linux.git/ > https://git.kernel.org/pub/scm/linux/kernel/git/sboyd/spmi.git > --000000000000bffdcb061ac0d570 Content-Type: application/pkcs7-signature; name="smime.p7s" Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="smime.p7s" Content-Description: S/MIME Cryptographic Signature MIIPqgYJKoZIhvcNAQcCoIIPmzCCD5cCAQExDzANBglghkgBZQMEAgEFADALBgkqhkiG9w0BBwGg gg0EMIIEtjCCA56gAwIBAgIQeAMYYHb81ngUVR0WyMTzqzANBgkqhkiG9w0BAQsFADBMMSAwHgYD VQQLExdHbG9iYWxTaWduIFJvb3QgQ0EgLSBSMzETMBEGA1UEChMKR2xvYmFsU2lnbjETMBEGA1UE AxMKR2xvYmFs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