clk: tests: Add missing test case for ranges
authorMaxime Ripard <maxime@cerno.tech>
Tue, 16 Aug 2022 11:25:30 +0000 (13:25 +0200)
committerStephen Boyd <sboyd@kernel.org>
Thu, 15 Sep 2022 16:32:34 +0000 (09:32 -0700)
Let's add a test on the rate range after a reparenting. This fails for
now, but it's worth having it to document the corner cases we don't
support yet.

Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Link: https://lore.kernel.org/r/20220816112530.1837489-26-maxime@cerno.tech
Tested-by: Naresh Kamboju <naresh.kamboju@linaro.org>
Tested-by: Linux Kernel Functional Testing <lkft@linaro.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/clk_test.c

index 3004ef3..509256c 100644 (file)
@@ -514,9 +514,62 @@ clk_test_multiple_parents_mux_has_parent(struct kunit *test)
        clk_put(clk);
 }
 
+/*
+ * Test that for a clock with a multiple parents, if we set a range on
+ * that clock and the parent is changed, its rate after the reparenting
+ * is still within the range we asked for.
+ *
+ * FIXME: clk_set_parent() only does the reparenting but doesn't
+ * reevaluate whether the new clock rate is within its boundaries or
+ * not.
+ */
+static void
+clk_test_multiple_parents_mux_set_range_set_parent_get_rate(struct kunit *test)
+{
+       struct clk_multiple_parent_ctx *ctx = test->priv;
+       struct clk_hw *hw = &ctx->hw;
+       struct clk *clk = clk_hw_get_clk(hw, NULL);
+       struct clk *parent1, *parent2;
+       unsigned long rate;
+       int ret;
+
+       kunit_skip(test, "This needs to be fixed in the core.");
+
+       parent1 = clk_hw_get_clk(&ctx->parents_ctx[0].hw, NULL);
+       KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent1);
+       KUNIT_ASSERT_TRUE(test, clk_is_match(clk_get_parent(clk), parent1));
+
+       parent2 = clk_hw_get_clk(&ctx->parents_ctx[1].hw, NULL);
+       KUNIT_ASSERT_NOT_ERR_OR_NULL(test, parent2);
+
+       ret = clk_set_rate(parent1, DUMMY_CLOCK_RATE_1);
+       KUNIT_ASSERT_EQ(test, ret, 0);
+
+       ret = clk_set_rate(parent2, DUMMY_CLOCK_RATE_2);
+       KUNIT_ASSERT_EQ(test, ret, 0);
+
+       ret = clk_set_rate_range(clk,
+                                DUMMY_CLOCK_RATE_1 - 1000,
+                                DUMMY_CLOCK_RATE_1 + 1000);
+       KUNIT_ASSERT_EQ(test, ret, 0);
+
+       ret = clk_set_parent(clk, parent2);
+       KUNIT_ASSERT_EQ(test, ret, 0);
+
+       rate = clk_get_rate(clk);
+       KUNIT_ASSERT_GT(test, rate, 0);
+       KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1 - 1000);
+       KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_1 + 1000);
+
+       clk_put(parent2);
+       clk_put(parent1);
+       clk_put(clk);
+}
+
 static struct kunit_case clk_multiple_parents_mux_test_cases[] = {
        KUNIT_CASE(clk_test_multiple_parents_mux_get_parent),
        KUNIT_CASE(clk_test_multiple_parents_mux_has_parent),
+       KUNIT_CASE(clk_test_multiple_parents_mux_set_range_set_parent_get_rate),
        {}
 };