Skip to content

Commit ac32d03

Browse files
jbrun3tbebarino
authored andcommitted
clk: tests: add clk_hw_get_dev() and clk_hw_get_of_node() tests
Add kunit test suites clk_hw_get_dev() and clk_hw_get_of_node() for clocks registered with clk_hw_register() and of_clk_hw_register() Signed-off-by: Jerome Brunet <[email protected]> Link: https://lore.kernel.org/r/[email protected] Reviewed-by: Brian Masney <[email protected]> [[email protected]: Drop genparams, rename tests, drop inits, combine suites, add test for non-DT platform device] Signed-off-by: Stephen Boyd <[email protected]>
1 parent b06ba1c commit ac32d03

File tree

3 files changed

+151
-0
lines changed

3 files changed

+151
-0
lines changed

drivers/clk/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ clk-test-y := clk_test.o \
1818
kunit_clk_assigned_rates_without_consumer.dtbo.o \
1919
kunit_clk_assigned_rates_zero.dtbo.o \
2020
kunit_clk_assigned_rates_zero_consumer.dtbo.o \
21+
kunit_clk_hw_get_dev_of_node.dtbo.o \
2122
kunit_clk_parent_data_test.dtbo.o
2223
obj-$(CONFIG_COMMON_CLK) += clk-divider.o
2324
obj-$(CONFIG_COMMON_CLK) += clk-fixed-factor.o

drivers/clk/clk_test.c

Lines changed: 140 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3403,8 +3403,148 @@ static struct kunit_suite clk_assigned_rates_suite = {
34033403
.init = clk_assigned_rates_test_init,
34043404
};
34053405

