1 From d75b267a431f5afd20cfea90021bb63cc8ecfc6b Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Fri, 15 Apr 2022 15:00:44 +0200
4 Subject: [PATCH] clk: tests: Add missing test case for ranges
6 Let's add a test on the rate range after a reparenting. This fails for
7 now, but it's worth having it to document the corner cases we don't
10 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
12 drivers/clk/clk_test.c | 52 ++++++++++++++++++++++++++++++++++++++++++
13 1 file changed, 52 insertions(+)
15 --- a/drivers/clk/clk_test.c
16 +++ b/drivers/clk/clk_test.c
17 @@ -488,9 +488,61 @@ clk_test_multiple_parents_mux_has_parent
18 KUNIT_EXPECT_TRUE(test, clk_has_parent(clk, ctx->parents_ctx[1].hw.clk));
22 + * Test that for a clock with a multiple parents, if we set a range on
23 + * that clock and the parent is changed, its rate after the reparenting
24 + * is still within the range we asked for.
26 + * FIXME: clk_set_parent() only does the reparenting but doesn't
27 + * reevaluate whether the new clock rate is within its boundaries or
31 +clk_test_multiple_parents_mux_set_range_set_parent_get_rate(struct kunit *test)
33 + struct clk_multiple_parent_ctx *ctx = test->priv;
34 + struct clk_hw *hw = &ctx->hw;
35 + struct clk *clk = hw->clk;
36 + struct clk *parent1, *parent2;
40 + kunit_skip(test, "This needs to be fixed in the core.");
42 + parent1 = clk_hw_get_clk(&ctx->parents_ctx[0].hw, NULL);
43 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent1);
44 + KUNIT_ASSERT_TRUE(test, clk_is_match(clk_get_parent(clk), parent1));
46 + parent2 = clk_hw_get_clk(&ctx->parents_ctx[1].hw, NULL);
47 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent2);
49 + ret = clk_set_rate(parent1, DUMMY_CLOCK_RATE_1);
50 + KUNIT_ASSERT_EQ(test, ret, 0);
52 + ret = clk_set_rate(parent2, DUMMY_CLOCK_RATE_2);
53 + KUNIT_ASSERT_EQ(test, ret, 0);
55 + ret = clk_set_rate_range(clk,
56 + DUMMY_CLOCK_RATE_1 - 1000,
57 + DUMMY_CLOCK_RATE_1 + 1000);
58 + KUNIT_ASSERT_EQ(test, ret, 0);
60 + ret = clk_set_parent(clk, parent2);
61 + KUNIT_ASSERT_EQ(test, ret, 0);
63 + rate = clk_get_rate(clk);
64 + KUNIT_ASSERT_GT(test, rate, 0);
65 + KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1 - 1000);
66 + KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_1 + 1000);
72 static struct kunit_case clk_multiple_parents_mux_test_cases[] = {
73 KUNIT_CASE(clk_test_multiple_parents_mux_get_parent),
74 KUNIT_CASE(clk_test_multiple_parents_mux_has_parent),
75 + KUNIT_CASE(clk_test_multiple_parents_mux_set_range_set_parent_get_rate),