1 From 93028ab89e186100ef28ba6d6adcc30f14fa3dc3 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Wed, 19 Jan 2022 16:22:19 +0100
4 Subject: [PATCH] clk: Introduce Kunit Tests for the framework
6 Let's test various parts of the rate-related clock API with the kunit
9 Cc: kunit-dev@googlegroups.com
10 Tested-by: Daniel Latypov <dlatypov@google.com>
11 Suggested-by: Stephen Boyd <sboyd@kernel.org>
12 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
14 drivers/clk/.kunitconfig | 3 +
15 drivers/clk/Kconfig | 8 +
16 drivers/clk/Makefile | 1 +
17 drivers/clk/clk_test.c | 787 +++++++++++++++++++++++++++++++++++++++
18 4 files changed, 799 insertions(+)
19 create mode 100644 drivers/clk/.kunitconfig
20 create mode 100644 drivers/clk/clk_test.c
23 +++ b/drivers/clk/.kunitconfig
27 +CONFIG_CLK_KUNIT_TEST=y
28 --- a/drivers/clk/Kconfig
29 +++ b/drivers/clk/Kconfig
30 @@ -427,4 +427,12 @@ source "drivers/clk/x86/Kconfig"
31 source "drivers/clk/xilinx/Kconfig"
32 source "drivers/clk/zynqmp/Kconfig"
35 +config CLK_KUNIT_TEST
36 + tristate "Basic Clock Framework Kunit Tests" if !KUNIT_ALL_TESTS
38 + default KUNIT_ALL_TESTS
40 + Kunit tests for the common clock framework.
43 --- a/drivers/clk/Makefile
44 +++ b/drivers/clk/Makefile
47 obj-$(CONFIG_HAVE_CLK) += clk-devres.o clk-bulk.o clkdev.o
48 obj-$(CONFIG_COMMON_CLK) += clk.o
49 +obj-$(CONFIG_CLK_KUNIT_TEST) += clk_test.o
50 obj-$(CONFIG_COMMON_CLK) += clk-divider.o
51 obj-$(CONFIG_COMMON_CLK) += clk-fixed-factor.o
52 obj-$(CONFIG_COMMON_CLK) += clk-fixed-rate.o
54 +++ b/drivers/clk/clk_test.c
56 +// SPDX-License-Identifier: GPL-2.0
58 + * Kunit test for clk rate management
60 +#include <linux/clk.h>
61 +#include <linux/clk-provider.h>
63 +/* Needed for clk_hw_get_clk() */
66 +#include <kunit/test.h>
68 +#define DUMMY_CLOCK_INIT_RATE (42 * 1000 * 1000)
69 +#define DUMMY_CLOCK_RATE_1 (142 * 1000 * 1000)
70 +#define DUMMY_CLOCK_RATE_2 (242 * 1000 * 1000)
72 +struct clk_dummy_context {
77 +static unsigned long clk_dummy_recalc_rate(struct clk_hw *hw,
78 + unsigned long parent_rate)
80 + struct clk_dummy_context *ctx =
81 + container_of(hw, struct clk_dummy_context, hw);
86 +static int clk_dummy_determine_rate(struct clk_hw *hw,
87 + struct clk_rate_request *req)
89 + /* Just return the same rate without modifying it */
93 +static int clk_dummy_maximize_rate(struct clk_hw *hw,
94 + struct clk_rate_request *req)
97 + * If there's a maximum set, always run the clock at the maximum
100 + if (req->max_rate < ULONG_MAX)
101 + req->rate = req->max_rate;
106 +static int clk_dummy_minimize_rate(struct clk_hw *hw,
107 + struct clk_rate_request *req)
110 + * If there's a minimum set, always run the clock at the minimum
113 + if (req->min_rate > 0)
114 + req->rate = req->min_rate;
119 +static int clk_dummy_set_rate(struct clk_hw *hw,
120 + unsigned long rate,
121 + unsigned long parent_rate)
123 + struct clk_dummy_context *ctx =
124 + container_of(hw, struct clk_dummy_context, hw);
130 +static const struct clk_ops clk_dummy_rate_ops = {
131 + .recalc_rate = clk_dummy_recalc_rate,
132 + .determine_rate = clk_dummy_determine_rate,
133 + .set_rate = clk_dummy_set_rate,
136 +static const struct clk_ops clk_dummy_maximize_rate_ops = {
137 + .recalc_rate = clk_dummy_recalc_rate,
138 + .determine_rate = clk_dummy_maximize_rate,
139 + .set_rate = clk_dummy_set_rate,
142 +static const struct clk_ops clk_dummy_minimize_rate_ops = {
143 + .recalc_rate = clk_dummy_recalc_rate,
144 + .determine_rate = clk_dummy_minimize_rate,
145 + .set_rate = clk_dummy_set_rate,
148 +static int clk_test_init_with_ops(struct kunit *test, const struct clk_ops *ops)
150 + struct clk_dummy_context *ctx;
151 + struct clk_init_data init = { };
154 + ctx = kunit_kzalloc(test, sizeof(*ctx), GFP_KERNEL);
157 + ctx->rate = DUMMY_CLOCK_INIT_RATE;
160 + init.name = "test_dummy_rate";
162 + ctx->hw.init = &init;
164 + ret = clk_hw_register(NULL, &ctx->hw);
171 +static int clk_test_init(struct kunit *test)
173 + return clk_test_init_with_ops(test, &clk_dummy_rate_ops);
176 +static int clk_maximize_test_init(struct kunit *test)
178 + return clk_test_init_with_ops(test, &clk_dummy_maximize_rate_ops);
181 +static int clk_minimize_test_init(struct kunit *test)
183 + return clk_test_init_with_ops(test, &clk_dummy_minimize_rate_ops);
186 +static void clk_test_exit(struct kunit *test)
188 + struct clk_dummy_context *ctx = test->priv;
190 + clk_hw_unregister(&ctx->hw);
194 + * Test that the actual rate matches what is returned by clk_get_rate()
196 +static void clk_test_get_rate(struct kunit *test)
198 + struct clk_dummy_context *ctx = test->priv;
199 + struct clk_hw *hw = &ctx->hw;
200 + struct clk *clk = hw->clk;
201 + unsigned long rate;
203 + rate = clk_get_rate(clk);
204 + KUNIT_ASSERT_GT(test, rate, 0);
205 + KUNIT_EXPECT_EQ(test, rate, ctx->rate);
209 + * Test that, after a call to clk_set_rate(), the rate returned by
210 + * clk_get_rate() matches.
212 + * This assumes that clk_ops.determine_rate or clk_ops.round_rate won't
213 + * modify the requested rate, which is our case in clk_dummy_rate_ops.
215 +static void clk_test_set_get_rate(struct kunit *test)
217 + struct clk_dummy_context *ctx = test->priv;
218 + struct clk_hw *hw = &ctx->hw;
219 + struct clk *clk = hw->clk;
220 + unsigned long rate;
222 + KUNIT_ASSERT_EQ(test,
223 + clk_set_rate(clk, DUMMY_CLOCK_RATE_1),
226 + rate = clk_get_rate(clk);
227 + KUNIT_ASSERT_GT(test, rate, 0);
228 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1);
232 + * Test that, after several calls to clk_set_rate(), the rate returned
233 + * by clk_get_rate() matches the last one.
235 + * This assumes that clk_ops.determine_rate or clk_ops.round_rate won't
236 + * modify the requested rate, which is our case in clk_dummy_rate_ops.
238 +static void clk_test_set_set_get_rate(struct kunit *test)
240 + struct clk_dummy_context *ctx = test->priv;
241 + struct clk_hw *hw = &ctx->hw;
242 + struct clk *clk = hw->clk;
243 + unsigned long rate;
245 + KUNIT_ASSERT_EQ(test,
246 + clk_set_rate(clk, DUMMY_CLOCK_RATE_1),
249 + KUNIT_ASSERT_EQ(test,
250 + clk_set_rate(clk, DUMMY_CLOCK_RATE_2),
253 + rate = clk_get_rate(clk);
254 + KUNIT_ASSERT_GT(test, rate, 0);
255 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2);
259 + * Test that clk_round_rate and clk_set_rate are consitent and will
260 + * return the same frequency.
262 +static void clk_test_round_set_get_rate(struct kunit *test)
264 + struct clk_dummy_context *ctx = test->priv;
265 + struct clk_hw *hw = &ctx->hw;
266 + struct clk *clk = hw->clk;
267 + unsigned long rounded_rate, set_rate;
269 + rounded_rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_1);
270 + KUNIT_ASSERT_GT(test, rounded_rate, 0);
271 + KUNIT_EXPECT_EQ(test, rounded_rate, DUMMY_CLOCK_RATE_1);
273 + KUNIT_ASSERT_EQ(test,
274 + clk_set_rate(clk, DUMMY_CLOCK_RATE_1),
277 + set_rate = clk_get_rate(clk);
278 + KUNIT_ASSERT_GT(test, set_rate, 0);
279 + KUNIT_EXPECT_EQ(test, rounded_rate, set_rate);
282 +static struct kunit_case clk_test_cases[] = {
283 + KUNIT_CASE(clk_test_get_rate),
284 + KUNIT_CASE(clk_test_set_get_rate),
285 + KUNIT_CASE(clk_test_set_set_get_rate),
286 + KUNIT_CASE(clk_test_round_set_get_rate),
290 +static struct kunit_suite clk_test_suite = {
291 + .name = "clk-test",
292 + .init = clk_test_init,
293 + .exit = clk_test_exit,
294 + .test_cases = clk_test_cases,
298 + * Test that clk_set_rate_range won't return an error for a valid range
299 + * and that it will make sure the rate of the clock is within the
302 +static void clk_range_test_set_range(struct kunit *test)
304 + struct clk_dummy_context *ctx = test->priv;
305 + struct clk_hw *hw = &ctx->hw;
306 + struct clk *clk = hw->clk;
307 + unsigned long rate;
309 + KUNIT_ASSERT_EQ(test,
310 + clk_set_rate_range(clk,
311 + DUMMY_CLOCK_RATE_1,
312 + DUMMY_CLOCK_RATE_2),
315 + rate = clk_get_rate(clk);
316 + KUNIT_ASSERT_GT(test, rate, 0);
317 + KUNIT_EXPECT_GE(test, rate, DUMMY_CLOCK_RATE_1);
318 + KUNIT_EXPECT_LE(test, rate, DUMMY_CLOCK_RATE_2);
322 + * Test that calling clk_set_rate_range with a minimum rate higher than
323 + * the maximum rate returns an error.
325 +static void clk_range_test_set_range_invalid(struct kunit *test)
327 + struct clk_dummy_context *ctx = test->priv;
328 + struct clk_hw *hw = &ctx->hw;
329 + struct clk *clk = hw->clk;
331 + KUNIT_EXPECT_LT(test,
332 + clk_set_rate_range(clk,
333 + DUMMY_CLOCK_RATE_1 + 1000,
334 + DUMMY_CLOCK_RATE_1),
339 + * Test that users can't set multiple, disjoints, range that would be
340 + * impossible to meet.
342 +static void clk_range_test_multiple_disjoints_range(struct kunit *test)
344 + struct clk_dummy_context *ctx = test->priv;
345 + struct clk_hw *hw = &ctx->hw;
346 + struct clk *user1, *user2;
348 + user1 = clk_hw_get_clk(hw, NULL);
349 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, user1);
351 + user2 = clk_hw_get_clk(hw, NULL);
352 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, user2);
354 + KUNIT_ASSERT_EQ(test,
355 + clk_set_rate_range(user1, 1000, 2000),
358 + KUNIT_EXPECT_LT(test,
359 + clk_set_rate_range(user2, 3000, 4000),
367 + * Test that if our clock has some boundaries and we try to round a rate
368 + * lower than the minimum, the returned rate won't be affected by the
371 +static void clk_range_test_set_range_round_rate_lower(struct kunit *test)
373 + struct clk_dummy_context *ctx = test->priv;
374 + struct clk_hw *hw = &ctx->hw;
375 + struct clk *clk = hw->clk;
378 + KUNIT_ASSERT_EQ(test,
379 + clk_set_rate_range(clk,
380 + DUMMY_CLOCK_RATE_1,
381 + DUMMY_CLOCK_RATE_2),
384 + rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_1 - 1000);
385 + KUNIT_ASSERT_GT(test, rate, 0);
386 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1 - 1000);
390 + * Test that if our clock has some boundaries and we try to set a rate
391 + * lower than the minimum, we'll get an error.
393 +static void clk_range_test_set_range_set_rate_lower(struct kunit *test)
395 + struct clk_dummy_context *ctx = test->priv;
396 + struct clk_hw *hw = &ctx->hw;
397 + struct clk *clk = hw->clk;
399 + KUNIT_ASSERT_EQ(test,
400 + clk_set_rate_range(clk,
401 + DUMMY_CLOCK_RATE_1,
402 + DUMMY_CLOCK_RATE_2),
405 + KUNIT_ASSERT_LT(test,
406 + clk_set_rate(clk, DUMMY_CLOCK_RATE_1 - 1000),
411 + * Test that if our clock has some boundaries and we try to round and
412 + * set a rate lower than the minimum, the values won't be consistent
413 + * between clk_round_rate() and clk_set_rate().
415 +static void clk_range_test_set_range_set_round_rate_consistent_lower(struct kunit *test)
417 + struct clk_dummy_context *ctx = test->priv;
418 + struct clk_hw *hw = &ctx->hw;
419 + struct clk *clk = hw->clk;
422 + KUNIT_ASSERT_EQ(test,
423 + clk_set_rate_range(clk,
424 + DUMMY_CLOCK_RATE_1,
425 + DUMMY_CLOCK_RATE_2),
428 + rounded = clk_round_rate(clk, DUMMY_CLOCK_RATE_1 - 1000);
429 + KUNIT_ASSERT_GT(test, rounded, 0);
431 + KUNIT_EXPECT_LT(test,
432 + clk_set_rate(clk, DUMMY_CLOCK_RATE_1 - 1000),
435 + KUNIT_EXPECT_NE(test, rounded, clk_get_rate(clk));
439 + * Test that if our clock has some boundaries and we try to round a rate
440 + * higher than the maximum, the returned rate won't be affected by the
443 +static void clk_range_test_set_range_round_rate_higher(struct kunit *test)
445 + struct clk_dummy_context *ctx = test->priv;
446 + struct clk_hw *hw = &ctx->hw;
447 + struct clk *clk = hw->clk;
450 + KUNIT_ASSERT_EQ(test,
451 + clk_set_rate_range(clk,
452 + DUMMY_CLOCK_RATE_1,
453 + DUMMY_CLOCK_RATE_2),
456 + rate = clk_round_rate(clk, DUMMY_CLOCK_RATE_2 + 1000);
457 + KUNIT_ASSERT_GT(test, rate, 0);
458 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2 + 1000);
462 + * Test that if our clock has some boundaries and we try to set a rate
463 + * lower than the maximum, we'll get an error.
465 +static void clk_range_test_set_range_set_rate_higher(struct kunit *test)
467 + struct clk_dummy_context *ctx = test->priv;
468 + struct clk_hw *hw = &ctx->hw;
469 + struct clk *clk = hw->clk;
471 + KUNIT_ASSERT_EQ(test,
472 + clk_set_rate_range(clk,
473 + DUMMY_CLOCK_RATE_1,
474 + DUMMY_CLOCK_RATE_2),
477 + KUNIT_ASSERT_LT(test,
478 + clk_set_rate(clk, DUMMY_CLOCK_RATE_2 + 1000),
483 + * Test that if our clock has some boundaries and we try to round and
484 + * set a rate higher than the maximum, the values won't be consistent
485 + * between clk_round_rate() and clk_set_rate().
487 +static void clk_range_test_set_range_set_round_rate_consistent_higher(struct kunit *test)
489 + struct clk_dummy_context *ctx = test->priv;
490 + struct clk_hw *hw = &ctx->hw;
491 + struct clk *clk = hw->clk;
494 + KUNIT_ASSERT_EQ(test,
495 + clk_set_rate_range(clk,
496 + DUMMY_CLOCK_RATE_1,
497 + DUMMY_CLOCK_RATE_2),
500 + rounded = clk_round_rate(clk, DUMMY_CLOCK_RATE_2 + 1000);
501 + KUNIT_ASSERT_GT(test, rounded, 0);
503 + KUNIT_EXPECT_LT(test,
504 + clk_set_rate(clk, DUMMY_CLOCK_RATE_2 + 1000),
507 + KUNIT_EXPECT_NE(test, rounded, clk_get_rate(clk));
511 + * Test that if our clock has a rate lower than the minimum set by a
512 + * call to clk_set_rate_range(), the rate will be raised to match the
515 + * This assumes that clk_ops.determine_rate or clk_ops.round_rate won't
516 + * modify the requested rate, which is our case in clk_dummy_rate_ops.
518 +static void clk_range_test_set_range_get_rate_raised(struct kunit *test)
520 + struct clk_dummy_context *ctx = test->priv;
521 + struct clk_hw *hw = &ctx->hw;
522 + struct clk *clk = hw->clk;
523 + unsigned long rate;
525 + KUNIT_ASSERT_EQ(test,
526 + clk_set_rate(clk, DUMMY_CLOCK_RATE_1 - 1000),
529 + KUNIT_ASSERT_EQ(test,
530 + clk_set_rate_range(clk,
531 + DUMMY_CLOCK_RATE_1,
532 + DUMMY_CLOCK_RATE_2),
535 + rate = clk_get_rate(clk);
536 + KUNIT_ASSERT_GT(test, rate, 0);
537 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1);
541 + * Test that if our clock has a rate higher than the maximum set by a
542 + * call to clk_set_rate_range(), the rate will be lowered to match the
545 + * This assumes that clk_ops.determine_rate or clk_ops.round_rate won't
546 + * modify the requested rate, which is our case in clk_dummy_rate_ops.
548 +static void clk_range_test_set_range_get_rate_lowered(struct kunit *test)
550 + struct clk_dummy_context *ctx = test->priv;
551 + struct clk_hw *hw = &ctx->hw;
552 + struct clk *clk = hw->clk;
553 + unsigned long rate;
555 + KUNIT_ASSERT_EQ(test,
556 + clk_set_rate(clk, DUMMY_CLOCK_RATE_2 + 1000),
559 + KUNIT_ASSERT_EQ(test,
560 + clk_set_rate_range(clk,
561 + DUMMY_CLOCK_RATE_1,
562 + DUMMY_CLOCK_RATE_2),
565 + rate = clk_get_rate(clk);
566 + KUNIT_ASSERT_GT(test, rate, 0);
567 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2);
570 +static struct kunit_case clk_range_test_cases[] = {
571 + KUNIT_CASE(clk_range_test_set_range),
572 + KUNIT_CASE(clk_range_test_set_range_invalid),
573 + KUNIT_CASE(clk_range_test_multiple_disjoints_range),
574 + KUNIT_CASE(clk_range_test_set_range_round_rate_lower),
575 + KUNIT_CASE(clk_range_test_set_range_set_rate_lower),
576 + KUNIT_CASE(clk_range_test_set_range_set_round_rate_consistent_lower),
577 + KUNIT_CASE(clk_range_test_set_range_round_rate_higher),
578 + KUNIT_CASE(clk_range_test_set_range_set_rate_higher),
579 + KUNIT_CASE(clk_range_test_set_range_set_round_rate_consistent_higher),
580 + KUNIT_CASE(clk_range_test_set_range_get_rate_raised),
581 + KUNIT_CASE(clk_range_test_set_range_get_rate_lowered),
585 +static struct kunit_suite clk_range_test_suite = {
586 + .name = "clk-range-test",
587 + .init = clk_test_init,
588 + .exit = clk_test_exit,
589 + .test_cases = clk_range_test_cases,
594 + * - we have several subsequent calls to clk_set_rate_range();
595 + * - and we have a round_rate ops that always return the maximum
596 + * frequency allowed;
598 + * The clock will run at the minimum of all maximum boundaries
599 + * requested, even if those boundaries aren't there anymore.
601 +static void clk_range_test_set_range_rate_maximized(struct kunit *test)
603 + struct clk_dummy_context *ctx = test->priv;
604 + struct clk_hw *hw = &ctx->hw;
605 + struct clk *clk = hw->clk;
606 + unsigned long rate;
608 + KUNIT_ASSERT_EQ(test,
609 + clk_set_rate(clk, DUMMY_CLOCK_RATE_2 + 1000),
612 + KUNIT_ASSERT_EQ(test,
613 + clk_set_rate_range(clk,
614 + DUMMY_CLOCK_RATE_1,
615 + DUMMY_CLOCK_RATE_2),
618 + rate = clk_get_rate(clk);
619 + KUNIT_ASSERT_GT(test, rate, 0);
620 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2);
622 + KUNIT_ASSERT_EQ(test,
623 + clk_set_rate_range(clk,
624 + DUMMY_CLOCK_RATE_1,
625 + DUMMY_CLOCK_RATE_2 - 1000),
628 + rate = clk_get_rate(clk);
629 + KUNIT_ASSERT_GT(test, rate, 0);
630 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2 - 1000);
632 + KUNIT_ASSERT_EQ(test,
633 + clk_set_rate_range(clk,
634 + DUMMY_CLOCK_RATE_1,
635 + DUMMY_CLOCK_RATE_2),
638 + rate = clk_get_rate(clk);
639 + KUNIT_ASSERT_GT(test, rate, 0);
640 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2 - 1000);
645 + * - we have several subsequent calls to clk_set_rate_range(), across
647 + * - and we have a round_rate ops that always return the maximum
648 + * frequency allowed;
650 + * The clock will run at the minimum of all maximum boundaries
651 + * requested, even if those boundaries aren't there anymore.
653 +static void clk_range_test_multiple_set_range_rate_maximized(struct kunit *test)
655 + struct clk_dummy_context *ctx = test->priv;
656 + struct clk_hw *hw = &ctx->hw;
657 + struct clk *clk = hw->clk;
658 + struct clk *user1, *user2;
659 + unsigned long rate;
661 + user1 = clk_hw_get_clk(hw, NULL);
662 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, user1);
664 + user2 = clk_hw_get_clk(hw, NULL);
665 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, user2);
667 + KUNIT_ASSERT_EQ(test,
668 + clk_set_rate(clk, DUMMY_CLOCK_RATE_2 + 1000),
671 + KUNIT_ASSERT_EQ(test,
672 + clk_set_rate_range(user1,
674 + DUMMY_CLOCK_RATE_2),
677 + rate = clk_get_rate(clk);
678 + KUNIT_ASSERT_GT(test, rate, 0);
679 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2);
681 + KUNIT_ASSERT_EQ(test,
682 + clk_set_rate_range(user2,
684 + DUMMY_CLOCK_RATE_1),
687 + rate = clk_get_rate(clk);
688 + KUNIT_ASSERT_GT(test, rate, 0);
689 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1);
691 + KUNIT_ASSERT_EQ(test,
692 + clk_set_rate_range(user2, 0, ULONG_MAX),
695 + rate = clk_get_rate(clk);
696 + KUNIT_ASSERT_GT(test, rate, 0);
697 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1);
703 +static struct kunit_case clk_range_maximize_test_cases[] = {
704 + KUNIT_CASE(clk_range_test_set_range_rate_maximized),
705 + KUNIT_CASE(clk_range_test_multiple_set_range_rate_maximized),
709 +static struct kunit_suite clk_range_maximize_test_suite = {
710 + .name = "clk-range-maximize-test",
711 + .init = clk_maximize_test_init,
712 + .exit = clk_test_exit,
713 + .test_cases = clk_range_maximize_test_cases,
718 + * - we have several subsequent calls to clk_set_rate_range()
719 + * - and we have a round_rate ops that always return the minimum
720 + * frequency allowed;
722 + * The clock will run at the maximum of all minimum boundaries
723 + * requested, even if those boundaries aren't there anymore.
725 +static void clk_range_test_set_range_rate_minimized(struct kunit *test)
727 + struct clk_dummy_context *ctx = test->priv;
728 + struct clk_hw *hw = &ctx->hw;
729 + struct clk *clk = hw->clk;
730 + unsigned long rate;
732 + KUNIT_ASSERT_EQ(test,
733 + clk_set_rate(clk, DUMMY_CLOCK_RATE_1 - 1000),
736 + KUNIT_ASSERT_EQ(test,
737 + clk_set_rate_range(clk,
738 + DUMMY_CLOCK_RATE_1,
739 + DUMMY_CLOCK_RATE_2),
742 + rate = clk_get_rate(clk);
743 + KUNIT_ASSERT_GT(test, rate, 0);
744 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1);
746 + KUNIT_ASSERT_EQ(test,
747 + clk_set_rate_range(clk,
748 + DUMMY_CLOCK_RATE_1 + 1000,
749 + DUMMY_CLOCK_RATE_2),
752 + rate = clk_get_rate(clk);
753 + KUNIT_ASSERT_GT(test, rate, 0);
754 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1 + 1000);
756 + KUNIT_ASSERT_EQ(test,
757 + clk_set_rate_range(clk,
758 + DUMMY_CLOCK_RATE_1,
759 + DUMMY_CLOCK_RATE_2),
762 + rate = clk_get_rate(clk);
763 + KUNIT_ASSERT_GT(test, rate, 0);
764 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1 + 1000);
769 + * - we have several subsequent calls to clk_set_rate_range(), across
771 + * - and we have a round_rate ops that always return the minimum
772 + * frequency allowed;
774 + * The clock will run at the maximum of all minimum boundaries
775 + * requested, even if those boundaries aren't there anymore.
777 +static void clk_range_test_multiple_set_range_rate_minimized(struct kunit *test)
779 + struct clk_dummy_context *ctx = test->priv;
780 + struct clk_hw *hw = &ctx->hw;
781 + struct clk *clk = hw->clk;
782 + struct clk *user1, *user2;
783 + unsigned long rate;
785 + user1 = clk_hw_get_clk(hw, NULL);
786 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, user1);
788 + user2 = clk_hw_get_clk(hw, NULL);
789 + KUNIT_ASSERT_NOT_ERR_OR_NULL(test, user2);
791 + KUNIT_ASSERT_EQ(test,
792 + clk_set_rate_range(user1,
793 + DUMMY_CLOCK_RATE_1,
797 + rate = clk_get_rate(clk);
798 + KUNIT_ASSERT_GT(test, rate, 0);
799 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_1);
801 + KUNIT_ASSERT_EQ(test,
802 + clk_set_rate_range(user2,
803 + DUMMY_CLOCK_RATE_2,
807 + rate = clk_get_rate(clk);
808 + KUNIT_ASSERT_GT(test, rate, 0);
809 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2);
811 + KUNIT_ASSERT_EQ(test,
812 + clk_set_rate_range(user2, 0, ULONG_MAX),
815 + rate = clk_get_rate(clk);
816 + KUNIT_ASSERT_GT(test, rate, 0);
817 + KUNIT_EXPECT_EQ(test, rate, DUMMY_CLOCK_RATE_2);
823 +static struct kunit_case clk_range_minimize_test_cases[] = {
824 + KUNIT_CASE(clk_range_test_set_range_rate_minimized),
825 + KUNIT_CASE(clk_range_test_multiple_set_range_rate_minimized),
829 +static struct kunit_suite clk_range_minimize_test_suite = {
830 + .name = "clk-range-minimize-test",
831 + .init = clk_minimize_test_init,
832 + .exit = clk_test_exit,
833 + .test_cases = clk_range_minimize_test_cases,
838 + &clk_range_test_suite,
839 + &clk_range_maximize_test_suite,
840 + &clk_range_minimize_test_suite
842 +MODULE_LICENSE("GPL v2");