3406+
static const struct clk_init_data clk_hw_get_dev_of_node_init_data = {
3407+
.name = "clk_hw_get_dev_of_node",
3408+
.ops = &empty_clk_ops,
3409+
};
3410+
3411+
/*
3412+
* Test that a clk registered with a struct device returns the device from
3413+
* clk_hw_get_dev() and the node from clk_hw_get_of_node()
3414+
*/
3415+
static void clk_hw_register_dev_get_dev_returns_dev(struct kunit *test)
3416+
{
3417+
struct device *dev;
3418+
struct clk_hw *hw;
3419+
static const struct of_device_id match_table[] = {
3420+
{ .compatible = "test,clk-hw-get-dev-of-node" },
3421+
{ }
3422+
};
3423+
3424+
KUNIT_ASSERT_EQ(test, 0, of_overlay_apply_kunit(test, kunit_clk_hw_get_dev_of_node));
3425+
3426+
dev = kunit_of_platform_driver_dev(test, match_table);
3427+
3428+
hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL);
3429+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
3430+
3431+
hw->init = &clk_hw_get_dev_of_node_init_data;
3432+
KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, dev, hw));
3433+
3434+
KUNIT_EXPECT_PTR_EQ(test, dev, clk_hw_get_dev(hw));
3435+
KUNIT_EXPECT_PTR_EQ(test, dev_of_node(dev), clk_hw_get_of_node(hw));
3436+
}
3437+
3438+
/*
3439+
* Test that a clk registered with a struct device that's not associated with
3440+
* an OF node returns the device from clk_hw_get_dev() and NULL from
3441+
* clk_hw_get_of_node()
3442+
*/
3443+
static void clk_hw_register_dev_no_node_get_dev_returns_dev(struct kunit *test)
3444+
{
3445+
struct platform_device *pdev;
3446+
struct device *dev;
3447+
struct clk_hw *hw;
3448+
3449+
pdev = kunit_platform_device_alloc(test, "clk_hw_register_dev_no_node", -1);
3450+
KUNIT_ASSERT_NOT_NULL(test, pdev);
3451+
KUNIT_ASSERT_EQ(test, 0, kunit_platform_device_add(test, pdev));
3452+
dev = &pdev->dev;
3453+
3454+
hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL);
3455+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
3456+
3457+
hw->init = &clk_hw_get_dev_of_node_init_data;
3458+
KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, dev, hw));
3459+
3460+
KUNIT_EXPECT_PTR_EQ(test, dev, clk_hw_get_dev(hw));
3461+
KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_of_node(hw));
3462+
}
3463+
3464+
/*
3465+
* Test that a clk registered without a struct device returns NULL from
3466+
* clk_hw_get_dev()
3467+
*/
3468+
static void clk_hw_register_NULL_get_dev_of_node_returns_NULL(struct kunit *test)
3469+
{
3470+
struct clk_hw *hw;
3471+
3472+
hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL);
3473+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
3474+
3475+
hw->init = &clk_hw_get_dev_of_node_init_data;
3476+
3477+
KUNIT_ASSERT_EQ(test, 0, clk_hw_register_kunit(test, NULL, hw));
3478+
3479+
KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_dev(hw));
3480+
KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_of_node(hw));
3481+
}
3482+
3483+
/*
3484+
* Test that a clk registered with an of_node returns the node from
3485+
* clk_hw_get_of_node() and NULL from clk_hw_get_dev()
3486+
*/
3487+
static void of_clk_hw_register_node_get_of_node_returns_node(struct kunit *test)
3488+
{
3489+
struct device_node *np;
3490+
struct clk_hw *hw;
3491+
3492+
hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL);
3493+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
3494+
3495+
KUNIT_ASSERT_EQ(test, 0, of_overlay_apply_kunit(test, kunit_clk_hw_get_dev_of_node));
3496+
3497+
np = of_find_compatible_node(NULL, NULL, "test,clk-hw-get-dev-of-node");
3498+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, np);
3499+
of_node_put_kunit(test, np);
3500+
3501+
hw->init = &clk_hw_get_dev_of_node_init_data;
3502+
KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, np, hw));
3503+
3504+
KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_dev(hw));
3505+
KUNIT_EXPECT_PTR_EQ(test, np, clk_hw_get_of_node(hw));
3506+
}
3507+
3508+
/*
3509+
* Test that a clk registered without an of_node returns the node from
3510+
* clk_hw_get_of_node() and clk_hw_get_dev()
3511+
*/
3512+
static void of_clk_hw_register_NULL_get_of_node_returns_NULL(struct kunit *test)
3513+
{
3514+
struct clk_hw *hw;
3515+
3516+
hw = kunit_kzalloc(test, sizeof(*hw), GFP_KERNEL);
3517+
KUNIT_ASSERT_NOT_ERR_OR_NULL(test, hw);
3518+
3519+
hw->init = &clk_hw_get_dev_of_node_init_data;
3520+
KUNIT_ASSERT_EQ(test, 0, of_clk_hw_register_kunit(test, NULL, hw));
3521+
3522+
KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_dev(hw));
3523+
KUNIT_EXPECT_PTR_EQ(test, NULL, clk_hw_get_of_node(hw));
3524+
}
3525+
3526+
static struct kunit_case clk_hw_get_dev_of_node_test_cases[] = {
3527+
KUNIT_CASE(clk_hw_register_dev_get_dev_returns_dev),
3528+
KUNIT_CASE(clk_hw_register_dev_no_node_get_dev_returns_dev),
3529+
KUNIT_CASE(clk_hw_register_NULL_get_dev_of_node_returns_NULL),
3530+
KUNIT_CASE(of_clk_hw_register_node_get_of_node_returns_node),
3531+
KUNIT_CASE(of_clk_hw_register_NULL_get_of_node_returns_NULL),
3532+
{}
3533+
};
3534+
3535+
/*
3536+
* Test suite to verify clk_hw_get_dev() and clk_hw_get_of_node() when clk
3537+
* registered with clk_hw_register() and of_clk_hw_register()
3538+
*/
3539+
static struct kunit_suite clk_hw_get_dev_of_node_test_suite = {
3540+
.name = "clk_hw_get_dev_of_node_test_suite",
3541+
.test_cases = clk_hw_get_dev_of_node_test_cases,
3542+
};
3543+
3544+
34063545
kunit_test_suites(
34073546
&clk_assigned_rates_suite,
3547+
&clk_hw_get_dev_of_node_test_suite,
34083548
&clk_leaf_mux_set_rate_parent_test_suite,
34093549
&clk_test_suite,
34103550
&clk_multiple_parents_mux_test_suite,
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/dts-v1/;
3+
/plugin/;
4+
5+
&{/} {
6+
kunit-clock-controller {
7+
compatible = "test,clk-hw-get-dev-of-node";
8+
#clock-cells = <0>;
9+
};
10+
};

0 commit comments

Comments
 (0)