clk: Parameterize clk_leaf_mux_set_rate_parent
authorStephen Boyd <sboyd@kernel.org>
Tue, 12 Sep 2023 17:55:31 +0000 (10:55 -0700)
committerStephen Boyd <sboyd@kernel.org>
Tue, 10 Oct 2023 03:08:25 +0000 (20:08 -0700)
Transform the existing clk_leaf_mux_set_rate_parent test into a
parameterized test that calls the various determine rate APIs that exist
for clk providers. This ensures that whatever determine rate API is used
by a clk provider will return the correct parent in the best_parent_hw
pointer of the clk_rate_request because clk_rate_requests are forwarded
properly.

Cc: Guenter Roeck <linux@roeck-us.net>
Cc: Maxime Ripard <mripard@kernel.org>
Link: https://lore.kernel.org/r/20230912175534.2427862-3-sboyd@kernel.org
Acked-by: Maxime Ripard <mripard@kernel.org>
Signed-off-by: Stephen Boyd <sboyd@kernel.org>
drivers/clk/clk_test.c

index 43e85fc0b025979be676f4e1dc396cbd611b478b..39e2b5ff4f5144addbc675e35b499a3a2822832e 100644 (file)
@@ -2159,6 +2159,7 @@ struct clk_leaf_mux_ctx {
        struct clk_hw hw;
        struct clk_hw parent;
        struct clk_rate_request *req;
+       int (*determine_rate_func)(struct clk_hw *hw, struct clk_rate_request *req);
 };
 
 static int clk_leaf_mux_determine_rate(struct clk_hw *hw, struct clk_rate_request *req)
@@ -2168,7 +2169,7 @@ static int clk_leaf_mux_determine_rate(struct clk_hw *hw, struct clk_rate_reques
        struct clk_rate_request *parent_req = ctx->req;
 
        clk_hw_forward_rate_request(hw, req, req->best_parent_hw, parent_req, req->rate);
-       ret = __clk_determine_rate(req->best_parent_hw, parent_req);
+       ret = ctx->determine_rate_func(req->best_parent_hw, parent_req);
        if (ret)
                return ret;
 
@@ -2246,20 +2247,83 @@ static void clk_leaf_mux_set_rate_parent_test_exit(struct kunit *test)
        clk_hw_unregister(&ctx->mux_ctx.parents_ctx[1].hw);
 }
 
+struct clk_leaf_mux_set_rate_parent_determine_rate_test_case {
+       const char *desc;
+       int (*determine_rate_func)(struct clk_hw *hw, struct clk_rate_request *req);
+};
+
+static void
+clk_leaf_mux_set_rate_parent_determine_rate_test_case_to_desc(
+               const struct clk_leaf_mux_set_rate_parent_determine_rate_test_case *t, char *desc)
+{
+       strcpy(desc, t->desc);
+}
+
+static const struct clk_leaf_mux_set_rate_parent_determine_rate_test_case
+clk_leaf_mux_set_rate_parent_determine_rate_test_cases[] = {
+       {
+               /*
+                * Test that __clk_determine_rate() on the parent that can't
+                * change rate doesn't return a clk_rate_request structure with
+                * the best_parent_hw pointer pointing to the parent.
+                */
+               .desc = "clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent",
+               .determine_rate_func = __clk_determine_rate,
+       },
+       {
+               /*
+                * Test that __clk_mux_determine_rate() on the parent that
+                * can't change rate doesn't return a clk_rate_request
+                * structure with the best_parent_hw pointer pointing to
+                * the parent.
+                */
+               .desc = "clk_leaf_mux_set_rate_parent__clk_mux_determine_rate_proper_parent",
+               .determine_rate_func = __clk_mux_determine_rate,
+       },
+       {
+               /*
+                * Test that __clk_mux_determine_rate_closest() on the parent
+                * that can't change rate doesn't return a clk_rate_request
+                * structure with the best_parent_hw pointer pointing to
+                * the parent.
+                */
+               .desc = "clk_leaf_mux_set_rate_parent__clk_mux_determine_rate_closest_proper_parent",
+               .determine_rate_func = __clk_mux_determine_rate_closest,
+       },
+       {
+               /*
+                * Test that clk_hw_determine_rate_no_reparent() on the parent
+                * that can't change rate doesn't return a clk_rate_request
+                * structure with the best_parent_hw pointer pointing to
+                * the parent.
+                */
+               .desc = "clk_leaf_mux_set_rate_parent_clk_hw_determine_rate_no_reparent_proper_parent",
+               .determine_rate_func = clk_hw_determine_rate_no_reparent,
+       },
+};
+
+KUNIT_ARRAY_PARAM(clk_leaf_mux_set_rate_parent_determine_rate_test,
+                 clk_leaf_mux_set_rate_parent_determine_rate_test_cases,
+                 clk_leaf_mux_set_rate_parent_determine_rate_test_case_to_desc)
+
 /*
- * Test that, for a clock that will forward any rate request to its parent, the
- * rate request structure returned by __clk_determine_rate() is sane and
- * doesn't have the clk_rate_request's best_parent_hw pointer point to the
- * clk_hw passed into __clk_determine_rate(). See commit 262ca38f4b6e ("clk:
- * Stop forwarding clk_rate_requests to the parent") for more background.
+ * Test that when a clk that can't change rate itself calls a function like
+ * __clk_determine_rate() on its parent it doesn't get back a clk_rate_request
+ * structure that has the best_parent_hw pointer point to the clk_hw passed
+ * into the determine rate function. See commit 262ca38f4b6e ("clk: Stop
+ * forwarding clk_rate_requests to the parent") for more background.
  */
-static void clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent(struct kunit *test)
+static void clk_leaf_mux_set_rate_parent_determine_rate_test(struct kunit *test)
 {
        struct clk_leaf_mux_ctx *ctx = test->priv;
        struct clk_hw *hw = &ctx->hw;
        struct clk *clk = clk_hw_get_clk(hw, NULL);
        struct clk_rate_request req;
        unsigned long rate;
+       const struct clk_leaf_mux_set_rate_parent_determine_rate_test_case *test_param;
+
+       test_param = test->param_value;
+       ctx->determine_rate_func = test_param->determine_rate_func;
 
        ctx->req = &req;
        rate = clk_get_rate(clk);
@@ -2274,7 +2338,8 @@ static void clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent(struc
 }
 
 static struct kunit_case clk_leaf_mux_set_rate_parent_test_cases[] = {
-       KUNIT_CASE(clk_leaf_mux_set_rate_parent__clk_determine_rate_proper_parent),
+       KUNIT_CASE_PARAM(clk_leaf_mux_set_rate_parent_determine_rate_test,
+                        clk_leaf_mux_set_rate_parent_determine_rate_test_gen_params),
        {}
 };